Skip to content

Commit 7a9b972

Browse files
committed
Render external review status in feature links.
1 parent 33441f4 commit 7a9b972

File tree

5 files changed

+436
-9
lines changed

5 files changed

+436
-9
lines changed

client-src/elements/chromedash-link.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// @ts-check
22

3+
import '@github/relative-time-element';
34
import {css, html, LitElement} from 'lit';
45
import {ifDefined} from 'lit/directives/if-defined.js';
56
import {SHARED_STYLES} from '../css/shared-css';
7+
import {ExternalReviewer} from './external-reviewers';
68

79
// LINK_TYPES should be consistent with the server link_helpers.py
810
const LINK_TYPE_CHROMIUM_BUG = 'chromium_bug';
@@ -97,7 +99,7 @@ function enhanceGithubIssueLink(featureLink, text) {
9799
}
98100
const information = featureLink.information;
99101
const assignee = information.assignee_login;
100-
const createdAt = information.created_at;
102+
const createdAt = new Date(information.created_at);
101103
const closedAt = information.closed_at;
102104
const updatedAt = information.updated_at;
103105
const state = information.state;
@@ -109,6 +111,45 @@ function enhanceGithubIssueLink(featureLink, text) {
109111
const typePath = featureLink.url.split('/').slice(-2)[0];
110112
const type = typePath === 'issues' ? 'Issue' : typePath === 'pull' ? 'Pull Request' : typePath;
111113

114+
// If this issue is an external review of the feature, find the summary description.
115+
const externalReviewer = ExternalReviewer.get(repo);
116+
let stateDescription = undefined;
117+
let stateVariant = undefined;
118+
if (externalReviewer) {
119+
for (const label of information.labels) {
120+
const labelInfo = externalReviewer.label(label);
121+
if (labelInfo) {
122+
({description: stateDescription, variant: stateVariant} = labelInfo);
123+
break;
124+
}
125+
}
126+
}
127+
128+
if (stateVariant === undefined) {
129+
if (state === 'open') {
130+
const age = Date.now() - createdAt.getTime();
131+
stateDescription = html`Opened <relative-time .date=${createdAt} format="relative" precision="day" threshold="P100Y">on ${_dateTimeFormat.format(createdAt)}</relative-time>`;
132+
const week = 7 * 24 * 60 * 60 * 1000;
133+
stateVariant = 'success';
134+
if (externalReviewer) {
135+
// If this is an issue asking for external review, having it filed too recently is a warning
136+
// sign, which we'll indicate using the tag's color.
137+
if (age < 2 * week) {
138+
stateVariant = 'danger';
139+
} else if (age < 4 * week) {
140+
stateVariant = 'warning';
141+
} else {
142+
// Still only neutral if the reviewer hasn't given a position yet.
143+
stateVariant = 'neutral';
144+
}
145+
}
146+
} else {
147+
console.assert(state === 'closed');
148+
stateDescription = 'Closed';
149+
stateVariant = 'neutral';
150+
}
151+
}
152+
112153
if (!text) {
113154
text = title;
114155
}
@@ -169,8 +210,8 @@ function enhanceGithubIssueLink(featureLink, text) {
169210
<sl-tooltip style="--sl-tooltip-arrow-size: 0;--max-width: 50vw;">
170211
<div slot="content">${renderTooltipContent()}</div>
171212
<sl-tag>
172-
<img src="https://docs.github.com/assets/cb-600/images/site/favicon.png" alt="icon" class="icon" />
173-
<sl-badge size="small" variant="${state === 'open' ? 'success' : 'neutral'}">${state}</sl-badge>
213+
<img src=${externalReviewer?.icon ?? 'https://docs.github.com/assets/cb-600/images/site/favicon.png'} alt="icon" class="icon" />
214+
<sl-badge size="small" variant=${stateVariant}>${stateDescription}</sl-badge>
174215
${_formatLongText(`#${number} ` + text)}
175216
</sl-tag>
176217
</sl-tooltip>
@@ -337,8 +378,8 @@ export class ChromedashLink extends LitElement {
337378
}
338379
339380
sl-badge::part(base) {
340-
height: 14px;
341-
padding: 4px;
381+
display: inline;
382+
padding: 0 4px;
342383
border-width: 0;
343384
text-transform: capitalize;
344385
font-weight: 400;

0 commit comments

Comments
 (0)