Skip to content

feat(pr): commit fork pull requests to the fork's repository - #342

Merged
nownabe merged 1 commit into
mainfrom
feat/273-fork-head-repo
Sep 20, 2026
Merged

nownabe merged 1 commit into
mainfrom
feat/273-fork-head-repo

Conversation

@nownabe

@nownabe nownabe commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Why

PullRequest carried only the base repository, so the Commit step's Git Data sequence (createBlob → createTree → createCommit → updateRef) always targeted {owner}/{repo}. For a PR opened from a fork, headRef lives in the fork: the updateRef either 404s or — worse — moves an unrelated upstream branch that happens to share the name. Forks appear in no spec, yet the author role is derived from login, and a fork author satisfies it. That is the common open-source contribution flow.

What

  • PullRequest.headRepo: { owner: string; repo: string } | null, read from head.repo (null when the fork was deleted).
  • The Planner passes it into the Commit step; the transport runs the four Git Data writes against headRepo. Reads stay on the base repo — fetchBlobSha for the [Medium] Planner ignores FileEdit.baseSha — a stale edit can silently overwrite newer remote changes #187 conflict check and fetchFileContent — because the base repository can address every commit of the PR by sha (the PR keeps them reachable via refs/pull/{n}/head).
  • computeRole withholds author only when headRepo is null: there is nowhere to commit, so the Commit button never appears for a deleted-fork PR. For every other PR the rule is unchanged — the PR author has push access to their own fork.
  • A 403/404 from a Git Data write to a repository other than the base becomes an actionable message: "Bark cannot write to {owner}/{repo}. Install the Bark GitHub App on that repository, or sign in with a personal access token, then try again." (the status code is preserved). A same-repo failure keeps GitHub's raw message.
  • App.tsx now reads role from repositoryAppState.role instead of re-deriving it with deriveRole — a login comparison in the UI cannot see the fork rule. The dev RoleFab override still works. (This is also [Refactor] Unify duplicated types and derivations: PrRef, ChangedFile, PullInfo, deriveRole #299's R9; whichever lands first, the other rebases onto a one-line change.) submitAuthor's post-commit file reload reads through headRepo, since the base repository only learns a fork's new commit once the PR ref updates.

Rejected: withholding the author role on every fork PR — it removes the product's core author feature from exactly the population most likely to use it, while the correct target is one field away. maintainer_can_modify for maintainers — a different role the model does not have; the role spec's "out of scope" line is reworded to say so precisely. Falling back to the base repo when head.repo is null — the ref does not exist there; failing at role-derivation time is clearer than a 404 at commit time.

Known risk: on a fork PR the next useSelectedFileContent fetch goes through the base and can 404 for a few seconds until GitHub updates refs/pull/{n}/head. Symptom: one Snackbar error, self-healing on the next refresh. If it shows up in manual testing, thread headRepo into useSelectedFileContent as a follow-up.

Red-test evidence (before the fix)

bun run test tests/pr/remote-fetcher.test.ts tests/pr/appstate.test.ts tests/pr/planner.test.ts tests/pr/github-transport.test.ts → 8 fail:

  • remote-fetcher — fork PRs (issue #273) > a fork PR maps head.repo to headRepo — Expected: { owner: "forker", repo: "r-fork" }, Received: undefined (and > a deleted fork yields headRepo null — Received: undefined).
  • appstate — deriveAppState: role > the PR author of a deleted-fork PR is a reviewer (issue #273) — Expected: "reviewer", Received: "author".
  • planner — CommitFileEdit > a CommitStep carries the context's headRepo (issue #273) — toMatchObject failed: the received step had no headRepo key.
  • github-transport — commit targets the head repository (issue #273) > Git Data writes go to headRepo while the conflict check reads the base — Received /repos/o/r/git/{blobs,trees,commits,refs/heads/topic}, Expected /repos/forker/r-fork/git/… (the two /repos/o/r/contents/a.md?ref=… conflict-check reads matched).
  • > a 404 from the fork explains the App-install requirement — Received "GitHub API 404: {\"message\":\"Not Found\"}", expected to contain "Install the Bark GitHub App on that repository".

Fixture churn, as predicted the widest of the cluster: headRepo was added to every PullRequest and CommitStep literal across tests/pr/{appstate,planner,repository,react,state-machine,executor,github-transport} and tests/{AppSubmitFailure,AppRejectSuggestion,AppV2}. bun run typecheck enumerated them.

Checks

bun run test 727 pass / 0 fail (64 files) · check:lint OK · check:format OK · typecheck OK · build OK.

Not verified: the manual fork flow against real GitHub (open a fork PR as its author with and without the Bark App installed on the fork; open a deleted-fork PR and confirm no Commit button). Everything here is covered by unit tests only.

Closes #273

@nownabe nownabe self-assigned this Sep 20, 2026
@nownabe
nownabe added this pull request to stack #343 September 20, 2026 06:34
@nownabe
nownabe force-pushed the feat/273-fork-head-repo branch from 45bfe5a to 92ca044 Compare September 20, 2026 07:32
@nownabe
nownabe force-pushed the feat/273-fork-head-repo branch from 92ca044 to 4337632 Compare September 20, 2026 08:37
@nownabe
nownabe force-pushed the feat/273-fork-head-repo branch from 4337632 to 3022428 Compare September 20, 2026 08:42
@nownabe
nownabe force-pushed the feat/273-fork-head-repo branch from 3022428 to ca251fe Compare September 20, 2026 08:43
Base automatically changed from fix/287-reject-resolves-thread to main September 20, 2026 08:46
PullRequest carried only the base repository, so the Git Data writes always targeted it: for a PR opened from a fork the updateRef either 404s or moves an unrelated upstream branch of the same name. Model head.repo, write there, and withhold the author role only when the fork is gone.
@nownabe
nownabe force-pushed the feat/273-fork-head-repo branch from ca251fe to d325e2f Compare September 20, 2026 08:46
@nownabe
nownabe merged commit 4e2adef into main Sep 20, 2026
10 checks passed
@nownabe
nownabe deleted the feat/273-fork-head-repo branch September 20, 2026 08:52
nownabe pushed a commit that referenced this pull request Sep 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.4.0](bark-v0.3.0...bark-v0.4.0)
(2026-09-20)


### Features

* **pr:** accept .markdown and .mdx as Markdown
([#322](#322))
([e22ee68](e22ee68)),
closes [#293](#293)
* **pr:** commit fork pull requests to the fork's repository
([#342](#342))
([4e2adef](4e2adef)),
closes [#273](#273)
* **pr:** create a top-level draft Comment's Thread with it
([#323](#323))
([6e192f3](6e192f3)),
closes [#272](#272)
* **pr:** resolve out-of-diff threads via the root comment fence
([#310](#310))
([7e0ecb9](7e0ecb9)),
closes [#270](#270)
* **reanchor:** bounded region search for single-line anchors and
line-local suggestion merge
([#309](#309))
([0f735da](0f735da)),
closes [#269](#269)
* **reanchor:** locate multi-line anchors per endpoint in the region
search ([#347](#347))
([f4fd457](f4fd457)),
closes [#311](#311)
* **review:** preview the merge for shifted suggestions in the editor
([#354](#354))
([f822f41](f822f41)),
closes [#312](#312)


### Bug Fixes

* **anchor:** define anchor.quote as the source text at anchor.range
([#327](#327))
([11a935d](11a935d)),
closes [#276](#276)
* **background:** focus an existing review tab instead of opening a
second one ([#325](#325))
([58efa63](58efa63)),
closes [#277](#277)
* **pr:** compose the quote and permalink for every out-of-diff post
([#351](#351))
([f85b99b](f85b99b)),
closes [#282](#282)
* **pr:** count patch lines starting with ++ or -- in parseRightRanges
([#314](#314))
([9dfbd46](9dfbd46)),
closes [#284](#284)
* **pr:** keep the rel=next link in the ETag cache so 304 pages still
paginate ([#318](#318))
([6472de2](6472de2)),
closes [#286](#286)
* **pr:** offer Resolve only when GitHub would accept it
([#335](#335))
([b05fdcc](b05fdcc)),
closes [#274](#274)
* **pr:** park a failed resolve toggle in synced, not draft
([#320](#320))
([56e815b](56e815b)),
closes [#275](#275)
* **pr:** post drafts in the current head's coordinates
([#303](#303))
([28ef345](28ef345))
* **pr:** recover comments stuck in syncing instead of re-posting them
([#305](#305))
([3548086](3548086))
* **pr:** refuse commits to a merged or closed PR
([#330](#330))
([2a239ff](2a239ff)),
closes [#288](#288)
* **pr:** refuse to submit a draft whose quoted text changed upstream
([#346](#346))
([d4118a4](d4118a4)),
closes [#313](#313)
* **pr:** route replies on the parent's GitHub object kind
([#326](#326))
([1df6462](1df6462)),
closes [#285](#285)
* **pr:** serialise refresh and execution under one Repository lock
([#336](#336))
([1864488](1864488)),
closes [#281](#281)
* **pr:** sweep entities left syncing at the end of a submit
([#331](#331))
([108caa9](108caa9)),
closes [#271](#271)
* **release:** pin publish-browser-extension to ^4.0.5
([#263](#263))
([b77104f](b77104f))
* **review:** derive a suggestion draft's cid from the hunk it
materialises ([#337](#337))
([963339d](963339d)),
closes [#308](#308)
* **review:** end a whole-line selection on the line it actually covers
([#319](#319))
([3364d18](3364d18)),
closes [#291](#291)
* **review:** map comment positions between head and edited coordinates
([#348](#348))
([9465718](9465718)),
closes [#283](#283)
* **review:** reject a suggestion by resolving its thread on GitHub
([#340](#340))
([d088a8d](d088a8d)),
closes [#287](#287)
* **review:** resolve accepted-suggestion threads only after the commit
lands ([#341](#341))
([770f901](770f901)),
closes [#278](#278)
* **review:** surface failed comment posts and keep the reviewer's edits
([#307](#307))
([48cb675](48cb675))
* **review:** validate the PR number from the review URL
([#321](#321))
([457a942](457a942)),
closes [#295](#295)
* **storage:** bound chrome.storage.local growth and stop quota errors
losing drafts ([#332](#332))
([1f96120](1f96120)),
closes [#289](#289)
* **suggest:** consume a longer closing fence instead of leaking a
backtick ([#316](#316))
([d2e0683](d2e0683)),
closes [#290](#290)


### Performance Improvements

* **reanchor:** replace the LCS table with a memoised line-level Myers
diff ([#344](#344))
([8caebdd](8caebdd)),
closes [#280](#280)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please-nownabe-bark[bot] <295690643+release-please-nownabe-bark[bot]@users.noreply.github.com>
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.

[Medium] Fork PRs: PullRequest has no head repository, so Commit targets the base repo

1 participant