Skip to content

(feat) Issue 3979 create fork api - #8348

Open
teodesian wants to merge 4 commits into
gogs:mainfrom
teodesian:issue-3979-create-fork-api
Open

teodesian wants to merge 4 commits into
gogs:mainfrom
teodesian:issue-3979-create-fork-api

Conversation

@teodesian

@teodesian teodesian commented Jun 9, 2026

Copy link
Copy Markdown

Fix Issue 3979

API call to create a fork mirroring github conventions. Lacks the boolean option default_branch_only, as I'm unsure whether that's something we are able or even want to support here.

I'm scratching my own itch here trying to add 'good enough' gogs support to my friendly neighborhood llm chatbot.

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code or have provided the test plan. (if applicable)
  • I have added an entry to CHANGELOG. (if applicable)
  • I have verified this locally versus my own installation
  • I have actually run the added unit tests and they have passed

Test plan

curl yon endpoint, verify it returns a plausible looking repo object & such is reflected in the UI subsequently.
Make sure the name passed is honored, and the organization is correctly set when passed.

teodesian and others added 3 commits June 8, 2026 22:01
…repo}/forks

Probably does not work.  Untested.
Fix the first-draft forkRepo implementation so it compiles and follows
project conventions, then add unit tests for the core fork logic.

Changes to repo_repo.go:
- Replace broken SearchByName approach with GetByUsername for exact match.
- Correct function signature (remove spurious owner/repository string args).
- Fix opt.Name nil-check (string, not pointer) and the apiFork make() call.
- Introduce forkStore interface and dbForkStore wrapper to decouple the
  handler logic from the database layer, enabling unit tests without a
  live database.
- Rename inner logic to doForkRepo; forkRepo is now a thin shim.

Changes to api.go:
- Add missing bind(forkRepoRequest{}) middleware to the POST /forks route.

New file repo_repo_test.go:
- TestDoForkRepo covers: fork to own namespace, fork to org, custom name,
  owner not found (404), repo not found (404), org not found (500), and
  fork creation failure (500).
test: unit tests for POST /repos/{owner}/{repo}/forks handler
@teodesian
teodesian requested a review from unknwon as a code owner June 9, 2026 17:58
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.

2 participants