From 5761e338be83f3c9c4557290113ee0e28b9a1113 Mon Sep 17 00:00:00 2001 From: Job Date: Sun, 18 Aug 2024 12:57:12 +0000 Subject: [PATCH 1/8] Fix PR creation on forked repositories --- routers/api/v1/repo/pull.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 7eb4a8b8a2d4d..3fd06d38d9c8b 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1124,9 +1124,19 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // Check if current user has fork of repository or in the same repository. headRepo := repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID) if headRepo == nil && !isSameRepo { - log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) - ctx.NotFound("GetForkedRepo") - return nil, nil, nil, "", "" + // Check if the base repository is a fork of the head repository. + headRepo, err = repo_model.GetRepositoryByID(ctx, baseRepo.ForkID) + + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err) + return nil, nil, nil, "", "" + } + + if headRepo == nil { + log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) + ctx.NotFound("GetForkedRepo") + return nil, nil, nil, "", "" + } } var headGitRepo *git.Repository From 54925ba8902518373bbe0d47b410390f72f82d58 Mon Sep 17 00:00:00 2001 From: Job Date: Sun, 18 Aug 2024 14:58:30 +0000 Subject: [PATCH 2/8] Resolved linter warnings --- routers/api/v1/repo/pull.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 3fd06d38d9c8b..e88fa24de2645 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1126,7 +1126,6 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) if headRepo == nil && !isSameRepo { // Check if the base repository is a fork of the head repository. headRepo, err = repo_model.GetRepositoryByID(ctx, baseRepo.ForkID) - if err != nil { ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err) return nil, nil, nil, "", "" From c6de6ebe8abf7172cc373d3b9f0ed5fa0e2e5ad7 Mon Sep 17 00:00:00 2001 From: Job Date: Mon, 19 Aug 2024 18:40:10 +0000 Subject: [PATCH 3/8] Fixed if statement to correctly check base repository --- routers/api/v1/repo/pull.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index e88fa24de2645..4e3de77032fb5 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1124,18 +1124,20 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) // Check if current user has fork of repository or in the same repository. headRepo := repo_model.GetForkedRepo(ctx, headUser.ID, baseRepo.ID) if headRepo == nil && !isSameRepo { - // Check if the base repository is a fork of the head repository. - headRepo, err = repo_model.GetRepositoryByID(ctx, baseRepo.ForkID) + err := baseRepo.GetBaseRepo(ctx) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetRepositoryByID", err) + ctx.Error(http.StatusInternalServerError, "GetBaseRepo", err) return nil, nil, nil, "", "" } - if headRepo == nil { + // Check if baseRepo's base repository is the same as headUser's repository. + if baseRepo.BaseRepo == nil || baseRepo.BaseRepo.OwnerID != headUser.ID { log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) - ctx.NotFound("GetForkedRepo") + ctx.NotFound("GetBaseRepo") return nil, nil, nil, "", "" } + // Assign headRepo so it can be used below. + headRepo = baseRepo.BaseRepo } var headGitRepo *git.Repository From ea697c3e0bdf89e7aad49dcd4717c7070f9ef436 Mon Sep 17 00:00:00 2001 From: Job Date: Wed, 21 Aug 2024 18:21:32 +0100 Subject: [PATCH 4/8] Added trigger for test branch --- .github/workflows/release-tag-version.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release-tag-version.yml b/.github/workflows/release-tag-version.yml index edf7ea1270df7..242e14c8b463c 100644 --- a/.github/workflows/release-tag-version.yml +++ b/.github/workflows/release-tag-version.yml @@ -6,6 +6,8 @@ on: - "v1.*" - "!v1*-rc*" - "!v1*-dev" + branches: + - "release/v1.22*" concurrency: group: ${{ github.workflow }}-${{ github.ref }} From 3ca27264201d18d7530a4ad99dbd5ef2fe5a0bc0 Mon Sep 17 00:00:00 2001 From: Job Date: Thu, 22 Aug 2024 11:05:46 +0100 Subject: [PATCH 5/8] Undo changes to workflows --- .github/workflows/release-tag-version.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/release-tag-version.yml b/.github/workflows/release-tag-version.yml index 242e14c8b463c..edf7ea1270df7 100644 --- a/.github/workflows/release-tag-version.yml +++ b/.github/workflows/release-tag-version.yml @@ -6,8 +6,6 @@ on: - "v1.*" - "!v1*-rc*" - "!v1*-dev" - branches: - - "release/v1.22*" concurrency: group: ${{ github.workflow }}-${{ github.ref }} From e368a6bfce72b85a8ffb0bba3b8b4d7107fee6f3 Mon Sep 17 00:00:00 2001 From: Job - Date: Fri, 13 Sep 2024 12:46:04 +0000 Subject: [PATCH 6/8] Added test in comments --- tests/integration/pull_create_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/integration/pull_create_test.go b/tests/integration/pull_create_test.go index 5a06a7817f661..9c3d255f6170d 100644 --- a/tests/integration/pull_create_test.go +++ b/tests/integration/pull_create_test.go @@ -199,3 +199,15 @@ func TestPullBranchDelete(t *testing.T) { session.MakeRequest(t, req, http.StatusOK) }) } + +/* +Setup: +Create a base repository on: user1/base-repo +Fork repository to: user2/fork-repo +Push extra commit to: user1/base-repo, which changes README.md +Create a PR on user2/fork-repo + +Test checks: +Check if pull request is created and has a changed README.md +*/ +// func TestPullCreatePrFromBaseToFork(t *testing.T) {} From a1c8f398af6ae74ab5f7e502e49fd354c3312a68 Mon Sep 17 00:00:00 2001 From: LordChunk Date: Sat, 14 Sep 2024 10:15:22 +0000 Subject: [PATCH 7/8] Added integration test for creating PRs from base repos to a fork --- tests/integration/pull_create_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/integration/pull_create_test.go b/tests/integration/pull_create_test.go index 9c3d255f6170d..73d7acee53cf6 100644 --- a/tests/integration/pull_create_test.go +++ b/tests/integration/pull_create_test.go @@ -210,4 +210,25 @@ Create a PR on user2/fork-repo Test checks: Check if pull request is created and has a changed README.md */ -// func TestPullCreatePrFromBaseToFork(t *testing.T) {} +func TestPullCreatePrFromBaseToFork(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + session := loginUser(t, "user1") + testRepoFork(t, session, "user2", "fork-repo", "user1", "base-repo", "") + + // Push extra commit to base-repo + testEditFile(t, session, "user1", "base-repo", "master", "README.md", "Hello, World (Edited)\n") + + // Create PR + resp := testPullCreate(t, session, "user1", "base-repo", false, "master", "master", "This is a pull title") + + // check the redirected URL + url := test.RedirectURL(resp) + assert.Regexp(t, "^/user2/fork-repo/pulls/[0-9]*$", url) + + // check .diff can be accessed and has a changed README.md + req := NewRequest(t, "GET", url+".diff") + resp = session.MakeRequest(t, req, http.StatusOK) + assert.Regexp(t, `\+Hello, World \(Edited\)`, resp.Body) + assert.Regexp(t, "^diff", resp.Body) + }) +} From 9a133c0e56eb6a480d2378a6864d9a1012b92ef3 Mon Sep 17 00:00:00 2001 From: LordChunk Date: Sun, 15 Sep 2024 12:26:01 +0000 Subject: [PATCH 8/8] Fixed TestPullCreatePrFromBaseToFork --- tests/integration/pull_create_test.go | 32 +++++++++++---------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/tests/integration/pull_create_test.go b/tests/integration/pull_create_test.go index 73d7acee53cf6..9812d2073d1e9 100644 --- a/tests/integration/pull_create_test.go +++ b/tests/integration/pull_create_test.go @@ -202,33 +202,27 @@ func TestPullBranchDelete(t *testing.T) { /* Setup: -Create a base repository on: user1/base-repo -Fork repository to: user2/fork-repo -Push extra commit to: user1/base-repo, which changes README.md -Create a PR on user2/fork-repo +The base repository is: user2/repo1 +Fork repository to: user1/repo1 +Push extra commit to: user2/repo1, which changes README.md +Create a PR on user1/repo1 Test checks: -Check if pull request is created and has a changed README.md +Check if pull request can be created from base to the fork repository. */ func TestPullCreatePrFromBaseToFork(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { - session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "fork-repo", "user1", "base-repo", "") - - // Push extra commit to base-repo - testEditFile(t, session, "user1", "base-repo", "master", "README.md", "Hello, World (Edited)\n") + sessionFork := loginUser(t, "user1") + testRepoFork(t, sessionFork, "user2", "repo1", "user1", "repo1", "") - // Create PR - resp := testPullCreate(t, session, "user1", "base-repo", false, "master", "master", "This is a pull title") + // Edit base repository + sessionBase := loginUser(t, "user2") + testEditFile(t, sessionBase, "user2", "repo1", "master", "README.md", "Hello, World (Edited)\n") + // Create a PR + resp := testPullCreateDirectly(t, sessionFork, "user1", "repo1", "master", "user2", "repo1", "master", "This is a pull title") // check the redirected URL url := test.RedirectURL(resp) - assert.Regexp(t, "^/user2/fork-repo/pulls/[0-9]*$", url) - - // check .diff can be accessed and has a changed README.md - req := NewRequest(t, "GET", url+".diff") - resp = session.MakeRequest(t, req, http.StatusOK) - assert.Regexp(t, `\+Hello, World \(Edited\)`, resp.Body) - assert.Regexp(t, "^diff", resp.Body) + assert.Regexp(t, "^/user1/repo1/pulls/[0-9]*$", url) }) }