Skip to content

Commit

Permalink
fix: tests for BitbucketService
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Oct 17, 2019
1 parent df0f91d commit f7537bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
5 changes: 2 additions & 3 deletions src/services/bitbucket/BitbucketService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ describe('Bitbucket Service', () => {
bitbucketNock = new BitbucketNock('pypy', 'pypy');
});

it.only('returns pull requests in own interface', async () => {
nock('https://api.bitbucket.org/2.0')
it('returns pull requests in own interface', async () => {
nock(bitbucketNock.url)
.get('/users/pypy')
.times(2)
.reply(200);
bitbucketNock.getApiResponse('pullrequests');

Expand Down
62 changes: 29 additions & 33 deletions src/services/bitbucket/BitbucketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { IGitHubService, GitHubPullRequestState } from '../git/IGitHubService';
import { ListGetterOptions } from '../../inspectors/common/ListGetterOptions';
import { PullsListResponseItem } from '@octokit/rest';
import { Paginated } from '../../inspectors/common/Paginated';
import { PullRequest, Issue } from '../git/model';
import { PullRequest, Issue, PullCommits, IssueComment } from '../git/model';
import GitUrlParse from 'git-url-parse';
import { BitbucketPaginatedPullRequestResponse } from './IBitbucketClient';
import { DeepRequired } from '../../lib/deepRequired';
import { Commits } from '../../../test/helpers/bibucketNock';
const debug = Debug('cli:services:git:github-service');

// implements IBitbucketService
Expand Down Expand Up @@ -65,8 +66,6 @@ export class BitbucketService {

const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedPullrequests>>>await this.client.pullrequests.list(paramas);
const url = 'www.bitbucket.org';
// const test = await this.client.users.get({ username: 'ashwinahuja' });
// console.log(test.data.nickname, 'test');

const values = response.data.values.map(async (val) => ({
user: {
Expand All @@ -89,22 +88,21 @@ export class BitbucketService {
id: val.destination.repository.uuid,
owner: {
login: <string>val.destination.repository.full_name.split('/').shift(),
id: <string>(<unknown>await this.client.users.get({ username: `${val.destination.repository.full_name.split('/').shift()}` })),
id: <string>(await this.client.users.get({ username: `${val.destination.repository.full_name.split('/').shift()}` })).data.uuid,
url: url.concat(`/${val.destination.repository.full_name.split('/').shift()}`),
},
},
},
}));

//`${val.destination.repository.full_name.split('/').shift()}`
const pagination = this.getPagination(response.data);

const items = await Promise.all(values);

return { items, ...pagination };
}

async getPullRequest(owner: string, repo: string, prNumber: number) {
async getPullRequest(owner: string, repo: string, prNumber: number): Promise<PullRequest> {
const params = {
pull_request_id: prNumber,
repo_slug: repo,
Expand All @@ -125,7 +123,7 @@ export class BitbucketService {
createdAt: response.data.created_on,
updatedAt: response.data.updated_on,
closedAt: response.data.closed_by.created_on,
mergedAt: response.data.merge_commit,
mergedAt: null,
state: response.data.state,
id: response.data.id,
base: {
Expand All @@ -147,7 +145,7 @@ export class BitbucketService {
throw new Error('Method not implemented.');
}

async getPullCommits(owner: string, repo: string, prNumber: number) {
async getPullCommits(owner: string, repo: string, prNumber: number): Promise<Paginated<PullCommits>> {
const params: Bitbucket.Params.PullrequestsListCommits = {
pull_request_id: prNumber.toString(),
repo_slug: repo,
Expand Down Expand Up @@ -177,59 +175,57 @@ export class BitbucketService {
return { items, ...pagination };
}

async getIssues(owner: string, repo: string) {
async getIssues(owner: string, repo: string): Promise<Paginated<Issue>> {
const params: Bitbucket.Params.IssueTrackerList = {
repo_slug: repo,
username: owner,
};
const response: Bitbucket.Response<Bitbucket.Schema.PaginatedIssues> = await this.client.issue_tracker.list(params);
const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedIssues>>>await this.client.issue_tracker.list(params);

const values = response.data.values!.map((val) => ({
const items = response.data.values.map((val) => ({
user: {
id: val.reporter!.uuid,
login: val.reporter!.nickname,
url: val.reporter!.links!.html!.href,
id: val.reporter.uuid,
login: val.reporter.nickname,
url: val.reporter.links.html.href,
},
url: val.repository!.links!.html!.href,
body: val.content!.raw,
url: val.repository.links.html.href,
body: val.content.raw,
createdAt: val.created_on,
updatedAt: val.updated_on,
closedAt: undefined,
closedAt: null,
state: val.state,
id: val.repository!.uuid,
id: val.repository.uuid,
}));
const pagination = this.getPagination(response.data);

const items = values ? values : [];

return { items, ...pagination };
}

async getIssue(owner: string, repo: string, issueNumber: number) {
async getIssue(owner: string, repo: string, issueNumber: number): Promise<Issue> {
const params: Bitbucket.Params.IssueTrackerGet = {
issue_id: issueNumber.toString(),
repo_slug: repo,
username: owner,
};
const response = await this.client.issue_tracker.get(params);
const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Issue>>>await this.client.issue_tracker.get(params);

return {
id: response.data.repository!.uuid,
id: response.data.repository.uuid,
user: {
login: response.data.reporter!.nickname,
id: response.data.reporter!.uuid,
url: response.data.reporter!.href,
login: response.data.reporter.nickname,
id: response.data.reporter.uuid,
url: response.data.reporter.href,
},
url: response.data.links!.html!.href,
body: response.data.content!.raw,
createdAt: <string>response.data.created_on,
updatedAt: <string>response.data.updated_on,
closedAt: undefined,
state: <string>response.data.state,
url: response.data.links.html.href,
body: response.data.content.raw,
createdAt: response.data.created_on,
updatedAt: response.data.updated_on,
closedAt: null,
state: response.data.state,
};
}

async getIssueComments(owner: string, repo: string, issueNumber: number) {
async getIssueComments(owner: string, repo: string, issueNumber: number): Promise<Paginated<IssueComment>> {
const params: Bitbucket.Params.IssueTrackerListComments = {
issue_id: issueNumber.toString(),
repo_slug: repo,
Expand Down
25 changes: 17 additions & 8 deletions test/helpers/bibucketNock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import nock from 'nock';
export class BitbucketNock {
user: string;
repoName: string;
url: string;

constructor(user: string, repoName: string) {
(this.user = user), (this.repoName = repoName);
this.url = 'https://api.bitbucket.org/2.0';
}

getApiResponse(resource: string, id?: number, value?: string) {
let url = `https://api.bitbucket.org/2.0/repositories/${this.user}/${this.repoName}/${resource}`;
let url = `${this.url}/repositories/${this.user}/${this.repoName}/${resource}`;
let response;

if (value !== undefined) {
Expand Down Expand Up @@ -584,15 +586,22 @@ export const getPullRequestsResponse = {
login: 'landtuna',
url: 'https://bitbucket.org/%7B9d65d517-4898-47ac-9d2f-fd902d25d9f6%7D/',
},
url: undefined,
url: 'https://bitbucket.org/pypy/pypy/pull-requests/1',
body: 'Added a floor() ufunc to micronumpy',
createdAt: '2011-06-22T19:44:39.555192+00:00',
updatedAt: '2011-06-23T13:52:30.230741+00:00',
closedAt: undefined,
mergedAt: undefined,
closedAt: null,
mergedAt: null,
state: 'DECLINED',
id: 1,
base: { repo: { url: 'https://bitbucket.org/pypy/pypy', name: 'pypy', id: '{54220cd1-b139-4188-9455-1e13e663f1ac}', owner: 'pypy' } },
base: {
repo: {
url: 'https://bitbucket.org/pypy/pypy',
name: 'pypy',
id: '{54220cd1-b139-4188-9455-1e13e663f1ac}',
owner: { id: undefined, login: 'pypy', url: 'www.bitbucket.org/pypy' },
},
},
},
],
totalCount: 1,
Expand All @@ -609,7 +618,7 @@ export const getPullRequestResponse = {
createdAt: '2011-06-22T19:44:39.555192+00:00',
updatedAt: '2011-06-23T13:52:30.230741+00:00',
closedAt: undefined,
mergedAt: undefined,
mergedAt: null,
state: 'DECLINED',
id: 1,
base: {
Expand Down Expand Up @@ -675,7 +684,7 @@ export const getIssuesResponse = {
'As mentioned on IRC over the last few days.\r\n\r\nWhen I translate a JIT pypy2.7 from the 7.2 release branch \\(or hg HEAD\\) under cPython on arm64, I get an interpreter with an unstable JIT. It constantly crashes, with some variant of:\r\n\r\n```\r\n$ pypy/goal/pypy-c lib_pypy/_sqlite3_build.py\r\nRPython traceback:\r\n File "rpython_jit_metainterp_10.c", line 25430, in send_loop_to_backend\r\n File "rpython_jit_backend_aarch64.c", line 1690, in AssemblerARM64_assemble_loop\r\n File "rpython_jit_backend_aarch64.c", line 4551, in AssemblerARM64__assemble\r\n File "rpython_jit_backend_aarch64.c", line 13381, in AssemblerARM64__walk_operations\r\n File "rpython_jit_backend_aarch64.c", line 52643, in ResOpAssembler_emit_op_zero_array\r\nFatal RPython error: AssertionError\r\n```\r\n\r\n`--jit off` works as usual.\r\n\r\nI can’t reproduce this with the pre-built [pypy2.7-v7.2.0rc0-aarch64.tar.bz2](https://bitbucket.org/pypy/pypy/downloads/pypy2.7-v7.2.0rc0-aarch64.tar.bz2), and it can translate pypy2.7 to produce a working JIT. OS is Debian sid. Haven’t tried pypy3.6, yet.\r\n\r\nFull build log attached. No toolchain details in there, but it will be almost identical to [this build, without JIT](https://buildd.debian.org/status/fetch.php?pkg=pypy3&arch=arm64&ver=7.2.0%7Erc1%2Bdfsg-1&stamp=1570132096&raw=0).\r\n\r\nHardware: kvm guest on an APM [X-Gene 1](https://www.gigabyte.com/Server-Motherboard/MP30-AR1-rev-11#ov) \\(a Mustang, something like that\\)',
createdAt: '2019-10-06T19:52:53.940697+00:00',
updatedAt: '2019-10-15T15:47:34.904758+00:00',
closedAt: undefined,
closedAt: null,
state: 'new',
id: '{54220cd1-b139-4188-9455-1e13e663f1ac}',
},
Expand All @@ -695,7 +704,7 @@ export const getIssueResponse = {
'As mentioned on IRC over the last few days.\r\n\r\nWhen I translate a JIT pypy2.7 from the 7.2 release branch \\(or hg HEAD\\) under cPython on arm64, I get an interpreter with an unstable JIT. It constantly crashes, with some variant of:\r\n\r\n```\r\n$ pypy/goal/pypy-c lib_pypy/_sqlite3_build.py\r\nRPython traceback:\r\n File "rpython_jit_metainterp_10.c", line 25430, in send_loop_to_backend\r\n File "rpython_jit_backend_aarch64.c", line 1690, in AssemblerARM64_assemble_loop\r\n File "rpython_jit_backend_aarch64.c", line 4551, in AssemblerARM64__assemble\r\n File "rpython_jit_backend_aarch64.c", line 13381, in AssemblerARM64__walk_operations\r\n File "rpython_jit_backend_aarch64.c", line 52643, in ResOpAssembler_emit_op_zero_array\r\nFatal RPython error: AssertionError\r\n```\r\n\r\n`--jit off` works as usual.\r\n\r\nI can’t reproduce this with the pre-built [pypy2.7-v7.2.0rc0-aarch64.tar.bz2](https://bitbucket.org/pypy/pypy/downloads/pypy2.7-v7.2.0rc0-aarch64.tar.bz2), and it can translate pypy2.7 to produce a working JIT. OS is Debian sid. Haven’t tried pypy3.6, yet.\r\n\r\nFull build log attached. No toolchain details in there, but it will be almost identical to [this build, without JIT](https://buildd.debian.org/status/fetch.php?pkg=pypy3&arch=arm64&ver=7.2.0%7Erc1%2Bdfsg-1&stamp=1570132096&raw=0).\r\n\r\nHardware: kvm guest on an APM [X-Gene 1](https://www.gigabyte.com/Server-Motherboard/MP30-AR1-rev-11#ov) \\(a Mustang, something like that\\)',
createdAt: '2019-10-06T19:52:53.940697+00:00',
updatedAt: '2019-10-15T15:47:34.904758+00:00',
closedAt: undefined,
closedAt: null,
state: 'new',
};

Expand Down

0 comments on commit f7537bf

Please sign in to comment.