mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Fix templating in pull request comparison (#33025)
Adds test for expected behavior Closes: https://github.com/go-gitea/gitea/issues/33013
This commit is contained in:
		| @@ -1,7 +1,11 @@ | |||||||
| {{.Message}} | {{.Message}} | ||||||
|  | {{if .Details}} | ||||||
| <details> | <details> | ||||||
| 	<summary>{{.Summary}}</summary> | 	<summary>{{.Summary}}</summary> | ||||||
| 	<code> | 	<code>{{.Details | SanitizeHTML}}</code> | ||||||
| 		{{.Details | SanitizeHTML}} |  | ||||||
| 	</code> |  | ||||||
| </details> | </details> | ||||||
|  | {{else}} | ||||||
|  | <div> | ||||||
|  | 	{{.Summary}} | ||||||
|  | </div> | ||||||
|  | {{end}} | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
|  |  | ||||||
|  | 	auth_model "code.gitea.io/gitea/models/auth" | ||||||
| 	"code.gitea.io/gitea/modules/git" | 	"code.gitea.io/gitea/modules/git" | ||||||
| 	"code.gitea.io/gitea/modules/test" | 	"code.gitea.io/gitea/modules/test" | ||||||
| 	"code.gitea.io/gitea/tests" | 	"code.gitea.io/gitea/tests" | ||||||
| @@ -83,6 +84,30 @@ func testPullCreateDirectly(t *testing.T, session *TestSession, baseRepoOwner, b | |||||||
| 	return resp | 	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) { | func TestPullCreate(t *testing.T) { | ||||||
| 	onGiteaRun(t, func(t *testing.T, u *url.URL) { | 	onGiteaRun(t, func(t *testing.T, u *url.URL) { | ||||||
| 		session := loginUser(t, "user1") | 		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) | ||||||
|  | 	}) | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user