Skip to content

Commit 4f42519

Browse files
feat: add PR open command (#280)
* feat: add PR open command * chore: update name of fn
1 parent cec34e3 commit 4f42519

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export enum Commands {
3030
BitbucketFetchPullRequests = 'atlascode.bb.fetchPullRequests',
3131
BitbucketRefreshPullRequests = 'atlascode.bb.refreshPullRequests',
3232
BitbucketToggleFileNesting = 'atlascode.bb.toggleFileNesting',
33+
BitbucketOpenPullRequest = 'atlascode.bb.openPullRequest',
3334
BitbucketShowOpenPullRequests = 'atlascode.bb.showOpenPullRequests',
3435
BitbucketShowPullRequestsToReview = 'atlascode.bb.showPullRequestsToReview',
3536
BitbucketShowPullRequestsCreatedByMe = 'atlascode.bb.showOpenPullRequestsCreatedByMe',
@@ -255,5 +256,8 @@ export function registerCommands(vscodeContext: ExtensionContext) {
255256
commands.registerCommand(Commands.DisableHelpExplorer, () => {
256257
configuration.updateEffective('helpExplorerEnabled', false, null, true);
257258
}),
259+
commands.registerCommand(Commands.BitbucketOpenPullRequest, (data: { pullRequestUrl: string }) => {
260+
Container.openPullRequestHandler(data.pullRequestUrl);
261+
}),
258262
);
259263
}

src/commands/bitbucket/pullRequest.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Uri } from 'vscode';
2+
import { CheckoutHelper } from 'src/bitbucket/interfaces';
3+
4+
const extractPullRequestComponents = (url: string): { repoUrl: string; prId: number } => {
5+
const repoUrl = url.slice(0, url.indexOf('/pull-requests'));
6+
const prUrlPath = Uri.parse(url).path;
7+
const prId = prUrlPath.slice(prUrlPath.lastIndexOf('/') + 1);
8+
return { repoUrl, prId: parseInt(prId) };
9+
};
10+
11+
/**
12+
* Opens a pull request using the provided URL
13+
* @param pullRequestUrl URL of the pull request to open
14+
*/
15+
export const openPullRequest = async (bitbucketHelper: CheckoutHelper, pullRequestUrl: string): Promise<void> => {
16+
const { repoUrl, prId } = extractPullRequestComponents(pullRequestUrl);
17+
await bitbucketHelper.pullRequest(repoUrl, prId);
18+
};

src/container.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import { AssignedWorkItemsViewProvider } from './views/jira/treeViews/jiraAssign
7474
import { Logger } from './logger';
7575
import { SearchJiraHelper } from './views/jira/searchJiraHelper';
7676
import { featureFlagClientInitializedEvent } from './analytics';
77+
import { openPullRequest } from './commands/bitbucket/pullRequest';
7778

7879
const isDebuggingRegex = /^--(debug|inspect)\b(-brk\b|(?!-))=?/;
7980
const ConfigTargetKey = 'configurationTarget';
@@ -219,6 +220,10 @@ export class Container {
219220
this.initializeNewSidebarView(context, config);
220221
}
221222

223+
static openPullRequestHandler = (pullRequestUrl: string) => {
224+
return openPullRequest(this._bitbucketHelper, pullRequestUrl);
225+
};
226+
222227
private static getAnalyticsEnable(): boolean {
223228
const telemetryConfig = workspace.getConfiguration('telemetry');
224229
return telemetryConfig.get<boolean>('enableTelemetry', true);

0 commit comments

Comments
 (0)