Skip to content

Commit

Permalink
fix: get the ownerId via repo info with one request
Browse files Browse the repository at this point in the history
  • Loading branch information
adelkahomolova committed Dec 9, 2019
1 parent 269f384 commit 2b83d63
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/services/bitbucket/BitbucketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,7 @@ export class BitbucketService implements IVCSService {

const ownerUrl = `www.bitbucket.org/${owner}`;

//Bitbucket uses two types of accounts - user and team. The request for users' uuid fails if it is a team account.
let ownerId: string;
try {
ownerId = `${(await this.client.users.get({ username: owner })).data.uuid}`;
} catch (error) {
if (error.message.includes('is a team account')) {
ownerId = `${(await this.client.teams.get({ username: owner })).data.uuid}`;
}
}
const ownerId = <string>(await this.client.repositories.get({ repo_slug: repo, username: owner })).data.owner?.uuid;

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

Expand Down Expand Up @@ -154,15 +146,8 @@ export class BitbucketService implements IVCSService {
};

const ownerUrl = `www.bitbucket.org/${owner}`;
//Bitbucket use two types of accounts - user and team. The request for users uuid fails if it is a team account.
let ownerId = '';
try {
ownerId = `${(await this.client.users.get({ username: owner })).data.uuid}`;
} catch (error) {
if (error.message.includes('is a team account')) {
ownerId = `${(await this.client.teams.get({ username: owner })).data.uuid}`;
}
}
const ownerId = <string>(await this.client.repositories.get({ repo_slug: repo, username: owner })).data.owner?.uuid;

const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.Pullrequest>>>await this.client.pullrequests.get(params);
response.data;

Expand Down

0 comments on commit 2b83d63

Please sign in to comment.