Created
September 6, 2023 21:26
-
-
Save Kalaiselvi84/bdc04f75d76008fc17ded1422cdd88f1 to your computer and use it in GitHub Desktop.
Log-label-pr
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
Run actions/github-script@v6 | |
with: | |
script: const keywords = { | |
"breaking": "kind/breaking", | |
"bug": "kind/bug", | |
"feature": "kind/feature", | |
"cleanup": "kind/cleanup", | |
"documentation": "kind/documentation", | |
"hotfix": "kind/hotfix", | |
"release": "kind/release" | |
}; | |
const prBody = context.payload.pull_request.body; | |
const prLabels = []; | |
if (prBody === null || prBody.trim() === "") { | |
console.log("Pull Request body is empty"); | |
prLabels.push("kind/other"); | |
} else { | |
const regex = /^\s*\/kind\s+(.+)$/m; | |
const match = prBody.match(regex); | |
console.log(`PR body: '${prBody}'`); | |
console.log(`Regex match: '${match}'`); | |
if (match && match[1] in keywords) { | |
const keyword = match[1]; | |
const label = keywords[keyword]; | |
console.log(`Adding label: '${label}' based on keyword '${keyword}'`); | |
prLabels.push(label); | |
} else { | |
console.log(`Adding label: 'kind/other' as no matching keyword found.`); | |
prLabels.push("kind/other"); | |
} | |
} | |
try { | |
github.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.pull_request.number, | |
labels: prLabels | |
}); | |
} catch (error) { | |
console.error(`Error retrieving files: ${error}`); | |
} | |
github-token: *** | |
debug: false | |
user-agent: actions/github-script | |
result-encoding: json | |
retries: 0 | |
retry-exempt-status-codes: 400,401,403,404,422 | |
PR body: '<!-- Thanks for sending a pull request! Here are some tips for you: | |
Error retrieving files: TypeError: Cannot read properties of undefined (reading 'addLabels') | |
1. If this is your first time, please read our contributor guidelines: https://github.com/googleforgames/agones/blob/main/CONTRIBUTING.md and developer guide https://github.com/googleforgames/agones/blob/main/build/README.md | |
2. Please label this pull request according to what type of issue you are addressing. | |
3. Ensure you have added or ran the appropriate tests for your PR: https://github.com/googleforgames/agones/blob/main/build/README.md#testing-and-building | |
--> | |
**What type of PR is this?** | |
> Uncomment only one ` /kind <>` line, press enter to put that in a new line, and remove leading whitespace from that line: | |
> | |
> /kind breaking | |
> /kind bug | |
/kind cleanup | |
> /kind documentation | |
> /kind feature | |
> /kind hotfix | |
> /kind release | |
**What this PR does / Why we need it**: | |
**Which issue(s) this PR fixes**: | |
<!-- | |
*Automatically closes linked issue when PR is merged. | |
Usage: `Closes #<issue number>`, or `Closes (paste link of issue)`. | |
--> | |
Closes # | |
**Special notes for your reviewer**: | |
' | |
Regex match: ' | |
/kind cleanup,cleanup' | |
Adding label: 'kind/cleanup' based on keyword 'cleanup' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment