Skip to content

Commit

Permalink
Merge pull request #169 from DXHeroes/feature/BB-get-commit
Browse files Browse the repository at this point in the history
Feature/Bitbucket get commit
  • Loading branch information
prokopsimek authored Nov 28, 2019
2 parents 0d125dc + 9800951 commit 40e3fe2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/services/bitbucket/BitbucketService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getIssuesResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/g
import { getIssueResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/getIssueResponse';
import { getIssueCommentsResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/getIssueCommentsResponse';
import { getRepoCommits } from '../git/__MOCKS__/bitbucketServiceMockFolder/getRepoCommits';
import { getRepoCommit } from '../git/__MOCKS__/bitbucketServiceMockFolder/getRepoCommit';

describe('Bitbucket Service', () => {
let service: BitbucketService;
Expand Down Expand Up @@ -70,4 +71,11 @@ describe('Bitbucket Service', () => {
const response = await service.getRepoCommits('pypy', 'pypy');
expect(response).toMatchObject(getRepoCommits);
});

it('return on commit in own interface', async () => {
bitbucketNock.getApiResponse('commit', '961b3a27');

const response = await service.getCommit('pypy', 'pypy', '961b3a27');
expect(response).toMatchObject(getRepoCommit);
});
});
23 changes: 22 additions & 1 deletion src/services/bitbucket/BitbucketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,28 @@ export class BitbucketService implements ICVSService {
}

async getCommit(owner: string, repo: string, commitSha: string): Promise<Commit> {
throw new Error('Method not implemented yet.');
const params: Bitbucket.Params.CommitsGet = {
node: commitSha,
repo_slug: repo,
username: owner,
};
const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Commit>>>await this.client.commits.get(params);
return {
sha: response.data.hash,
url: response.data.links.html.href,
message: response.data.rendered.message.raw,
author: {
name: response.data.author.user.nickname,
email: this.extractEmailFromString(response.data.author.raw) || '',
date: response.data.date,
},
tree: {
sha: response.data.parents[0].hash,
url: response.data.parents[0].links.html.href,
},
// TODO
verified: false,
};
}

async getContributors(owner: string, repo: string): Promise<Paginated<Contributor>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Commit } from '../../model';

export const getRepoCommit: Commit = {
sha: 'f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df',
url: 'https://bitbucket.org/pypy/pypy/commits/f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df',
message:
'This checkin might win the prize for the highest amount of XXXs/lines of code:\n' +
'it needs a deep review, please :)\n' +
'\n' +
'Fix W_ExtensionFunction_call_varargs to use the updated calling convention,\n' +
'and implement ctx_Arg_Parse.',
author: {
name: 'antocuni',
email: 'anto.cuni@gmail.com',
date: '2019-11-19T10:48:09+00:00',
},
tree: {
sha: '5c9a3fd99fc743f49aaad30952397ab34ad4f40b',
url: 'https://bitbucket.org/pypy/pypy/commits/5c9a3fd99fc743f49aaad30952397ab34ad4f40b',
},
verified: false,
};
6 changes: 5 additions & 1 deletion test/helpers/bitbucketNock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class BitbucketNock {
this.url = 'https://api.bitbucket.org/2.0';
}

getApiResponse(resource: string, id?: number, value?: string): nock.Scope {
getApiResponse(resource: string, id?: number | string, value?: string): nock.Scope {
let url = `${this.url}/repositories/${this.user}/${this.repoName}/${resource}`;
let response;

Expand Down Expand Up @@ -51,6 +51,10 @@ export class BitbucketNock {
case 'commits':
response = new RepoCommits().repoCommits;
break;
case 'commit':
url = url.concat(`/${id}`);
response = new RepoCommit().repoCommit;
break;
default:
throw Error('You passed wrong value or id');
}
Expand Down

0 comments on commit 40e3fe2

Please sign in to comment.