diff --git a/src/lib/get_comments.mjs b/src/lib/get_comments.mjs index c2268a4..7199d79 100644 --- a/src/lib/get_comments.mjs +++ b/src/lib/get_comments.mjs @@ -1,3 +1,5 @@ +import logger from './logger.mjs'; + export default async function getEvents(repo, { body, actor } = {}) { const events = await repo.events.fetch(); @@ -13,11 +15,30 @@ export default async function getEvents(repo, { body, actor } = {}) { return items .map(comment => { - // only comments created by specific user - if (comment.type !== 'IssueCommentEvent') return false; - if (comment.payload.action !== 'created') return false; - if (comment.actor.login !== actor) return false; - if (body && !body.test(comment.payload.comment.body)) return false; + let skip = false; + const isComment = comment.type === 'IssueCommentEvent'; + const bodyMatch = isComment && (!body || body.test(comment.payload.comment.body)); + const isActor = comment.actor.login === actor; + + // skip events that don't match the criteria + if (!isComment) skip = true; + if (comment.payload.action !== 'created') skip = true; + if (!isActor) skip = true; + if (isComment && !bodyMatch) skip = true; + + if (skip) { + if (isActor) { + logger.debug( + `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)})` + ); + } + return false; + } + + logger.debug(`PROCESS #${comment.payload.issue.number}`); return { id: comment.id,