Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Bitbucket get repo commits #165

Merged
merged 18 commits into from Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/services/bitbucket/BitbucketService.spec.ts
Expand Up @@ -7,6 +7,8 @@ import { getPullCommits } from '../git/__MOCKS__/bitbucketServiceMockFolder/getP
import { getIssuesResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/getIssuesResponse';
import { getIssueResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/getIssueResponse';
import { getIssueCommentsResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/getIssueCommentsResponse';
import util from 'util';
import { getRepoCommits } from '../git/__MOCKS__/bitbucketServiceMockFolder/getRepoCommits';

describe('Bitbucket Service', () => {
let service: BitbucketService;
Expand Down Expand Up @@ -62,4 +64,11 @@ describe('Bitbucket Service', () => {
const response = await service.getIssueComments('pypy', 'pypy', 3086);
expect(response).toMatchObject(getIssueCommentsResponse);
});

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

const response = await service.getRepoCommits('pypy', 'pypy');
expect(response).toMatchObject(getRepoCommits);
});
});
31 changes: 28 additions & 3 deletions src/services/bitbucket/BitbucketService.ts
Expand Up @@ -45,7 +45,7 @@ export class BitbucketService implements ICVSService {

let username: string;
let password: string | undefined;
if (argumentsProvider.auth?.includes(':')) {
if (argumentsProvider.auth && argumentsProvider.auth.includes(':')) {
username = argumentsProvider.auth.split(':')[0];
password = argumentsProvider.auth.split(':')[1];
} else {
Expand Down Expand Up @@ -282,8 +282,33 @@ export class BitbucketService implements ICVSService {
throw new Error('Method not implemented yet.');
}

async getRepoCommits(owner: string, repo: string) {
throw new Error('Method not implemented yet.');
async getRepoCommits(owner: string, repo: string): Promise<Paginated<PullCommits>> {
const params: Bitbucket.Params.RepositoriesListCommits = {
repo_slug: repo,
username: owner,
};
const response = <DeepRequired<Bitbucket.Response<BitbucketCommit>>>await this.client.repositories.listCommits(params);
const items = response.data.values.map((val) => ({
sha: val.hash,
commit: {
url: val.links.html.href,
message: val.rendered.message.raw,
author: {
name: val.author.user.nickname,
email: 'undefined',
date: val.date,
},
tree: {
sha: val.parents[0].hash,
url: val.parents[0].links.html.href,
},
// TODO
verified: false,
},
}));
const pagination = this.getPagination(response.data);

return { items, ...pagination };
}

async getCommit(owner: string, repo: string, commitSha: string): Promise<Commit> {
Expand Down
@@ -0,0 +1,35 @@
import { Paginated } from '../../../../inspectors/common/Paginated';

import { PullCommits } from '../../model';
export const getRepoCommits: Paginated<PullCommits> = {
items: [
{
sha: 'f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df',
commit: {
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: 'undefined',
date: '2019-11-19T10:48:09+00:00',
},
tree: {
sha: '5c9a3fd99fc743f49aaad30952397ab34ad4f40b',
url: 'https://bitbucket.org/pypy/pypy/commits/5c9a3fd99fc743f49aaad30952397ab34ad4f40b',
},

verified: false,
},
},
],
totalCount: 1,
hasNextPage: false,
hasPreviousPage: false,
page: 1,
perPage: 1,
};
130 changes: 126 additions & 4 deletions test/helpers/bitbucketNock.ts
Expand Up @@ -15,6 +15,9 @@ export class BitbucketNock {
let url = `${this.url}/repositories/${this.user}/${this.repoName}/${resource}`;
let response;

const params = {};
const persist = true;

if (value !== undefined) {
switch (value) {
case 'comments':
Expand Down Expand Up @@ -44,15 +47,14 @@ export class BitbucketNock {
response = new Issues().issues;
}
break;

case 'commits':
response = new RepoCommits().repoCommits;
break;
default:
throw Error('You passed wrong value or id');
}
}

const params = {};
const persist = true;

return BitbucketNock.get(url, params, persist).reply(200, response);
}

Expand Down Expand Up @@ -577,3 +579,123 @@ export class IssueComments {
};
}
}

export class RepoCommit {
repoCommit: Bitbucket.Schema.Commit;
constructor() {
this.repoCommit = {
rendered: {
message: {
raw:
'This checkin might win the prize for the highest amount of XXXs/lines of code:\nit needs a deep review, please :)\n\nFix W_ExtensionFunction_call_varargs to use the updated calling convention,\nand implement ctx_Arg_Parse.',
markup: 'markdown',
html:
'<p>This checkin might win the prize for the highest amount of XXXs/lines of code:<br />\nit needs a deep review, please :)</p>\n<p>Fix W_ExtensionFunction_call_varargs to use the updated calling convention,<br />\nand implement ctx_Arg_Parse.</p>',
type: 'rendered',
},
},
hash: 'f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df',
repository: {
links: {
self: {
href: 'https://api.bitbucket.org/2.0/repositories/pypy/pypy',
},
html: {
href: 'https://bitbucket.org/pypy/pypy',
},
avatar: {
href: 'https://bytebucket.org/ravatar/%7B54220cd1-b139-4188-9455-1e13e663f1ac%7D?ts=105930',
},
},
type: 'repository',
name: 'pypy',
full_name: 'pypy/pypy',
uuid: '{54220cd1-b139-4188-9455-1e13e663f1ac}',
},
links: {
self: {
href: 'https://api.bitbucket.org/2.0/repositories/pypy/pypy/commit/f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df',
},
comments: {
href: 'https://api.bitbucket.org/2.0/repositories/pypy/pypy/commit/f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df/comments',
},
patch: {
href: 'https://api.bitbucket.org/2.0/repositories/pypy/pypy/patch/f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df',
},
html: {
href: 'https://bitbucket.org/pypy/pypy/commits/f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df',
},
diff: {
href: 'https://api.bitbucket.org/2.0/repositories/pypy/pypy/diff/f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df',
},
approve: {
href: 'https://api.bitbucket.org/2.0/repositories/pypy/pypy/commit/f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df/approve',
},
statuses: {
href: 'https://api.bitbucket.org/2.0/repositories/pypy/pypy/commit/f9c2cfcfaafa644dcc286ce2fc8b3386d46c11df/statuses',
},
},
author: {
raw: 'Antonio Cuni <anto.cuni@gmail.com>',
type: 'author',
user: {
display_name: 'Antonio Cuni',
uuid: '{2ba51dad-da92-44d7-96b9-9d7b6eb196cb}',
links: {
self: {
href: 'https://api.bitbucket.org/2.0/users/%7B2ba51dad-da92-44d7-96b9-9d7b6eb196cb%7D',
},
html: {
href: 'https://bitbucket.org/%7B2ba51dad-da92-44d7-96b9-9d7b6eb196cb%7D/',
},
avatar: {
href:
'https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:136fd9cc-4f8c-4548-8dbc-dd50a6d749d9/8cc41205-88c2-4279-b475-27189150a116/128',
},
},
nickname: 'antocuni',
type: 'user',
account_id: '557058:136fd9cc-4f8c-4548-8dbc-dd50a6d749d9',
},
},
summary: {
raw:
'This checkin might win the prize for the highest amount of XXXs/lines of code:\nit needs a deep review, please :)\n\nFix W_ExtensionFunction_call_varargs to use the updated calling convention,\nand implement ctx_Arg_Parse.',
markup: 'markdown',
html:
'<p>This checkin might win the prize for the highest amount of XXXs/lines of code:<br />\nit needs a deep review, please :)</p>\n<p>Fix W_ExtensionFunction_call_varargs to use the updated calling convention,<br />\nand implement ctx_Arg_Parse.</p>',
},
parents: [
{
hash: '5c9a3fd99fc743f49aaad30952397ab34ad4f40b',
type: 'commit',
links: {
self: {
href: 'https://api.bitbucket.org/2.0/repositories/pypy/pypy/commit/5c9a3fd99fc743f49aaad30952397ab34ad4f40b',
},
html: {
href: 'https://bitbucket.org/pypy/pypy/commits/5c9a3fd99fc743f49aaad30952397ab34ad4f40b',
},
},
},
],
date: '2019-11-19T10:48:09+00:00',
message:
'This checkin might win the prize for the highest amount of XXXs/lines of code:\nit needs a deep review, please :)\n\nFix W_ExtensionFunction_call_varargs to use the updated calling convention,\nand implement ctx_Arg_Parse.',
type: 'commit',
};
}
}

export class RepoCommits {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
prokopsimek marked this conversation as resolved.
Show resolved Hide resolved
repoCommits: any;
prokopsimek marked this conversation as resolved.
Show resolved Hide resolved
constructor() {
this.repoCommits = {
values: [new RepoCommit().repoCommit],
pagelen: 20,
page: 1,
size: 14,
};
}
}