fix: use PR base branch as sourceBranch to support non-default branch backports#1
Open
larryng-rapyuta wants to merge 1 commit into
Open
fix: use PR base branch as sourceBranch to support non-default branch backports#1larryng-rapyuta wants to merge 1 commit into
larryng-rapyuta wants to merge 1 commit into
Conversation
… backports The backport library's getOptionsFromGithub always reads .backportrc.json from the repo's default branch. When a PR targets a non-default branch (e.g. release/2.10), the sourceBranch from the default branch config doesn't match the PR's base branch, causing the backport to abort with 'no branches to backport to'. This fix extracts the PR's base branch from the event payload and passes it via processArgs (which has the highest precedence in option merging), ensuring sourceBranch always matches the actual target branch of the PR.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
backportlibrary'sgetOptionsFromGithub()fetches.backportrc.jsonfrom the repo's default branch (via theGithubConfigOptionsGraphQL query which usesdefaultBranchRef). This meanssourceBranchis always read from the default branch's config.When a PR targets a non-default branch (e.g.
release/2.10), thesourceBranchfrom the default branch config (e.g."devel") doesn't match the PR's actual base branch, causing the backport to abort with:This was observed on rr_oks#11525 — a PR merged to
release/2.10withbackport-to-release/2.9label. The backport action ran successfully but aborted because it readsourceBranch: "devel"from the default branch config instead of usingrelease/2.10.Even though
release/2.10has its own.backportrc.jsonwithsourceBranch: "release/2.10", the library never reads it.Fix
Extract the PR's base branch from the GitHub event payload (
context.payload.pull_request.base.ref) and pass it viaprocessArgs(['--sourceBranch', prBaseBranch]), which has the highest precedence in thebackportlibrary's option merging chain:This ensures
sourceBranchalways matches the actual base branch of the PR, regardless of which branch's.backportrc.jsonthe library reads.Changes
src/run.ts: Extract PR base branch and pass as--sourceBranchviaprocessArgssrc/run.test.ts: Updated existing test, added new test for non-default branch scenariodist/index.js: Rebuilt bundleTesting
All 8 tests pass: