-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
601 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import * as core from '@actions/core'; | ||
import * as github from '@actions/github'; | ||
import type { components } from '@octokit/openapi-types'; | ||
|
||
import packageJSON from '../../package.json'; | ||
|
||
type Milestone = components['schemas']['nullable-milestone']; | ||
|
||
const { version } = packageJSON; | ||
|
||
const repo = { | ||
owner: 'bangumi', | ||
repo: 'frontend', | ||
}; | ||
|
||
async function main() { | ||
const githubToken = process.env.GH_TOKEN; | ||
if (!githubToken) { | ||
throw new Error('process.env.GH_TOKEN is empty'); | ||
} | ||
|
||
const octokit = github.getOctokit(githubToken); | ||
|
||
const milestones = await octokit.paginate('GET /repos/{owner}/{repo}/milestones', { ...repo }); | ||
|
||
let oldNextMilestone: undefined | Milestone; | ||
|
||
for (const milestone of milestones) { | ||
if (milestone.title === 'next') { | ||
oldNextMilestone = milestone; | ||
break; | ||
} | ||
} | ||
|
||
if (!oldNextMilestone) { | ||
core.info('missing previous `next` milestone, skipping script'); | ||
return; | ||
} | ||
|
||
const openIssues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', { | ||
...repo, | ||
state: 'open', | ||
milestone: oldNextMilestone.number.toString(), | ||
}); | ||
|
||
core.info(`close and rename old milestone ${oldNextMilestone.number}`); | ||
await octokit.request('PATCH /repos/{owner}/{repo}/milestones/{milestone_number}', { | ||
...repo, | ||
milestone_number: oldNextMilestone.number, | ||
title: version, | ||
state: 'closed', | ||
description: | ||
'# script is still moving issues, DO NOT EDIT IT NOW\n' + | ||
(oldNextMilestone.description ?? ''), | ||
}); | ||
|
||
core.info(`create new next milestone`); | ||
const newNextMileStone = await octokit.request('POST /repos/{owner}/{repo}/milestones', { | ||
...repo, | ||
title: 'next', | ||
description: '# script is still moving issues, DO NOT EDIT IT NOW', | ||
}); | ||
|
||
for (const issue of openIssues) { | ||
core.info(`moving issue ${issue.number} to new milestone ${newNextMileStone.data.number}`); | ||
await octokit.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', { | ||
...repo, | ||
issue_number: issue.number, | ||
milestone: newNextMileStone.data.number, | ||
}); | ||
} | ||
|
||
core.info(`restore issue description`); | ||
await octokit.request('PATCH /repos/{owner}/{repo}/milestones/{milestone_number}', { | ||
...repo, | ||
milestone_number: oldNextMilestone.number, | ||
description: oldNextMilestone.description ?? '', | ||
}); | ||
|
||
core.info(`update new issue next title`); | ||
await octokit.request('PATCH /repos/{owner}/{repo}/milestones/{milestone_number}', { | ||
...repo, | ||
milestone_number: newNextMileStone.data.number, | ||
title: 'next', | ||
description: 'milestone for next release', | ||
}); | ||
} | ||
|
||
await main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.