Skip to content

Commit 9f66ea6

Browse files
committed
Retrieve a Bitbucket PR by its id, that lets us show it in autolinks
(#4045, #4070)
1 parent 06a4359 commit 9f66ea6

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/plus/integrations/providers/bitbucket.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ export class BitbucketIntegration extends HostingIntegration<
7575
}
7676

7777
protected override async getProviderIssueOrPullRequest(
78-
_session: AuthenticationSession,
79-
_repo: BitbucketRepositoryDescriptor,
80-
_id: string,
78+
{ accessToken }: AuthenticationSession,
79+
repo: BitbucketRepositoryDescriptor,
80+
id: string,
8181
): Promise<IssueOrPullRequest | undefined> {
82-
return Promise.resolve(undefined);
82+
return (await this.container.bitbucket)?.getIssueOrPullRequest(this, accessToken, repo.owner, repo.name, id, {
83+
baseUrl: this.apiBaseUrl,
84+
});
8385
}
8486

8587
protected override async getProviderIssue(

src/plus/integrations/providers/bitbucket/bitbucket.ts

+33
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import {
1313
RequestClientError,
1414
RequestNotFoundError,
1515
} from '../../../../errors';
16+
import type { IssueOrPullRequest } from '../../../../git/models/issueOrPullRequest';
1617
import type { PullRequest } from '../../../../git/models/pullRequest';
1718
import type { Provider } from '../../../../git/models/remoteProvider';
1819
import { showIntegrationRequestFailed500WarningMessage } from '../../../../messages';
1920
import { configuration } from '../../../../system/-webview/configuration';
21+
import { debug } from '../../../../system/decorators/log';
2022
import { Logger } from '../../../../system/logger';
2123
import type { LogScope } from '../../../../system/logger.scope';
2224
import { getLogScope } from '../../../../system/logger.scope';
@@ -56,6 +58,7 @@ export class BitbucketApi implements Disposable {
5658
this._proxyAgent = null;
5759
}
5860

61+
@debug<BitbucketApi['getPullRequestForBranch']>({ args: { 0: p => p.name, 1: '<token>' } })
5962
public async getPullRequestForBranch(
6063
provider: Provider,
6164
token: string,
@@ -90,6 +93,36 @@ export class BitbucketApi implements Disposable {
9093
return fromBitbucketPullRequest(response.values[0], provider);
9194
}
9295

96+
@debug<BitbucketApi['getIssueOrPullRequest']>({ args: { 0: p => p.name, 1: '<token>' } })
97+
public async getIssueOrPullRequest(
98+
provider: Provider,
99+
token: string,
100+
owner: string,
101+
repo: string,
102+
id: string,
103+
options: {
104+
baseUrl: string;
105+
},
106+
): Promise<IssueOrPullRequest | undefined> {
107+
const scope = getLogScope();
108+
109+
const response = await this.request<BitbucketPullRequest>(
110+
provider,
111+
token,
112+
options.baseUrl,
113+
`repositories/${owner}/${repo}/pullrequests/${id}?fields=*`,
114+
{
115+
method: 'GET',
116+
},
117+
scope,
118+
);
119+
120+
if (!response) {
121+
return undefined;
122+
}
123+
return fromBitbucketPullRequest(response, provider);
124+
}
125+
93126
private async request<T>(
94127
provider: Provider,
95128
token: string,

0 commit comments

Comments
 (0)