Skip to content

Commit 63e533a

Browse files
committed
Adds Explain WIP to inspect view
1 parent 32686a4 commit 63e533a

File tree

2 files changed

+56
-25
lines changed

2 files changed

+56
-25
lines changed

src/webviews/apps/commitDetails/components/gl-commit-details.ts

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { customElement, property, state } from 'lit/decorators.js';
33
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
44
import { when } from 'lit/directives/when.js';
55
import type { Autolink } from '../../../../autolinks/models/autolinks';
6+
import type { ExplainWipCommandArgs } from '../../../../commands/explainWip';
67
import type { IssueOrPullRequest } from '../../../../git/models/issueOrPullRequest';
78
import type { PullRequestShape } from '../../../../git/models/pullRequest';
9+
import { createCommandLink } from '../../../../system/commands';
810
import type { Serialized } from '../../../../system/serialize';
911
import type { State } from '../../../commitDetails/protocol';
1012
import { messageHeadlineSplitterToken } from '../../../commitDetails/protocol';
@@ -120,6 +122,37 @@ export class GlCommitDetails extends GlDetailsBase {
120122
`;
121123
}
122124

125+
private renderExplainChanges() {
126+
if (this.state?.orgSettings.ai === false || this.state?.preferences.aiEnabled === false) return undefined;
127+
128+
if (this.isUncommitted) {
129+
return html`
130+
<gl-action-chip
131+
label="Explain Working Changes"
132+
icon="sparkle"
133+
data-action="explain-commit"
134+
aria-busy="${this.explainBusy ? 'true' : nothing}"
135+
?disabled="${this.explainBusy ? true : nothing}"
136+
@click=${this.onExplainChanges}
137+
@keydown=${this.onExplainChanges}
138+
><span>explain</span></gl-action-chip
139+
>
140+
`;
141+
}
142+
return html`
143+
<gl-action-chip
144+
label="Explain this ${this.isStash ? 'Stash' : 'Commit'}"
145+
icon="sparkle"
146+
data-action="explain-commit"
147+
aria-busy="${this.explainBusy ? 'true' : nothing}"
148+
?disabled="${this.explainBusy ? true : nothing}"
149+
@click=${this.onExplainChanges}
150+
@keydown=${this.onExplainChanges}
151+
><span>explain</span></gl-action-chip
152+
>
153+
`;
154+
}
155+
123156
private renderCommitMessage() {
124157
const details = this.state?.commit;
125158
if (details == null) return undefined;
@@ -140,21 +173,7 @@ export class GlCommitDetails extends GlDetailsBase {
140173
></gl-commit-author>
141174
`,
142175
)}
143-
${when(
144-
this.state?.orgSettings.ai !== false && this.state?.preferences.aiEnabled !== false,
145-
() => html`
146-
<gl-action-chip
147-
label="Explain this ${this.isStash ? 'Stash' : 'Commit'}"
148-
icon="sparkle"
149-
data-action="explain-commit"
150-
aria-busy="${this.explainBusy ? 'true' : nothing}"
151-
?disabled="${this.explainBusy ? true : nothing}"
152-
@click=${this.onExplainChanges}
153-
@keydown=${this.onExplainChanges}
154-
><span>explain</span></gl-action-chip
155-
>
156-
`,
157-
)}
176+
${this.renderExplainChanges()}
158177
</div>
159178
<div>
160179
<div class="message-block">
@@ -284,7 +303,7 @@ export class GlCommitDetails extends GlDetailsBase {
284303

285304
private renderAutoLinksChips() {
286305
const autolinkState = this.autolinkState;
287-
if (autolinkState == null) return html`<span></span>`;
306+
if (autolinkState == null) return this.renderLearnAboutAutolinks();
288307

289308
const { autolinks, issues, prs, size } = autolinkState;
290309

src/webviews/commitDetails/commitDetailsWebview.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { CopyMessageToClipboardCommandArgs } from '../../commands/copyMessa
88
import type { CopyShaToClipboardCommandArgs } from '../../commands/copyShaToClipboard';
99
import type { ExplainCommitCommandArgs } from '../../commands/explainCommit';
1010
import type { ExplainStashCommandArgs } from '../../commands/explainStash';
11+
import type { ExplainWipCommandArgs } from '../../commands/explainWip';
1112
import type { OpenPullRequestOnRemoteCommandArgs } from '../../commands/openPullRequestOnRemote';
1213
import type { ContextKeys } from '../../constants.context';
1314
import type { InspectTelemetryContext, Sources } from '../../constants.telemetry';
@@ -1121,15 +1122,26 @@ export class CommitDetailsWebviewProvider
11211122
private async explainRequest<T extends typeof ExplainRequest>(requestType: T, msg: IpcCallMessageType<T>) {
11221123
let params: DidExplainParams;
11231124
try {
1124-
const isStashCommit = isStash(this._context.commit);
1125-
await executeCommand<ExplainCommitCommandArgs | ExplainStashCommandArgs>(
1126-
isStashCommit ? 'gitlens.ai.explainStash' : 'gitlens.ai.explainCommit',
1127-
{
1128-
repoPath: this._context.commit!.repoPath,
1129-
rev: this._context.commit!.sha,
1130-
source: { source: 'inspect', type: isStashCommit ? 'stash' : 'commit' },
1131-
},
1132-
);
1125+
// check for uncommitted changes
1126+
if (
1127+
this._context.commit != null &&
1128+
(this._context.commit.isUncommitted || this._context.commit.isUncommittedStaged)
1129+
) {
1130+
await executeCommand<ExplainWipCommandArgs>('gitlens.ai.explainWip', {
1131+
repoPath: this._context.commit.repoPath,
1132+
source: { source: 'inspect', type: 'wip' },
1133+
});
1134+
} else {
1135+
const isStashCommit = isStash(this._context.commit);
1136+
await executeCommand<ExplainCommitCommandArgs | ExplainStashCommandArgs>(
1137+
isStashCommit ? 'gitlens.ai.explainStash' : 'gitlens.ai.explainCommit',
1138+
{
1139+
repoPath: this._context.commit!.repoPath,
1140+
rev: this._context.commit!.sha,
1141+
source: { source: 'inspect', type: isStashCommit ? 'stash' : 'commit' },
1142+
},
1143+
);
1144+
}
11331145

11341146
params = { result: { summary: '', body: '' } };
11351147
} catch (ex) {

0 commit comments

Comments
 (0)