Skip to content

Commit 490eec0

Browse files
committed
Hides AI PR creation button for repos that we cannot preset title and body
1 parent 9edd4b8 commit 490eec0

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

src/git/remotes/remoteProvider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export type RemoteProviderId =
2525
| 'gitlab'
2626
| 'google-source';
2727

28+
export const remotesSupportTitleOnPullRequestCreation: RemoteProviderId[] = [
29+
'github',
30+
'gitlab',
31+
'cloud-github-enterprise',
32+
'cloud-gitlab-self-hosted',
33+
];
34+
2835
export abstract class RemoteProvider<T extends ResourceDescriptor = ResourceDescriptor> implements ProviderReference {
2936
protected readonly _name: string | undefined;
3037

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -747,19 +747,21 @@ export abstract class GlBranchCardBase extends GlElement {
747747
href="${this.createCommandLink('gitlens.home.createPullRequest')}"
748748
>Create a Pull Request</gl-button
749749
>
750-
<gl-button
751-
class="branch-item__missing"
752-
tooltip="Create a Pull Request with AI"
753-
appearance="secondary"
754-
href="${this.createCommandLink('gitlens.home.createPullRequest', {
755-
source: 'home',
756-
useAI: true,
757-
})}"
758-
>
759-
<code-icon class="branch-item__is-wide" icon="sparkle" slot="prefix"></code-icon>
760-
<code-icon class="branch-item__is-narrow" icon="sparkle"></code-icon>
761-
<span class="branch-item__is-wide">Create with AI</span>
762-
</gl-button>
750+
${this.branch.aiPullRequestCreationAvailable
751+
? html`<gl-button
752+
class="branch-item__missing"
753+
tooltip="Create a Pull Request with AI"
754+
appearance="secondary"
755+
href="${this.createCommandLink('gitlens.home.createPullRequest', {
756+
source: 'home',
757+
useAI: true,
758+
})}"
759+
>
760+
<code-icon class="branch-item__is-wide" icon="sparkle" slot="prefix"></code-icon>
761+
<code-icon class="branch-item__is-narrow" icon="sparkle"></code-icon>
762+
<span class="branch-item__is-wide">Create with AI</span>
763+
</gl-button>`
764+
: nothing}
763765
</div>
764766
`;
765767
}

src/webviews/home/homeWebview.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { RepositoryChange, RepositoryChangeComparisonMode } from '../../git/mode
2929
import { uncommitted } from '../../git/models/revision';
3030
import type { GitStatus } from '../../git/models/status';
3131
import type { GitWorktree } from '../../git/models/worktree';
32+
import { remotesSupportTitleOnPullRequestCreation } from '../../git/remotes/remoteProvider';
3233
import { getAssociatedIssuesForBranch } from '../../git/utils/-webview/branch.issue.utils';
3334
import { getBranchTargetInfo } from '../../git/utils/-webview/branch.utils';
3435
import { getReferenceFromBranch } from '../../git/utils/-webview/reference.utils';
@@ -756,10 +757,15 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
756757
const activeBranch = branches.find(
757758
branch => this.getBranchOverviewType(branch, worktreesByBranch) === 'active',
758759
)!;
760+
const aiPullRequestCreationAvailable =
761+
(await repo.git.remotes().getBestRemotesWithProviders()).find(r =>
762+
remotesSupportTitleOnPullRequestCreation.includes(r.provider.id),
763+
) != null;
759764

760765
const isPro = await this.isSubscriptionPro();
761766
const [activeOverviewBranch] = getOverviewBranchesCore(
762767
[activeBranch],
768+
aiPullRequestCreationAvailable,
763769
branchesAndWorktrees.worktreesByBranch,
764770
isPro,
765771
this.container,
@@ -791,6 +797,10 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
791797

792798
const forceRepo = this._invalidateOverview === 'repo';
793799
const branchesAndWorktrees = await this.getBranchesData(repo, forceRepo);
800+
const aiPullRequestCreationAvailable =
801+
(await repo.git.remotes().getBestRemotesWithProviders()).find(r =>
802+
remotesSupportTitleOnPullRequestCreation.includes(r.provider.id),
803+
) != null;
794804

795805
const recentBranches = branchesAndWorktrees.branches.filter(
796806
branch => this.getBranchOverviewType(branch, branchesAndWorktrees.worktreesByBranch) === 'recent',
@@ -823,14 +833,21 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
823833
const isPro = await this.isSubscriptionPro();
824834
const recentOverviewBranches = getOverviewBranchesCore(
825835
recentBranches,
836+
aiPullRequestCreationAvailable,
826837
branchesAndWorktrees.worktreesByBranch,
827838
isPro,
828839
this.container,
829840
);
830841
const staleOverviewBranches =
831842
staleBranches == null
832843
? undefined
833-
: getOverviewBranchesCore(staleBranches, branchesAndWorktrees.worktreesByBranch, isPro, this.container);
844+
: getOverviewBranchesCore(
845+
staleBranches,
846+
aiPullRequestCreationAvailable,
847+
branchesAndWorktrees.worktreesByBranch,
848+
isPro,
849+
this.container,
850+
);
834851

835852
// TODO: revisit invalidation
836853
if (!forceRepo) {
@@ -1460,6 +1477,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
14601477

14611478
function getOverviewBranchesCore(
14621479
branches: GitBranch[],
1480+
aiPullRequestCreationAvailable: boolean,
14631481
worktreesByBranch: Map<string, GitWorktree>,
14641482
isPro: boolean,
14651483
container: Container,
@@ -1518,6 +1536,7 @@ function getOverviewBranchesCore(
15181536
reference: getReferenceFromBranch(branch),
15191537
repoPath: branch.repoPath,
15201538
id: branch.id,
1539+
aiPullRequestCreationAvailable: aiPullRequestCreationAvailable,
15211540
name: branch.name,
15221541
opened: isActive,
15231542
timestamp: timestamp,

src/webviews/home/protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface GetOverviewBranch {
7474
id: string;
7575
name: string;
7676
opened: boolean;
77+
aiPullRequestCreationAvailable: boolean;
7778
timestamp?: number;
7879
status: GitBranchStatus;
7980
upstream: GitTrackingUpstream | undefined;

0 commit comments

Comments
 (0)