Skip to content

Commit ec5f3b7

Browse files
committed
Add AI explain and recompose branch actions to Branch Views
Introduces AI-powered branch actions ("Recompose" and "Explain") directly into the branches view, enabling context menu options when branches are recomposable or have unpushed commits. Refactors and centralizes branch recomposability detection to ensure consistent logic across graph and views, improving maintainability and user experience. Enhances discoverability and workflow integration for AI-assisted Git operations. (#4443, #4522)
1 parent c077c67 commit ec5f3b7

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

contributions.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@
126126
]
127127
}
128128
},
129+
"gitlens.ai.explainUnpushed:views": {
130+
"label": "Explain Unpushed Changes (Preview)",
131+
"icon": "$(sparkle)",
132+
"menus": {
133+
"view/item/context": [
134+
{
135+
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+ahead\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled",
136+
"group": "1_gitlens_ai",
137+
"order": 20
138+
}
139+
]
140+
}
141+
},
129142
"gitlens.ai.explainWip": {
130143
"label": "Explain Working Changes (Preview)...",
131144
"commandPalette": "gitlens:enabled && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled"

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6239,6 +6239,11 @@
62396239
"title": "Explain Unpushed Changes (Preview)",
62406240
"icon": "$(sparkle)"
62416241
},
6242+
{
6243+
"command": "gitlens.ai.explainUnpushed:views",
6244+
"title": "Explain Unpushed Changes (Preview)",
6245+
"icon": "$(sparkle)"
6246+
},
62426247
{
62436248
"command": "gitlens.ai.explainWip",
62446249
"title": "Explain Working Changes (Preview)...",
@@ -11049,6 +11054,10 @@
1104911054
"command": "gitlens.ai.explainUnpushed:graph",
1105011055
"when": "false"
1105111056
},
11057+
{
11058+
"command": "gitlens.ai.explainUnpushed:views",
11059+
"when": "false"
11060+
},
1105211061
{
1105311062
"command": "gitlens.ai.explainWip",
1105411063
"when": "gitlens:enabled && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled"
@@ -17481,6 +17490,11 @@
1748117490
"when": "viewItem =~ /gitlens:branch\\b/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled",
1748217491
"group": "1_gitlens_ai@10"
1748317492
},
17493+
{
17494+
"command": "gitlens.ai.explainUnpushed:views",
17495+
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+ahead\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled",
17496+
"group": "1_gitlens_ai@20"
17497+
},
1748417498
{
1748517499
"command": "gitlens.views.openBranchOnRemote",
1748617500
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(tracking|remote)\\b)/ && !listMultiSelection",

src/constants.commands.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type ContributedCommands =
1111
| 'gitlens.ai.explainStash:graph'
1212
| 'gitlens.ai.explainStash:views'
1313
| 'gitlens.ai.explainUnpushed:graph'
14+
| 'gitlens.ai.explainUnpushed:views'
1415
| 'gitlens.ai.explainWip:graph'
1516
| 'gitlens.ai.explainWip:views'
1617
| 'gitlens.ai.feedback.helpful'

src/views/viewCommands.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { CreatePullRequestActionContext, OpenPullRequestActionContext } fro
55
import type { DiffWithCommandArgs } from '../commands/diffWith';
66
import type { DiffWithPreviousCommandArgs } from '../commands/diffWithPrevious';
77
import type { DiffWithWorkingCommandArgs } from '../commands/diffWithWorking';
8+
import type { ExplainBranchCommandArgs } from '../commands/explainBranch';
89
import type { GenerateChangelogCommandArgs } from '../commands/generateChangelog';
910
import { generateChangelogAndOpenMarkdownDocument } from '../commands/generateChangelog';
1011
import type { GenerateRebaseCommandArgs } from '../commands/generateRebase';
@@ -926,6 +927,21 @@ export class ViewCommands implements Disposable {
926927
});
927928
}
928929

930+
@command('gitlens.ai.explainUnpushed:views')
931+
@log()
932+
private async explainUnpushed(node: BranchNode) {
933+
if (!node.is('branch') || !node.branch.upstream) {
934+
return Promise.resolve();
935+
}
936+
937+
await executeCommand<ExplainBranchCommandArgs>('gitlens.ai.explainBranch', {
938+
repoPath: node.repoPath,
939+
ref: node.branch.ref,
940+
baseBranch: node.branch.upstream.name,
941+
source: { source: 'view', context: { type: 'branch' } },
942+
});
943+
}
944+
929945
@command('gitlens.views.rebaseOntoUpstream')
930946
@log()
931947
private rebaseToRemote(node: BranchNode | BranchTrackingStatusNode) {

0 commit comments

Comments
 (0)