react/scripts/release/get-build-id-for-commit.js
Andrew Clark f8b6969da6
Add --commit param to release scripts (#20703)
Alternative to `--build`. Uses same logic as sizebot and www
sync script.

Immediate motivation is I want sizebot to use the
`download-experimental-build` command in CI. Will do that next.
2021-02-01 08:27:59 -08:00

35 lines
961 B
JavaScript

'use strict';
const fetch = require('node-fetch');
async function getBuildIdForCommit(sha) {
let ciBuildId = null;
const statusesResponse = await fetch(
`https://api.github.com/repos/facebook/react/commits/${sha}/status`
);
if (!statusesResponse.ok) {
throw Error('Could not find commit for: ' + sha);
}
const {statuses, state} = await statusesResponse.json();
if (state === 'failure') {
throw new Error(`Base commit is broken: ${sha}`);
}
for (let i = 0; i < statuses.length; i++) {
const status = statuses[i];
if (status.context === `ci/circleci: process_artifacts_combined`) {
if (status.state === 'success') {
ciBuildId = /\/facebook\/react\/([0-9]+)/.exec(status.target_url)[1];
break;
}
if (status.state === 'pending') {
throw new Error(`Build job for base commit is still pending: ${sha}`);
}
}
}
return ciBuildId;
}
module.exports = getBuildIdForCommit;