diff --git a/src/index.mjs b/src/index.mjs index 7cecb45..2658b49 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -41,19 +41,30 @@ async function ghActionBot() { // keep track of comments that have been processed history.add(comment); + logger.debug(`PROCESS COMMENT ON #${comment.number}`); + const pull = await getPull(repo, comment.number); + // filter out any closed pulls if (pull.state !== 'open') { - logger.debug(`SKIP #${pull.number}: state is ${pull.state}`); - return false; // filter out any closed pulls + logger.debug(`SKIP PULL #${pull.number}: state is ${pull.state}`); + return false; } + + // filter on owner if (PULL_AUTHOR_FILTER && pull.owner !== PULL_AUTHOR_FILTER) { - logger.debug(`SKIP #${pull.number}: author is ${pull.owner}`); - return false; // filter on owner + logger.debug(`SKIP PULL #${pull.number}: author is ${pull.owner}`); + return false; } + + // filter on label if (PULL_LABEL_FILTER && !pull.labels.includes(PULL_LABEL_FILTER)) { - logger.debug(`SKIP #${pull.number}: labels are ${pull.labels.join(',')}`); - return false; // filter on label + logger.debug( + `SKIP PULL #${ + pull.number + }: labels missing '${PULL_LABEL_FILTER}', found ${pull.labels.join(',')}` + ); + return false; } return { comment, pull }; @@ -64,20 +75,18 @@ async function ghActionBot() { pulls.map(async ({ pull, comment }) => { const commit = await getCommits(repo, pull.number, true); const buildStatus = await getCommitStatus(repo, commit.sha); + // do nothing if the build has not started, or is pending or successful if (!buildStatus || buildStatus.state === 'pending' || buildStatus.state === 'success') { - logger.debug(`SKIP #${pull.number}: build status is ${buildStatus.state}`); + logger.debug(`SKIP PULL #${pull.number}: build status is ${buildStatus.state}`); return false; } + return { comment, pull, commit, buildStatus }; }) )).filter(Boolean); - if (records.length) { - logger.log(`Found ${records.length} outstanding failures`); - } else { - logger.debug(`Found ${records.length} outstanding failures`); - } + logger.log(`${records.length ? `Found ${records.length}` : `≧(´▽`)≦ No`} outstanding failures`); await Promise.all( records.map(record => diff --git a/src/lib/get_comments.mjs b/src/lib/get_comments.mjs index 7199d79..c08ec01 100644 --- a/src/lib/get_comments.mjs +++ b/src/lib/get_comments.mjs @@ -1,5 +1,10 @@ import logger from './logger.mjs'; +function truncate(str, len = 26) { + if (str.length <= len) return str; + return `${str.slice(0, len)}...`; +} + export default async function getEvents(repo, { body, actor } = {}) { const events = await repo.events.fetch(); @@ -32,14 +37,12 @@ export default async function getEvents(repo, { body, actor } = {}) { `SKIP EVENT ${isComment ? `#${comment.payload.issue.number}` : comment.id}: ${ comment.type } ${comment.payload.action} by ${comment.actor.login}`, - isComment && !bodyMatch && `(${comment.payload.comment.body.slice(0, 30)})` + isComment && !bodyMatch && `(${truncate(comment.payload.comment.body)})` ); } return false; } - logger.debug(`PROCESS #${comment.payload.issue.number}`); - return { id: comment.id, number: comment.payload.issue.number,