Skip to content

FR-223: Add option for changing the target repository - #224

Open
synecdoche wants to merge 2 commits into
kiegroup:mainfrom
synecdoche:fr-223
Open

FR-223: Add option for changing the target repository#224
synecdoche wants to merge 2 commits into
kiegroup:mainfrom
synecdoche:fr-223

Conversation

@synecdoche

@synecdoche synecdoche commented Jul 31, 2026

Copy link
Copy Markdown

Thank you for submitting this pull request

fixes #223

Description

Adds a new flag, --tb-repo, which allows a different destination repository for the backport as described in issue 223

How Has This Been Tested?

This was tested with the following command:

node dist/cli/index.js -tb master --no-squash --tb-repo zakkak/graalvm-community-jdk25u -pr https://github.com/oracle/graal/pull/13276 -a $(gh auth token) --bp-repo synecdoche/graalvm-community-jdk25u -d

The output of that command was:

[WARN ] Dry run enabled
[DEBUG] Setting up github client: apiUrl=https://api.github.com/, token=****
[DEBUG] Parsing configs..
[DEBUG] Fetching pull request oracle/graal/13276
[DEBUG] [master] Cloning repo..
[INFO ] [master] Cloning repository https://github.com/zakkak/graalvm-community-jdk25u.git to /local/home/spurn/prog/backport-automation/git-backporting/bp
[DEBUG] [master] Creating local branch..
[INFO ] [master] Creating branch bp-master-1dd97e6
[INFO ] [master] Adding new remote https://github.com/oracle/graal.git
[DEBUG] [master] Fetching pull request remote..
[INFO ] [master] Fetching upstream pull/13276/head:pr/13276
[DEBUG] [master] Cherry picking commits..
[INFO ] [master] Cherry picking 1dd97e6aef659a379ad28c9d4c38182d1f89249b
[DEBUG] [master] Cherry picking command git cherry-pick,-m,1,--strategy=recursive,--strategy-option=theirs,1dd97e6aef659a379ad28c9d4c38182d1f89249b
[INFO ] [master] Adding new remote https://github.com/synecdoche/graalvm-community-jdk25u.git
[WARN ] [master] Pull request creation and remote push skipped
[INFO ] [master] {
  "owner": "zakkak",
  "repo": "graalvm-community-jdk25u",
  "cloneUrl": "https://github.com/zakkak/graalvm-community-jdk25u.git",
  "head": "bp-master-1dd97e6",
  "headRepo": {
    "owner": "synecdoche",
    "project": "graalvm-community-jdk25u",
    "cloneUrl": "https://github.com/synecdoche/graalvm-community-jdk25u.git"
  },
  "base": "master",
  "title": "[master] [GR-74161] Add declaration for pread.",
  "body": "**Backport:** https://github.com/oracle/graal/pull/13276\r\n\r\nAdd declaration for pread, which allows reading from a file at a specific position without seeking first.",
  "reviewers": [
    "graalvmbot"
  ],
  "assignees": [],
  "labels": [],
  "comments": []
}
[INFO ] Process succeeded

Checklist

  • Tests added if applicable.
  • Documentation updated if applicable.

Merge criteria:

  • The commits and have meaningful messages; the author will squash them after approval or will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Note: dist/cli/index.js and dist/gha/index.js are automatically generated by git hooks and gh workflows.

First time here?

This project follows git conventional commits pattern, therefore the commits should have the following format:

<type>(<optional scope>): <subject>
empty separator line
<optional body>
empty separator line
<optional footer>

Where the type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test]

NOTE: if you are still in a work in progress branch and you want to push your changes remotely, consider adding --no-verify for both commit and push, e.g., git push origin <feat-branch> --no-verify - this could become useful to push changes where there are still tests failures. Once the pull request is ready, please amend the commit and force-push it to keep following the adopted git commit standard.

How to prepare for a new release?

There is no need to manually update package.json version and CHANGELOG.md information. This process has been automated in Prepare Release Github workflow.

Therefore whenever enough changes are merged into the main branch, one of the maintainers will trigger this workflow that will automatically update version and changelog based on the commits on the git tree.

More details can be found in package release section of the README.

john spurling added 2 commits July 31, 2026 09:02
…iegroup#223)

Adds a --tb-repo/tb-repo flag, mirroring the existing --bp-repo, so the
backport pull request can be opened against a repository other than the
one targeted by the original PR. This unblocks workflows like GraalVM's
community LTS repos, where backports of oracle/graal PRs need to land in
a separate downstream repo (e.g. graalvm/graalvm-community-jdk25u)
rather than in a fork of the same repository.

Unlike --bp-repo, which only changes where the branch is pushed, --tb-repo
changes where the repo is cloned from and where the PR is ultimately
opened. Because the original PR's commits generally don't exist in the
history of an unrelated target repository, the runner now adds an
"upstream" remote back to the original PR's repo and fetches the PR ref
from there before cherry-picking, rather than assuming origin. Also made
addRemote idempotent (update the URL if the remote already exists)
since the working folder is reused across multiple target branches, which
would otherwise make --tb-repo (and pre-existing --bp-repo) usage with
multiple target branches fail on the second iteration.
…artifact

Correct the README note for the 'backport to a different target repository'
mode (kiegroup#223): the required permissions differ depending on whether --bp-repo is
also used. With --tb-repo alone the branch is pushed straight to the target
repo (needs push access there); combined with --bp-repo the branch goes to the
fork and only PR-open ability is needed on the target repo.

Also drop the unrelated allowScripts entry that had leaked into the bundled
package.json inside dist/cli/index.js during an earlier rebuild.
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
90.49% (+0.72% 🔼)
609/673
🟢 Branches
86.55% (+0.75% 🔼)
296/342
🟢 Functions
88.89% (+0.91% 🔼)
144/162
🟢 Lines
90.31% (+0.73% 🔼)
587/650

Test suite run success

228 tests passing in 19 suites.

Report generated by 🧪jest coverage report action from 8bf1c82

@lampajr
lampajr self-requested a review July 31, 2026 20:49

@lampajr lampajr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @synecdoche, first of all thanks a lot for opening the PR ❤️

Overall looks great to me, I just noticed one possible pitfall.

I tried using --tb-repo without the --no-squash and it fails to cherry-pick when backporting a merged PR:

node dist/cli/index.js -tb master --tb-repo zakkak/graalvm-community-jdk25u \
  -pr https://github.com/oracle/graal/pull/13276 -a $(gh auth token) \
  --bp-repo synecdoche/graalvm-community-jdk25u -f /tmp/test-2 -d

[INFO ] Fetching upstream pull/13276/head:pr/13276
[INFO ] Cherry picking efcf7228fe0616970cb399685553f57b3aa60160
[ERROR] fatal: remote error: upload-pack: not our ref efcf7228fe0616970cb399685553f57b3aa60160
        fatal: bad object efcf7228fe0616970cb399685553f57b3aa60160

I believe this happens because in --tb-repo mode we clone the target repo and fetch only pull/<N>/head from the original repo (upstream). But for a merged PR the commit we cherry-pick is the merge/squash commit (merge_commit_sha), which lives on the original repo's base branch - it is not reachable from pull/<N>/head, so it never gets downloaded.

It gets worse because the clone is a partial clone (--filter=blob:none), which makes origin (the tb-repo) the promisor remote. When cherry-pick looks for the missing commit, git lazily asks origin for it - not upstream - and origin doesn't have it either, hence upload-pack: not our ref → bad object.

This means:

  • works: --no-squash (individual commits are on pull/N/head) and open PRs (head sha is on pull/N/head)
  • fails: the default merged/squashed case - the most common scenario

The current tests don't catch this because they mock fetch/cherryPick, so commit reachability is never exercised.

We could Instead of fetching pull//head, fetch the actual commit SHAs we're about to cherry-pick directly from upstream git fetch upstream <sha> for each commit in the PR. There might be other better solution I did not think of, I am open to suggestion here 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Add option for changing the target repository

3 participants