UNPKG

@yuki-no/plugin-release-tracking

Version:

Release tracking plugin for yuki-no - Tracks release status for commits and manages issue labels/comments automatically

32 lines (31 loc) 1.32 kB
export const getLastIssueComment = async (github, issueNumber) => { const response = await github.api.issues.listComments({ ...github.ownerAndRepo, issue_number: issueNumber, }); const comments = response.data.map(item => ({ body: item.body, })); const lastReleaseComment = findLastReleaseComment(comments)?.body; if (!lastReleaseComment) { return ''; } return extractReleaseComment(lastReleaseComment); }; const findLastReleaseComment = (comments) => comments.findLast(isReleaseTrackingComment); const isReleaseTrackingComment = ({ body }) => { if (!body) { return false; } const hasPrereleaseComment = body.includes('- pre-release: none') || body.match(/- pre-release: \[.+?\]\(https:\/\/github\.com\/.+?\)/) !== null; const hasReleaseComment = body.includes('- release: none') || body.match(/- release: \[.+?\]\(https:\/\/github\.com\/.+?\)/) !== null; return hasPrereleaseComment && hasReleaseComment; }; const extractReleaseComment = (body) => { const lines = body.split('\n'); const preReleaseComment = lines.find(line => line.startsWith('- pre-release: ')); const releaseComment = lines.find(line => line.startsWith('- release: ')); return [preReleaseComment, releaseComment].join('\n'); };