Pull request creation to forked repository via web api fails #9270

Closed
opened 2025-11-02 08:33:44 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @lixfel on GitHub (Jul 25, 2022).

Description

Gitea prevents pull request creation with the web api from the original repository to the fork with the error message: <Response [404]> b'{"errors":null,"message":"GetForkedRepo","url":"https://try.gitea.io/api/swagger"}\n'.

I managed to reproduce the issue on https://try.gitea.io/Lixfel/FreeSql .

Reproduction code:

token = "?"
import requests
response = requests.post(
        f'https://try.gitea.io/api/v1/repos/Lixfel/FreeSql/pulls?token={token}',
        json={
            "base": "master",
            "head": "huihuiyule:master",
            "title": "Update Upstream"
        })
print(f"{response} {response.content}")

Bug origin assumption:
https://github.com/go-gitea/gitea/blob/main/routers/api/v1/repo/pull.go#L967 seems to only allow PRs from the fork to the original repository, a method call GetForkingRepo is missing.

Gitea Version

1.16.9

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

https://gist.github.com/lixfel/e0c36e3b85a1b8ffbf994baf275e49bd

Screenshots

No response

Git Version

1:2.30.2-1 (apt version)

Operating System

Debian

How are you running Gitea?

Use of Gitea Downloads site; execution with systemd

Database

MySQL

Originally created by @lixfel on GitHub (Jul 25, 2022). ### Description Gitea prevents pull request creation with the web api from the original repository to the fork with the error message: `<Response [404]> b'{"errors":null,"message":"GetForkedRepo","url":"https://try.gitea.io/api/swagger"}\n'`. I managed to reproduce the issue on https://try.gitea.io/Lixfel/FreeSql . Reproduction code: ``` token = "?" import requests response = requests.post( f'https://try.gitea.io/api/v1/repos/Lixfel/FreeSql/pulls?token={token}', json={ "base": "master", "head": "huihuiyule:master", "title": "Update Upstream" }) print(f"{response} {response.content}") ``` Bug origin assumption: https://github.com/go-gitea/gitea/blob/main/routers/api/v1/repo/pull.go#L967 seems to only allow PRs from the fork to the original repository, a method call `GetForkingRepo` is missing. ### Gitea Version 1.16.9 ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist https://gist.github.com/lixfel/e0c36e3b85a1b8ffbf994baf275e49bd ### Screenshots _No response_ ### Git Version 1:2.30.2-1 (apt version) ### Operating System Debian ### How are you running Gitea? Use of Gitea Downloads site; execution with systemd ### Database MySQL
GiteaMirror added the type/bug label 2025-11-02 08:33:44 -06:00
Author
Owner

@haru3me commented on GitHub (Sep 28, 2023):

Since #26785, it become able to create PR to forked repository from origin via web.
But, I think the API still have the issue.

I've tested with try.gitea.io using this repository.
the result is below:

$ curl -X 'POST' \
>   'https://try.gitea.io/api/v1/repos/haru3me/test2/pulls?token=<secret>' \
>   -H 'accept: application/json' \
>   -H 'Content-Type: application/json' \
>   -d '{
>   "base": "main",
>   "body": "This is a PR",
>   "head": "lng2023:main",
>   "title": "PR title"
> }'
{"errors":null,"message":"GetForkedRepo","url":"https://try.gitea.io/api/swagger"}

On the my instance running 1.20.4 also have same issue.
additionally, I tested with tea command and also got fail.

.\tea.exe pr create --repo "haru/test_action_dummy" --head "dummy:main" --base "main"
Error: could not create PR from dummy:main to haru:main: GetForkedRepo

By the way, I know #20479 is closed recently. Is there any plan with this ..?
I think it would be really helpful with Gitea Actions.

@haru3me commented on GitHub (Sep 28, 2023): Since #26785, it become able to create PR to forked repository from origin via web. But, I think the API still have the issue. I've tested with try.gitea.io using [this](https://try.gitea.io/haru3me/test2) repository. the result is below: ``` $ curl -X 'POST' \ > 'https://try.gitea.io/api/v1/repos/haru3me/test2/pulls?token=<secret>' \ > -H 'accept: application/json' \ > -H 'Content-Type: application/json' \ > -d '{ > "base": "main", > "body": "This is a PR", > "head": "lng2023:main", > "title": "PR title" > }' {"errors":null,"message":"GetForkedRepo","url":"https://try.gitea.io/api/swagger"} ``` On the my instance running 1.20.4 also have same issue. additionally, I tested with tea command and also got fail. ``` .\tea.exe pr create --repo "haru/test_action_dummy" --head "dummy:main" --base "main" Error: could not create PR from dummy:main to haru:main: GetForkedRepo ``` By the way, I know #20479 is closed recently. Is there any plan with this ..? I think it would be really helpful with Gitea Actions.
Author
Owner

@LordChunk commented on GitHub (Aug 14, 2024):

I'm also running into the exaqct issue on v1.22.1

@LordChunk commented on GitHub (Aug 14, 2024): I'm also running into the exaqct issue on v1.22.1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#9270