Skip to content

Commit 0013ca9

Browse files
committed
Makes AI usage in create PR optional, adds button that creates PR using AI
1 parent d7c7528 commit 0013ca9

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

src/api/gitlens.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Disposable } from 'vscode';
2+
import type { Sources } from '../constants.telemetry';
23

34
export type { Disposable } from 'vscode';
45

@@ -24,6 +25,8 @@ export interface CreatePullRequestActionContext {
2425
readonly url?: string;
2526
}
2627
| undefined;
28+
readonly source?: Sources;
29+
readonly useAI?: boolean;
2730
}
2831

2932
export interface OpenPullRequestActionContext {

src/commands/createPullRequestOnRemote.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { window } from 'vscode';
2+
import type { Sources } from '../constants.telemetry';
23
import type { Container } from '../container';
34
import type { GitRemote } from '../git/models/remote';
45
import type { RemoteResource } from '../git/models/remoteResource';
@@ -17,6 +18,8 @@ export interface CreatePullRequestOnRemoteCommandArgs {
1718
repoPath: string;
1819

1920
clipboard?: boolean;
21+
source?: Sources;
22+
useAI?: boolean;
2023
}
2124

2225
@command()
@@ -74,26 +77,31 @@ export class CreatePullRequestOnRemoteCommand extends GlCommandBase {
7477
branch: args.compare,
7578
remote: { path: compareRemote.path, url: compareRemote.url, name: compareRemote.name },
7679
},
77-
describePullRequest: async (
78-
completedResource: RemoteResource & { type: RemoteResourceType.CreatePullRequest },
79-
) => {
80-
const base = completedResource.base;
81-
const compare = completedResource.compare;
82-
if (!base?.remote || !compare?.remote || !base?.branch || !compare?.branch) {
83-
return undefined;
84-
}
85-
const baseRef = `${base.remote.name}/${base.branch}`;
86-
const compareRef = `${compare.remote.name}/${compare.branch}`;
87-
try {
88-
const result = await this.container.ai.generatePullRequestMessage(repo, baseRef, compareRef, {
89-
source: 'scm-input',
90-
});
91-
return result?.parsed;
92-
} catch (e) {
93-
void window.showErrorMessage(`Unable to generate pull request message: ${e}`);
94-
return undefined;
95-
}
96-
},
80+
describePullRequest: !args.useAI
81+
? undefined
82+
: async (completedResource: RemoteResource & { type: RemoteResourceType.CreatePullRequest }) => {
83+
const base = completedResource.base;
84+
const compare = completedResource.compare;
85+
if (!base?.remote || !compare?.remote || !base?.branch || !compare?.branch) {
86+
return undefined;
87+
}
88+
const baseRef = `${base.remote.name}/${base.branch}`;
89+
const compareRef = `${compare.remote.name}/${compare.branch}`;
90+
try {
91+
const result = await this.container.ai.generatePullRequestMessage(
92+
repo,
93+
baseRef,
94+
compareRef,
95+
{
96+
source: args.source ?? 'scm-input',
97+
},
98+
);
99+
return result?.parsed;
100+
} catch (e) {
101+
void window.showErrorMessage(`Unable to generate pull request message: ${e}`);
102+
return undefined;
103+
}
104+
},
97105
};
98106

99107
void (await executeCommand<OpenOnRemoteCommandArgs>('gitlens.openOnRemote', {

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ function registerBuiltInActionRunners(container: Container): void {
309309
: ctx.branch.name,
310310
remote: ctx.remote?.name ?? '',
311311
repoPath: ctx.repoPath,
312+
source: ctx.source,
313+
useAI: ctx.useAI,
312314
}));
313315
},
314316
}),

src/webviews/apps/plus/home/components/branch-card.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ export abstract class GlBranchCardBase extends GlElement {
640640
}
641641

642642
protected createCommandLink<T>(command: GlCommands, args?: T | any): string {
643-
return createCommandLink<T>(command, args ?? this.branchRef);
643+
return createCommandLink<T>(command, args ? { ...args, ...this.branchRef } : this.branchRef);
644644
}
645645

646646
protected renderTimestamp(): TemplateResult | NothingType {
@@ -722,6 +722,15 @@ export abstract class GlBranchCardBase extends GlElement {
722722
href="${this.createCommandLink('gitlens.home.createPullRequest')}"
723723
>Create a Pull Request</gl-button
724724
>
725+
<gl-button
726+
class="branch-item__missing"
727+
appearance="secondary"
728+
href="${this.createCommandLink('gitlens.home.createPullRequest', {
729+
source: 'home',
730+
useAI: true,
731+
})}"
732+
>AI</gl-button
733+
>
725734
`;
726735
}
727736
return nothing;

src/webviews/home/homeWebview.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
supportedCloudIntegrationDescriptors,
1313
supportedOrderedCloudIntegrationIds,
1414
} from '../../constants.integrations';
15-
import type { HomeTelemetryContext, Source } from '../../constants.telemetry';
15+
import type { HomeTelemetryContext, Source, Sources } from '../../constants.telemetry';
1616
import type { Container } from '../../container';
1717
import { executeGitCommand } from '../../git/actions';
1818
import { openComparisonChanges } from '../../git/actions/commit';
@@ -1346,7 +1346,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
13461346
@log<HomeWebviewProvider['pullRequestCreate']>({
13471347
args: { 0: r => `${r.branchId}, upstream: ${r.branchUpstreamName}` },
13481348
})
1349-
private async pullRequestCreate(ref: BranchRef) {
1349+
private async pullRequestCreate(ref: BranchRef & { source?: Sources; useAI?: boolean }) {
13501350
const { branch } = await this.getRepoInfoFromRef(ref);
13511351
if (branch == null) return;
13521352

@@ -1374,6 +1374,8 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
13741374
upstream: branch.upstream?.name,
13751375
isRemote: branch.remote,
13761376
},
1377+
source: ref.source,
1378+
useAI: ref.useAI,
13771379
});
13781380
}
13791381

0 commit comments

Comments
 (0)