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 e0ba50cef7..68f49f3707 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 @@ -8,9 +8,10 @@ import {assertNotMissingOrEmpty} from '../common/utils'; // Classes export class BuildCleaner { // Constructor - constructor(protected buildsDir: string, protected repoSlug: string, protected githubToken?: string) { + constructor(protected buildsDir: string, protected repoSlug: string, protected githubToken: string) { assertNotMissingOrEmpty('buildsDir', buildsDir); assertNotMissingOrEmpty('repoSlug', repoSlug); + assertNotMissingOrEmpty('githubToken', githubToken); } // Methods - Public 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 0cdd28733b..cc44b73b86 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,16 +18,14 @@ export class GithubApi { protected requestHeaders: {[key: string]: string}; // Constructor - constructor(protected repoSlug: string, githubToken?: string) { + constructor(protected repoSlug: string, githubToken: string) { assertNotMissingOrEmpty('repoSlug', repoSlug); - if (!githubToken) { - console.warn('No GitHub access-token specified. Requests will be unauthenticated.'); - } + assertNotMissingOrEmpty('githubToken', githubToken); - this.requestHeaders = {'User-Agent': `Node/${process.versions.node}`}; - if (githubToken) { - this.requestHeaders.Authorization = `token ${githubToken}`; - } + this.requestHeaders = { + 'Authorization': `token ${githubToken}`, + 'User-Agent': `Node/${process.versions.node}`, + }; } // Methods - Public diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/test/clean-up/build-cleaner.spec.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/test/clean-up/build-cleaner.spec.ts index 2730f9906a..d326edb844 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/test/clean-up/build-cleaner.spec.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/test/clean-up/build-cleaner.spec.ts @@ -14,12 +14,20 @@ describe('BuildCleaner', () => { describe('constructor()', () => { it('should throw if \'buildsDir\' is empty', () => { - expect(() => new BuildCleaner('', '/baz/qux')).toThrowError('Missing or empty required parameter \'buildsDir\'!'); + expect(() => new BuildCleaner('', '/baz/qux', '12345')). + toThrowError('Missing or empty required parameter \'buildsDir\'!'); }); it('should throw if \'repoSlug\' is empty', () => { - expect(() => new BuildCleaner('/foo/bar', '')).toThrowError('Missing or empty required parameter \'repoSlug\'!'); + expect(() => new BuildCleaner('/foo/bar', '', '12345')). + toThrowError('Missing or empty required parameter \'repoSlug\'!'); + }); + + + it('should throw if \'githubToken\' is empty', () => { + expect(() => new BuildCleaner('/foo/bar', 'baz/qux', '')). + toThrowError('Missing or empty required parameter \'githubToken\'!'); }); }); 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 22103070f8..557bf5cdba 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 @@ -18,18 +18,8 @@ describe('GithubApi', () => { }); - it('should log a warning if \'githubToken\' is not defined or empty', () => { - const warningMessage = 'No GitHub access-token specified. Requests will be unauthenticated.'; - const consoleWarnSpy = spyOn(console, 'warn'); - - /* tslint:disable: no-unused-new */ - new GithubApi('repo/slug'); - new GithubApi('repo/slug', ''); - /* tslint:enable: no-unused-new */ - - expect(consoleWarnSpy).toHaveBeenCalledTimes(2); - expect(consoleWarnSpy.calls.argsFor(0)[0]).toBe(warningMessage); - expect(consoleWarnSpy.calls.argsFor(1)[0]).toBe(warningMessage); + it('should throw if \'githubToken\' is missing or empty', () => { + expect(() => new GithubApi('repo/slug', '')).toThrowError('Missing or empty required parameter \'githubToken\'!'); }); }); 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 fb41ecf1f3..3c3b13c83b 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,19 +6,15 @@ describe('GithubPullRequests', () => { describe('constructor()', () => { - it('should log a warning if \'githubToken\' is not defined', () => { - const warningMessage = 'No GitHub access-token specified. Requests will be unauthenticated.'; - const consoleWarnSpy = spyOn(console, 'warn'); - - // tslint:disable-next-line: no-unused-new - new GithubPullRequests('repo/slug'); - - expect(consoleWarnSpy).toHaveBeenCalledWith(warningMessage); + it('should throw if \'repoSlug\' is missing or empty', () => { + expect(() => new GithubPullRequests('', '12345')). + toThrowError('Missing or empty required parameter \'repoSlug\'!'); }); - it('should throw if \'repoSlug\' is not defined', () => { - expect(() => new GithubPullRequests('', '12345')).toThrowError('Missing required parameter \'repoSlug\'!'); + it('should throw if \'githubToken\' is missing or empty', () => { + expect(() => new GithubPullRequests('foo/bar', '')). + toThrowError('Missing or empty required parameter \'githubToken\'!'); }); });