fix(aio): remove unnecessary `repoSlug` parameter from `GithubApi`

This commit is contained in:
Georgios Kalpakas 2017-02-28 14:17:20 +02:00 committed by Chuck Jazdzewski
parent 951e653b0c
commit 060d02eb82
5 changed files with 20 additions and 19 deletions

View File

@ -40,7 +40,7 @@ export class BuildCleaner {
} }
protected getOpenPrNumbers(): Promise<number[]> { protected getOpenPrNumbers(): Promise<number[]> {
const githubPullRequests = new GithubPullRequests(this.repoSlug, this.githubToken); const githubPullRequests = new GithubPullRequests(this.githubToken, this.repoSlug);
return githubPullRequests. return githubPullRequests.
fetchAll('open'). fetchAll('open').

View File

@ -18,8 +18,7 @@ export class GithubApi {
protected requestHeaders: {[key: string]: string}; protected requestHeaders: {[key: string]: string};
// Constructor // Constructor
constructor(protected repoSlug: string, githubToken: string) { constructor(githubToken: string) {
assertNotMissingOrEmpty('repoSlug', repoSlug);
assertNotMissingOrEmpty('githubToken', githubToken); assertNotMissingOrEmpty('githubToken', githubToken);
this.requestHeaders = { this.requestHeaders = {

View File

@ -1,4 +1,5 @@
// Imports // Imports
import {assertNotMissingOrEmpty} from '../common/utils';
import {GithubApi} from './github-api'; import {GithubApi} from './github-api';
// Interfaces - Types // Interfaces - Types
@ -10,6 +11,12 @@ export type PullRequestState = 'all' | 'closed' | 'open';
// Classes // Classes
export class GithubPullRequests extends GithubApi { export class GithubPullRequests extends GithubApi {
// Constructor
constructor(githubToken: string, protected repoSlug: string) {
super(githubToken);
assertNotMissingOrEmpty('repoSlug', repoSlug);
}
// Methods - Public // Methods - Public
public addComment(pr: number, body: string): Promise<void> { public addComment(pr: number, body: string): Promise<void> {
if (!(pr > 0)) { if (!(pr > 0)) {

View File

@ -8,18 +8,13 @@ import {GithubApi} from '../../lib/common/github-api';
describe('GithubApi', () => { describe('GithubApi', () => {
let api: GithubApi; let api: GithubApi;
beforeEach(() => api = new GithubApi('repo/slug', '12345')); beforeEach(() => api = new GithubApi('12345'));
describe('constructor()', () => { 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', () => { 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 => { 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'); expect(err).toBe('Test');
done(); done();
}); });

View File

@ -6,15 +6,15 @@ describe('GithubPullRequests', () => {
describe('constructor()', () => { describe('constructor()', () => {
it('should throw if \'repoSlug\' is missing or empty', () => { it('should throw if \'githubToken\' is missing or empty', () => {
expect(() => new GithubPullRequests('', '12345')). expect(() => new GithubPullRequests('', 'foo/bar')).
toThrowError('Missing or empty required parameter \'repoSlug\'!'); toThrowError('Missing or empty required parameter \'githubToken\'!');
}); });
it('should throw if \'githubToken\' is missing or empty', () => { it('should throw if \'repoSlug\' is missing or empty', () => {
expect(() => new GithubPullRequests('foo/bar', '')). expect(() => new GithubPullRequests('12345', '')).
toThrowError('Missing or empty required parameter \'githubToken\'!'); toThrowError('Missing or empty required parameter \'repoSlug\'!');
}); });
}); });
@ -25,7 +25,7 @@ describe('GithubPullRequests', () => {
let deferred: {resolve: Function, reject: Function}; let deferred: {resolve: Function, reject: Function};
beforeEach(() => { 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})); spyOn(prs, 'post').and.callFake(() => new Promise((resolve, reject) => deferred = {resolve, reject}));
}); });
@ -81,7 +81,7 @@ describe('GithubPullRequests', () => {
let prsGetPaginatedSpy: jasmine.Spy; let prsGetPaginatedSpy: jasmine.Spy;
beforeEach(() => { beforeEach(() => {
prs = new GithubPullRequests('foo/bar', '12345'); prs = new GithubPullRequests('12345', 'foo/bar');
prsGetPaginatedSpy = spyOn(prs as any, 'getPaginated'); prsGetPaginatedSpy = spyOn(prs as any, 'getPaginated');
spyOn(console, 'log'); spyOn(console, 'log');
}); });