Skip to content

Commit

Permalink
Add linesAdded and linesRemoved to own interface of Commit (#184)
Browse files Browse the repository at this point in the history
Add linesAdded and linesRemoved to own interface of Commit
  • Loading branch information
adelkahomolova authored Dec 17, 2019
2 parents 30ad683 + eb92a77 commit 3b92dae
Show file tree
Hide file tree
Showing 14 changed files with 458 additions and 220 deletions.
8 changes: 5 additions & 3 deletions src/inspectors/CollaborationInspector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ describe('Collaboration Inspector', () => {
});

it('returns paginated pull requests', async () => {
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls([
{ number: 1347, state: 'open', title: 'new-feature', body: 'Please pull these awesome changes', head: 'new-topic', base: 'master' },
]);
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls({
pulls: [
{ number: 1347, state: 'open', title: 'new-feature', body: 'Please pull these awesome changes', head: 'new-topic', base: 'master' },
],
});

const response = await inspector.getPullRequests('octocat', 'Hello-World');
expect(response).toMatchObject(getPullsServiceResponse);
Expand Down
14 changes: 11 additions & 3 deletions src/inspectors/CollaborationInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ export class CollaborationInspector implements ICollaborationInspector {
this.service = service;
}

async getPullRequests(owner: string, repo: string, options?: ListGetterOptions<{ state?: PullRequestState }>) {
async getPullRequests(
owner: string,
repo: string,
options?: { withDiffStat?: boolean } & ListGetterOptions<{ state?: PullRequestState }>,
) {
return this.service.getPullRequests(owner, repo, options);
}

async getPullRequest(owner: string, repo: string, prNumber: number) {
return this.service.getPullRequest(owner, repo, prNumber);
async getPullRequest(owner: string, repo: string, prNumber: number, withDiffStat?: boolean) {
return this.service.getPullRequest(owner, repo, prNumber, withDiffStat);
}

async getPullRequestFiles(owner: string, repo: string, prNumber: number) {
Expand All @@ -31,4 +35,8 @@ export class CollaborationInspector implements ICollaborationInspector {
async getRepoCommits(owner: string, repo: string, sha?: string) {
return this.service.getRepoCommits(owner, repo, sha);
}

async getPullsDiffStat(owner: string, repo: string, prNumber: string) {
return this.service.getPullsDiffStat(owner, repo, prNumber);
}
}
11 changes: 8 additions & 3 deletions src/inspectors/ICollaborationInspector.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Paginated } from './common/Paginated';
import { PullCommits, PullFiles, PullRequest, Commit } from '../services/git/model';
import { PullCommits, PullFiles, PullRequest, Commit, Lines } from '../services/git/model';
import { ListGetterOptions } from './common/ListGetterOptions';

export interface ICollaborationInspector {
getPullRequests(owner: string, repo: string, options?: ListGetterOptions<{ state?: PullRequestState }>): Promise<Paginated<PullRequest>>;
getPullRequest(owner: string, repo: string, prNumber: number): Promise<PullRequest>;
getPullRequests(
owner: string,
repo: string,
options?: { withDiffStat?: boolean } & ListGetterOptions<{ state?: PullRequestState }>,
): Promise<Paginated<PullRequest>>;
getPullRequest(owner: string, repo: string, prNumber: number, withDiffStat?: boolean): Promise<PullRequest>;
getPullCommits(owner: string, repo: string, prNumber: number): Promise<Paginated<PullCommits>>;
getPullRequestFiles(owner: string, repo: string, prNumber: number): Promise<Paginated<PullFiles>>;
getRepoCommits(owner: string, repo: string, sha?: string): Promise<Paginated<Commit>>;
getPullsDiffStat(owner: string, repo: string, prNumber: string): Promise<Lines>;
}

export enum PullRequestState {
Expand Down
20 changes: 11 additions & 9 deletions src/practices/LanguageIndependent/DoesPullRequests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ describe('DoesPullRequests', () => {

it('return practicing if there is at least one PR which is newer than last commit in master minus 30 days', async () => {
containerCtx.practiceContext.projectComponent.repositoryPath = 'https://github.com/octocat/Hello-World';
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls(
[{ number: 1347, state: 'open', title: 'new-feature', body: 'Please pull these awesome changes', head: 'new-topic', base: 'master' }],
PullRequestState.all,
);
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls({
pulls: [
{ number: 1347, state: 'open', title: 'new-feature', body: 'Please pull these awesome changes', head: 'new-topic', base: 'master' },
],
queryState: PullRequestState.all,
});
new GitHubNock('1', 'octocat', 1, 'Hello-World').getCommits().reply(200, getRepoCommitsResponse);

const evaluated = await practice.evaluate(containerCtx.practiceContext);
Expand All @@ -39,7 +41,7 @@ describe('DoesPullRequests', () => {

it('return notPracticing if there is no PR which is newer than last commit in master minus 30 days', async () => {
containerCtx.practiceContext.projectComponent.repositoryPath = 'https://github.com/octocat/Hello-World';
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls([], PullRequestState.all);
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls({ pulls: [], queryState: PullRequestState.all });
new GitHubNock('1', 'octocat', 1, 'Hello-World').getCommits().reply(200, getRepoCommitsResponse);

const evaluated = await practice.evaluate(containerCtx.practiceContext);
Expand All @@ -48,8 +50,8 @@ describe('DoesPullRequests', () => {

it('return notPracticing if there is PR older than 30 days than the last commit in master', async () => {
containerCtx.practiceContext.projectComponent.repositoryPath = 'https://github.com/octocat/Hello-World';
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls(
[
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls({
pulls: [
{
number: 1348,
state: 'opened',
Expand All @@ -61,8 +63,8 @@ describe('DoesPullRequests', () => {
created_at: '2000-03-06T23:06:50Z',
},
],
PullRequestState.all,
);
queryState: PullRequestState.all,
});
new GitHubNock('1', 'octocat', 1, 'Hello-World').getCommits().reply(200, getRepoCommitsResponse);

const evaluated = await practice.evaluate(containerCtx.practiceContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('TimeToSolvePullRequestsPractice', () => {

it('returns practicing if there are open pullrequests updated or created less than 30 days from now', async () => {
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, BitbucketPullRequestState.open);
bitbucketNock.getApiResponse({ resource: 'pullrequests', state: BitbucketPullRequestState.open });
const args = { states: BitbucketPullRequestState.open, updatedAt: Date.now() - moment.duration(10, 'days').asMilliseconds() };
mockCollaborationInspector.getPullRequests = async () => {
return bitbucketNock.mockBitbucketPullRequestsResponse(args);
Expand All @@ -51,7 +51,7 @@ describe('TimeToSolvePullRequestsPractice', () => {

it('returns practicing if there are open pullrequests updated or created more than 30 days from now', async () => {
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, BitbucketPullRequestState.open);
bitbucketNock.getApiResponse({ resource: 'pullrequests', state: BitbucketPullRequestState.open });
const args = { states: BitbucketPullRequestState.open, updatedAt: Date.now() - moment.duration(100, 'days').asMilliseconds() };
mockCollaborationInspector.getPullRequests = async () => {
return bitbucketNock.mockBitbucketPullRequestsResponse(args);
Expand Down
69 changes: 50 additions & 19 deletions src/services/bitbucket/BitbucketService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import nock from 'nock';
import { BitbucketNock } from '../../test/helpers/bitbucketNock';
import { BitbucketService } from './BitbucketService';
import { ListGetterOptions, PullRequestState } from '../../inspectors';
import {
getPullRequestResponse,
getIssueCommentsResponse,
getIssueResponse,
getIssuesResponse,
getPullCommits,
getRepoCommits,
getPullRequestResponse,
getRepoCommit,
getIssuesResponse,
getIssueResponse,
getIssueCommentsResponse,
getRepoCommits,
} from '../../services/git/__MOCKS__/bitbucketServiceMockFolder';
import { BitbucketNock } from '../../test/helpers/bitbucketNock';
import { BitbucketPullRequestState, VCSService } from '../git/IVCSService';
import { VCSServicesUtils } from '../git/VCSServicesUtils';
import { PullRequestState, ListGetterOptions } from '../../inspectors';
import { BitbucketService } from './BitbucketService';

describe('Bitbucket Service', () => {
let service: BitbucketService;
Expand All @@ -26,16 +26,40 @@ describe('Bitbucket Service', () => {

it('returns open pull requests in own interface', async () => {
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests');
bitbucketNock.getApiResponse({ resource: 'pullrequests' });

const response = await service.getPullRequests('pypy', 'pypy');
const getOpenPullRequestsResponse = bitbucketNock.mockBitbucketPullRequestsResponse({ states: BitbucketPullRequestState.open });
expect(response).toMatchObject(getOpenPullRequestsResponse);
});

it('returns one open pull requests in own interface', async () => {
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse({ resource: 'pullrequests', state: BitbucketPullRequestState.open, pagination: { page: 1, perPage: 1 } });

const response = await service.getPullRequests('pypy', 'pypy', { pagination: { page: 1, perPage: 1 } });
const getOpenPullRequestsResponse = bitbucketNock.mockBitbucketPullRequestsResponse({ states: BitbucketPullRequestState.open });
expect(response).toMatchObject(getOpenPullRequestsResponse);
});

it('returns open pull requests with diffStat in own interface', async () => {
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse({ resource: 'pullrequests' });
bitbucketNock.getAdditionsAndDeletions('1');

const response = await service.getPullRequests('pypy', 'pypy', { withDiffStat: true });
const getOpenPullRequestsResponse = bitbucketNock.mockBitbucketPullRequestsResponse({
states: BitbucketPullRequestState.open,
withDiffStat: true,
});

expect(response).toMatchObject(getOpenPullRequestsResponse);
});

it('returns all pull requests in own interface', async () => {
const state = <BitbucketPullRequestState>VCSServicesUtils.getPRState(PullRequestState.all, VCSService.bitbucket);
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, state);
bitbucketNock.getApiResponse({ resource: 'pullrequests', state: state });

const response = await service.getPullRequests('pypy', 'pypy', { filter: { state: PullRequestState.all } });
const allPullrequestsResponse = bitbucketNock.mockBitbucketPullRequestsResponse({ states: state });
Expand All @@ -45,35 +69,35 @@ describe('Bitbucket Service', () => {

it('returns specific pull request in own interface', async () => {
bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', 1);
bitbucketNock.getApiResponse({ resource: 'pullrequests', id: 1 });

const response = await service.getPullRequest('pypy', 'pypy', 1);
expect(response).toMatchObject(getPullRequestResponse);
});

it('returns pullrequest commits in own interface', async () => {
bitbucketNock.getApiResponse('pullrequests', 622, 'commits');
bitbucketNock.getApiResponse({ resource: 'pullrequests', id: 622, value: 'commits' });

const response = await service.getPullCommits('pypy', 'pypy', 622);
expect(response).toMatchObject(getPullCommits);
});

it('returns issues in own interface', async () => {
bitbucketNock.getApiResponse('issues');
bitbucketNock.getApiResponse({ resource: 'issues' });

const response = await service.getIssues('pypy', 'pypy');
expect(response).toMatchObject(getIssuesResponse);
});

it('returns issue in own interface', async () => {
bitbucketNock.getApiResponse('issues', 3086);
bitbucketNock.getApiResponse({ resource: 'issues', id: 3086 });

const response = await service.getIssue('pypy', 'pypy', 3086);
expect(response).toMatchObject(getIssueResponse);
});

it('returns issue comments in own interface', async () => {
bitbucketNock.getApiResponse('issues', 3086, 'comments');
bitbucketNock.getApiResponse({ resource: 'issues', id: 3086, value: 'comments' });

const response = await service.getIssueComments('pypy', 'pypy', 3086);
expect(response).toMatchObject(getIssueCommentsResponse);
Expand All @@ -87,7 +111,7 @@ describe('Bitbucket Service', () => {
};

bitbucketNock.getOwnerId();
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, BitbucketPullRequestState.closed);
bitbucketNock.getApiResponse({ resource: 'pullrequests', state: BitbucketPullRequestState.closed });

const response = await service.getPullRequests('pypy', 'pypy', state);
const getMergedPullRequestsResponse = bitbucketNock.mockBitbucketPullRequestsResponse({ states: BitbucketPullRequestState.closed });
Expand All @@ -96,16 +120,23 @@ describe('Bitbucket Service', () => {
});

it('returns repo commits in own interface', async () => {
bitbucketNock.getApiResponse('commits');
bitbucketNock.getApiResponse({ resource: 'commits' });

const response = await service.getRepoCommits('pypy', 'pypy');
expect(response).toMatchObject(getRepoCommits);
});

it('return on commit in own interface', async () => {
bitbucketNock.getApiResponse('commit', '961b3a27');
it('returns one commit in own interface', async () => {
bitbucketNock.getApiResponse({ resource: 'commit', id: '961b3a27' });

const response = await service.getCommit('pypy', 'pypy', '961b3a27');
expect(response).toMatchObject(getRepoCommit);
});

it('returns pulls diff stat in own interface', async () => {
bitbucketNock.getAdditionsAndDeletions('622');

const response = await service.getPullsDiffStat('pypy', 'pypy', '622');
expect(response).toMatchObject({ additions: 2, deletions: 1, changes: 3 });
});
});
Loading

0 comments on commit 3b92dae

Please sign in to comment.