Skip to content

Commit 1eee698

Browse files
vicky1999alexr00
andauthored
feat: Display commit status icon for each commit (#8142)
* feat(timeline): Display commit status checks in PR timeline * fix: CommitEvent status * fix: CommitStateIcon status prop type * Prefer undefined --------- Co-authored-by: Alex Ross <38270282+alexr00@users.noreply.github.com>
1 parent a683997 commit 1eee698

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

src/common/timelineEvent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface CommitEvent {
8181
message: string;
8282
bodyHTML?: string;
8383
committedDate: Date;
84+
status?: 'EXPECTED' | 'ERROR' | 'FAILURE' | 'PENDING' | 'SUCCESS';
8485
}
8586

8687
export interface NewCommitsSinceReviewEvent {

src/github/graphql.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ export interface Commit {
188188
oid: string;
189189
message: string;
190190
committedDate: Date;
191+
statusCheckRollup?: {
192+
state: 'EXPECTED' | 'ERROR' | 'FAILURE' | 'PENDING' | 'SUCCESS';
193+
};
191194
};
192195

193196
url: string;

src/github/queriesShared.gql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ fragment Commit on PullRequestCommit {
123123
oid
124124
message
125125
committedDate
126+
statusCheckRollup {
127+
state
128+
}
126129
}
127130
url
128131
}

src/github/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,7 @@ export async function parseCombinedTimelineEvents(
12001200
htmlUrl: commitEv.url,
12011201
message: commitEv.commit.message,
12021202
committedDate: new Date(commitEv.commit.committedDate),
1203+
status: commitEv.commit.statusCheckRollup?.state
12031204
} as Common.CommitEvent); // TODO remove cast
12041205
break;
12051206
case Common.EventType.Merged:

webviews/components/timeline.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import React, { useContext, useRef, useState } from 'react';
77
import { CommentView } from './comment';
88
import Diff from './diff';
9-
import { addIcon, errorIcon, gitCommitIcon, gitMergeIcon, loadingIcon, tasklistIcon, threeBars } from './icon';
9+
import { addIcon, checkIcon, circleFilledIcon, closeIcon, errorIcon, gitCommitIcon, gitMergeIcon, loadingIcon, tasklistIcon, threeBars } from './icon';
1010
import { nbsp } from './space';
1111
import { Timestamp } from './timestamp';
1212
import { AuthorLink, Avatar } from './user';
@@ -105,6 +105,20 @@ export const Timeline = ({ events, isIssue }: { events: TimelineEvent[], isIssue
105105

106106
export default Timeline;
107107

108+
109+
function CommitStateIcon({ status }: { status: 'EXPECTED' | 'ERROR' | 'FAILURE' | 'PENDING' | 'SUCCESS' | undefined; }) {
110+
switch (status) {
111+
case 'PENDING':
112+
return circleFilledIcon;
113+
case 'SUCCESS':
114+
return checkIcon;
115+
case 'FAILURE':
116+
case 'ERROR':
117+
return closeIcon;
118+
}
119+
return null;
120+
}
121+
108122
const CommitEventView = (event: CommitEvent) => {
109123
const context = useContext(PullRequestContext);
110124
const [clickedElement, setClickedElement] = useState<'title' | 'sha' | undefined>(undefined);
@@ -139,6 +153,9 @@ const CommitEventView = (event: CommitEvent) => {
139153
</div>
140154
</div>
141155
<div className="timeline-detail">
156+
<div className='status-section'>
157+
<CommitStateIcon status={event.status} />
158+
</div>
142159
<a
143160
className="sha"
144161
onClick={(e) => handleCommitClick(e, 'sha')}

0 commit comments

Comments
 (0)