Skip to content

Commit 0a19579

Browse files
committed
Adds Bitbucket PR commit links app not installed warning
Displays a warning message when Bitbucket PR commit links are unavailable. This informs the user about the need to install the Bitbucket app for their commits. (#4192, #4243)
1 parent aa14a3a commit 0a19579

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4995,6 +4995,7 @@
49954995
"gitlens.advanced.messages": {
49964996
"type": "object",
49974997
"default": {
4998+
"suppressBitbucketPRCommitLinksAppNotInstalledWarning": false,
49984999
"suppressCommitHasNoPreviousCommitWarning": false,
49995000
"suppressCommitNotFoundWarning": false,
50005001
"suppressCreatePullRequestPrompt": false,

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export type StatusBarCommands =
151151

152152
// NOTE: Must be kept in sync with `gitlens.advanced.messages` setting in the package.json
153153
export type SuppressedMessages =
154+
| 'suppressBitbucketPRCommitLinksAppNotInstalledWarning'
154155
| 'suppressCommitHasNoPreviousCommitWarning'
155156
| 'suppressCommitNotFoundWarning'
156157
| 'suppressCreatePullRequestPrompt'

src/messages.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ export async function showGenericErrorMessage(message: string): Promise<void> {
9494
}
9595
}
9696

97+
export async function showBitbucketPRCommitLinksAppNotInstalledWarningMessage(revLink: string): Promise<void> {
98+
const allowAccess = { title: 'Allow Access' };
99+
const result = await showMessage(
100+
'warn',
101+
`GitLens cannot access Bitbucket PRs for commits.
102+
Allow access by visiting [this commit](${revLink}) on Bitbucket and click “Pull requests” under the “Apps” section on the bottom right
103+
or [read our docs](https://help.gitkraken.com/gitlens/gitlens-troubleshooting/#enable-showing-bitbucket-pull-request-for-a-commit) for more info.`,
104+
'suppressBitbucketPRCommitLinksAppNotInstalledWarning',
105+
{ title: "Don't Show Again" },
106+
allowAccess,
107+
);
108+
if (result === allowAccess) {
109+
void openUrl(revLink);
110+
}
111+
}
112+
97113
export function showFileNotUnderSourceControlWarningMessage(message: string): Promise<MessageItem | undefined> {
98114
return showMessage(
99115
'warn',

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import type { IssueOrPullRequest, IssueOrPullRequestType } from '../../../../git
1919
import type { PullRequest } from '../../../../git/models/pullRequest';
2020
import type { Provider } from '../../../../git/models/remoteProvider';
2121
import type { RepositoryMetadata } from '../../../../git/models/repositoryMetadata';
22-
import { showIntegrationRequestFailed500WarningMessage } from '../../../../messages';
22+
import {
23+
showBitbucketPRCommitLinksAppNotInstalledWarningMessage,
24+
showIntegrationRequestFailed500WarningMessage,
25+
} from '../../../../messages';
2326
import { configuration } from '../../../../system/-webview/configuration';
2427
import { debug } from '../../../../system/decorators/log';
2528
import { Logger } from '../../../../system/logger';
@@ -457,6 +460,16 @@ export class BitbucketApi implements Disposable {
457460
if (!pr) return undefined;
458461
return fromBitbucketPullRequest(pr, provider);
459462
} catch (ex) {
463+
if (ex.original instanceof ProviderFetchError) {
464+
const json = await ex.original.response.json();
465+
if (json?.error === 'Invalid or unknown installation') {
466+
// TODO: In future get it on to home as an worning on the integratin istelf "this integration has issues"
467+
// even user suppresses the message it's still visible with some capacity. It's a broader thing to get other errors.
468+
const commitWebUrl = `https://bitbucket.org/${owner}/${repo}/commits/${rev}`;
469+
void showBitbucketPRCommitLinksAppNotInstalledWarningMessage(commitWebUrl);
470+
return undefined;
471+
}
472+
}
460473
Logger.error(ex, scope);
461474
return undefined;
462475
}

0 commit comments

Comments
 (0)