Skip to content

Commit c262d60

Browse files
authored
"Copilot stopped work" not shown in PR view when running into an error (#7056)
Fixes #7040
1 parent ec08597 commit c262d60

File tree

6 files changed

+60
-4
lines changed

6 files changed

+60
-4
lines changed

resources/icons/error.svg

Lines changed: 1 addition & 0 deletions
Loading

src/common/timelineEvent.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export enum EventType {
2424
Reopened,
2525
CopilotStarted,
2626
CopilotFinished,
27+
CopilotFinishedError,
2728
Other,
2829
}
2930

@@ -165,4 +166,12 @@ export interface CopilotFinishedEvent {
165166
onBehalfOf: IAccount;
166167
}
167168

168-
export type TimelineEvent = CommitEvent | ReviewEvent | CommentEvent | NewCommitsSinceReviewEvent | MergedEvent | AssignEvent | UnassignEvent | HeadRefDeleteEvent | CrossReferencedEvent | ClosedEvent | ReopenedEvent | CopilotStartedEvent | CopilotFinishedEvent;
169+
export interface CopilotFinishedErrorEvent {
170+
id: string;
171+
event: EventType.CopilotFinishedError;
172+
createdAt: string;
173+
onBehalfOf: IAccount;
174+
sessionUrl: string;
175+
}
176+
177+
export type TimelineEvent = CommitEvent | ReviewEvent | CommentEvent | NewCommitsSinceReviewEvent | MergedEvent | AssignEvent | UnassignEvent | HeadRefDeleteEvent | CrossReferencedEvent | ClosedEvent | ReopenedEvent | CopilotStartedEvent | CopilotFinishedEvent | CopilotFinishedErrorEvent;

src/github/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ export function parseSelectRestTimelineEvents(
10021002
events: OctokitCommon.ListEventsForTimelineResponse[]
10031003
): Common.TimelineEvent[] {
10041004
const parsedEvents: Common.TimelineEvent[] = [];
1005+
const sessionUrl = `https://${issueModel.githubRepository.remote.gitProtocol.host}/${issueModel.githubRepository.remote.owner}/${issueModel.githubRepository.remote.repositoryName}/pull/${issueModel.number}/agent-sessions`;
10051006
let indexLastStart = -1;
10061007
for (const event of events) {
10071008
const eventNode = event as { created_at?: string; node_id?: string; actor: RestAccount };
@@ -1021,12 +1022,20 @@ export function parseSelectRestTimelineEvents(
10211022
createdAt: eventNode.created_at,
10221023
onBehalfOf: parseAccount(eventNode.actor)
10231024
});
1025+
} else if (event.event === 'copilot_work_finished_failure') {
1026+
parsedEvents.push({
1027+
id: eventNode.node_id,
1028+
event: Common.EventType.CopilotFinishedError,
1029+
createdAt: eventNode.created_at,
1030+
onBehalfOf: parseAccount(eventNode.actor),
1031+
sessionUrl
1032+
});
10241033
}
10251034
}
10261035
}
10271036
if (indexLastStart > -1) {
10281037
const startEvent: Common.CopilotStartedEvent = parsedEvents[indexLastStart] as Common.CopilotStartedEvent;
1029-
startEvent.sessionUrl = `https://${issueModel.githubRepository.remote.gitProtocol.host}/${issueModel.githubRepository.remote.owner}/${issueModel.githubRepository.remote.repositoryName}/pull/${issueModel.number}/agent-sessions`;
1038+
startEvent.sessionUrl = sessionUrl;
10301039
}
10311040
return parsedEvents;
10321041
}
@@ -1044,6 +1053,7 @@ function eventTime(event: Common.TimelineEvent): Date | undefined {
10441053
case Common.EventType.Reopened:
10451054
case Common.EventType.CopilotStarted:
10461055
case Common.EventType.CopilotFinished:
1056+
case Common.EventType.CopilotFinishedError:
10471057
return new Date(event.createdAt);
10481058
case Common.EventType.Reviewed:
10491059
return new Date(event.submittedAt);

webviews/components/icon.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ export const issueClosedIcon = <Icon src={require('../../resources/icons/issue_c
4848
export const copilotIcon = <Icon src={require('../../resources/icons/copilot.svg')} />;
4949
export const threeBars = <Icon src={require('../../resources/icons/three-bars.svg')} />;
5050
export const tasklistIcon = <Icon src={require('../../resources/icons/tasklist.svg')} />;
51+
export const errorIcon = <Icon src={require('../../resources/icons/error.svg')} />;

webviews/components/timeline.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ClosedEvent,
1111
CommentEvent,
1212
CommitEvent,
13+
CopilotFinishedErrorEvent,
1314
CopilotFinishedEvent,
1415
CopilotStartedEvent,
1516
CrossReferencedEvent,
@@ -27,7 +28,7 @@ import { ReviewType } from '../../src/github/views';
2728
import PullRequestContext from '../common/context';
2829
import { CommentView } from './comment';
2930
import Diff from './diff';
30-
import { commitIcon, mergeIcon, plusIcon, tasklistIcon, threeBars } from './icon';
31+
import { commitIcon, errorIcon, mergeIcon, plusIcon, tasklistIcon, threeBars } from './icon';
3132
import { nbsp } from './space';
3233
import { Timestamp } from './timestamp';
3334
import { AuthorLink, Avatar } from './user';
@@ -95,6 +96,8 @@ export const Timeline = ({ events, isIssue }: { events: TimelineEvent[], isIssue
9596
return <CopilotStartedEventView key={`copilotStarted${event.id}`} {...event} />;
9697
case EventType.CopilotFinished:
9798
return <CopilotFinishedEventView key={`copilotFinished${event.id}`} {...event} />;
99+
case EventType.CopilotFinishedError:
100+
return <CopilotFinishedErrorEventView key={`copilotFinishedError${event.id}`} {...event} />;
98101
default:
99102
throw new UnreachableCaseError(event);
100103
}
@@ -466,4 +469,23 @@ const CopilotFinishedEventView = (event: CopilotFinishedEvent) => {
466469
<Timestamp date={createdAt} />
467470
</div>
468471
);
472+
};
473+
474+
const CopilotFinishedErrorEventView = (event: CopilotFinishedErrorEvent) => {
475+
const { createdAt, onBehalfOf } = event;
476+
return (
477+
<div className="comment-container commit">
478+
<div className='timeline-with-detail'>
479+
<div className='commit-message'>
480+
{errorIcon}
481+
{nbsp}
482+
<div className="message">Copilot stopped work on behalf of <AuthorLink for={onBehalfOf} /> due to an error</div>
483+
</div>
484+
<div className="commit-message-detail">
485+
<a href={event.sessionUrl}>Copilot has encountered an error. See logs for additional details.</a>
486+
</div>
487+
</div>
488+
<Timestamp date={createdAt} />
489+
</div>
490+
);
469491
};

webviews/editorWebview/index.css

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,13 +660,26 @@ body button .icon {
660660
}
661661

662662
.commit .commit-message,
663+
.commit .timeline-with-detail,
663664
.merged .merged-message {
664-
display: flex;
665665
align-items: center;
666666
overflow: hidden;
667667
flex-grow: 1;
668668
}
669669

670+
.commit .commit-message,
671+
.merged .merged-message {
672+
display: flex;
673+
}
674+
675+
.commit .timeline-with-detail {
676+
display: block;
677+
}
678+
679+
.commit-message-detail {
680+
margin-left: 20px;
681+
}
682+
670683
.commit .commit-message .avatar-container,
671684
.merged .merged-message .avatar-container {
672685
margin-right: 4px;

0 commit comments

Comments
 (0)