@yuki-no/plugin-release-tracking
Version:
Release tracking plugin for yuki-no - Tracks release status for commits and manages issue labels/comments automatically
39 lines (38 loc) • 1.97 kB
JavaScript
import { getLastIssueComment } from './getLastIssueComments';
import { getReleaseTrackingLabels } from './getReleaseTrackingLabels';
import { log } from '@yuki-no/plugin-sdk/utils/log';
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 github.api.issues.createComment({
...github.ownerAndRepo,
issue_number: issue.number,
body: 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');
};