mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	@@ -17,7 +17,8 @@ import (
 | 
			
		||||
 | 
			
		||||
func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
 | 
			
		||||
	token := getUserToken(t, "user2", auth_model.AccessTokenScopeReadRepository)
 | 
			
		||||
	req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s?token=%s", branchName, token)
 | 
			
		||||
	req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s", branchName).
 | 
			
		||||
		AddTokenAuth(token)
 | 
			
		||||
	resp := MakeRequest(t, req, NoExpectedStatus)
 | 
			
		||||
	if !exists {
 | 
			
		||||
		assert.EqualValues(t, http.StatusNotFound, resp.Code)
 | 
			
		||||
@@ -33,7 +34,8 @@ func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
 | 
			
		||||
 | 
			
		||||
func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) *api.BranchProtection {
 | 
			
		||||
	token := getUserToken(t, "user2", auth_model.AccessTokenScopeReadRepository)
 | 
			
		||||
	req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token)
 | 
			
		||||
	req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branch_protections/%s", branchName).
 | 
			
		||||
		AddTokenAuth(token)
 | 
			
		||||
	resp := MakeRequest(t, req, expectedHTTPStatus)
 | 
			
		||||
 | 
			
		||||
	if resp.Code == http.StatusOK {
 | 
			
		||||
@@ -47,9 +49,9 @@ func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPSta
 | 
			
		||||
 | 
			
		||||
func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) {
 | 
			
		||||
	token := getUserToken(t, "user2", auth_model.AccessTokenScopeWriteRepository)
 | 
			
		||||
	req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/branch_protections?token="+token, &api.BranchProtection{
 | 
			
		||||
	req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/branch_protections", &api.BranchProtection{
 | 
			
		||||
		RuleName: branchName,
 | 
			
		||||
	})
 | 
			
		||||
	}).AddTokenAuth(token)
 | 
			
		||||
	resp := MakeRequest(t, req, expectedHTTPStatus)
 | 
			
		||||
 | 
			
		||||
	if resp.Code == http.StatusCreated {
 | 
			
		||||
@@ -61,7 +63,8 @@ func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTP
 | 
			
		||||
 | 
			
		||||
func testAPIEditBranchProtection(t *testing.T, branchName string, body *api.BranchProtection, expectedHTTPStatus int) {
 | 
			
		||||
	token := getUserToken(t, "user2", auth_model.AccessTokenScopeWriteRepository)
 | 
			
		||||
	req := NewRequestWithJSON(t, "PATCH", "/api/v1/repos/user2/repo1/branch_protections/"+branchName+"?token="+token, body)
 | 
			
		||||
	req := NewRequestWithJSON(t, "PATCH", "/api/v1/repos/user2/repo1/branch_protections/"+branchName, body).
 | 
			
		||||
		AddTokenAuth(token)
 | 
			
		||||
	resp := MakeRequest(t, req, expectedHTTPStatus)
 | 
			
		||||
 | 
			
		||||
	if resp.Code == http.StatusOK {
 | 
			
		||||
@@ -73,13 +76,15 @@ func testAPIEditBranchProtection(t *testing.T, branchName string, body *api.Bran
 | 
			
		||||
 | 
			
		||||
func testAPIDeleteBranchProtection(t *testing.T, branchName string, expectedHTTPStatus int) {
 | 
			
		||||
	token := getUserToken(t, "user2", auth_model.AccessTokenScopeWriteRepository)
 | 
			
		||||
	req := NewRequestf(t, "DELETE", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token)
 | 
			
		||||
	req := NewRequestf(t, "DELETE", "/api/v1/repos/user2/repo1/branch_protections/%s", branchName).
 | 
			
		||||
		AddTokenAuth(token)
 | 
			
		||||
	MakeRequest(t, req, expectedHTTPStatus)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func testAPIDeleteBranch(t *testing.T, branchName string, expectedHTTPStatus int) {
 | 
			
		||||
	token := getUserToken(t, "user2", auth_model.AccessTokenScopeWriteRepository)
 | 
			
		||||
	req := NewRequestf(t, "DELETE", "/api/v1/repos/user2/repo1/branches/%s?token=%s", branchName, token)
 | 
			
		||||
	req := NewRequestf(t, "DELETE", "/api/v1/repos/user2/repo1/branches/%s", branchName).
 | 
			
		||||
		AddTokenAuth(token)
 | 
			
		||||
	MakeRequest(t, req, expectedHTTPStatus)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -152,10 +157,10 @@ func testAPICreateBranches(t *testing.T, giteaURL *url.URL) {
 | 
			
		||||
 | 
			
		||||
func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBranch, newBranch string, status int) bool {
 | 
			
		||||
	token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
 | 
			
		||||
	req := NewRequestWithJSON(t, "POST", "/api/v1/repos/"+user+"/"+repo+"/branches?token="+token, &api.CreateBranchRepoOption{
 | 
			
		||||
	req := NewRequestWithJSON(t, "POST", "/api/v1/repos/"+user+"/"+repo+"/branches", &api.CreateBranchRepoOption{
 | 
			
		||||
		BranchName:    newBranch,
 | 
			
		||||
		OldBranchName: oldBranch,
 | 
			
		||||
	})
 | 
			
		||||
	}).AddTokenAuth(token)
 | 
			
		||||
	resp := MakeRequest(t, req, status)
 | 
			
		||||
 | 
			
		||||
	var branch api.Branch
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user