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

Fix PR creation via api between branches of same repo with head field namespaced #26986

Merged
merged 24 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6c72e9e
Fix via api PR creation between same repo with repo in `head` field s…
norohind Sep 8, 2023
6c75281
Add test create PR with both branches in the same repo
norohind Sep 8, 2023
d1c28a2
Merge branch 'main' into fix-20175-api-pr
techknowlogick Nov 15, 2023
389d819
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
d82c724
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
cf8dd4c
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
d74593e
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
230ddc2
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
f40c2ad
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
88269e6
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
1afa062
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
c03644b
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
27bc339
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 15, 2024
1a68f62
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
3ce9284
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
2c7117c
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
f64cf45
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
1df1b66
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
c0a9680
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
4daa422
TestAPICreatePullSameRepoSuccess: send auth token as header
norohind Mar 16, 2024
3fb6512
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
7bd5075
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
8edb9b5
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 16, 2024
e6d6433
Merge branch 'main' into fix-20175-api-pr
GiteaBot Mar 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,8 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
return nil, nil, nil, nil, "", ""
}
headBranch = headInfos[1]
// The head repository can also point to the same repo
isSameRepo = ctx.Repo.Owner.ID == headUser.ID
lunny marked this conversation as resolved.
Show resolved Hide resolved

} else {
ctx.NotFound()
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/api_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ func TestAPICreatePullSuccess(t *testing.T) {
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?token=%s", owner.Name, repo.Name, token), &api.CreatePullRequestOption{
Head: fmt.Sprintf("%s:pr-to-update", owner.Name),
Base: "master",
Title: "successfully create a PR between branches of the same repository",
})
MakeRequest(t, req, http.StatusCreated)
MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
}

func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
defer tests.PrepareTestEnv(t)()
// repo10 have code, pulls units.
Expand Down