import type { RequestOptions } from 'https'; import https from 'https'; import type { CodelyzerRule, PRDetails } from './interfaces'; /** * Calls the github api for the specified path and returns a Promise for the json response. */ const callGithubApi = (optionOverrides: RequestOptions) => { const options = { protocol: 'https:', host: 'api.github.com', headers: { 'User-Agent': 'angular-eslint', }, ...optionOverrides, }; return new Promise((resolve) => { https.get(options, (response) => { let data = ''; response.on('data', (chunk) => { data += chunk; }); response.on('end', () => { resolve(JSON.parse(data)); }); }); }); }; /** * Returns a list of rule names that are currently in progress. */ export const getAngularESLintPRs = async (): Promise => { const prsJson = await callGithubApi({ path: '/repos/angular-eslint/angular-eslint/pulls?state=open', }); return prsJson.map(({ title, state, url, number }) => ({ title, state, url, number, })); }; /** * Returns a list of `CodelyzerRule`s from the Codelyzer repository. */ export const getCodelyzerRulesList = async (): Promise => { const rulesJson = await callGithubApi({ host: 'raw.githubusercontent.com', path: '/mgechev/codelyzer/master/docs/_data/rules.json', }); return rulesJson; };