// Imports import {assertNotMissingOrEmpty} from '../common/utils'; import {GithubApi} from './github-api'; // Interfaces - Types export interface PullRequest { number: number; user: {login: string}; } export type PullRequestState = 'all' | 'closed' | 'open'; // Classes export class GithubPullRequests extends GithubApi { // Constructor constructor(githubToken: string, protected repoSlug: string) { super(githubToken); assertNotMissingOrEmpty('repoSlug', repoSlug); } // Methods - Public public addComment(pr: number, body: string): Promise { if (!(pr > 0)) { throw new Error(`Invalid PR number: ${pr}`); } else if (!body) { throw new Error(`Invalid or empty comment body: ${body}`); } return this.post(`/repos/${this.repoSlug}/issues/${pr}/comments`, null, {body}); } public fetch(pr: number): Promise { return this.get(`/repos/${this.repoSlug}/pulls/${pr}`); } public fetchAll(state: PullRequestState = 'all'): Promise { console.log(`Fetching ${state} pull requests...`); const pathname = `/repos/${this.repoSlug}/pulls`; const params = {state}; return this.getPaginated(pathname, params); } }