Skip to content

Commit 545b2b0

Browse files
committed
fix: label name
1 parent c286066 commit 545b2b0

File tree

2 files changed

+115
-1
lines changed

2 files changed

+115
-1
lines changed

.github/scripts/post_release.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
const { LABEL_PENDING_RELEASE, LABEL_RELEASED } = require("./constants");
2+
3+
/**
4+
* Fetch issues using GitHub REST API
5+
*
6+
* @param {object} gh_client - Pre-authenticated REST client (Octokit)
7+
* @param {string} org - GitHub Organization
8+
* @param {string} repository - GitHub repository
9+
* @param {string} state - GitHub issue state (open, closed)
10+
* @param {string} label - Comma-separated issue labels to fetch
11+
* @return {Object[]} issues - Array of issues matching params
12+
* @see {@link https://octokit.github.io/rest.js/v18#usage|Octokit client}
13+
*/
14+
15+
const fetchIssues = async ({
16+
gh_client,
17+
org,
18+
repository,
19+
state = "all",
20+
label = LABEL_PENDING_RELEASE,
21+
}) => {
22+
try {
23+
const { data: issues } = await gh_client.rest.issues.listForRepo({
24+
owner: org,
25+
repo: repository,
26+
state: state,
27+
labels: label,
28+
});
29+
30+
return issues;
31+
} catch (error) {
32+
console.error(error);
33+
throw new Error("Failed to fetch issues");
34+
}
35+
36+
};
37+
38+
/**
39+
* Notify new release and close staged GitHub issue
40+
*
41+
* @param {object} gh_client - Pre-authenticated REST client (Octokit)
42+
* @param {string} owner - GitHub Organization
43+
* @param {string} repository - GitHub repository
44+
* @param {string} release_version - GitHub Release version
45+
* @see {@link https://octokit.github.io/rest.js/v18#usage|Octokit client}
46+
*/
47+
48+
const notifyRelease = async ({
49+
gh_client,
50+
owner,
51+
repository,
52+
release_version,
53+
}) => {
54+
const release_url = `https://github.com/${owner}/${repository}/releases/tag/v${release_version}`;
55+
56+
const issues = await fetchIssues({
57+
gh_client: gh_client,
58+
org: owner,
59+
repository: repository,
60+
});
61+
62+
issues.forEach(async (issue) => {
63+
console.info(`Updating issue number ${issue.number}`);
64+
65+
const comment = `This is now released under [${release_version}](${release_url}) version!`;
66+
try {
67+
await gh_client.rest.issues.createComment({
68+
owner: owner,
69+
repo: repository,
70+
body: comment,
71+
issue_number: issue.number,
72+
});
73+
} catch (error) {
74+
console.error(error);
75+
throw new Error(`Failed to update issue ${issue.number} about ${release_version} release`)
76+
}
77+
78+
79+
// Close issue and remove staged label; keep existing ones
80+
const labels = issue.labels
81+
.filter((label) => label.name != LABEL_PENDING_RELEASE)
82+
.map((label) => label.name);
83+
84+
try {
85+
await gh_client.rest.issues.update({
86+
repo: repository,
87+
owner: owner,
88+
issue_number: issue.number,
89+
state: "closed",
90+
labels: [...labels, LABEL_RELEASED],
91+
});
92+
} catch (error) {
93+
console.error(error);
94+
throw new Error("Failed to close issue")
95+
}
96+
97+
console.info(`Issue number ${issue.number} closed and updated`);
98+
});
99+
};
100+
101+
// context: https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts
102+
103+
module.exports = async ({ github, context }) => {
104+
const { RELEASE_VERSION } = process.env;
105+
console.log(`Running post-release script for ${RELEASE_VERSION} version`);
106+
107+
await notifyRelease({
108+
gh_client: github,
109+
owner: context.repo.owner,
110+
repository: context.repo.repo,
111+
release_version: RELEASE_VERSION,
112+
});
113+
};

MAINTAINERS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ These are the most common labels used by maintainers to triage issues, pull requ
8484
| type/deprecation | This item contains code deprecation | |
8585
| type/duplicate | This issue is a duplicate of an existing one | Analytics |
8686
| type/feature-request | Issue requesting new or enhancements to existing features | Issue template |
87-
| type/feature | PRs that introduce new features or minor changes | PR automation |
87+
| type/feature | PRs that introduce new features | PR automation |
88+
| type/enhancement | PRs that introduce minor changes, usually to existing features | PR automation |
8889
| type/RFC | Technical design documents related to a feature request | |
8990
| type/internal | PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.) | PR automation |
9091
| type/tests | PRs that add or change tests | PR automation |

0 commit comments

Comments
 (0)