fix(gerrit-tvl): Support all documented Buildkite job statuses
I'm not sure where the previous list originated, but it was missing some officially documented statuses. However, the API definitely returns statuses that are documented to only appear in other types, so this commit simply maps ALL statuses that Buildkite has documented for any type. Also adds a log statement in case we encounter a brand new, unknown, undocumented status. Change-Id: Iff003a3bd2608702019ae0f4137958435ad0856f Reviewed-on: https://cl.tvl.fyi/c/depot/+/4888 Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Reviewed-by: lukegb <lukegb@tvl.fyi>
This commit is contained in:
parent
058bf61193
commit
e1ffaee1dd
1 changed files with 58 additions and 12 deletions
|
@ -24,6 +24,59 @@ function formatDuration(from, to) {
|
||||||
return `${hoursTook}hr ${minutesRemainder}min`;
|
return `${hoursTook}hr ${minutesRemainder}min`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maps the status of a Buildkite *job* to the statuses available for
|
||||||
|
// a Gerrit check.
|
||||||
|
//
|
||||||
|
// Note that jobs can have statuses that, according to the Buildkite
|
||||||
|
// documentation, are only available for builds, and maybe vice-versa.
|
||||||
|
// To deal with this we simply cover all statuses for all types here.
|
||||||
|
//
|
||||||
|
// Buildkite job statuses: https://buildkite.com/docs/pipelines/notifications#job-states
|
||||||
|
//
|
||||||
|
// Gerrit check statuses: https://gerrit.googlesource.com/gerrit/+/v3.4.0/polygerrit-ui/app/api/checks.ts#167
|
||||||
|
//
|
||||||
|
// TODO(tazjin): Use SCHEDULED status once we have upgraded Gerrit
|
||||||
|
// past 3.4
|
||||||
|
function jobStateToCheckRunStatus(state) {
|
||||||
|
const status = {
|
||||||
|
// Statuses documented for both types
|
||||||
|
'blocked': 'RUNNABLE',
|
||||||
|
'canceled': 'COMPLETED',
|
||||||
|
'canceling': 'RUNNING',
|
||||||
|
'running': 'RUNNING',
|
||||||
|
'scheduled': 'RUNNABLE',
|
||||||
|
'skipped': 'COMPLETED',
|
||||||
|
|
||||||
|
// Statuses only documented for builds
|
||||||
|
'creating': 'RUNNABLE',
|
||||||
|
'failed': 'COMPLETED',
|
||||||
|
'not_run': 'COMPLETED',
|
||||||
|
'passed': 'COMPLETED',
|
||||||
|
|
||||||
|
// Statuses only documented for jobs
|
||||||
|
'accepted': 'RUNNABLE',
|
||||||
|
'assigned': 'RUNNABLE',
|
||||||
|
'blocked_failed': 'COMPLETED',
|
||||||
|
'broken': 'COMPLETED',
|
||||||
|
'finished': 'COMPLETED',
|
||||||
|
'limited': 'RUNNABLE',
|
||||||
|
'limiting': 'RUNNABLE',
|
||||||
|
'pending': 'RUNNABLE',
|
||||||
|
'timed_out': 'COMPLETED',
|
||||||
|
'timing_out': 'RUNNING',
|
||||||
|
'unblocked': 'RUNNABLE',
|
||||||
|
'unblocked_failed': 'COMPLETED',
|
||||||
|
'waiting': 'RUNNABLE',
|
||||||
|
'waiting_failed': 'COMPLETED',
|
||||||
|
}[state];
|
||||||
|
|
||||||
|
if (!status) {
|
||||||
|
console.log(`unknown Buildkite job state: ${state}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
const tvlChecksProvider = {
|
const tvlChecksProvider = {
|
||||||
async fetch(change) {
|
async fetch(change) {
|
||||||
let {changeNumber, patchsetNumber, repo} = change;
|
let {changeNumber, patchsetNumber, repo} = change;
|
||||||
|
@ -58,32 +111,25 @@ const tvlChecksProvider = {
|
||||||
const build = respJSON[i];
|
const build = respJSON[i];
|
||||||
|
|
||||||
for (let job of build.jobs) {
|
for (let job of build.jobs) {
|
||||||
// TODO(lukegb): add the ability to retry these (sometimes whitby runs out of disk...)
|
// TODO(lukegb): add the ability to retry these
|
||||||
const checkRun = {
|
const checkRun = {
|
||||||
attempt: attempt,
|
attempt: attempt,
|
||||||
externalId: job.id,
|
externalId: job.id,
|
||||||
checkName: job.name,
|
checkName: job.name,
|
||||||
checkDescription: job.command,
|
checkDescription: job.command,
|
||||||
checkLink: job.web_url,
|
checkLink: job.web_url,
|
||||||
status: {
|
status: jobStateToCheckRunStatus(job.state),
|
||||||
'running': 'RUNNING',
|
|
||||||
'scheduled': 'RUNNABLE',
|
|
||||||
'passed': 'COMPLETED',
|
|
||||||
'failed': 'COMPLETED',
|
|
||||||
'blocked': 'RUNNABLE',
|
|
||||||
'canceled': 'COMPLETED',
|
|
||||||
'canceling': 'RUNNING',
|
|
||||||
'skipped': 'COMPLETED',
|
|
||||||
'not_run': 'COMPLETED',
|
|
||||||
}[job.state],
|
|
||||||
labelName: 'Verified',
|
labelName: 'Verified',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (job.scheduled_at) {
|
if (job.scheduled_at) {
|
||||||
checkRun.scheduledTimestamp = new Date(job.scheduled_at);
|
checkRun.scheduledTimestamp = new Date(job.scheduled_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (job.started_at) {
|
if (job.started_at) {
|
||||||
checkRun.startedTimestamp = new Date(job.started_at);
|
checkRun.startedTimestamp = new Date(job.started_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (job.finished_at) {
|
if (job.finished_at) {
|
||||||
checkRun.finishedTimestamp = new Date(job.finished_at);
|
checkRun.finishedTimestamp = new Date(job.finished_at);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue