-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
fee1724
commit d6144bf
Showing
3 changed files
with
63 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Set Labels | ||
description: Issue or PR title must follow conventional commits. | ||
|
||
inputs: | ||
github-token: | ||
description: The GitHub token to use. | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Set Labels | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ inputs.github-token }} | ||
script: | | ||
const { NUMBER, OWNER, REPO, TITLE } = process.env | ||
const regex = /^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(?:\((\w+)\))?(!)?: (.+)$/; | ||
console.log(`Checking title "${TITLE}"`); | ||
console.log("For more information: https://www.conventionalcommits.org/en/v1.0.0/"); | ||
if (!regex.test(TITLE)) { | ||
throw new Error("Title must follow conventional commit format"); | ||
} | ||
const labels = []; | ||
const match = TITLE.match(regex); | ||
switch (match[1]) { | ||
case "feat": | ||
labels.push("feature"); | ||
break; | ||
default: | ||
labels.push(match[1]); | ||
break; | ||
} | ||
if (match[3]) { | ||
labels.push("major"); | ||
} | ||
else if (labels.includes("feature")) { | ||
labels.push("minor"); | ||
} | ||
else if (labels.includes("fix")) { | ||
labels.push("patch"); | ||
} | ||
console.log(`@${OWNER}/${REPO}#${NUMBER}: Setting labels to ${labels}`); | ||
await github.rest.issues.setLabels({ | ||
owner: OWNER, | ||
repo: REPO, | ||
issue_number: NUMBER, | ||
labels | ||
}); | ||
env: | ||
NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }} | ||
OWNER: ${{ github.repository_owner }} | ||
REPO: ${{ github.event.repository.name }} | ||
TITLE: ${{ github.event.issue.title || github.event.pull_request.title }} |
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