Skip to content

Commit

Permalink
refactor: use DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Dec 4, 2019
1 parent 3904444 commit 6145355
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/services/bitbucket/BitbucketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class BitbucketService implements IVCSService {
}

const ownerUrl = `www.bitbucket.org/${owner}`;
const ownerId =`${await this.client.users.get({ username: owner })).data.uuid}`;
const ownerId =`${(await this.client.users.get({ username: owner })).data.uuid}`;

const response: DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedPullrequests>> = await axios.get(apiUrl);

Expand Down
28 changes: 12 additions & 16 deletions test/helpers/bitbucketNock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,25 @@ export class BitbucketNock {
url = url.concat(`/${id}`);
response = new PullRequestMock(<BitbucketPullRequestState>state).pullRequest;
} else {
if (typeof state !== 'string') {
const pullRequests: Bitbucket.Schema.Pullrequest[] = [];
state.forEach((state) => {
pullRequests.push(new PullRequestMock(state).pullRequest);
});

const stateForUri = qs.stringify({ state: state }, { addQueryPrefix: true, indices: false, arrayFormat: 'repeat' });
url = url.concat(`${stateForUri}`);

response = new PullRequestsMock(pullRequests).pullrequests;

params = { state: state };
} else if (state === BitbucketPullRequestState.open) {
if (state === BitbucketPullRequestState.open) {
const pullRequest = new PullRequestMock(state).pullRequest;
response = new PullRequestsMock([pullRequest]).pullrequests;
} else {
const stateForUri = qs.stringify({ state: state }, { addQueryPrefix: true, indices: false, arrayFormat: 'repeat' });
url = url.concat(`${stateForUri}`);
params = { state: state };

const pullRequest = new PullRequestMock(<BitbucketPullRequestState>state).pullRequest;
response = new PullRequestsMock([pullRequest]).pullrequests;
if (typeof state !== 'string') {
const pullRequests: Bitbucket.Schema.Pullrequest[] = [];
state.forEach((state) => {
pullRequests.push(new PullRequestMock(state).pullRequest);
});

params = { state: state };
response = new PullRequestsMock(pullRequests).pullrequests;
} else {
const pullRequest = new PullRequestMock(<BitbucketPullRequestState>state).pullRequest;
response = new PullRequestsMock([pullRequest]).pullrequests;
}
}
}
break;
Expand Down

0 comments on commit 6145355

Please sign in to comment.