UNPKG

yuki-no-plugin-release-tracking

Version:

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

36 lines (35 loc) 1.99 kB
import { getReleaseTrackingLabels } from './getReleaseTrackingLabels'; import { createIssueComment } from '@gumball12/yuki-no/github/createIssueComment'; import { getLastIssueComment } from '@gumball12/yuki-no/github/getLastIssueComments'; import { log } from '@gumball12/yuki-no/utils'; export const updateIssueCommentByRelease = async (github, issue, releaseInfo, releasesAvailable) => { const comment = await getLastIssueComment(github, issue.number); const isReleased = comment.includes('- release: ['); log('I', `updateIssueCommentByRelease :: Attempting to add #${issue.number} comment`); if (isReleased) { log('I', 'updateIssueCommentByRelease :: Release comment already exists'); return; } const nextComment = createReleaseComment(github, releaseInfo, releasesAvailable); log('I', `updateIssueCommentByRelease :: Creating comment (${nextComment})`); if (nextComment === comment) { log('S', 'updateIssueCommentByRelease :: Not added (identical comment already exists)'); return; } await createIssueComment(github, issue.number, nextComment); log('S', 'updateIssueCommentByRelease :: Comment added successfully'); }; const createReleaseComment = (github, { prerelease, release }, releasesAvailable) => { const pRelContent = `- pre-release: ${prerelease ? `[${prerelease.version}](${prerelease.url})` : 'none'}`; const relContent = `- release: ${release ? `[${release.version}](${release.url})` : 'none'}`; const releaseTrackingLabels = getReleaseTrackingLabels(github); const releaseAvailableContent = !releasesAvailable && [ `> This comment and the \`${releaseTrackingLabels.join(', ')}\` label appear because release-tracking is enabled.`, '> To disable, remove `release-tracking` from the plugins list.', '\n', ].join('\n'); return [releaseAvailableContent, pRelContent, relContent] .filter(Boolean) .join('\n'); };