Skip to content

Handle issues:labeled trigger for cherry-pick on already-merged PRs - #71

Closed
bunnam988 wants to merge 3 commits into
rdkcentral:developfrom
bunnam988:feature/auto-cherry-pick-gatekeeper
Closed

Handle issues:labeled trigger for cherry-pick on already-merged PRs#71
bunnam988 wants to merge 3 commits into
rdkcentral:developfrom
bunnam988:feature/auto-cherry-pick-gatekeeper

Conversation

@bunnam988

Copy link
Copy Markdown
Contributor

Follow-up to #70. Adds support for adding a cherry-pick to <branch> label to a PR that was already merged days/weeks ago.

Problem: GitHub does not fire pull_request: labeled events on closed/merged PRs, so labels added after merge were silently ignored.

Fix:

  • Added pr_number_override input to the shared engine
  • When triggered via issues: labeled on a merged PR, fetches PR title, URL and merge SHA from the API
  • Guards against running on non-merged PRs (state != MERGED check)
  • CURRENT_PR_URL in the propagation step constructed correctly for the issues event

Reason for change: Enable cherry-pick labels to be added at any time after merge
Test Procedure: Add label to an already-merged PR — workflow fires and creates backport PR
Risks: Low
Priority: P1

- Remove set -e; add error handling around push/PR create so loop continues
- Fix commit range for squash/rebase merges via PR API commit count
- Fix empty cherry-pick detection: use stderr grep instead of fragile diff check
- Fix unquoted LABEL_ARGS: separate gh pr create calls per label presence
- Add --limit 100 to all gh search prs calls (was silently capping at 30)
- Fix jq -s 'add' -> 'add // []' to prevent null on empty array inputs
- Fix ticket regex [A-Z0-9]+ -> [A-Z][A-Z0-9]+ to match rdkcentral format
- Add CROSS_REPO_TOKEN secret input to shared gatekeeper for org-wide search
- Add pr_number_override input to support triggering from issues:labeled event
- Fetch PR context (title, URL, merge SHA) via API when pull_request context is empty
- Fix CURRENT_PR_URL in parse_meta for issues event using format() expression

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds reusable GitHub Actions workflows for cross-repo backporting and merge gating, including support for applying cherry-pick to <branch> labels to already-merged PRs via an issues:labeled trigger workaround.

Changes:

  • Introduces a shared cherry-pick engine reusable workflow with pr_number_override to support issues:labeled on merged PRs.
  • Adds a shared cross-repo gatekeeper reusable workflow that audits “sister” PRs for required approvals (and missing release/support backports).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/cherry-pick.yml New reusable workflow to propagate cherry-pick labels cross-repo and create backport PRs, including post-merge labeling support via PR-number override.
.github/workflows/gatekeeper.yml New reusable workflow to block/allow merges based on cross-repo PR approval status (and stable-branch cherry-pick completeness checks).
Suppressed comments (1)

.github/workflows/gatekeeper.yml:35

  • grep returns exit code 1 when there are no matches. With GitHub Actions’ default bash -e -o pipefail, both of these command substitutions can abort the job on PRs that have only ticket IDs (no topic: label) or no ticket IDs at all (the intended skip validation branch is never reached).
          ALL_IDS=$(echo -e "${PR_TITLE}\n${PR_BODY}" | grep -oE '[A-Z][A-Z0-9]+-[0-9]+' | sort -u)

          # Extract any user-defined custom topic label (e.g., topic:billing-engine-v2)
          CUSTOM_TOPIC=$(echo "$PR_DATA" | jq -r '.labels[].name' 2>/dev/null | grep "^topic:" | head -n 1)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

TARGET_BRANCHES=$(echo '${{ inputs.raw_labels }}' | jq -r '.[] | .name' | grep "cherry-pick to " | sed 's/cherry-pick to //' || true)
fi

CUSTOM_TOPIC=$(echo '${{ inputs.raw_labels }}' | jq -r '.[] | .name' | grep "^topic:" | head -n 1)
ORIGINAL_REPOS=$(echo "$HISTORICAL_PRS" | jq -r '.[].repository.name' | sort -u)

while read -r repo; do
if [ -n "$repo" ] && ! echo "$REPOS_WITH_RELEASE_PRS" | grep -q "^$repo$"; then
@@ -0,0 +1,215 @@
name: Shared Cross-Repo Gatekeeper
@bunnam988

Copy link
Copy Markdown
Contributor Author

Closing — replaced by a clean single-commit PR from the correct base.

@bunnam988 bunnam988 closed this Aug 7, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants