yuki-no-plugin-release-tracking
Version:
Release tracking plugin for yuki-no - Tracks release status for commits and manages issue labels/comments automatically
49 lines (48 loc) • 2.48 kB
JavaScript
import { updateIssueCommentByRelease } from './updateIssueCommentsByRelease';
import { updateIssueLabelsByRelease } from './updateIssueLabelsByRelease';
import { Git } from '@gumball12/yuki-no/git/core';
import { getRelease } from '@gumball12/yuki-no/git/getRelease';
import { hasAnyRelease } from '@gumball12/yuki-no/git/hasAnyRelease';
import { GitHub } from '@gumball12/yuki-no/github/core';
import { getOpenedIssues, } from '@gumball12/yuki-no/github/getOpenedIssues';
import { log, mergeArray, uniqueWith } from '@gumball12/yuki-no/utils';
const releaseTrackingPlugin = {
name: 'release-tracking',
async onAfterCreateIssue(ctx) {
const git = new Git({ ...ctx.config, repoSpec: ctx.config.headRepoSpec });
const github = new GitHub({
...ctx.config,
repoSpec: ctx.config.upstreamRepoSpec,
});
await processReleaseTrackingForIssue(github, git, ctx.result);
},
async onExit(ctx) {
const git = new Git({ ...ctx.config, repoSpec: ctx.config.headRepoSpec });
const github = new GitHub({
...ctx.config,
repoSpec: ctx.config.upstreamRepoSpec,
});
await processReleaseTracking(github, git);
},
};
export default releaseTrackingPlugin;
const processReleaseTracking = async (github, git, additionalIssues = []) => {
log('I', '=== Release tracking started ===');
const openedIssues = await getOpenedIssues(github);
const releaseTrackingIssues = uniqueWith(mergeArray(openedIssues, additionalIssues), ({ hash }) => hash);
const releaseInfos = releaseTrackingIssues.map(issue => getRelease(git, issue.hash));
const releasesAvailable = hasAnyRelease(git);
for (let ind = 0; ind < releaseInfos.length; ind++) {
const releaseInfo = releaseInfos[ind];
const openedIssue = releaseTrackingIssues[ind];
await updateIssueLabelsByRelease(github, openedIssue, releaseInfo);
await updateIssueCommentByRelease(github, openedIssue, releaseInfo, releasesAvailable);
}
log('S', `releaseTracking :: Release information updated for ${releaseTrackingIssues.length} issues`);
};
const processReleaseTrackingForIssue = async (github, git, issue) => {
const releaseInfo = getRelease(git, issue.hash);
const releasesAvailable = hasAnyRelease(git);
await updateIssueLabelsByRelease(github, issue, releaseInfo);
await updateIssueCommentByRelease(github, issue, releaseInfo, releasesAvailable);
};