From 690a5279ebb1599a47ce6f098fa6af8ed408856e Mon Sep 17 00:00:00 2001 From: "Galantsev, Dmitrii" Date: Tue, 15 Apr 2025 23:41:17 +0000 Subject: [PATCH] CI - Add cherrypick labels automatically Change-Id: Ibea66f45e082a7c425f1b927775629c2f05d7c32 Signed-off-by: Galantsev, Dmitrii --- .github/workflows/label_cherrypicks.yml | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/label_cherrypicks.yml diff --git a/.github/workflows/label_cherrypicks.yml b/.github/workflows/label_cherrypicks.yml new file mode 100644 index 0000000000..4048b66c7e --- /dev/null +++ b/.github/workflows/label_cherrypicks.yml @@ -0,0 +1,46 @@ +# 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 and release 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'); + }