Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ae28a3

Browse files
authored
ci: Add release labels job to pr.yaml to sync labels/title (#5724)
1 parent8db87c6 commit8ae28a3

File tree

1 file changed

+119
-4
lines changed

1 file changed

+119
-4
lines changed

‎.github/workflows/pr.yaml‎

Lines changed: 119 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,135 @@
1-
name:Lint PR
1+
name:Pull Request
22

33
on:
44
pull_request_target:
55
types:
6+
-labeled
7+
-unlabeled
68
-opened
79
-reopened
810
-edited
9-
-synchronize
11+
12+
# Only run one instance per PR to ensure in-order execution.
13+
concurrency:pr-${{ github.ref }}
1014

1115
jobs:
12-
main:
13-
name:Validate PR title
16+
lint-title:
17+
name:Lint title
1418
runs-on:ubuntu-latest
1519
steps:
1620
-uses:amannn/action-semantic-pull-request@v5
1721
env:
1822
GITHUB_TOKEN:${{ secrets.GITHUB_TOKEN }}
1923
with:
2024
requireScope:false
25+
26+
release-labels:
27+
name:Release labels
28+
runs-on:ubuntu-latest
29+
# Depend on lint so that title is Conventional Commits-compatible.
30+
needs:[lint-title]
31+
# Skip tagging for draft PRs.
32+
if:${{ success() && !github.event.pull_request.draft }}
33+
steps:
34+
-uses:actions/github-script@v6
35+
with:
36+
# This script ensures PR title and labels are in sync:
37+
#
38+
# When release/breaking label is:
39+
# - Added, rename PR title to include ! (e.g. feat!:)
40+
# - Removed, rename PR title to strip ! (e.g. feat:)
41+
#
42+
# When title is:
43+
# - Renamed (+!), add the release/breaking label
44+
# - Renamed (-!), remove the release/breaking label
45+
script:|
46+
const releaseLabels = {
47+
breaking: "release/breaking",
48+
}
49+
50+
const { action, changes, label, pull_request } = context.payload
51+
const { title } = pull_request
52+
const labels = pull_request.labels.map((label) => label.name)
53+
const isBreakingTitle = isBreaking(title)
54+
55+
// Debug information.
56+
console.log("Action: %s", action)
57+
console.log("Title: %s", title)
58+
console.log("Labels: %s", labels.join(", "))
59+
60+
const params = {
61+
issue_number: context.issue.number,
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
}
65+
66+
if (action === "opened" || action === "reopened") {
67+
if (isBreakingTitle && !labels.includes(releaseLabels.breaking)) {
68+
console.log('Add "%s" label', releaseLabels.breaking)
69+
await github.rest.issues.addLabels({
70+
...params,
71+
labels: [releaseLabels.breaking],
72+
})
73+
}
74+
}
75+
76+
if (action === "edited" && changes.title) {
77+
if (isBreakingTitle && !labels.includes(releaseLabels.breaking)) {
78+
console.log('Add "%s" label', releaseLabels.breaking)
79+
await github.rest.issues.addLabels({
80+
...params,
81+
labels: [releaseLabels.breaking],
82+
})
83+
}
84+
85+
if (!isBreakingTitle && labels.includes(releaseLabels.breaking)) {
86+
const wasBreakingTitle = isBreaking(changes.title.from)
87+
if (wasBreakingTitle) {
88+
console.log('Remove "%s" label', releaseLabels.breaking)
89+
await github.rest.issues.removeLabel({
90+
...params,
91+
name: releaseLabels.breaking,
92+
})
93+
} else {
94+
console.log('Rename title from "%s" to "%s"', title, toBreaking(title))
95+
await github.rest.issues.update({
96+
...params,
97+
title: toBreaking(title),
98+
})
99+
}
100+
}
101+
}
102+
103+
if (action === "labeled") {
104+
if (label.name === releaseLabels.breaking && !isBreakingTitle) {
105+
console.log('Rename title from "%s" to "%s"', title, toBreaking(title))
106+
await github.rest.issues.update({
107+
...params,
108+
title: toBreaking(title),
109+
})
110+
}
111+
}
112+
113+
if (action === "unlabeled") {
114+
if (label.name === releaseLabels.breaking && isBreakingTitle) {
115+
console.log('Rename title from "%s" to "%s"', title, fromBreaking(title))
116+
await github.rest.issues.update({
117+
...params,
118+
title: fromBreaking(title),
119+
})
120+
}
121+
}
122+
123+
function isBreaking(t) {
124+
return t.split(" ")[0].endsWith("!:")
125+
}
126+
127+
function toBreaking(t) {
128+
const parts = t.split(" ")
129+
return [parts[0].replace(/:$/, "!:"), ...parts.slice(1)].join(" ")
130+
}
131+
132+
function fromBreaking(t) {
133+
const parts = t.split(" ")
134+
return [parts[0].replace(/!:$/, ":"), ...parts.slice(1)].join(" ")
135+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp