go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
45.11k stars 5.49k forks source link

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

Closed herrhotzenplotz closed 8 months ago

herrhotzenplotz commented 2 years ago

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/
#
norohind commented 1 year ago

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.