diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/clean-up/build-cleaner.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/clean-up/build-cleaner.ts index 68f49f3707..64e2a33f7e 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/clean-up/build-cleaner.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/clean-up/build-cleaner.ts @@ -40,7 +40,7 @@ export class BuildCleaner { } protected getOpenPrNumbers(): Promise { - const githubPullRequests = new GithubPullRequests(this.repoSlug, this.githubToken); + const githubPullRequests = new GithubPullRequests(this.githubToken, this.repoSlug); return githubPullRequests. fetchAll('open'). diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-api.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-api.ts index 3283ed75c9..aec1ad74af 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-api.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-api.ts @@ -18,8 +18,7 @@ export class GithubApi { protected requestHeaders: {[key: string]: string}; // Constructor - constructor(protected repoSlug: string, githubToken: string) { - assertNotMissingOrEmpty('repoSlug', repoSlug); + constructor(githubToken: string) { assertNotMissingOrEmpty('githubToken', githubToken); this.requestHeaders = { diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-pull-requests.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-pull-requests.ts index 84b926a593..cf31f2bd99 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-pull-requests.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/common/github-pull-requests.ts @@ -1,4 +1,5 @@ // Imports +import {assertNotMissingOrEmpty} from '../common/utils'; import {GithubApi} from './github-api'; // Interfaces - Types @@ -10,6 +11,12 @@ 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)) { diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-api.spec.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-api.spec.ts index 5cf50d9e18..04e93da42d 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-api.spec.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-api.spec.ts @@ -8,18 +8,13 @@ import {GithubApi} from '../../lib/common/github-api'; describe('GithubApi', () => { let api: GithubApi; - beforeEach(() => api = new GithubApi('repo/slug', '12345')); + beforeEach(() => api = new GithubApi('12345')); describe('constructor()', () => { - it('should throw if \'repoSlug\' is missing or empty', () => { - expect(() => new GithubApi('', '12345')).toThrowError('Missing or empty required parameter \'repoSlug\'!'); - }); - - it('should throw if \'githubToken\' is missing or empty', () => { - expect(() => new GithubApi('repo/slug', '')).toThrowError('Missing or empty required parameter \'githubToken\'!'); + expect(() => new GithubApi('')).toThrowError('Missing or empty required parameter \'githubToken\'!'); }); }); @@ -172,7 +167,7 @@ describe('GithubApi', () => { it('should reject if the request fails', done => { - (api as any).getPaginated('/foo/bar').catch(err => { + (api as any).getPaginated('/foo/bar').catch((err: any) => { expect(err).toBe('Test'); done(); }); diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-pull-requests.spec.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-pull-requests.spec.ts index 2f35abc4b0..b01beeead8 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-pull-requests.spec.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/test/common/github-pull-requests.spec.ts @@ -6,15 +6,15 @@ describe('GithubPullRequests', () => { describe('constructor()', () => { - it('should throw if \'repoSlug\' is missing or empty', () => { - expect(() => new GithubPullRequests('', '12345')). - toThrowError('Missing or empty required parameter \'repoSlug\'!'); + it('should throw if \'githubToken\' is missing or empty', () => { + expect(() => new GithubPullRequests('', 'foo/bar')). + toThrowError('Missing or empty required parameter \'githubToken\'!'); }); - it('should throw if \'githubToken\' is missing or empty', () => { - expect(() => new GithubPullRequests('foo/bar', '')). - toThrowError('Missing or empty required parameter \'githubToken\'!'); + it('should throw if \'repoSlug\' is missing or empty', () => { + expect(() => new GithubPullRequests('12345', '')). + toThrowError('Missing or empty required parameter \'repoSlug\'!'); }); }); @@ -25,7 +25,7 @@ describe('GithubPullRequests', () => { let deferred: {resolve: Function, reject: Function}; beforeEach(() => { - prs = new GithubPullRequests('foo/bar', '12345'); + prs = new GithubPullRequests('12345', 'foo/bar'); spyOn(prs, 'post').and.callFake(() => new Promise((resolve, reject) => deferred = {resolve, reject})); }); @@ -81,7 +81,7 @@ describe('GithubPullRequests', () => { let prsGetPaginatedSpy: jasmine.Spy; beforeEach(() => { - prs = new GithubPullRequests('foo/bar', '12345'); + prs = new GithubPullRequests('12345', 'foo/bar'); prsGetPaginatedSpy = spyOn(prs as any, 'getPaginated'); spyOn(console, 'log'); });