Extend fork API to support custom repo name and owner #3108

Closed
opened 2025-11-02 05:01:00 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @yosiov on GitHub (Mar 27, 2019).

  • Gitea Version: 1.6.4
  • Git Version: 2.15.3
  • Operating System: Alpine Linux 3.7.1

The current fork API (implemented in routers/api/v1/repo/fork.go) support forking a repo with two restrictions:

  1. The forked repo name remains the same as the source repo name
  2. The forked repo is owned by the API caller

My suggestion is to support a custom repo name for the forked repo, and to allow an admin user to create forks for other users.

Do you think such an extension is reasonable? Should I send a PR for this?

Originally created by @yosiov on GitHub (Mar 27, 2019). - Gitea Version: 1.6.4 - Git Version: 2.15.3 - Operating System: Alpine Linux 3.7.1 The current fork API (implemented in routers/api/v1/repo/fork.go) support forking a repo with two restrictions: 1. The forked repo name remains the same as the source repo name 2. The forked repo is owned by the API caller My suggestion is to support a custom repo name for the forked repo, and to allow an admin user to create forks for other users. Do you think such an extension is reasonable? Should I send a PR for this?
GiteaMirror added the type/proposalmodifies/api labels 2025-11-02 05:01:00 -06:00
Author
Owner

@strahe commented on GitHub (May 30, 2019):

Good idea, really need it.

@strahe commented on GitHub (May 30, 2019): Good idea, really need it.
Author
Owner

@6543 commented on GitHub (Sep 21, 2020):

... "allow an admin user to create forks for other users." -> you can use sudo header

@6543 commented on GitHub (Sep 21, 2020): ... "allow an admin user to create forks for other users." -> you can use sudo header
Author
Owner

@milichev commented on GitHub (Mar 11, 2021):

@yosiov , there is a workaround:

PATCH /repos/owner/old-name

{
  "name": "new-name"
}

Interesting is that successive same requests result with

302 Found
Location: /api/v1/repos/owner/new-name
@milichev commented on GitHub (Mar 11, 2021): @yosiov , there is a workaround: ``` PATCH /repos/owner/old-name { "name": "new-name" } ``` Interesting is that successive same requests result with ``` 302 Found Location: /api/v1/repos/owner/new-name ```
Author
Owner

@pi3ch commented on GitHub (Sep 2, 2021):

@yosiov , there is a workaround:

PATCH /repos/owner/old-name

{
  "name": "new-name"
}

Interesting is that successive same requests result with

302 Found
Location: /api/v1/repos/owner/new-name

Doesn't look like a workaround to me. It does not fork for a user and set a new name at the same time.

@pi3ch commented on GitHub (Sep 2, 2021): > @yosiov , there is a workaround: > > ``` > PATCH /repos/owner/old-name > > { > "name": "new-name" > } > ``` > > Interesting is that successive same requests result with > > ``` > 302 Found > Location: /api/v1/repos/owner/new-name > ``` Doesn't look like a workaround to me. It does not fork for a user and set a new name at the same time.
Author
Owner

@realaravinth commented on GitHub (Dec 21, 2021):

Hello, I'm new to the Gitea codebase but I'm willing to submit a patch for this issue.

From what I understand, the necessary plumbing is already available in the web form implementation at routers/web/pull.go.

For the API endpoint, we could respond with 409: Conflict, like the one you get when you try to create a repository with a duplicate name:

{
  "message": "The repository with the same name already exists.",
  "url": "https://git.batsense.net/api/swagger"
}

So that the user can retry their request with an optional name parameter:

curl -X 'POST' \
  'https://git.example.com/api/v1/repos/owner/myrepo/forks' \
  -H 'accept: application/json' \
  -H 'authorization: Basic xxx' \
  -H 'Content-Type: application/json' \
  -d '{
"name": "forkOf-myrepo"
}'
@realaravinth commented on GitHub (Dec 21, 2021): Hello, I'm new to the Gitea codebase but I'm willing to submit a patch for this issue. From what I understand, the necessary plumbing is already available in the web form implementation at [routers/web/pull.go](https://github.com/go-gitea/gitea/blob/7821370c0bc88bd1a02966cad172f33667394bd4/routers/web/repo/pull.go#L178). For the API endpoint, we could respond with `409: Conflict`, like the one you get when you try to create a repository with a duplicate name: ```json { "message": "The repository with the same name already exists.", "url": "https://git.batsense.net/api/swagger" } ``` So that the user can retry their request with an optional name parameter: ```bash curl -X 'POST' \ 'https://git.example.com/api/v1/repos/owner/myrepo/forks' \ -H 'accept: application/json' \ -H 'authorization: Basic xxx' \ -H 'Content-Type: application/json' \ -d '{ "name": "forkOf-myrepo" }' ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3108