Skip to content

feat(domain): add auto-fork support for remote repos without push access#434

Open
arielshad wants to merge 3 commits intofeat/remote-repo-supportfrom
feat/073-auto-fork-support
Open

feat(domain): add auto-fork support for remote repos without push access#434
arielshad wants to merge 3 commits intofeat/remote-repo-supportfrom
feat/073-auto-fork-support

Conversation

@arielshad
Copy link
Copy Markdown
Contributor

Summary

  • When --remote targets a repo the user can't push to, shep auto-forks it, clones the fork, sets upstream remote, and records fork metadata
  • Adds isFork and upstreamUrl fields to the Repository domain model (TypeSpec + migration + mapper)
  • Adds checkPushAccess, forkRepository, getAuthenticatedUser methods to IGitHubRepositoryService
  • Extends ImportGitHubRepositoryUseCase with automatic fork detection and conditional fork/clone flow
  • CLI shows fork status in output and handles GitHubForkError
  • Web UI shows "Fork" badge on forked repos in the repository combobox
  • Duplicate detection enhanced: checks both remoteUrl and upstreamUrl to avoid re-importing

Test plan

  • pnpm validate passes (lint, format, typecheck, tsp)
  • pnpm test:unit — 334 files, 4573 tests pass
  • pnpm build succeeds
  • CI passes on this PR
  • Manual: shep feat new --remote <public-repo-you-dont-own> "test" → forks, clones fork, sets upstream
  • Manual: shep feat new --remote <repo-you-own> "test" → clones directly, no fork

🤖 Generated with Claude Code

When --remote targets a repo the user cannot push to, shep now
auto-forks it to the user's GitHub account, clones the fork, sets
upstream remote, and records fork metadata (isFork, upstreamUrl).

- Add isFork/upstreamUrl fields to Repository TypeSpec model
- Add DB migration 044 for fork columns
- Add checkPushAccess, forkRepository, getAuthenticatedUser to
  IGitHubRepositoryService
- Extend ImportGitHubRepositoryUseCase with fork detection flow
- Show fork status in CLI output and handle GitHubForkError
- Add Fork badge in Web UI repository combobox
- Return forked status from import server action
- Add comprehensive unit tests for all new functionality

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@arielshad
Copy link
Copy Markdown
Contributor Author

This might be redundant

arielshad and others added 2 commits March 22, 2026 10:24
Add UI evidence for the remote repo support feature:
- RepositoryCombobox: stories for forked repos with badge display,
  pre-selected fork with upstream tooltip, and forks with import
- FeatureCreateDrawer: story demonstrating forked repos in selector
- GitHubImportDialog: complete placeholder stories with interactive
  play functions for URL tab, Browse tab, and pre-opened states

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
replace manual expand/collapse state with radix accordion primitive
so all task cards are collapsed by default with smooth animated
accordion-like expand and collapse behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
arielshad added a commit that referenced this pull request Apr 6, 2026
)

## Summary

Adds three related capabilities for working with remote GitHub
repositories, unifying the work from PRs #409, #430, and #434 into a
single feature on current main:

- **`shep repo init-remote [name]`** — creates a GitHub repository from
a local one with no remote (via `gh repo create --source=.
--remote=origin --push`)
- **`shep feat new --remote <url>`** — clones (or auto-forks) a GitHub
repo then creates a feature on it, conflicts with `--repo`
- **Web UI** — shows a "Fork" badge on forked repositories in the repo
picker; `githubImport` feature flag now defaults to `true`

## Key changes

### Domain
- `Repository` entity gains `isFork?: boolean` and `upstreamUrl?:
string` (TypeSpec + generated output)
- Migration `055-add-repository-fork-fields` adds `is_fork` and
`upstream_url` columns + `idx_repositories_upstream_url` index
(idempotent)

### Auto-fork detection
- `IGitHubRepositoryService` gains `getAuthenticatedUser()`,
`checkPushAccess()`, `forkRepository()` + `GitHubForkError`
- `ImportGitHubRepositoryUseCase` now checks push access before cloning.
When the user lacks write permission, it forks via `gh repo fork`,
clones the fork, sets `upstream` remote, and persists fork metadata
- `IRepositoryRepository.findByUpstreamUrl()` for fork deduplication

### Init remote
- `IGitPrService` gains `createGitHubRepo()`, `addRemote()` +
`REMOTE_ALREADY_EXISTS`, `REPO_CREATE_FAILED` error codes
- New `InitRemoteRepositoryUseCase` guards against existing remotes and
delegates to `gh repo create`

### Feature creation from remote
- New `CreateFeatureFromRemoteUseCase` — composite that chains import →
create feature
- Two-phase API: `execute()` for CLI, `createRecord()` +
`initializeAndSpawn()` for Web (fast optimistic UI)

### i18n
- New translation keys for `repo.initRemote.*` and
`feat.new.{remoteOption,remoteConflict,forkedInfo}` added to all 8
locales

## Test plan

- [x] `pnpm typecheck` — zero errors
- [x] `pnpm lint:fix` — clean
- [x] `pnpm test:unit` — **388 files, 5585 tests passing** (includes 44
new tests)
- [x] `pnpm test:int` — **50 files, 595 tests passing** (migration 055
runs cleanly)
- [x] `pnpm build` — clean CLI build
- [x] `pnpm build:storybook` — clean storybook build with new
`WithForkBadges` story
- [ ] Manual: `shep repo init-remote my-test-repo` on a fresh local repo
- [ ] Manual: `shep feat new --remote
https://github.com/someone/public-repo "test feature"` (triggers
auto-fork path)
- [ ] Manual: Web UI — import a repo you don't have push access to,
verify "Fork" badge appears

## Notes

- Complementary to existing `IGitForkService` (PR #525, merged) which
handles fork-and-PR **within** worktrees. The new fork methods on
`IGitHubRepositoryService` handle auto-fork at **import time** — these
are different code paths and do not conflict.
- Migration 055 uses the umzug `MigrationParams` signature with
idempotent column/index checks, consistent with migration 054.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
blackpc pushed a commit that referenced this pull request Apr 6, 2026
# [1.175.0](v1.174.0...v1.175.0) (2026-04-06)

### Features

* **domain:** add unified remote repository support with auto-fork ([#531](#531)) ([64b8dfe](64b8dfe)), closes [#409](#409) [#430](#430) [#434](#434) [#525](#525)
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.

1 participant