2017-03-07 04:39:37 -05:00
|
|
|
// Imports
|
|
|
|
import {getEnvVar} from '../common/utils';
|
|
|
|
import {BuildVerifier} from './build-verifier';
|
|
|
|
|
|
|
|
// Run
|
|
|
|
_main();
|
|
|
|
|
|
|
|
// Functions
|
|
|
|
function _main() {
|
|
|
|
const secret = 'unused';
|
|
|
|
const githubToken = getEnvVar('AIO_GITHUB_TOKEN');
|
|
|
|
const repoSlug = getEnvVar('AIO_REPO_SLUG');
|
|
|
|
const organization = getEnvVar('AIO_GITHUB_ORGANIZATION');
|
|
|
|
const allowedTeamSlugs = getEnvVar('AIO_GITHUB_TEAM_SLUGS').split(',');
|
2017-06-18 18:15:07 -04:00
|
|
|
const trustedPrLabel = getEnvVar('AIO_TRUSTED_PR_LABEL');
|
2017-03-07 04:39:37 -05:00
|
|
|
const pr = +getEnvVar('AIO_PREVERIFY_PR');
|
|
|
|
|
2017-06-18 18:15:07 -04:00
|
|
|
const buildVerifier = new BuildVerifier(secret, githubToken, repoSlug, organization, allowedTeamSlugs,
|
|
|
|
trustedPrLabel);
|
2017-03-07 04:39:37 -05:00
|
|
|
|
|
|
|
// Exit codes:
|
2017-06-18 18:15:07 -04:00
|
|
|
// - 0: The PR can be automatically trusted (i.e. author belongs to trusted team or PR has the "trusted PR" label).
|
2017-05-12 04:01:42 -04:00
|
|
|
// - 1: An error occurred.
|
2017-06-18 18:15:07 -04:00
|
|
|
// - 2: The PR cannot be automatically trusted.
|
|
|
|
buildVerifier.getPrIsTrusted(pr).
|
|
|
|
then(isTrusted => {
|
|
|
|
if (!isTrusted) {
|
|
|
|
console.warn(
|
|
|
|
`The PR cannot be automatically verified, because it doesn't have the "${trustedPrLabel}" label and the ` +
|
|
|
|
`the author is not an active member of any of the following teams: ${allowedTeamSlugs.join(', ')}`);
|
2017-03-07 04:39:37 -05:00
|
|
|
}
|
|
|
|
|
2017-06-18 18:15:07 -04:00
|
|
|
process.exit(isTrusted ? 0 : 2);
|
|
|
|
}).
|
|
|
|
catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2017-03-07 04:39:37 -05:00
|
|
|
}
|