CI - Add cherrypick labels automatically

Change-Id: Icbd0c70c9cbee2b119e7e74d6cdfe83e93a83df9
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
This commit is contained in:
Galantsev, Dmitrii
2025-04-15 23:35:46 +00:00
committed by Galantsev, Dmitrii
parent a5cb334f8b
commit 5efdcc23fc
+47
View File
@@ -0,0 +1,47 @@
# caution: this whole file was written using Claude 3.7 Sonnet
name: Auto Label Cherry-Pick
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
add-label:
runs-on: ubuntu-latest
container:
image: node:16-alpine
permissions:
pull-requests: write
steps:
- name: Add label to cherry-pick PRs
uses: actions/github-script@v6
with:
script: |
const pr = context.payload.pull_request;
const headBranch = pr.head.ref;
const baseBranch = pr.base.ref;
// Check if head branch contains cherry-pick pattern or base branch starts with release/
const isCherryPick = /cherry.*pick/i.test(headBranch);
const isReleaseTarget = baseBranch.startsWith('release/');
if (isCherryPick || isReleaseTarget) {
// Label to apply
const labelToAdd = 'cherry-pick';
// Try to add the label
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [labelToAdd]
});
console.log(`Added label "${labelToAdd}" to PR #${pr.number}`);
} catch (error) {
console.error(`Error adding label: ${error.message}`);
}
} else {
console.log('PR does not match criteria for automatic labeling');
}