Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSTing to /repos/{owner}/{repo}/pulls with explicit head incorrectly returns 404 if base and head are the same repository #20175

Closed
herrhotzenplotz opened this issue Jun 29, 2022 · 1 comment · Fixed by #26986
Labels
Milestone

Comments

@herrhotzenplotz
Copy link

Observed

When POSTing to /repos/{owner}/{repo}/pulls to create a pull request
with a payload which specifies head to be the same repository as in
the request such that the source and the target repository are the
same and not a fork, the REST API returns a 404 with an error message
GetForkedRepo.

e.g. in route myuser/repo and myuser:some-branch in payload.

Expected

I expect this to create the pull request instead of just returning an
incorrect and confusing error message.

Details

The bug seems to be that the branch in
https://github.com/go-gitea/gitea/blob/main/routers/api/v1/repo/pull.go#L940-L951
does not check if it actually is the same repository and thus doesn't
set isSameRepo to true.

Versions

I saw this behaviour when runnig gitea in a FreeBSD 13.1-RELEASE jail:

# jexec gitea freebsd-version
13.1-RELEASE
# jexec gitea uname -a
FreeBSD gitea 13.1-RELEASE FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 TRITON131 amd64
#
#
# pkg -j gitea info gitea
gitea-1.16.7
Name           : gitea
Version        : 1.16.7
Installed on   : Sat Jun 18 15:48:24 2022 CEST
Origin         : www/gitea
Architecture   : FreeBSD:13:amd64
Prefix         : /usr/local
Categories     : www
Licenses       : MIT
Maintainer     : stb@lassitu.de
WWW            : https://gitea.io/en-US/
Comment        : Compact self-hosted Git service
Options        :
	BINDATA        : off
	GIT_LFS        : on
	PAM            : on
	SQLITE         : on
Annotations    :
	FreeBSD_version: 1300139
	cpe            : cpe:2.3:a:gitea:gitea:1.16.7:::::freebsd13:x64
	repo_type      : binary
	repository     : FreeBSD
Flat size      : 104MiB
Description    :
A self-hosted Git service.

Gitea is a community managed fork of Gogs, lightweight code hosting solution
written in Go and published under the MIT license.

WWW: https://gitea.io/en-US/
#
herrhotzenplotz added a commit to herrhotzenplotz/gcli that referenced this issue Jun 29, 2022
This is currently broken as there is a bug in gitea itself preventing
us to submit PRs easily: go-gitea/gitea#20175
@norohind
Copy link
Contributor

norohind commented Sep 8, 2023

I've encountered the same problem using GitHub actions create-pull-request module in conjunction with Gitea actions. This module in order to create pull request uses mentioned in title endpoint and specifies in head field repository name even if it creates pull request between branches of the same repository.
I have a working fix. Going to investigate if I can cover this with tests and prepare a pull request in next couple of days.

@lunny lunny added the type/bug label Mar 15, 2024
@lunny lunny added this to the 1.21.9 milestone Mar 15, 2024
lunny pushed a commit that referenced this issue Mar 17, 2024
… namespaced (#26986)

Fix #20175

Current implementation of API does not allow creating pull requests
between branches of the same
repo when you specify *namespace* (owner of the repo) in `head` field in
http request body.

--- 

Although GitHub implementation of API allows performing such action and
since Gitea targeting
compatibility with GitHub API I see it as an appropriate change.

I'm proposing a fix to the described problem and test case which covers
this logic.

My use-case just in case:
#20175 (comment)
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Mar 17, 2024
… namespaced (go-gitea#26986)

Fix go-gitea#20175

Current implementation of API does not allow creating pull requests
between branches of the same
repo when you specify *namespace* (owner of the repo) in `head` field in
http request body.

--- 

Although GitHub implementation of API allows performing such action and
since Gitea targeting
compatibility with GitHub API I see it as an appropriate change.

I'm proposing a fix to the described problem and test case which covers
this logic.

My use-case just in case:
go-gitea#20175 (comment)
silverwind pushed a commit to silverwind/gitea that referenced this issue Mar 17, 2024
… namespaced (go-gitea#26986)

Fix go-gitea#20175

Current implementation of API does not allow creating pull requests
between branches of the same
repo when you specify *namespace* (owner of the repo) in `head` field in
http request body.

--- 

Although GitHub implementation of API allows performing such action and
since Gitea targeting
compatibility with GitHub API I see it as an appropriate change.

I'm proposing a fix to the described problem and test case which covers
this logic.

My use-case just in case:
go-gitea#20175 (comment)
lunny added a commit that referenced this issue Mar 20, 2024
… namespaced (#26986) (#29857)

Backport #26986 by @norohind

Fix #20175

Current implementation of API does not allow creating pull requests
between branches of the same
repo when you specify *namespace* (owner of the repo) in `head` field in
http request body.

---------

Co-authored-by: norohind <60548839+norohind@users.noreply.github.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this issue Mar 20, 2024
… namespaced (#26986)

Fix #20175

Current implementation of API does not allow creating pull requests
between branches of the same
repo when you specify *namespace* (owner of the repo) in `head` field in
http request body.

---

Although GitHub implementation of API allows performing such action and
since Gitea targeting
compatibility with GitHub API I see it as an appropriate change.

I'm proposing a fix to the described problem and test case which covers
this logic.

My use-case just in case:
go-gitea/gitea#20175 (comment)

(cherry picked from commit ed02d1fab85c9b8206c0af84dcfc3792e61609cf)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants