mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-28 09:21:13 -05:00
Fix PR creation via api between branches of same repo with head field 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: https://github.com/go-gitea/gitea/issues/20175#issuecomment-1711283022 (cherry picked from commit ed02d1fab85c9b8206c0af84dcfc3792e61609cf)
This commit is contained in:
parent
cd83e8bce6
commit
d74f74a025
2 changed files with 19 additions and 0 deletions
|
@ -1065,6 +1065,8 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
|
||||||
return nil, nil, nil, nil, "", ""
|
return nil, nil, nil, nil, "", ""
|
||||||
}
|
}
|
||||||
headBranch = headInfos[1]
|
headBranch = headInfos[1]
|
||||||
|
// The head repository can also point to the same repo
|
||||||
|
isSameRepo = ctx.Repo.Owner.ID == headUser.ID
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
|
|
|
@ -126,6 +126,23 @@ func TestAPICreatePullSuccess(t *testing.T) {
|
||||||
MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
|
MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAPICreatePullSameRepoSuccess(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
|
|
||||||
|
session := loginUser(t, owner.Name)
|
||||||
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||||
|
|
||||||
|
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner.Name, repo.Name), &api.CreatePullRequestOption{
|
||||||
|
Head: fmt.Sprintf("%s:pr-to-update", owner.Name),
|
||||||
|
Base: "master",
|
||||||
|
Title: "successfully create a PR between branches of the same repository",
|
||||||
|
}).AddTokenAuth(token)
|
||||||
|
MakeRequest(t, req, http.StatusCreated)
|
||||||
|
MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
|
||||||
|
}
|
||||||
|
|
||||||
func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
|
func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
// repo10 have code, pulls units.
|
// repo10 have code, pulls units.
|
||||||
|
|
Loading…
Reference in a new issue