Skip to content

Commit

Permalink
[Refactor] log checks in bin/can-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Ranger11 authored and ljharb committed Nov 7, 2021
1 parent c28af03 commit 6d01272
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
11 changes: 11 additions & 0 deletions bin/can-merge
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const getSHA = require('../utils/getSHA');

const runQuery = require('../utils/runQuery');
const evaluatePullRequest = require('../utils/evaluatePullRequest');
const evaluateChecks = require('../utils/evaluateChecks');
const logger = require('../utils/logger');
const parsePullRequest = require('../utils/parsePullRequest');
const pullRequestStatus = require('../utils/models/pullRequestStatus');
Expand Down Expand Up @@ -70,6 +71,16 @@ runQuery(args.repo, args.pr, token).then((response) => {
if (status !== pullRequestStatus.MERGEABLE) {
process.exitCode = (process.exitCode ?? 0) + 1;
}
if (status === pullRequestStatus.STATUS_FAILURE || status === pullRequestStatus.STATUS_PENDING) {
const { failure, pending } = evaluateChecks(pr);

if (pending.length > 0) {
console.info(chalk.yellowBright(`Pending Checks (${pending.length}): ${pending.join(', ')}`));
}
if (failure.length > 0) {
console.info(chalk.redBright(`Failed Checks (${failure.length}): ${failure.join(', ')}`));
}
}
});
}
});
Expand Down
24 changes: 5 additions & 19 deletions utils/evaluateChecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

'use strict';

const chalk = require('chalk');

const parseChecks = (statusCheckRollup, name) => {
let pending = [];
let failure = [];
Expand All @@ -27,32 +25,20 @@ const parseChecks = (statusCheckRollup, name) => {
return { failure, pending };
};

module.exports = function evaluateChecks(response) {
const { repository: { pullRequest: { commits: { nodes: [{ commit: { statusCheckRollup } }] } } } } = response;
module.exports = function evaluateChecks(pullRequest) {
const { commits: { nodes: [{ commit: { statusCheckRollup } }] } } = pullRequest;

for (const ctx of statusCheckRollup.contexts.nodes) {
if (ctx.__typename === 'StatusContext' && ctx.state !== 'SUCCESS') {
const { failure, pending } = parseChecks(statusCheckRollup, 'statusCheck');
if (pending.length) {
console.info(chalk.yellowBright(`Pending Checks (${pending.length}): ${pending.join(', ')}`));
}
if (failure.length) {
console.info(chalk.redBright(`Failed Checks (${failure.length}): ${failure.join(', ')}`));
}
return false;
return { failure, pending };
} else if (
ctx.__typename === 'CheckRun' && ctx.conclusion !== 'SUCCESS'
) {
const { failure, pending } = parseChecks(statusCheckRollup, 'checkRun');
if (pending.length > 0) {
console.info(chalk.yellowBright(`Pending Checks (${pending.length}): ${pending.join(', ')}`));
}
if (failure.length > 0) {
console.info(chalk.redBright(`Failed Checks (${failure.length}): ${failure.join(', ')}`));
}
return false;
return { failure, pending };
}
}

return true;
return { failure: [], pending: [] };
};

0 comments on commit 6d01272

Please sign in to comment.