diff options
author | TheFox0x7 <thefox0x7@gmail.com> | 2024-12-29 02:32:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-29 01:32:19 +0000 |
commit | ff96873e3e14f6eae853ec8eee59ab4482962c43 (patch) | |
tree | 34c356537f80998ccb3a5dbadad9697b3afb4d7a | |
parent | 0ed160ffea91ac1903bd33866fa93c24e3ace65c (diff) | |
download | gitea-ff96873e3e14f6eae853ec8eee59ab4482962c43.tar.gz gitea-ff96873e3e14f6eae853ec8eee59ab4482962c43.zip |
Fix templating in pull request comparison (#33025)
Adds test for expected behavior
Closes: https://github.com/go-gitea/gitea/issues/33013
-rw-r--r-- | templates/base/alert_details.tmpl | 10 | ||||
-rw-r--r-- | tests/integration/pull_create_test.go | 68 |
2 files changed, 75 insertions, 3 deletions
diff --git a/templates/base/alert_details.tmpl b/templates/base/alert_details.tmpl index 6801c8240f..6d4c1fb2db 100644 --- a/templates/base/alert_details.tmpl +++ b/templates/base/alert_details.tmpl @@ -1,7 +1,11 @@ {{.Message}} +{{if .Details}} <details> <summary>{{.Summary}}</summary> - <code> - {{.Details | SanitizeHTML}} - </code> + <code>{{.Details | SanitizeHTML}}</code> </details> +{{else}} +<div> + {{.Summary}} +</div> +{{end}} diff --git a/tests/integration/pull_create_test.go b/tests/integration/pull_create_test.go index 4bc2a1da9a..162ea532c8 100644 --- a/tests/integration/pull_create_test.go +++ b/tests/integration/pull_create_test.go @@ -12,6 +12,7 @@ import ( "strings" "testing" + auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/tests" @@ -83,6 +84,30 @@ func testPullCreateDirectly(t *testing.T, session *TestSession, baseRepoOwner, b return resp } +func testPullCreateFailure(t *testing.T, session *TestSession, baseRepoOwner, baseRepoName, baseBranch, headRepoOwner, headRepoName, headBranch, title string) *httptest.ResponseRecorder { + headCompare := headBranch + if headRepoOwner != "" { + if headRepoName != "" { + headCompare = fmt.Sprintf("%s/%s:%s", headRepoOwner, headRepoName, headBranch) + } else { + headCompare = fmt.Sprintf("%s:%s", headRepoOwner, headBranch) + } + } + req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/compare/%s...%s", baseRepoOwner, baseRepoName, baseBranch, headCompare)) + resp := session.MakeRequest(t, req, http.StatusOK) + + // Submit the form for creating the pull + htmlDoc := NewHTMLParser(t, resp.Body) + link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action") + assert.True(t, exists, "The template has changed") + req = NewRequestWithValues(t, "POST", link, map[string]string{ + "_csrf": htmlDoc.GetCSRF(), + "title": title, + }) + resp = session.MakeRequest(t, req, http.StatusBadRequest) + return resp +} + func TestPullCreate(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { session := loginUser(t, "user1") @@ -245,3 +270,46 @@ func TestCreateAgitPullWithReadPermission(t *testing.T) { }) }) } + +/* +Setup: user2 has repository, user1 forks it +--- + +1. User2 blocks User1 +2. User1 adds changes to fork +3. User1 attempts to create a pull request +4. User1 sees alert that the action is not allowed because of the block +*/ +func TestCreatePullWhenBlocked(t *testing.T) { + RepoOwner := "user2" + ForkOwner := "user16" + onGiteaRun(t, func(t *testing.T, u *url.URL) { + // Setup + // User1 forks repo1 from User2 + sessionFork := loginUser(t, ForkOwner) + testRepoFork(t, sessionFork, RepoOwner, "repo1", ForkOwner, "forkrepo1", "") + + // 1. User2 blocks user1 + // sessionBase := loginUser(t, "user2") + token := getUserToken(t, RepoOwner, auth_model.AccessTokenScopeWriteUser) + + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/user/blocks/%s", ForkOwner)). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusNotFound) + req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/user/blocks/%s", ForkOwner)). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusNoContent) + + // 2. User1 adds changes to fork + testEditFile(t, sessionFork, ForkOwner, "forkrepo1", "master", "README.md", "Hello, World (Edited)\n") + + // 3. User1 attempts to create a pull request + testPullCreateFailure(t, sessionFork, RepoOwner, "repo1", "master", ForkOwner, "forkrepo1", "master", "This is a pull title") + + // Teardown + // Unblock user + req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/user/blocks/%s", ForkOwner)). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusNoContent) + }) +} |