diff --git a/tests/integration/actions_job_test.go b/tests/integration/actions_job_test.go index 78259a2d4c..1a4cb95f80 100644 --- a/tests/integration/actions_job_test.go +++ b/tests/integration/actions_job_test.go @@ -154,11 +154,8 @@ jobs: } // check result - var groupSegment string - if apiRepo.GroupID > 0 { - groupSegment = fmt.Sprintf("%d/", apiRepo.GroupID) - } - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/actions/tasks", user2.Name, groupSegment, apiRepo.Name)). + + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/actions/tasks", user2.Name, maybeGroupSegment(apiRepo.GroupID), apiRepo.Name)). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) var actionTaskRespAfter api.ActionTaskResponse @@ -739,11 +736,7 @@ func getWorkflowCreateFileOptions(u *user_model.User, branch, msg, content strin } func createWorkflowFile(t *testing.T, authToken, ownerName, repoName string, groupID int64, treePath string, opts *api.CreateFileOptions) *api.FileResponse { - var groupSegment string - if groupID > 0 { - groupSegment = fmt.Sprintf("%d/", groupID) - } - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", ownerName, groupSegment, repoName, treePath), opts). + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", ownerName, maybeGroupSegment(groupID), repoName, treePath), opts). AddTokenAuth(authToken) resp := MakeRequest(t, req, http.StatusCreated) var fileResponse api.FileResponse diff --git a/tests/integration/actions_log_test.go b/tests/integration/actions_log_test.go index 5260411a1c..1465d4ae51 100644 --- a/tests/integration/actions_log_test.go +++ b/tests/integration/actions_log_test.go @@ -198,11 +198,8 @@ jobs: } // download task logs from API and check content - var groupSegment string - if repo.GroupID > 0 { - groupSegment = fmt.Sprintf("%d/", repo.GroupID) - } - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/actions/jobs/%d/logs", user2.Name, groupSegment, repo.Name, job.ID)). + + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/actions/jobs/%d/logs", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name, job.ID)). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n") diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go index 6f517e2387..0ddc73aab5 100644 --- a/tests/integration/actions_trigger_test.go +++ b/tests/integration/actions_trigger_test.go @@ -1563,7 +1563,7 @@ jobs: createWorkflowFile(t, user2Token, baseRepo.OwnerName, baseRepo.Name, baseRepo.GroupID, wfTreePath, opts1) // user4 forks the repo - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/forks", baseRepo.OwnerName, baseRepo.GroupID, baseRepo.Name), + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/forks", baseRepo.OwnerName, maybeGroupSegment(baseRepo.GroupID), baseRepo.Name), &api.CreateForkOption{ Name: new("close-pull-request-with-path-fork"), }).AddTokenAuth(user4Token) diff --git a/tests/integration/api_branch_test.go b/tests/integration/api_branch_test.go index e55e0126ff..2b61d0a52b 100644 --- a/tests/integration/api_branch_test.go +++ b/tests/integration/api_branch_test.go @@ -173,11 +173,8 @@ func testAPICreateBranches(t *testing.T, giteaURL *url.URL) { func testAPICreateBranch(t testing.TB, session *TestSession, groupID int64, user, repo, oldBranch, newBranch string, status int) bool { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - var groupSegment string - if groupID > 0 { - groupSegment = fmt.Sprintf("%d/", groupID) - } - req := NewRequestWithJSON(t, "POST", "/api/v1/repos/"+user+"/"+groupSegment+repo+"/branches", &api.CreateBranchRepoOption{ + + req := NewRequestWithJSON(t, "POST", "/api/v1/repos/"+user+"/"+maybeGroupSegment(groupID)+repo+"/branches", &api.CreateBranchRepoOption{ BranchName: newBranch, OldBranchName: oldBranch, }).AddTokenAuth(token) diff --git a/tests/integration/api_comment_attachment_test.go b/tests/integration/api_comment_attachment_test.go index 8cf74e5ff4..826b970df6 100644 --- a/tests/integration/api_comment_attachment_test.go +++ b/tests/integration/api_comment_attachment_test.go @@ -36,17 +36,17 @@ func TestAPIGetCommentAttachment(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID, attachment.ID). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/comments/%d/assets/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID, attachment.ID). AddTokenAuth(token) MakeRequest(t, req, http.StatusNotFound) }) session := loginUser(t, repoOwner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID, attachment.ID). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/comments/%d/assets/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID, attachment.ID). AddTokenAuth(token) session.MakeRequest(t, req, http.StatusOK) - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID, attachment.ID). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/comments/%d/assets/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID, attachment.ID). AddTokenAuth(token) resp := session.MakeRequest(t, req, http.StatusOK) @@ -71,7 +71,7 @@ func TestAPIListCommentAttachments(t *testing.T) { session := loginUser(t, repoOwner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, comment.ID). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/comments/%d/assets", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID). AddTokenAuth(token) resp := session.MakeRequest(t, req, http.StatusOK) @@ -105,7 +105,7 @@ func TestAPICreateCommentAttachment(t *testing.T) { err = writer.Close() assert.NoError(t, err) - req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/comments/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, comment.ID), body). + req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/comments/%d/assets", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID), body). AddTokenAuth(token). SetHeader("Content-Type", writer.FormDataContentType()) resp := session.MakeRequest(t, req, http.StatusCreated) @@ -137,7 +137,7 @@ func TestAPICreateCommentAttachmentWithUnallowedFile(t *testing.T) { err = writer.Close() assert.NoError(t, err) - req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/comments/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, comment.ID), body). + req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/comments/%d/assets", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID), body). AddTokenAuth(token). SetHeader("Content-Type", writer.FormDataContentType()) @@ -202,7 +202,7 @@ func TestAPIDeleteCommentAttachment(t *testing.T) { session := loginUser(t, repoOwner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) - req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID, attachment.ID)). + req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/comments/%d/assets/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID, attachment.ID)). AddTokenAuth(token) session.MakeRequest(t, req, http.StatusNoContent) diff --git a/tests/integration/api_comment_test.go b/tests/integration/api_comment_test.go index 24cb5e3ca4..d0249d6884 100644 --- a/tests/integration/api_comment_test.go +++ b/tests/integration/api_comment_test.go @@ -30,7 +30,7 @@ func TestAPIListRepoComments(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/comments", repoOwner.Name, repo.GroupID, repo.Name)) + link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/comments", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name)) req := NewRequest(t, "GET", link.String()) resp := MakeRequest(t, req, http.StatusOK) @@ -76,7 +76,7 @@ func TestAPIListIssueComments(t *testing.T) { repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeReadIssue) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/%d/comments", repoOwner.Name, repo.GroupID, repo.Name, issue.Index). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/%d/comments", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) @@ -115,7 +115,7 @@ func TestAPICreateComment(t *testing.T) { issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) - req := NewRequestWithValues(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/comments", repo.OwnerName, repo.GroupID, repo.Name, issue.Index), map[string]string{ + req := NewRequestWithValues(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/comments", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index), map[string]string{ "body": commentBody, }).AddTokenAuth(getUserToken(t, user34.Name, auth_model.AccessTokenScopeWriteRepository)) MakeRequest(t, req, http.StatusForbidden) @@ -128,7 +128,7 @@ func TestAPICreateComment(t *testing.T) { issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 13}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) - req := NewRequestWithValues(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/comments", repo.OwnerName, repo.GroupID, repo.Name, issue.Index), map[string]string{ + req := NewRequestWithValues(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/comments", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index), map[string]string{ "body": commentBody, }).AddTokenAuth(getUserToken(t, user34.Name, auth_model.AccessTokenScopeWriteRepository)) MakeRequest(t, req, http.StatusForbidden) @@ -144,9 +144,9 @@ func TestAPIGetComment(t *testing.T) { repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeReadIssue) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/comments/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID) MakeRequest(t, req, http.StatusOK) - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/comments/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) @@ -183,7 +183,7 @@ func TestAPIGetSystemUserComment(t *testing.T) { }) assert.NoError(t, err) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/comments/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID) resp := MakeRequest(t, req, http.StatusOK) var apiComment api.Comment @@ -251,13 +251,13 @@ func TestAPIDeleteComment(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) - req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID). + req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s%s/issues/comments/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID). AddTokenAuth(token) MakeRequest(t, req, http.StatusNotFound) }) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) - req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID). + req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s%s/issues/comments/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) @@ -273,7 +273,7 @@ func TestAPIListIssueTimeline(t *testing.T) { repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) // make request - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/%d/timeline", repoOwner.Name, repo.GroupID, repo.Name, issue.Index) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/issues/%d/timeline", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index) resp := MakeRequest(t, req, http.StatusOK) // check if lens of list returned by API and diff --git a/tests/integration/api_issue_attachment_test.go b/tests/integration/api_issue_attachment_test.go index e55602c96d..8b2eb30c8b 100644 --- a/tests/integration/api_issue_attachment_test.go +++ b/tests/integration/api_issue_attachment_test.go @@ -32,7 +32,7 @@ func TestAPIGetIssueAttachment(t *testing.T) { session := loginUser(t, repoOwner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, issue.Index, attachment.ID)). + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/assets/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index, attachment.ID)). AddTokenAuth(token) resp := session.MakeRequest(t, req, http.StatusOK) apiAttachment := new(api.Attachment) @@ -52,7 +52,7 @@ func TestAPIListIssueAttachments(t *testing.T) { session := loginUser(t, repoOwner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, issue.Index)). + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/assets", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)). AddTokenAuth(token) resp := session.MakeRequest(t, req, http.StatusOK) apiAttachment := new([]api.Attachment) @@ -82,7 +82,7 @@ func TestAPICreateIssueAttachment(t *testing.T) { err = writer.Close() assert.NoError(t, err) - req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, issue.Index), body). + req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/assets", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index), body). AddTokenAuth(token) req.Header.Add("Content-Type", writer.FormDataContentType()) resp := session.MakeRequest(t, req, http.StatusCreated) @@ -113,7 +113,7 @@ func TestAPICreateIssueAttachmentWithUnallowedFile(t *testing.T) { err = writer.Close() assert.NoError(t, err) - req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, issue.Index), body). + req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/assets", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index), body). AddTokenAuth(token) req.Header.Add("Content-Type", writer.FormDataContentType()) @@ -156,7 +156,7 @@ func TestAPIEditIssueAttachmentWithUnallowedFile(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) filename := "file.bad" - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, issue.Index, attachment.ID) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/assets/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index, attachment.ID) req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ "name": filename, }).AddTokenAuth(token) @@ -175,7 +175,7 @@ func TestAPIDeleteIssueAttachment(t *testing.T) { session := loginUser(t, repoOwner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) - req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, issue.Index, attachment.ID)). + req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/assets/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index, attachment.ID)). AddTokenAuth(token) session.MakeRequest(t, req, http.StatusNoContent) diff --git a/tests/integration/api_issue_config_test.go b/tests/integration/api_issue_config_test.go index e0b33804d9..db3d7f821e 100644 --- a/tests/integration/api_issue_config_test.go +++ b/tests/integration/api_issue_config_test.go @@ -150,7 +150,7 @@ func TestAPIRepoValidateIssueConfig(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 49}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issue_config/validate", owner.Name, repo.GroupID, repo.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issue_config/validate", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name) t.Run("Valid", func(t *testing.T) { req := NewRequest(t, "GET", urlStr) diff --git a/tests/integration/api_issue_label_test.go b/tests/integration/api_issue_label_test.go index 4899bccbc0..1b15ba794c 100644 --- a/tests/integration/api_issue_label_test.go +++ b/tests/integration/api_issue_label_test.go @@ -26,7 +26,7 @@ func TestAPIModifyLabels(t *testing.T) { owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/labels", owner.Name, repo.GroupID, repo.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/labels", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name) // CreateLabel req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateLabelOption{ @@ -62,7 +62,7 @@ func TestAPIModifyLabels(t *testing.T) { assert.Len(t, apiLabels, 2) // GetLabel - singleURLStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/labels/%d", owner.Name, repo.GroupID, repo.Name, dbLabel.ID) + singleURLStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/labels/%d", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, dbLabel.ID) req = NewRequest(t, "GET", singleURLStr). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) @@ -127,7 +127,7 @@ func TestAPIAddIssueLabelsWithLabelNames(t *testing.T) { token := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeWriteIssue) // add the org label and the repo label to the issue - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/labels", owner.Name, repo.GroupID, repo.Name, issue.Index) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/labels", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index) req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{ Labels: []any{repoLabel.Name, orgLabel.Name}, }).AddTokenAuth(token) diff --git a/tests/integration/api_issue_lock_test.go b/tests/integration/api_issue_lock_test.go index 6f8ddbf7af..724b73d2f3 100644 --- a/tests/integration/api_issue_lock_test.go +++ b/tests/integration/api_issue_lock_test.go @@ -27,7 +27,7 @@ func TestAPILockIssue(t *testing.T) { assert.False(t, issueBefore.IsLocked) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/lock", owner.Name, repo.GroupID, repo.Name, issueBefore.Index) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/lock", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issueBefore.Index) session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) @@ -50,7 +50,7 @@ func TestAPILockIssue(t *testing.T) { issueBefore := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/lock", owner.Name, repo.GroupID, repo.Name, issueBefore.Index) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/lock", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, issueBefore.Index) session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) diff --git a/tests/integration/api_issue_milestone_test.go b/tests/integration/api_issue_milestone_test.go index d27dc99b9e..ad798b9298 100644 --- a/tests/integration/api_issue_milestone_test.go +++ b/tests/integration/api_issue_milestone_test.go @@ -34,7 +34,7 @@ func TestAPIIssuesMilestone(t *testing.T) { // update values of issue milestoneState := "closed" - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones/%d", owner.Name, repo.GroupID, repo.Name, milestone.ID) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/milestones/%d", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, milestone.ID) req := NewRequestWithJSON(t, "PATCH", urlStr, structs.EditMilestoneOption{ State: &milestoneState, }).AddTokenAuth(token) @@ -50,7 +50,7 @@ func TestAPIIssuesMilestone(t *testing.T) { DecodeJSON(t, resp, &apiMilestone2) assert.EqualValues(t, "closed", apiMilestone2.State) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones", owner.Name, repo.GroupID, repo.Name), structs.CreateMilestoneOption{ + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/milestones", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name), structs.CreateMilestoneOption{ Title: "wow", Description: "closed one", State: "closed", @@ -62,27 +62,27 @@ func TestAPIIssuesMilestone(t *testing.T) { assert.Nil(t, apiMilestone.Deadline) var apiMilestones []structs.Milestone - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones?state=%s", owner.Name, repo.GroupID, repo.Name, "all")). + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/milestones?state=%s", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, "all")). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiMilestones) assert.Len(t, apiMilestones, 4) assert.Nil(t, apiMilestones[0].Deadline) - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones/%s", owner.Name, repo.GroupID, repo.Name, apiMilestones[2].Title)). + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/milestones/%s", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, apiMilestones[2].Title)). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiMilestone) assert.Equal(t, apiMilestones[2], apiMilestone) - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones?state=%s&name=%s", owner.Name, repo.GroupID, repo.Name, "all", "milestone2")). + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/milestones?state=%s&name=%s", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, "all", "milestone2")). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiMilestones) assert.Len(t, apiMilestones, 1) assert.Equal(t, int64(2), apiMilestones[0].ID) - req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones/%d", owner.Name, repo.GroupID, repo.Name, apiMilestone.ID)). + req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/milestones/%d", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, apiMilestone.ID)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) } diff --git a/tests/integration/api_issue_pin_test.go b/tests/integration/api_issue_pin_test.go index 445f4d3116..b25e6f9557 100644 --- a/tests/integration/api_issue_pin_test.go +++ b/tests/integration/api_issue_pin_test.go @@ -32,12 +32,12 @@ func TestAPIPinIssue(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) // Pin the Issue - req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)). + req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/pin", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // Check if the Issue is pinned - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)) resp := MakeRequest(t, req, http.StatusOK) var issueAPI api.Issue DecodeJSON(t, resp, &issueAPI) @@ -57,24 +57,24 @@ func TestAPIUnpinIssue(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) // Pin the Issue - req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)). + req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/pin", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // Check if the Issue is pinned - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)) resp := MakeRequest(t, req, http.StatusOK) var issueAPI api.Issue DecodeJSON(t, resp, &issueAPI) assert.Equal(t, 1, issueAPI.PinOrder) // Unpin the Issue - req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)). + req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/pin", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // Check if the Issue is no longer pinned - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &issueAPI) assert.Equal(t, 0, issueAPI.PinOrder) @@ -94,36 +94,36 @@ func TestAPIMoveIssuePin(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) // Pin the first Issue - req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)). + req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/pin", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // Check if the first Issue is pinned at position 1 - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)) resp := MakeRequest(t, req, http.StatusOK) var issueAPI api.Issue DecodeJSON(t, resp, &issueAPI) assert.Equal(t, 1, issueAPI.PinOrder) // Pin the second Issue - req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue2.Index)). + req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/pin", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue2.Index)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // Move the first Issue to position 2 - req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin/2", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)). + req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/pin/2", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // Check if the first Issue is pinned at position 2 - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)) resp = MakeRequest(t, req, http.StatusOK) var issueAPI3 api.Issue DecodeJSON(t, resp, &issueAPI3) assert.Equal(t, 2, issueAPI3.PinOrder) // Check if the second Issue is pinned at position 1 - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue2.Index)) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue2.Index)) resp = MakeRequest(t, req, http.StatusOK) var issueAPI4 api.Issue DecodeJSON(t, resp, &issueAPI4) @@ -143,12 +143,12 @@ func TestAPIListPinnedIssues(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) // Pin the Issue - req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)). + req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/pin", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, issue.Index)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // Check if the Issue is in the List - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/pinned", repo.OwnerName, repo.GroupID, repo.Name)) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/pinned", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name)) resp := MakeRequest(t, req, http.StatusOK) var issueList []api.Issue DecodeJSON(t, resp, &issueList) @@ -164,7 +164,7 @@ func TestAPIListPinnedPullrequests(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/pinned", repo.OwnerName, repo.GroupID, repo.Name)) + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/pinned", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name)) resp := MakeRequest(t, req, http.StatusOK) var prList []api.PullRequest DecodeJSON(t, resp, &prList) @@ -178,7 +178,7 @@ func TestAPINewPinAllowed(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/new_pin_allowed", owner.Name, repo.GroupID, repo.Name)) + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/new_pin_allowed", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp := MakeRequest(t, req, http.StatusOK) var newPinsAllowed api.NewIssuePinsAllowed diff --git a/tests/integration/api_issue_reaction_test.go b/tests/integration/api_issue_reaction_test.go index 0e26b63a0f..3b94ef367a 100644 --- a/tests/integration/api_issue_reaction_test.go +++ b/tests/integration/api_issue_reaction_test.go @@ -118,7 +118,7 @@ func TestAPICommentReactions(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/comments/%d/reactions", repoOwner.Name, repo.GroupID, repo.Name, comment.ID) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/comments/%d/reactions", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, comment.ID) req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{ Reaction: "+1", }).AddTokenAuth(token) diff --git a/tests/integration/api_issue_subscription_test.go b/tests/integration/api_issue_subscription_test.go index 90085d8961..0980a80643 100644 --- a/tests/integration/api_issue_subscription_test.go +++ b/tests/integration/api_issue_subscription_test.go @@ -36,7 +36,7 @@ func TestAPIIssueSubscriptions(t *testing.T) { testSubscription := func(issue *issues_model.Issue, isWatching bool) { issueRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/subscriptions/check", issueRepo.OwnerName, issueRepo.GroupID, issueRepo.Name, issue.Index)). + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/subscriptions/check", issueRepo.OwnerName, maybeGroupSegment(issueRepo.GroupID), issueRepo.Name, issue.Index)). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) wi := new(api.WatchInfo) @@ -56,7 +56,7 @@ func TestAPIIssueSubscriptions(t *testing.T) { testSubscription(issue5, false) issue1Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue1.RepoID}) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/subscriptions/%s", issue1Repo.OwnerName, issue1Repo.GroupID, issue1Repo.Name, issue1.Index, owner.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/subscriptions/%s", issue1Repo.OwnerName, maybeGroupSegment(issue1Repo.GroupID), issue1Repo.Name, issue1.Index, owner.Name) req := NewRequest(t, "DELETE", urlStr). AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) @@ -68,7 +68,7 @@ func TestAPIIssueSubscriptions(t *testing.T) { testSubscription(issue1, false) issue5Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue5.RepoID}) - urlStr = fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/subscriptions/%s", issue5Repo.OwnerName, issue5Repo.GroupID, issue5Repo.Name, issue5.Index, owner.Name) + urlStr = fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d/subscriptions/%s", issue5Repo.OwnerName, maybeGroupSegment(issue5Repo.GroupID), issue5Repo.Name, issue5.Index, owner.Name) req = NewRequest(t, "PUT", urlStr). AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index 2e94504ae3..163da0a9e1 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -43,7 +43,7 @@ func testAPIListIssues(t *testing.T) { session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) - link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner.Name, repo.GroupID, repo.Name)) + link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/issues", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name)) link.RawQuery = url.Values{"token": {token}, "state": {"all"}}.Encode() resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) @@ -91,7 +91,7 @@ func testAPIListIssuesPublicOnly(t *testing.T) { session := loginUser(t, owner1.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) - link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner1.Name, repo1.GroupID, repo1.Name)) + link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/issues", owner1.Name, maybeGroupSegment(repo1.GroupID), repo1.Name)) link.RawQuery = url.Values{"state": {"all"}}.Encode() req := NewRequest(t, "GET", link.String()).AddTokenAuth(token) MakeRequest(t, req, http.StatusOK) @@ -101,7 +101,7 @@ func testAPIListIssuesPublicOnly(t *testing.T) { session = loginUser(t, owner2.Name) token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) - link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner2.Name, repo2.GroupID, repo2.Name)) + link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/issues", owner2.Name, maybeGroupSegment(repo2.GroupID), repo2.Name)) link.RawQuery = url.Values{"state": {"all"}}.Encode() req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) MakeRequest(t, req, http.StatusOK) @@ -119,7 +119,7 @@ func testAPICreateIssue(t *testing.T) { session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner.Name, repoBefore.GroupID, repoBefore.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues", owner.Name, maybeGroupSegment(repoBefore.GroupID), repoBefore.Name) req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{ Body: body, Title: title, @@ -168,7 +168,7 @@ func testAPICreateIssueParallel(t *testing.T) { session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner.Name, repoBefore.GroupID, repoBefore.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues", owner.Name, maybeGroupSegment(repoBefore.GroupID), repoBefore.Name) var wg sync.WaitGroup for i := range 10 { @@ -220,7 +220,7 @@ func testAPIEditIssue(t *testing.T) { body := "new content!" title := "new title from api set" - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", owner.Name, repoBefore.GroupID, repoBefore.Name, issueBefore.Index) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues/%d", owner.Name, maybeGroupSegment(repoBefore.GroupID), repoBefore.Name, issueBefore.Index) req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{ State: &issueState, RemoveDeadline: &removeDeadline, diff --git a/tests/integration/api_keys_test.go b/tests/integration/api_keys_test.go index 187a728a53..12c4080822 100644 --- a/tests/integration/api_keys_test.go +++ b/tests/integration/api_keys_test.go @@ -55,7 +55,7 @@ func TestCreateReadOnlyDeployKey(t *testing.T) { session := loginUser(t, repoOwner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - keysURL := fmt.Sprintf("/api/v1/repos/%s/%d/%s/keys", repoOwner.Name, repo.GroupID, repo.Name) + keysURL := fmt.Sprintf("/api/v1/repos/%s/%s%s/keys", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name) rawKeyBody := api.CreateKeyOption{ Title: "read-only", Key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n", @@ -76,7 +76,7 @@ func TestCreateReadOnlyDeployKey(t *testing.T) { // Using the ID of a key that does not belong to the repository must fail { - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/keys/%d", repoOwner.Name, repo.GroupID, repo.Name, newDeployKey.ID)). + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/keys/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, newDeployKey.ID)). AddTokenAuth(token) MakeRequest(t, req, http.StatusOK) @@ -95,7 +95,7 @@ func TestCreateReadWriteDeployKey(t *testing.T) { session := loginUser(t, repoOwner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - keysURL := fmt.Sprintf("/api/v1/repos/%s/%d/%s/keys", repoOwner.Name, repo.GroupID, repo.Name) + keysURL := fmt.Sprintf("/api/v1/repos/%s/%s%s/keys", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name) rawKeyBody := api.CreateKeyOption{ Title: "read-write", Key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n", diff --git a/tests/integration/api_notification_test.go b/tests/integration/api_notification_test.go index 06b66430bc..398cd7c417 100644 --- a/tests/integration/api_notification_test.go +++ b/tests/integration/api_notification_test.go @@ -63,7 +63,7 @@ func TestAPINotification(t *testing.T) { assert.False(t, apiNL[2].Pinned) // -- GET /repos/{owner}/{repo}/notifications -- - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/notifications?status-types=unread", user2.Name, repo1.GroupID, repo1.Name)). + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/notifications?status-types=unread", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name)). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiNL) @@ -72,7 +72,7 @@ func TestAPINotification(t *testing.T) { assert.EqualValues(t, 4, apiNL[0].ID) // -- GET /repos/{owner}/{repo}/notifications -- multiple status-types - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/notifications?status-types=unread&status-types=pinned", user2.Name, repo1.GroupID, repo1.Name)). + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/notifications?status-types=unread&status-types=pinned", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name)). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiNL) @@ -129,7 +129,7 @@ func TestAPINotification(t *testing.T) { assert.Len(t, apiNL, 2) lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ... - req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/notifications?last_read_at=%s", user2.Name, repo1.GroupID, repo1.Name, lastReadAt)). + req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/notifications?last_read_at=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, lastReadAt)). AddTokenAuth(token) MakeRequest(t, req, http.StatusResetContent) diff --git a/tests/integration/api_packages_helm_test.go b/tests/integration/api_packages_helm_test.go index 02df4ae906..c86bf267b1 100644 --- a/tests/integration/api_packages_helm_test.go +++ b/tests/integration/api_packages_helm_test.go @@ -159,7 +159,7 @@ dependencies: assert.Len(t, cv.Maintainers, 1) assert.Equal(t, packageAuthor, cv.Maintainers[0].Name) assert.Len(t, cv.Dependencies, 1) - assert.ElementsMatch(t, []string{fmt.Sprintf("%s%s/%s", setting.AppURL, url[1:], filename)}, cv.URLs) + assert.ElementsMatch(t, []string{fmt.Sprintf("%s/%s%s", setting.AppURL, url[1:], filename)}, cv.URLs) assert.Equal(t, url, result.ServerInfo.ContextPath) }) diff --git a/tests/integration/api_pull_commits_test.go b/tests/integration/api_pull_commits_test.go index 45ab4cf344..9a99562cd5 100644 --- a/tests/integration/api_pull_commits_test.go +++ b/tests/integration/api_pull_commits_test.go @@ -23,7 +23,7 @@ func TestAPIPullCommits(t *testing.T) { assert.NoError(t, pr.LoadIssue(t.Context())) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pr.HeadRepoID}) - req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%d/%s/pulls/%d/commits", repo.OwnerName, repo.GroupID, repo.Name, pr.Index) + req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s%s/pulls/%d/commits", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pr.Index) resp := MakeRequest(t, req, http.StatusOK) var commits []*api.Commit diff --git a/tests/integration/api_pull_review_test.go b/tests/integration/api_pull_review_test.go index 7b92e7453c..187d6ef139 100644 --- a/tests/integration/api_pull_review_test.go +++ b/tests/integration/api_pull_review_test.go @@ -36,7 +36,7 @@ func TestAPIPullReview(t *testing.T) { // test ListPullReviews session := loginUser(t, "user2") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index). + req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) @@ -61,14 +61,14 @@ func TestAPIPullReview(t *testing.T) { assert.True(t, reviews[5].Official) // test GetPullReview - req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%d/%s/pulls/%d/reviews/%d", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index, reviews[3].ID). + req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s%s/pulls/%d/reviews/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index, reviews[3].ID). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) var review api.PullReview DecodeJSON(t, resp, &review) assert.Equal(t, *reviews[3], review) - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/pulls/%d/reviews/%d", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index, reviews[5].ID). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/pulls/%d/reviews/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index, reviews[5].ID). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &review) @@ -76,7 +76,7 @@ func TestAPIPullReview(t *testing.T) { // test GetPullReviewComments comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 7}) - req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%d/%s/pulls/%d/reviews/%d/comments", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index, 10). + req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s%s/pulls/%d/reviews/%d/comments", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index, 10). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) var reviewComments []*api.PullReviewComment @@ -89,7 +89,7 @@ func TestAPIPullReview(t *testing.T) { assert.Equal(t, comment.HTMLURL(t.Context()), reviewComments[0].HTMLURL) // test CreatePullReview - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ Body: "body1", // Event: "" # will result in PENDING Comments: []api.CreatePullReviewComment{ @@ -118,7 +118,7 @@ func TestAPIPullReview(t *testing.T) { assert.Equal(t, 3, review.CodeCommentsCount) // test SubmitPullReview - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews/%d", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index, review.ID), &api.SubmitPullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index, review.ID), &api.SubmitPullReviewOptions{ Event: "APPROVED", Body: "just two nits", }).AddTokenAuth(token) @@ -129,7 +129,7 @@ func TestAPIPullReview(t *testing.T) { assert.Equal(t, 3, review.CodeCommentsCount) // test dismiss review - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews/%d/dismissals", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index, review.ID), &api.DismissPullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews/%d/dismissals", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index, review.ID), &api.DismissPullReviewOptions{ Message: "test", }).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) @@ -138,7 +138,7 @@ func TestAPIPullReview(t *testing.T) { assert.True(t, review.Dismissed) // test dismiss review - req = NewRequest(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews/%d/undismissals", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index, review.ID)). + req = NewRequest(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews/%d/undismissals", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index, review.ID)). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &review) @@ -146,7 +146,7 @@ func TestAPIPullReview(t *testing.T) { assert.False(t, review.Dismissed) // test DeletePullReview - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ Body: "just a comment", Event: "COMMENT", }).AddTokenAuth(token) @@ -154,12 +154,12 @@ func TestAPIPullReview(t *testing.T) { DecodeJSON(t, resp, &review) assert.EqualValues(t, "COMMENT", review.State) assert.Equal(t, 0, review.CodeCommentsCount) - req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%d/%s/pulls/%d/reviews/%d", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index, review.ID). + req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s%s/pulls/%d/reviews/%d", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index, review.ID). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // test CreatePullReview Comment without body but with comments - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ // Body: "", Event: "COMMENT", Comments: []api.CreatePullReviewComment{ @@ -187,7 +187,7 @@ func TestAPIPullReview(t *testing.T) { // test CreatePullReview Comment with body but without comments commentBody := "This is a body of the comment." - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ Body: commentBody, Event: "COMMENT", Comments: []api.CreatePullReviewComment{}, @@ -201,7 +201,7 @@ func TestAPIPullReview(t *testing.T) { assert.False(t, commentReview.Dismissed) // test CreatePullReview Comment without body and no comments - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ Body: "", Event: "COMMENT", Comments: []api.CreatePullReviewComment{}, @@ -217,7 +217,7 @@ func TestAPIPullReview(t *testing.T) { assert.NoError(t, pullIssue12.LoadAttributes(t.Context())) repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID}) - req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo3.OwnerName, repo3.GroupID, repo3.Name, pullIssue12.Index). + req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo3.OwnerName, maybeGroupSegment(repo3.GroupID), repo3.Name, pullIssue12.Index). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &reviews) @@ -245,19 +245,19 @@ func TestAPIPullReviewRequest(t *testing.T) { // Test add Review Request session := loginUser(t, "user2") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user4@example.com", "user8"}, }).AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) // poster of pr can't be reviewer - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user1"}, }).AddTokenAuth(token) MakeRequest(t, req, http.StatusUnprocessableEntity) // test user not exist - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"testOther"}, }).AddTokenAuth(token) MakeRequest(t, req, http.StatusNotFound) @@ -266,18 +266,18 @@ func TestAPIPullReviewRequest(t *testing.T) { session2 := loginUser(t, "user4") token2 := getTokenForLoggedInUser(t, session2, auth_model.AccessTokenScopeWriteRepository) - req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user4"}, }).AddTokenAuth(token2) MakeRequest(t, req, http.StatusNoContent) // doer is not admin - req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user8"}, }).AddTokenAuth(token2) MakeRequest(t, req, http.StatusUnprocessableEntity) - req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user8"}, }).AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) @@ -288,12 +288,12 @@ func TestAPIPullReviewRequest(t *testing.T) { pull21Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue21.RepoID}) // repo60 user38Session := loginUser(t, "user38") user38Token := getTokenForLoggedInUser(t, user38Session, auth_model.AccessTokenScopeWriteRepository) - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.GroupID, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, maybeGroupSegment(pull21Repo.GroupID), pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user4@example.com"}, }).AddTokenAuth(user38Token) MakeRequest(t, req, http.StatusCreated) - req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.GroupID, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, maybeGroupSegment(pull21Repo.GroupID), pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user4@example.com"}, }).AddTokenAuth(user38Token) MakeRequest(t, req, http.StatusNoContent) @@ -301,12 +301,12 @@ func TestAPIPullReviewRequest(t *testing.T) { // the poster of the PR can add/remove a review request user39Session := loginUser(t, "user39") user39Token := getTokenForLoggedInUser(t, user39Session, auth_model.AccessTokenScopeWriteRepository) - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.GroupID, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, maybeGroupSegment(pull21Repo.GroupID), pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user8"}, }).AddTokenAuth(user39Token) MakeRequest(t, req, http.StatusCreated) - req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.GroupID, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, maybeGroupSegment(pull21Repo.GroupID), pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user8"}, }).AddTokenAuth(user39Token) MakeRequest(t, req, http.StatusNoContent) @@ -315,12 +315,12 @@ func TestAPIPullReviewRequest(t *testing.T) { pullIssue22 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 22}) assert.NoError(t, pullIssue22.LoadAttributes(t.Context())) pull22Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue22.RepoID}) // repo61 - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, pull22Repo.GroupID, pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, maybeGroupSegment(pull22Repo.GroupID), pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user38"}, }).AddTokenAuth(user39Token) // user39 is from a team with read permission on pull requests unit MakeRequest(t, req, http.StatusCreated) - req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, pull22Repo.GroupID, pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, maybeGroupSegment(pull22Repo.GroupID), pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{ Reviewers: []string{"user38"}, }).AddTokenAuth(user39Token) // user39 is from a team with read permission on pull requests unit MakeRequest(t, req, http.StatusNoContent) @@ -331,35 +331,35 @@ func TestAPIPullReviewRequest(t *testing.T) { repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID}) // Test add Team Review Request - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.GroupID, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo3.OwnerName, maybeGroupSegment(repo3.GroupID), repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ TeamReviewers: []string{"team1", "owners"}, }).AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) // Test add Team Review Request to not allowned - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.GroupID, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo3.OwnerName, maybeGroupSegment(repo3.GroupID), repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ TeamReviewers: []string{"test_team"}, }).AddTokenAuth(token) MakeRequest(t, req, http.StatusUnprocessableEntity) // Test add Team Review Request to not exist - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.GroupID, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo3.OwnerName, maybeGroupSegment(repo3.GroupID), repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ TeamReviewers: []string{"not_exist_team"}, }).AddTokenAuth(token) MakeRequest(t, req, http.StatusNotFound) // Test Remove team Review Request - req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.GroupID, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo3.OwnerName, maybeGroupSegment(repo3.GroupID), repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ TeamReviewers: []string{"team1"}, }).AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) // empty request test - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.GroupID, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{}). + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo3.OwnerName, maybeGroupSegment(repo3.GroupID), repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{}). AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) - req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.GroupID, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{}). + req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo3.OwnerName, maybeGroupSegment(repo3.GroupID), repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{}). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) } @@ -452,7 +452,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) { token8 := getTokenForLoggedInUser(t, session8, auth_model.AccessTokenScopeWriteRepository) // user2 request user8 - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{user8.LoginName}, }).AddTokenAuth(token2) MakeRequest(t, req, http.StatusCreated) @@ -462,7 +462,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) { pullIssue.ID, user8.ID, 0, 1, 1, false) // user2 request user8 again, it is expected to be ignored - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{user8.LoginName}, }).AddTokenAuth(token2) MakeRequest(t, req, http.StatusCreated) @@ -472,7 +472,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) { pullIssue.ID, user8.ID, 0, 1, 1, false) // user8 reviews it as accept - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ Event: "APPROVED", Body: "lgtm", }).AddTokenAuth(token8) @@ -488,7 +488,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) { assert.NoError(t, err) // user2 request user8 again - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/requested_reviewers", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ Reviewers: []string{user8.LoginName}, }).AddTokenAuth(token2) MakeRequest(t, req, http.StatusCreated) @@ -508,7 +508,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) { pullIssue.ID, user8.ID, 1, 0, 1, false) // add a new valid approval - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ Event: "APPROVED", Body: "lgtm", }).AddTokenAuth(token8) @@ -519,7 +519,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) { pullIssue.ID, user8.ID, 1, 0, 2, true) // now add a change request witch should dismiss the approval - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/reviews", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ Event: "REQUEST_CHANGES", Body: "please change XYZ", }).AddTokenAuth(token8) diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go index cb6511933c..8396d09f72 100644 --- a/tests/integration/api_pull_test.go +++ b/tests/integration/api_pull_test.go @@ -43,7 +43,7 @@ func TestAPIViewPulls(t *testing.T) { ctx := NewAPITestContext(t, "user2", repo.Name, repo.GroupID, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/pulls?state=all", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/pulls?state=all", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(ctx.Token) resp := ctx.Session.MakeRequest(t, req, http.StatusOK) @@ -152,7 +152,7 @@ func TestAPIViewPullsByBaseHead(t *testing.T) { ctx := NewAPITestContext(t, "user2", repo.Name, repo.GroupID, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/pulls/master/branch2", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/pulls/master/branch2", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(ctx.Token) resp := ctx.Session.MakeRequest(t, req, http.StatusOK) @@ -161,7 +161,7 @@ func TestAPIViewPullsByBaseHead(t *testing.T) { assert.EqualValues(t, 3, pull.Index) assert.EqualValues(t, 2, pull.ID) - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/pulls/master/branch-not-exist", owner.Name, repo.GroupID, repo.Name). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/pulls/master/branch-not-exist", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(ctx.Token) ctx.Session.MakeRequest(t, req, http.StatusNotFound) } @@ -182,7 +182,7 @@ func TestAPIMergePullWIP(t *testing.T) { session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d/merge", owner.Name, repo.GroupID, repo.Name, pr.Index), &forms.MergePullRequestForm{ + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d/merge", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, pr.Index), &forms.MergePullRequestForm{ MergeMessageField: pr.Issue.Title, Do: string(repo_model.MergeStyleMerge), }).AddTokenAuth(token) @@ -272,7 +272,7 @@ func TestAPICreatePullSuccess(t *testing.T) { session := loginUser(t, owner11.Name) prTitle := "test pull request title " + time.Now().String() token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &api.CreatePullRequestOption{ + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), &api.CreatePullRequestOption{ Head: owner11.Name + ":master", Base: "master", Title: prTitle, @@ -306,7 +306,7 @@ func TestAPICreatePullBasePermission(t *testing.T) { AllowMaintainerEdit: new(false), } - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token) + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), &opts).AddTokenAuth(token) MakeRequest(t, req, http.StatusForbidden) // add user4 to be a collaborator to base repo @@ -314,7 +314,7 @@ func TestAPICreatePullBasePermission(t *testing.T) { t.Run("AddUser4AsCollaborator", doAPIAddCollaborator(ctx, user4.Name, perm.AccessModeRead)) // create again - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token) + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), &opts).AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) // Also test that AllowMaintainerEdit is set to false, the default "true" case is covered by TestAPICreatePullSuccess @@ -339,18 +339,18 @@ func TestAPICreatePullHeadPermission(t *testing.T) { Base: "master", Title: "create a failure pr", } - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token) + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), &opts).AddTokenAuth(token) MakeRequest(t, req, http.StatusForbidden) // add user4 to be a collaborator to head repo with read permission ctx := NewAPITestContext(t, repo11.OwnerName, repo11.Name, repo11.GroupID, auth_model.AccessTokenScopeWriteRepository) t.Run("AddUser4AsCollaboratorWithRead", doAPIAddCollaborator(ctx, user4.Name, perm.AccessModeRead)) - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token) + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), &opts).AddTokenAuth(token) MakeRequest(t, req, http.StatusForbidden) // add user4 to be a collaborator to head repo with write permission t.Run("AddUser4AsCollaboratorWithWrite", doAPIAddCollaborator(ctx, user4.Name, perm.AccessModeWrite)) - req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token) + req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), &opts).AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) } @@ -362,7 +362,7 @@ func TestAPICreatePullSameRepoSuccess(t *testing.T) { session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner.Name, repo.GroupID, repo.Name), &api.CreatePullRequestOption{ + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name), &api.CreatePullRequestOption{ Head: owner.Name + ":pr-to-update", Base: "master", Title: "successfully create a PR between branches of the same repository", @@ -393,7 +393,7 @@ func TestAPICreatePullWithFieldsSuccess(t *testing.T) { Labels: []int64{5}, } - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), opts). + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), opts). AddTokenAuth(token) res := MakeRequest(t, req, http.StatusCreated) @@ -426,7 +426,7 @@ func TestAPICreatePullWithFieldsFailure(t *testing.T) { Base: "master", } - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), opts). + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), opts). AddTokenAuth(token) MakeRequest(t, req, http.StatusUnprocessableEntity) opts.Title = "is required" @@ -452,7 +452,7 @@ func TestAPIEditPull(t *testing.T) { session := loginUser(t, owner10.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) title := "create a success pr" - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &api.CreatePullRequestOption{ + req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name), &api.CreatePullRequestOption{ Head: "develop", Base: "master", Title: title, @@ -463,7 +463,7 @@ func TestAPIEditPull(t *testing.T) { newTitle := "edit a this pr" newBody := "edited body" - req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d", owner10.Name, repo10.GroupID, repo10.Name, apiPull.Index), &api.EditPullRequestOption{ + req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name, apiPull.Index), &api.EditPullRequestOption{ Base: "feature/1", Title: newTitle, Body: &newBody, @@ -479,7 +479,7 @@ func TestAPIEditPull(t *testing.T) { unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: pull.Issue.ID, OldTitle: title, NewTitle: newTitle}) unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{IssueID: pull.Issue.ID, ContentText: newBody, IsFirstCreated: false}) - req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/%d", owner10.Name, repo10.GroupID, repo10.Name, pull.Index), &api.EditPullRequestOption{ + req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s%s/pulls/%d", owner10.Name, maybeGroupSegment(repo10.GroupID), repo10.Name, pull.Index), &api.EditPullRequestOption{ Base: "not-exist", }).AddTokenAuth(token) MakeRequest(t, req, http.StatusNotFound) @@ -567,11 +567,11 @@ func TestAPICommitPullRequest(t *testing.T) { ctx := NewAPITestContext(t, "user2", repo.Name, repo.GroupID, auth_model.AccessTokenScopeReadRepository) mergedCommitSHA := "1a8823cd1a9549fde083f992f6b9b87a7ab74fb3" - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/commits/%s/pull", owner.Name, repo.GroupID, repo.Name, mergedCommitSHA).AddTokenAuth(ctx.Token) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/commits/%s/pull", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, mergedCommitSHA).AddTokenAuth(ctx.Token) ctx.Session.MakeRequest(t, req, http.StatusOK) invalidCommitSHA := "abcd1234abcd1234abcd1234abcd1234abcd1234" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/commits/%s/pull", owner.Name, repo.GroupID, repo.Name, invalidCommitSHA).AddTokenAuth(ctx.Token) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/commits/%s/pull", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, invalidCommitSHA).AddTokenAuth(ctx.Token) ctx.Session.MakeRequest(t, req, http.StatusNotFound) } diff --git a/tests/integration/api_releases_attachment_test.go b/tests/integration/api_releases_attachment_test.go index 4ed714e256..f92915ec22 100644 --- a/tests/integration/api_releases_attachment_test.go +++ b/tests/integration/api_releases_attachment_test.go @@ -31,7 +31,7 @@ func testAPIEditReleaseAttachmentWithUnallowedFile(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) filename := "file.bad" - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, release.ID, attachment.ID) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/releases/%d/assets/%d", repoOwner.Name, maybeGroupSegment(repo.GroupID), repo.Name, release.ID, attachment.ID) req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ "name": filename, }).AddTokenAuth(token) diff --git a/tests/integration/api_releases_test.go b/tests/integration/api_releases_test.go index 7ac94f58d1..a46ab60319 100644 --- a/tests/integration/api_releases_test.go +++ b/tests/integration/api_releases_test.go @@ -46,7 +46,7 @@ func testAPIListReleasesWithWriteToken(t *testing.T) { user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository) - link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases", user2.Name, repo.GroupID, repo.Name)) + link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/releases", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) var apiReleases []*api.Release DecodeJSON(t, resp, &apiReleases) @@ -158,7 +158,7 @@ func testAPIGetDraftRelease(t *testing.T) { } func createNewReleaseUsingAPI(t *testing.T, token string, owner *user_model.User, repo *repo_model.Repository, name, target, title, desc string) *api.Release { - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases", owner.Name, repo.GroupID, repo.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/releases", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name) req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{ TagName: name, Title: title, @@ -202,7 +202,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) { newRelease := createNewReleaseUsingAPI(t, token, owner, repo, "v0.0.1", target, "v0.0.1", "test") - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/%d", owner.Name, repo.GroupID, repo.Name, newRelease.ID) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/releases/%d", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, newRelease.ID) req := NewRequest(t, "GET", urlStr). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) @@ -249,7 +249,7 @@ func TestAPICreateProtectedTagRelease(t *testing.T) { commit, err := gitRepo.GetBranchCommit("master") assert.NoError(t, err) - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases", repo.OwnerName, repo.GroupID, repo.Name), &api.CreateReleaseOption{ + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/releases", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name), &api.CreateReleaseOption{ TagName: "v0.0.1", Title: "v0.0.1", IsDraft: false, @@ -296,7 +296,7 @@ func TestAPICreateReleaseGivenInvalidTarget(t *testing.T) { session := loginUser(t, owner.LowerName) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases", owner.Name, repo.GroupID, repo.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/releases", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name) req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{ TagName: "i-point-to-an-invalid-target", Title: "Invalid Target", @@ -310,7 +310,7 @@ func testAPIGetLatestRelease(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/latest", owner.Name, repo.GroupID, repo.Name)) + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/releases/latest", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp := MakeRequest(t, req, http.StatusOK) var release *api.Release @@ -325,7 +325,7 @@ func testAPIGetReleaseByTag(t *testing.T) { tag := "v1.1" - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/tags/%s", owner.Name, repo.GroupID, repo.Name, tag)) + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/releases/tags/%s", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, tag)) resp := MakeRequest(t, req, http.StatusOK) var release *api.Release @@ -335,7 +335,7 @@ func testAPIGetReleaseByTag(t *testing.T) { nonexistingtag := "nonexistingtag" - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/tags/%s", owner.Name, repo.GroupID, repo.Name, nonexistingtag)) + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/releases/tags/%s", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, nonexistingtag)) resp = MakeRequest(t, req, http.StatusNotFound) var err *api.APIError @@ -388,17 +388,17 @@ func TestAPIDeleteReleaseByTagName(t *testing.T) { createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test") // delete release - req := NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%d/%s/releases/tags/release-tag", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s%s/releases/tags/release-tag", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) _ = MakeRequest(t, req, http.StatusNoContent) // make sure release is deleted - req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%d/%s/releases/tags/release-tag", owner.Name, repo.GroupID, repo.Name). + req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s%s/releases/tags/release-tag", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) _ = MakeRequest(t, req, http.StatusNotFound) // delete release tag too - req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%d/%s/tags/release-tag", owner.Name, repo.GroupID, repo.Name). + req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s%s/tags/release-tag", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) _ = MakeRequest(t, req, http.StatusNoContent) } @@ -416,7 +416,7 @@ func TestAPIUploadAssetRelease(t *testing.T) { bufLargeBytes := bytes.Repeat([]byte{' '}, 2*1024*1024) release := createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test") - assetURL := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/%d/assets", owner.Name, repo.GroupID, repo.Name, release.ID) + assetURL := fmt.Sprintf("/api/v1/repos/%s/%s%s/releases/%d/assets", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, release.ID) t.Run("multipart/form-data", func(t *testing.T) { defer tests.PrintCurrentTest(t)() diff --git a/tests/integration/api_repo_archive_test.go b/tests/integration/api_repo_archive_test.go index cb6382687a..ce64440343 100644 --- a/tests/integration/api_repo_archive_test.go +++ b/tests/integration/api_repo_archive_test.go @@ -30,13 +30,13 @@ func TestAPIDownloadArchive(t *testing.T) { session := loginUser(t, user2.LowerName) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) - link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/archive/master.zip", user2.Name, repo.GroupID, repo.Name)) + link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/archive/master.zip", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) bs, err := io.ReadAll(resp.Body) assert.NoError(t, err) assert.Len(t, bs, 320) - link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/archive/master.tar.gz", user2.Name, repo.GroupID, repo.Name)) + link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/archive/master.tar.gz", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) bs, err = io.ReadAll(resp.Body) assert.NoError(t, err) @@ -52,13 +52,13 @@ func TestAPIDownloadArchive(t *testing.T) { // The locked URL should give the same bytes as the non-locked one assert.Equal(t, bs, bs2) - link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/archive/master.bundle", user2.Name, repo.GroupID, repo.Name)) + link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/archive/master.bundle", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) bs, err = io.ReadAll(resp.Body) assert.NoError(t, err) assert.Len(t, bs, 382) - link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/archive/master", user2.Name, repo.GroupID, repo.Name)) + link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/archive/master", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name)) MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest) t.Run("GitHubStyle", testAPIDownloadArchiveGitHubStyle) @@ -73,13 +73,13 @@ func testAPIDownloadArchiveGitHubStyle(t *testing.T) { session := loginUser(t, user2.LowerName) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) - link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/zipball/master", user2.Name, repo.GroupID, repo.Name)) + link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/zipball/master", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) bs, err := io.ReadAll(resp.Body) assert.NoError(t, err) assert.Len(t, bs, 320) - link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/tarball/master", user2.Name, repo.GroupID, repo.Name)) + link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/tarball/master", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) bs, err = io.ReadAll(resp.Body) assert.NoError(t, err) @@ -95,7 +95,7 @@ func testAPIDownloadArchiveGitHubStyle(t *testing.T) { // The locked URL should give the same bytes as the non-locked one assert.Equal(t, bs, bs2) - link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/bundle/master", user2.Name, repo.GroupID, repo.Name)) + link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s%s/bundle/master", user2.Name, maybeGroupSegment(repo.GroupID), repo.Name)) resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) bs, err = io.ReadAll(resp.Body) assert.NoError(t, err) diff --git a/tests/integration/api_repo_avatar_test.go b/tests/integration/api_repo_avatar_test.go index 1a17d63dab..7f73bcfffb 100644 --- a/tests/integration/api_repo_avatar_test.go +++ b/tests/integration/api_repo_avatar_test.go @@ -38,7 +38,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) { Image: base64.StdEncoding.EncodeToString(avatar), } - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/avatar", repo.OwnerName, repo.GroupID, repo.Name), &opts). + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/avatar", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name), &opts). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) @@ -47,7 +47,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) { Image: "Invalid", } - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/avatar", repo.OwnerName, repo.GroupID, repo.Name), &opts). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/avatar", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name), &opts). AddTokenAuth(token) MakeRequest(t, req, http.StatusBadRequest) @@ -62,7 +62,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) { Image: base64.StdEncoding.EncodeToString(text), } - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/avatar", repo.OwnerName, repo.GroupID, repo.Name), &opts). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/avatar", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name), &opts). AddTokenAuth(token) MakeRequest(t, req, http.StatusInternalServerError) } @@ -74,7 +74,7 @@ func TestAPIDeleteRepoAvatar(t *testing.T) { user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository) - req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/avatar", repo.OwnerName, repo.GroupID, repo.Name)). + req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/avatar", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name)). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) } diff --git a/tests/integration/api_repo_collaborator_test.go b/tests/integration/api_repo_collaborator_test.go index 0d8e29b4df..ff5435b8e8 100644 --- a/tests/integration/api_repo_collaborator_test.go +++ b/tests/integration/api_repo_collaborator_test.go @@ -32,7 +32,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { testCtx := NewAPITestContext(t, repo2Owner.Name, repo2.Name, repo2.GroupID, auth_model.AccessTokenScopeWriteRepository) t.Run("RepoOwnerShouldBeOwner", func(t *testing.T) { - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, repo2Owner.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, repo2Owner.Name). AddTokenAuth(testCtx.Token) resp := MakeRequest(t, req, http.StatusOK) @@ -45,7 +45,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { t.Run("CollaboratorWithReadAccess", func(t *testing.T) { t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeRead)) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user4.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, user4.Name). AddTokenAuth(testCtx.Token) resp := MakeRequest(t, req, http.StatusOK) @@ -58,7 +58,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { t.Run("CollaboratorWithWriteAccess", func(t *testing.T) { t.Run("AddUserAsCollaboratorWithWriteAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeWrite)) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user4.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, user4.Name). AddTokenAuth(testCtx.Token) resp := MakeRequest(t, req, http.StatusOK) @@ -71,7 +71,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { t.Run("CollaboratorWithAdminAccess", func(t *testing.T) { t.Run("AddUserAsCollaboratorWithAdminAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeAdmin)) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user4.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, user4.Name). AddTokenAuth(testCtx.Token) resp := MakeRequest(t, req, http.StatusOK) @@ -82,7 +82,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { }) t.Run("CollaboratorNotFound", func(t *testing.T) { - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, "non-existent-user"). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, "non-existent-user"). AddTokenAuth(testCtx.Token) MakeRequest(t, req, http.StatusNotFound) }) @@ -99,7 +99,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { _session := loginUser(t, user5.Name) _testCtx := NewAPITestContext(t, user5.Name, repo2.Name, repo2.GroupID, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user5.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, user5.Name). AddTokenAuth(_testCtx.Token) resp := _session.MakeRequest(t, req, http.StatusOK) @@ -112,7 +112,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { session := loginUser(t, user5.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user5.Name).AddTokenAuth(token) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, user5.Name).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) repoCollPerm := api.RepoCollaboratorPermission{} @@ -128,7 +128,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { _session := loginUser(t, user5.Name) _testCtx := NewAPITestContext(t, user5.Name, repo2.Name, repo2.GroupID, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user5.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, user5.Name). AddTokenAuth(_testCtx.Token) resp := _session.MakeRequest(t, req, http.StatusOK) @@ -145,7 +145,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) { _session := loginUser(t, user10.Name) _testCtx := NewAPITestContext(t, user10.Name, repo2.Name, repo2.GroupID, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user11.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/collaborators/%s/permission", repo2Owner.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, user11.Name). AddTokenAuth(_testCtx.Token) resp := _session.MakeRequest(t, req, http.StatusOK) diff --git a/tests/integration/api_repo_file_create_test.go b/tests/integration/api_repo_file_create_test.go index 26867fdcdc..7aebf1a169 100644 --- a/tests/integration/api_repo_file_create_test.go +++ b/tests/integration/api_repo_file_create_test.go @@ -179,7 +179,7 @@ func TestAPICreateFile(t *testing.T) { createFileOptions.BranchName = branch fileID++ treePath := fmt.Sprintf("new/file%d.txt", fileID) - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions). + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &createFileOptions). AddTokenAuth(token2) resp := MakeRequest(t, req, http.StatusCreated) gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1) @@ -214,7 +214,7 @@ func TestAPICreateFile(t *testing.T) { createFileOptions.NewBranchName = "new_branch" fileID++ treePath := fmt.Sprintf("new/file%d.txt", fileID) - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions). + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &createFileOptions). AddTokenAuth(token2) resp := MakeRequest(t, req, http.StatusCreated) var fileResponse api.FileResponse @@ -232,7 +232,7 @@ func TestAPICreateFile(t *testing.T) { createFileOptions.Message = "" fileID++ treePath = fmt.Sprintf("new/file%d.txt", fileID) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &createFileOptions). AddTokenAuth(token2) resp = MakeRequest(t, req, http.StatusCreated) DecodeJSON(t, resp, &fileResponse) @@ -242,7 +242,7 @@ func TestAPICreateFile(t *testing.T) { // Test trying to create a file that already exists, should fail createFileOptions = getCreateFileOptions() treePath = "README.md" - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &createFileOptions). AddTokenAuth(token2) resp = MakeRequest(t, req, http.StatusUnprocessableEntity) expectedAPIError := context.APIError{ @@ -257,7 +257,7 @@ func TestAPICreateFile(t *testing.T) { createFileOptions = getCreateFileOptions() fileID++ treePath = fmt.Sprintf("new/file%d.txt", fileID) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &createFileOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &createFileOptions). AddTokenAuth(token4) MakeRequest(t, req, http.StatusNotFound) @@ -265,14 +265,14 @@ func TestAPICreateFile(t *testing.T) { createFileOptions = getCreateFileOptions() fileID++ treePath = fmt.Sprintf("new/file%d.txt", fileID) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &createFileOptions) + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &createFileOptions) MakeRequest(t, req, http.StatusNotFound) // Test using access token for a private repo that the user of the token owns createFileOptions = getCreateFileOptions() fileID++ treePath = fmt.Sprintf("new/file%d.txt", fileID) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &createFileOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &createFileOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusCreated) @@ -280,7 +280,7 @@ func TestAPICreateFile(t *testing.T) { createFileOptions = getCreateFileOptions() fileID++ treePath = fmt.Sprintf("new/file%d.txt", fileID) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &createFileOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, treePath), &createFileOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusCreated) @@ -288,14 +288,14 @@ func TestAPICreateFile(t *testing.T) { createFileOptions = getCreateFileOptions() fileID++ treePath = fmt.Sprintf("new/file%d.txt", fileID) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &createFileOptions) + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, treePath), &createFileOptions) MakeRequest(t, req, http.StatusNotFound) // Test using repo "user2/repo1" where user4 is a NOT collaborator createFileOptions = getCreateFileOptions() fileID++ treePath = fmt.Sprintf("new/file%d.txt", fileID) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &createFileOptions). AddTokenAuth(token4) MakeRequest(t, req, http.StatusForbidden) diff --git a/tests/integration/api_repo_file_delete_test.go b/tests/integration/api_repo_file_delete_test.go index ff648baa28..f6ec8db280 100644 --- a/tests/integration/api_repo_file_delete_test.go +++ b/tests/integration/api_repo_file_delete_test.go @@ -64,7 +64,7 @@ func TestAPIDeleteFile(t *testing.T) { createFile(user2, repo1, treePath) deleteFileOptions := getDeleteFileOptions() deleteFileOptions.BranchName = branch - req := NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions). + req := NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &deleteFileOptions). AddTokenAuth(token2) resp := MakeRequest(t, req, http.StatusOK) var fileResponse api.FileResponse @@ -80,7 +80,7 @@ func TestAPIDeleteFile(t *testing.T) { deleteFileOptions := getDeleteFileOptions() deleteFileOptions.BranchName = repo1.DefaultBranch deleteFileOptions.NewBranchName = "new_branch" - req := NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions). + req := NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &deleteFileOptions). AddTokenAuth(token2) resp := MakeRequest(t, req, http.StatusOK) var fileResponse api.FileResponse @@ -95,7 +95,7 @@ func TestAPIDeleteFile(t *testing.T) { createFile(user2, repo1, treePath) deleteFileOptions = getDeleteFileOptions() deleteFileOptions.Message = "" - req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions). + req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &deleteFileOptions). AddTokenAuth(token2) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &fileResponse) @@ -108,7 +108,7 @@ func TestAPIDeleteFile(t *testing.T) { createFile(user2, repo1, treePath) deleteFileOptions = getDeleteFileOptions() deleteFileOptions.SHA = "badsha" - req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions). + req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &deleteFileOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusUnprocessableEntity) @@ -117,7 +117,7 @@ func TestAPIDeleteFile(t *testing.T) { treePath = fmt.Sprintf("delete/file%d.txt", fileID) createFile(user2, repo16, treePath) deleteFileOptions = getDeleteFileOptions() - req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &deleteFileOptions). + req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &deleteFileOptions). AddTokenAuth(token4) MakeRequest(t, req, http.StatusNotFound) @@ -126,7 +126,7 @@ func TestAPIDeleteFile(t *testing.T) { treePath = fmt.Sprintf("delete/file%d.txt", fileID) createFile(user2, repo16, treePath) deleteFileOptions = getDeleteFileOptions() - req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &deleteFileOptions) + req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &deleteFileOptions) MakeRequest(t, req, http.StatusNotFound) // Test using access token for a private repo that the user of the token owns @@ -134,7 +134,7 @@ func TestAPIDeleteFile(t *testing.T) { treePath = fmt.Sprintf("delete/file%d.txt", fileID) createFile(user2, repo16, treePath) deleteFileOptions = getDeleteFileOptions() - req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &deleteFileOptions). + req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &deleteFileOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) @@ -143,7 +143,7 @@ func TestAPIDeleteFile(t *testing.T) { treePath = fmt.Sprintf("delete/file%d.txt", fileID) createFile(org3, repo3, treePath) deleteFileOptions = getDeleteFileOptions() - req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &deleteFileOptions). + req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, treePath), &deleteFileOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) @@ -152,7 +152,7 @@ func TestAPIDeleteFile(t *testing.T) { treePath = fmt.Sprintf("delete/file%d.txt", fileID) createFile(org3, repo3, treePath) deleteFileOptions = getDeleteFileOptions() - req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &deleteFileOptions) + req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, treePath), &deleteFileOptions) MakeRequest(t, req, http.StatusNotFound) // Test using repo "user2/repo1" where user4 is a NOT collaborator @@ -160,7 +160,7 @@ func TestAPIDeleteFile(t *testing.T) { treePath = fmt.Sprintf("delete/file%d.txt", fileID) createFile(user2, repo1, treePath) deleteFileOptions = getDeleteFileOptions() - req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions). + req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &deleteFileOptions). AddTokenAuth(token4) MakeRequest(t, req, http.StatusForbidden) }) diff --git a/tests/integration/api_repo_file_update_test.go b/tests/integration/api_repo_file_update_test.go index 3b0e26cf37..79eec65544 100644 --- a/tests/integration/api_repo_file_update_test.go +++ b/tests/integration/api_repo_file_update_test.go @@ -133,7 +133,7 @@ func TestAPIUpdateFile(t *testing.T) { createFile(user2, repo1, treePath) updateFileOptions := getUpdateFileOptions() updateFileOptions.BranchName = branch - req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions). + req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &updateFileOptions). AddTokenAuth(token2) resp := MakeRequest(t, req, http.StatusOK) gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1) @@ -164,7 +164,7 @@ func TestAPIUpdateFile(t *testing.T) { fileID++ treePath := fmt.Sprintf("update/file%d.txt", fileID) createFile(user2, repo1, treePath) - req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions). + req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &updateFileOptions). AddTokenAuth(token2) resp := MakeRequest(t, req, http.StatusOK) var fileResponse api.FileResponse @@ -194,7 +194,7 @@ func TestAPIUpdateFile(t *testing.T) { createFile(user2, repo1, treePath) updateFileOptions.FromPath = treePath treePath = "rename/" + treePath - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions). + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &updateFileOptions). AddTokenAuth(token2) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &fileResponse) @@ -212,7 +212,7 @@ func TestAPIUpdateFile(t *testing.T) { fileID++ treePath = fmt.Sprintf("update/file%d.txt", fileID) createFile(user2, repo1, treePath) - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions). + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &updateFileOptions). AddTokenAuth(token2) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &fileResponse) @@ -226,7 +226,7 @@ func TestAPIUpdateFile(t *testing.T) { updateFileOptions = getUpdateFileOptions() correctSHA := updateFileOptions.SHA updateFileOptions.SHA = "badsha" - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions). + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &updateFileOptions). AddTokenAuth(token2) resp = MakeRequest(t, req, http.StatusUnprocessableEntity) expectedAPIError := context.APIError{ @@ -242,7 +242,7 @@ func TestAPIUpdateFile(t *testing.T) { treePath = fmt.Sprintf("update/file%d.txt", fileID) createFile(user2, repo16, treePath) updateFileOptions = getUpdateFileOptions() - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &updateFileOptions). + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &updateFileOptions). AddTokenAuth(token4) MakeRequest(t, req, http.StatusNotFound) @@ -251,7 +251,7 @@ func TestAPIUpdateFile(t *testing.T) { treePath = fmt.Sprintf("update/file%d.txt", fileID) createFile(user2, repo16, treePath) updateFileOptions = getUpdateFileOptions() - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &updateFileOptions) + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &updateFileOptions) MakeRequest(t, req, http.StatusNotFound) // Test using access token for a private repo that the user of the token owns @@ -259,7 +259,7 @@ func TestAPIUpdateFile(t *testing.T) { treePath = fmt.Sprintf("update/file%d.txt", fileID) createFile(user2, repo16, treePath) updateFileOptions = getUpdateFileOptions() - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &updateFileOptions). + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath), &updateFileOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) @@ -268,7 +268,7 @@ func TestAPIUpdateFile(t *testing.T) { treePath = fmt.Sprintf("update/file%d.txt", fileID) createFile(org3, repo3, treePath) updateFileOptions = getUpdateFileOptions() - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &updateFileOptions). + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, treePath), &updateFileOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) @@ -277,7 +277,7 @@ func TestAPIUpdateFile(t *testing.T) { treePath = fmt.Sprintf("update/file%d.txt", fileID) createFile(org3, repo3, treePath) updateFileOptions = getUpdateFileOptions() - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &updateFileOptions) + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, treePath), &updateFileOptions) MakeRequest(t, req, http.StatusNotFound) // Test using repo "user2/repo1" where user4 is a NOT collaborator @@ -285,7 +285,7 @@ func TestAPIUpdateFile(t *testing.T) { treePath = fmt.Sprintf("update/file%d.txt", fileID) createFile(user2, repo1, treePath) updateFileOptions = getUpdateFileOptions() - req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions). + req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath), &updateFileOptions). AddTokenAuth(token4) MakeRequest(t, req, http.StatusForbidden) }) diff --git a/tests/integration/api_repo_files_change_test.go b/tests/integration/api_repo_files_change_test.go index e9fb866d4f..f22e7db675 100644 --- a/tests/integration/api_repo_files_change_test.go +++ b/tests/integration/api_repo_files_change_test.go @@ -90,7 +90,7 @@ func TestAPIChangeFiles(t *testing.T) { changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[2].Path = deleteTreePath - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo1.GroupID, repo1.Name), &changeFilesOptions). + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name), &changeFilesOptions). AddTokenAuth(token2) resp := MakeRequest(t, req, http.StatusCreated) gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1) @@ -142,7 +142,7 @@ func TestAPIChangeFiles(t *testing.T) { changeFilesOptions.Files[2].Path = deleteTreePath createFile(user2, repo1, updateTreePath) createFile(user2, repo1, deleteTreePath) - url := fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo1.GroupID, repo1.Name) + url := fmt.Sprintf("/api/v1/repos/%s/%s%s/contents", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name) req := NewRequestWithJSON(t, "POST", url, &changeFilesOptions). AddTokenAuth(token2) resp := MakeRequest(t, req, http.StatusCreated) @@ -314,7 +314,7 @@ func TestAPIChangeFiles(t *testing.T) { changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[2].Path = deleteTreePath - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo16.GroupID, repo16.Name), &changeFilesOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name), &changeFilesOptions). AddTokenAuth(token4) MakeRequest(t, req, http.StatusNotFound) @@ -329,7 +329,7 @@ func TestAPIChangeFiles(t *testing.T) { changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[2].Path = deleteTreePath - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo16.GroupID, repo16.Name), &changeFilesOptions) + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name), &changeFilesOptions) MakeRequest(t, req, http.StatusNotFound) // Test using access token for a private repo that the user of the token owns @@ -343,7 +343,7 @@ func TestAPIChangeFiles(t *testing.T) { changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[2].Path = deleteTreePath - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo16.GroupID, repo16.Name), &changeFilesOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name), &changeFilesOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusCreated) @@ -358,7 +358,7 @@ func TestAPIChangeFiles(t *testing.T) { changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[2].Path = deleteTreePath - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", org3.Name, repo3.GroupID, repo3.Name), &changeFilesOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name), &changeFilesOptions). AddTokenAuth(token2) MakeRequest(t, req, http.StatusCreated) @@ -373,7 +373,7 @@ func TestAPIChangeFiles(t *testing.T) { changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[2].Path = deleteTreePath - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", org3.Name, repo3.GroupID, repo3.Name), &changeFilesOptions) + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name), &changeFilesOptions) MakeRequest(t, req, http.StatusNotFound) // Test using repo "user2/repo1" where user4 is a NOT collaborator @@ -387,7 +387,7 @@ func TestAPIChangeFiles(t *testing.T) { changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[2].Path = deleteTreePath - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo1.GroupID, repo1.Name), &changeFilesOptions). + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/contents", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name), &changeFilesOptions). AddTokenAuth(token4) MakeRequest(t, req, http.StatusForbidden) }) diff --git a/tests/integration/api_repo_files_get_test.go b/tests/integration/api_repo_files_get_test.go index fc3980caa8..446e5c4dc7 100644 --- a/tests/integration/api_repo_files_get_test.go +++ b/tests/integration/api_repo_files_get_test.go @@ -95,13 +95,13 @@ func TestAPIGetRequestedFiles(t *testing.T) { t.Run("PermissionCheck", func(t *testing.T) { filesOptions := &api.GetFilesOptions{Files: []string{"README.md"}} // Test accessing private ref with user token that does not have access - should fail - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/file-contents", user2.Name, repo16.GroupID, repo16.Name), &filesOptions).AddTokenAuth(token4) + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/file-contents", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name), &filesOptions).AddTokenAuth(token4) MakeRequest(t, req, http.StatusNotFound) // Test access private ref of owner of token - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/file-contents", user2.Name, repo16.GroupID, repo16.Name), &filesOptions).AddTokenAuth(token2) + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/file-contents", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name), &filesOptions).AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) // Test access of org org3 private repo file by owner user2 - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/file-contents", org3.Name, repo3.GroupID, repo3.Name), &filesOptions).AddTokenAuth(token2) + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/file-contents", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name), &filesOptions).AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) }) diff --git a/tests/integration/api_repo_get_contents_list_test.go b/tests/integration/api_repo_get_contents_list_test.go index 8d9462b484..81ef86e36f 100644 --- a/tests/integration/api_repo_get_contents_list_test.go +++ b/tests/integration/api_repo_get_contents_list_test.go @@ -92,7 +92,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) { // ref is default ref ref := repo1.DefaultBranch refType := "branch" - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, ref) resp := MakeRequest(t, req, http.StatusOK) var contentsListResponse []*api.ContentsResponse DecodeJSON(t, resp, &contentsListResponse) @@ -104,7 +104,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) { // No ref refType = "branch" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/", user2.Name, repo1.GroupID, repo1.Name) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &contentsListResponse) assert.NotNil(t, contentsListResponse) @@ -115,7 +115,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) { // ref is the branch we created above in setup ref = newBranch refType = "branch" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, ref) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &contentsListResponse) assert.NotNil(t, contentsListResponse) @@ -129,7 +129,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) { // ref is the new tag we created above in setup ref = newTag refType = "tag" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, ref) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &contentsListResponse) assert.NotNil(t, contentsListResponse) @@ -143,7 +143,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) { // ref is a commit ref = commitID refType = "commit" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, ref) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &contentsListResponse) assert.NotNil(t, contentsListResponse) @@ -152,21 +152,21 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) { // Test file contents a file with a bad ref ref = "badref" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, ref) MakeRequest(t, req, http.StatusNotFound) // Test accessing private ref with user token that does not have access - should fail - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/", user2.Name, repo16.GroupID, repo16.Name). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name). AddTokenAuth(token4) MakeRequest(t, req, http.StatusNotFound) // Test access private ref of owner of token - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/", user2.Name, repo16.GroupID, repo16.Name). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name). AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) // Test access of org org3 private repo file by owner user2 - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/", org3.Name, repo3.GroupID, repo3.Name). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name). AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) } diff --git a/tests/integration/api_repo_get_contents_test.go b/tests/integration/api_repo_get_contents_test.go index 98dbd3befc..7bb0044385 100644 --- a/tests/integration/api_repo_get_contents_test.go +++ b/tests/integration/api_repo_get_contents_test.go @@ -96,14 +96,14 @@ func testAPIGetContents(t *testing.T, _ *url.URL) { /*** END SETUP ***/ // not found - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/no-such/file.md", user2.Name, repo1.GroupID, repo1.Name) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/no-such/file.md", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name) resp := MakeRequest(t, req, http.StatusNotFound) assert.Contains(t, resp.Body.String(), "object does not exist [id: , rel_path: no-such]") // ref is default ref ref := repo1.DefaultBranch refType := "branch" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/%s?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath, ref) resp = MakeRequest(t, req, http.StatusOK) var contentsResponse api.ContentsResponse DecodeJSON(t, resp, &contentsResponse) @@ -113,7 +113,7 @@ func testAPIGetContents(t *testing.T, _ *url.URL) { // No ref refType = "branch" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &contentsResponse) expectedContentsResponse = getExpectedContentsResponseForContents(repo1.DefaultBranch, refType, lastCommit.ID.String()) @@ -122,7 +122,7 @@ func testAPIGetContents(t *testing.T, _ *url.URL) { // ref is the branch we created above in setup ref = newBranch refType = "branch" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/%s?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath, ref) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &contentsResponse) branchCommit, _ := gitRepo.GetBranchCommit(ref) @@ -133,7 +133,7 @@ func testAPIGetContents(t *testing.T, _ *url.URL) { // ref is the new tag we created above in setup ref = newTag refType = "tag" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/%s?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath, ref) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &contentsResponse) tagCommit, _ := gitRepo.GetTagCommit(ref) @@ -144,7 +144,7 @@ func testAPIGetContents(t *testing.T, _ *url.URL) { // ref is a commit ref = commitID refType = "commit" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/%s?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath, ref) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &contentsResponse) expectedContentsResponse = getExpectedContentsResponseForContents(ref, refType, commitID) @@ -152,21 +152,21 @@ func testAPIGetContents(t *testing.T, _ *url.URL) { // Test file contents a file with a bad ref ref = "badref" - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/%s?ref=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, treePath, ref) MakeRequest(t, req, http.StatusNotFound) // Test accessing private ref with user token that does not have access - should fail - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, treePath). AddTokenAuth(token4) MakeRequest(t, req, http.StatusNotFound) // Test access private ref of owner of token - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/readme.md", user2.Name, repo16.GroupID, repo16.Name). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/readme.md", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name). AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) // Test access of org org3 private repo file by owner user2 - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/contents/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, treePath). AddTokenAuth(token2) MakeRequest(t, req, http.StatusOK) } diff --git a/tests/integration/api_repo_git_blobs_test.go b/tests/integration/api_repo_git_blobs_test.go index 5f1fe7f9f3..fd9f4b2bde 100644 --- a/tests/integration/api_repo_git_blobs_test.go +++ b/tests/integration/api_repo_git_blobs_test.go @@ -35,7 +35,7 @@ func TestAPIReposGitBlobs(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) // Test a public repo that anyone can GET the blob of - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", user2.Name, repo1.GroupID, repo1.Name, repo1ReadmeSHA) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/blobs/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, repo1ReadmeSHA) resp := MakeRequest(t, req, http.StatusOK) var gitBlobResponse api.GitBlobResponse DecodeJSON(t, resp, &gitBlobResponse) @@ -44,30 +44,30 @@ func TestAPIReposGitBlobs(t *testing.T) { assert.Equal(t, expectedContent, *gitBlobResponse.Content) // Tests a private repo with no token so will fail - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", user2.Name, repo16.GroupID, repo16.Name, repo16ReadmeSHA) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/blobs/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, repo16ReadmeSHA) MakeRequest(t, req, http.StatusNotFound) // Test using access token for a private repo that the user of the token owns - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", user2.Name, repo16.GroupID, repo16.Name, repo16ReadmeSHA). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/blobs/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, repo16ReadmeSHA). AddTokenAuth(token) MakeRequest(t, req, http.StatusOK) // Test using bad sha - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", user2.Name, repo1.GroupID, repo1.Name, badSHA) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/blobs/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, badSHA) MakeRequest(t, req, http.StatusBadRequest) // Test using org repo "org3/repo3" where user2 is a collaborator - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", org3.Name, repo3.GroupID, repo3.Name, repo3ReadmeSHA). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/blobs/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, repo3ReadmeSHA). AddTokenAuth(token) MakeRequest(t, req, http.StatusOK) // Test using org repo "org3/repo3" where user2 is a collaborator - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", org3.Name, repo3.GroupID, repo3.Name, repo3ReadmeSHA). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/blobs/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, repo3ReadmeSHA). AddTokenAuth(token) MakeRequest(t, req, http.StatusOK) // Test using org repo "org3/repo3" with no user token - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", org3.Name, repo3.GroupID, repo3.Name, repo3ReadmeSHA) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/blobs/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, repo3ReadmeSHA) MakeRequest(t, req, http.StatusNotFound) // Login as User4. @@ -75,6 +75,6 @@ func TestAPIReposGitBlobs(t *testing.T) { token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAll) // Test using org repo "org3/repo3" where user4 is a NOT collaborator - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", org3.Name, repo3.GroupID, repo3.Name, token4) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/blobs/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, token4) MakeRequest(t, req, http.StatusNotFound) } diff --git a/tests/integration/api_repo_git_hook_test.go b/tests/integration/api_repo_git_hook_test.go index 00e8ef93e4..0aec30654d 100644 --- a/tests/integration/api_repo_git_hook_test.go +++ b/tests/integration/api_repo_git_hook_test.go @@ -37,7 +37,7 @@ echo "TestGitHookScript" // user1 is an admin user session := loginUser(t, "user1") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/hooks/git", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) var apiGitHooks []*api.GitHook @@ -63,7 +63,7 @@ echo "TestGitHookScript" // user1 is an admin user session := loginUser(t, "user1") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/hooks/git", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) var apiGitHooks []*api.GitHook @@ -83,7 +83,7 @@ echo "TestGitHookScript" session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/hooks/git", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) MakeRequest(t, req, http.StatusForbidden) }) @@ -97,7 +97,7 @@ echo "TestGitHookScript" // user1 is an admin user session := loginUser(t, "user1") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/hooks/git/pre-receive", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) var apiGitHook *api.GitHook @@ -113,7 +113,7 @@ echo "TestGitHookScript" session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/hooks/git/pre-receive", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) MakeRequest(t, req, http.StatusForbidden) }) @@ -139,7 +139,7 @@ echo "TestGitHookScript" assert.True(t, apiGitHook.IsActive) assert.Equal(t, testHookContent, apiGitHook.Content) - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/hooks/git/pre-receive", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) var apiGitHook2 *api.GitHook @@ -156,7 +156,7 @@ echo "TestGitHookScript" session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/hooks/git/pre-receive", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name) req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditGitHookOption{ Content: testHookContent, }).AddTokenAuth(token) @@ -173,11 +173,11 @@ echo "TestGitHookScript" session := loginUser(t, "user1") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s%s/hooks/git/pre-receive", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) MakeRequest(t, req, http.StatusNoContent) - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/hooks/git/pre-receive", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) var apiGitHook2 *api.GitHook @@ -194,7 +194,7 @@ echo "TestGitHookScript" session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s%s/hooks/git/pre-receive", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) MakeRequest(t, req, http.StatusForbidden) }) diff --git a/tests/integration/api_repo_git_tags_test.go b/tests/integration/api_repo_git_tags_test.go index c6fa4361c6..581242bf2c 100644 --- a/tests/integration/api_repo_git_tags_test.go +++ b/tests/integration/api_repo_git_tags_test.go @@ -44,7 +44,7 @@ func TestAPIGitTags(t *testing.T) { aTag, _ := gitRepo.GetTag(aTagName) // SHOULD work for annotated tags - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/tags/%s", user.Name, repo.GroupID, repo.Name, aTag.ID.String()). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/tags/%s", user.Name, maybeGroupSegment(repo.GroupID), repo.Name, aTag.ID.String()). AddTokenAuth(token) res := MakeRequest(t, req, http.StatusOK) @@ -60,7 +60,7 @@ func TestAPIGitTags(t *testing.T) { assert.Equal(t, repo.APIURL()+"/git/tags/"+aTag.ID.String(), tag.URL) // Should NOT work for lightweight tags - badReq := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/tags/%s", user.Name, repo.GroupID, repo.Name, commit.ID.String()). + badReq := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/tags/%s", user.Name, maybeGroupSegment(repo.GroupID), repo.Name, commit.ID.String()). AddTokenAuth(token) MakeRequest(t, badReq, http.StatusBadRequest) } @@ -73,14 +73,14 @@ func TestAPIDeleteTagByName(t *testing.T) { session := loginUser(t, owner.LowerName) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequest(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/tags/delete-tag", owner.Name, repo.GroupID, repo.Name)). + req := NewRequest(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/tags/delete-tag", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name)). AddTokenAuth(token) _ = MakeRequest(t, req, http.StatusNoContent) // Make sure that actual releases can't be deleted outright createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test") - req = NewRequest(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/tags/release-tag", owner.Name, repo.GroupID, repo.Name)). + req = NewRequest(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s%s/tags/release-tag", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name)). AddTokenAuth(token) _ = MakeRequest(t, req, http.StatusConflict) } diff --git a/tests/integration/api_repo_git_trees_test.go b/tests/integration/api_repo_git_trees_test.go index 2664ff8479..a225dc977b 100644 --- a/tests/integration/api_repo_git_trees_test.go +++ b/tests/integration/api_repo_git_trees_test.go @@ -57,26 +57,26 @@ func TestAPIReposGitTrees(t *testing.T) { "master", // Branch repo1TreeSHA, // Tag } { - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", user2.Name, repo16.GroupID, repo16.Name, ref) + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/trees/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, ref) MakeRequest(t, req, http.StatusNotFound) } // Test using access token for a private repo that the user of the token owns - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", user2.Name, repo16.GroupID, repo16.Name, repo16TreeSHA). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/trees/%s", user2.Name, maybeGroupSegment(repo16.GroupID), repo16.Name, repo16TreeSHA). AddTokenAuth(token) MakeRequest(t, req, http.StatusOK) // Test using bad sha - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", user2.Name, repo1.GroupID, repo1.Name, badSHA) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/trees/%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, badSHA) MakeRequest(t, req, http.StatusBadRequest) // Test using org repo "org3/repo3" where user2 is a collaborator - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", org3.Name, repo3.GroupID, repo3.Name, repo3TreeSHA). + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/trees/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, repo3TreeSHA). AddTokenAuth(token) MakeRequest(t, req, http.StatusOK) // Test using org repo "org3/repo3" with no user token - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", org3.Name, repo3.GroupID, repo3.Name, repo3TreeSHA) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/trees/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, repo3TreeSHA) MakeRequest(t, req, http.StatusNotFound) // Login as User4. @@ -84,6 +84,6 @@ func TestAPIReposGitTrees(t *testing.T) { token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAll) // Test using org repo "org3/repo3" where user4 is a NOT collaborator - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", org3.Name, repo3.GroupID, repo3.Name, token4) + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/git/trees/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, token4) MakeRequest(t, req, http.StatusNotFound) } diff --git a/tests/integration/api_repo_hook_test.go b/tests/integration/api_repo_hook_test.go index 74f087948f..b2b46e6e78 100644 --- a/tests/integration/api_repo_hook_test.go +++ b/tests/integration/api_repo_hook_test.go @@ -27,7 +27,7 @@ func TestAPICreateHook(t *testing.T) { // user1 is an admin user session := loginUser(t, "user1") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/%s", owner.Name, repo.GroupID, repo.Name, "hooks"), api.CreateHookOption{ + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/%s", owner.Name, maybeGroupSegment(repo.GroupID), repo.Name, "hooks"), api.CreateHookOption{ Type: "gitea", Config: api.CreateHookOptionConfig{ "content_type": "json", diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index 3b94156a72..926e4ce82d 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -82,66 +82,66 @@ func TestAPISearchRepo(t *testing.T) { }{ { name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ - nil: {count: 36}, - user: {count: 36}, - user2: {count: 36}, - }, + nil: {count: 36}, + user: {count: 36}, + user2: {count: 36}, + }, }, { name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10&private=false", expectedResults: expectedResults{ - nil: {count: 10}, - user: {count: 10}, - user2: {count: 10}, - }, + nil: {count: 10}, + user: {count: 10}, + user2: {count: 10}, + }, }, { name: "RepositoriesDefault", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{ - nil: {count: 10}, - user: {count: 10}, - user2: {count: 10}, - }, + nil: {count: 10}, + user: {count: 10}, + user2: {count: 10}, + }, }, { name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s&private=false", "big_test_"), expectedResults: expectedResults{ - nil: {count: 7, repoName: "big_test_"}, - user: {count: 7, repoName: "big_test_"}, - user2: {count: 7, repoName: "big_test_"}, - }, + nil: {count: 7, repoName: "big_test_"}, + user: {count: 7, repoName: "big_test_"}, + user2: {count: 7, repoName: "big_test_"}, + }, }, { name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s&private=false", "user2/big_test_"), expectedResults: expectedResults{ - user2: {count: 2, repoName: "big_test_"}, - }, + user2: {count: 2, repoName: "big_test_"}, + }, }, { name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{ - nil: {count: 5}, - user: {count: 9, includesPrivate: true}, - user2: {count: 6, includesPrivate: true}, - }, + nil: {count: 5}, + user: {count: 9, includesPrivate: true}, + user2: {count: 6, includesPrivate: true}, + }, }, { name: "RepositoriesAccessibleAndRelatedToUser2", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user2.ID), expectedResults: expectedResults{ - nil: {count: 1}, - user: {count: 2, includesPrivate: true}, - user2: {count: 2, includesPrivate: true}, - user4: {count: 1}, - }, + nil: {count: 1}, + user: {count: 2, includesPrivate: true}, + user2: {count: 2, includesPrivate: true}, + user4: {count: 1}, + }, }, { name: "RepositoriesAccessibleAndRelatedToUser3", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", org3.ID), expectedResults: expectedResults{ - nil: {count: 1}, - user: {count: 4, includesPrivate: true}, - user2: {count: 3, includesPrivate: true}, - org3: {count: 4, includesPrivate: true}, - }, + nil: {count: 1}, + user: {count: 4, includesPrivate: true}, + user2: {count: 3, includesPrivate: true}, + org3: {count: 4, includesPrivate: true}, + }, }, { name: "RepositoriesOwnedByOrganization", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", orgUser.ID), expectedResults: expectedResults{ - nil: {count: 1, repoOwnerID: orgUser.ID}, - user: {count: 2, repoOwnerID: orgUser.ID, includesPrivate: true}, - user2: {count: 1, repoOwnerID: orgUser.ID}, - }, + nil: {count: 1, repoOwnerID: orgUser.ID}, + user: {count: 2, repoOwnerID: orgUser.ID, includesPrivate: true}, + user2: {count: 1, repoOwnerID: orgUser.ID}, + }, }, {name: "RepositoriesAccessibleAndRelatedToUser4", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user4.ID), expectedResults: expectedResults{ nil: {count: 3}, @@ -565,7 +565,7 @@ func TestAPIRepoTransfer(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}) session = loginUser(t, user.Name) token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer", repo.OwnerName, repo.GroupID, repo.Name), &api.TransferRepoOption{ + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/transfer", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name), &api.TransferRepoOption{ NewOwner: testCase.newOwner, TeamIDs: testCase.teams, }).AddTokenAuth(token) @@ -596,7 +596,7 @@ func transfer(t *testing.T) *repo_model.Repository { DecodeJSON(t, resp, apiRepo) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}) - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer", repo.OwnerName, repo.GroupID, repo.Name), &api.TransferRepoOption{ + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/transfer", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name), &api.TransferRepoOption{ NewOwner: "user4", }).AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) @@ -612,7 +612,7 @@ func TestAPIAcceptTransfer(t *testing.T) { // try to accept with not authorized user session := loginUser(t, "user2") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) - req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer/reject", repo.OwnerName, repo.GroupID, repo.Name)). + req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/transfer/reject", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name)). AddTokenAuth(token) MakeRequest(t, req, http.StatusForbidden) @@ -625,7 +625,7 @@ func TestAPIAcceptTransfer(t *testing.T) { session = loginUser(t, "user4") token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) - req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer/accept", repo.OwnerName, repo.GroupID, repo.Name)). + req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/transfer/accept", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name)). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusAccepted) apiRepo := new(api.Repository) @@ -641,7 +641,7 @@ func TestAPIRejectTransfer(t *testing.T) { // try to reject with not authorized user session := loginUser(t, "user2") token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer/reject", repo.OwnerName, repo.GroupID, repo.Name)). + req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/transfer/reject", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name)). AddTokenAuth(token) MakeRequest(t, req, http.StatusForbidden) @@ -654,7 +654,7 @@ func TestAPIRejectTransfer(t *testing.T) { session = loginUser(t, "user4") token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) - req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer/reject", repo.OwnerName, repo.GroupID, repo.Name)). + req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/transfer/reject", repo.OwnerName, maybeGroupSegment(repo.GroupID), repo.Name)). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) apiRepo := new(api.Repository) @@ -673,7 +673,7 @@ func TestAPIGenerateRepo(t *testing.T) { // user repo := new(api.Repository) - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/generate", templateRepo.OwnerName, templateRepo.GroupID, templateRepo.Name), &api.GenerateRepoOption{ + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/generate", templateRepo.OwnerName, maybeGroupSegment(templateRepo.GroupID), templateRepo.Name), &api.GenerateRepoOption{ Owner: user.Name, Name: "new-repo", Description: "test generate repo", @@ -686,7 +686,7 @@ func TestAPIGenerateRepo(t *testing.T) { assert.Equal(t, "new-repo", repo.Name) // org - req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/generate", templateRepo.OwnerName, templateRepo.GroupID, templateRepo.Name), &api.GenerateRepoOption{ + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/generate", templateRepo.OwnerName, maybeGroupSegment(templateRepo.GroupID), templateRepo.Name), &api.GenerateRepoOption{ Owner: "org3", Name: "new-repo", Description: "test generate repo", @@ -706,7 +706,7 @@ func TestAPIRepoGetReviewers(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/reviewers", user.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/reviewers", user.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) var reviewers []*api.User @@ -723,7 +723,7 @@ func TestAPIRepoGetAssignees(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/assignees", user.Name, repo.GroupID, repo.Name). + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s%s/assignees", user.Name, maybeGroupSegment(repo.GroupID), repo.Name). AddTokenAuth(token) resp := MakeRequest(t, req, http.StatusOK) var assignees []*api.User diff --git a/tests/integration/api_repo_topic_test.go b/tests/integration/api_repo_topic_test.go index a9760b1701..9d4a156333 100644 --- a/tests/integration/api_repo_topic_test.go +++ b/tests/integration/api_repo_topic_test.go @@ -83,7 +83,7 @@ func TestAPIRepoTopic(t *testing.T) { token2 := getUserToken(t, user2.Name, auth_model.AccessTokenScopeWriteRepository) // Test read topics using login - req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/topics", user2.Name, repo2.GroupID, repo2.Name)). + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/topics", user2.Name, maybeGroupSegment(repo2.GroupID), repo2.Name)). AddTokenAuth(token2) res := MakeRequest(t, req, http.StatusOK) var topics *api.TopicName @@ -91,21 +91,21 @@ func TestAPIRepoTopic(t *testing.T) { assert.ElementsMatch(t, []string{"topicname1", "topicname2"}, topics.TopicNames) // Test delete a topic - req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "Topicname1"). + req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s%s/topics/%s", user2.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, "Topicname1"). AddTokenAuth(token2) MakeRequest(t, req, http.StatusNoContent) // Test add an existing topic - req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "Golang"). + req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s%s/topics/%s", user2.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, "Golang"). AddTokenAuth(token2) MakeRequest(t, req, http.StatusNoContent) // Test add a topic - req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "topicName3"). + req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s%s/topics/%s", user2.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, "topicName3"). AddTokenAuth(token2) MakeRequest(t, req, http.StatusNoContent) - url := fmt.Sprintf("/api/v1/repos/%s/%d/%s/topics", user2.Name, repo2.GroupID, repo2.Name) + url := fmt.Sprintf("/api/v1/repos/%s/%s%s/topics", user2.Name, maybeGroupSegment(repo2.GroupID), repo2.Name) // Test read topics using token req = NewRequest(t, "GET", url). @@ -158,12 +158,12 @@ func TestAPIRepoTopic(t *testing.T) { MakeRequest(t, req, http.StatusUnprocessableEntity) // Test add a topic when there is already maximum - req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "t26"). + req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s%s/topics/%s", user2.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, "t26"). AddTokenAuth(token2) MakeRequest(t, req, http.StatusUnprocessableEntity) // Test delete a topic that repo doesn't have - req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "Topicname1"). + req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s%s/topics/%s", user2.Name, maybeGroupSegment(repo2.GroupID), repo2.Name, "Topicname1"). AddTokenAuth(token2) MakeRequest(t, req, http.StatusNotFound) @@ -171,14 +171,14 @@ func TestAPIRepoTopic(t *testing.T) { token4 := getUserToken(t, user4.Name, auth_model.AccessTokenScopeWriteRepository) // Test read topics with write access - req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/topics", org3.Name, repo3.GroupID, repo3.Name)). + req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s%s/topics", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name)). AddTokenAuth(token4) res = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, res, &topics) assert.Empty(t, topics.TopicNames) // Test add a topic to repo with write access (requires repo admin access) - req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%d/%s/topics/%s", org3.Name, repo3.GroupID, repo3.Name, "topicName"). + req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s%s/topics/%s", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name, "topicName"). AddTokenAuth(token4) MakeRequest(t, req, http.StatusForbidden) } diff --git a/tests/integration/editor_test.go b/tests/integration/editor_test.go index 2bc8a0e84e..3ea3125e58 100644 --- a/tests/integration/editor_test.go +++ b/tests/integration/editor_test.go @@ -121,11 +121,8 @@ func testEditorActionPostRequestError(t *testing.T, session *TestSession, reques func testEditorActionEdit(t *testing.T, session *TestSession, groupID int64, user, repo, editorAction, branch, filePath string, params map[string]string) *httptest.ResponseRecorder { params["tree_path"] = util.IfZero(params["tree_path"], filePath) newBranchName := util.Iif(params["commit_choice"] == "direct", branch, params["new_branch_name"]) - var groupSegment string - if groupID > 0 { - groupSegment = fmt.Sprintf("%d/", groupID) - } - resp := testEditorActionPostRequest(t, session, fmt.Sprintf("/%s/%s%s/%s/%s/%s", user, groupSegment, repo, editorAction, branch, filePath), params) + + resp := testEditorActionPostRequest(t, session, fmt.Sprintf("/%s/%s/%s%s/%s/%s", user, maybeWebGroupSegment(groupID), repo, editorAction, branch, filePath), params) assert.Equal(t, http.StatusOK, resp.Code) assert.NotEmpty(t, test.RedirectURL(resp)) req := NewRequest(t, "GET", path.Join(user, repo, "raw/branch", newBranchName, params["tree_path"])) diff --git a/tests/integration/eventsource_test.go b/tests/integration/eventsource_test.go index f7ec3e5edd..c3daa0e25b 100644 --- a/tests/integration/eventsource_test.go +++ b/tests/integration/eventsource_test.go @@ -72,7 +72,7 @@ func TestEventSourceManagerRun(t *testing.T) { assert.Len(t, apiNL, 2) lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ... - req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/notifications?last_read_at=%s", user2.Name, repo1.GroupID, repo1.Name, lastReadAt)). + req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s%s/notifications?last_read_at=%s", user2.Name, maybeGroupSegment(repo1.GroupID), repo1.Name, lastReadAt)). AddTokenAuth(token) session.MakeRequest(t, req, http.StatusResetContent) diff --git a/tests/integration/migrate_test.go b/tests/integration/migrate_test.go index 8c8f053ede..e3804f75ca 100644 --- a/tests/integration/migrate_test.go +++ b/tests/integration/migrate_test.go @@ -97,7 +97,7 @@ func TestMigrateGiteaForm(t *testing.T) { migratedRepoName := "otherrepo" req = NewRequestWithValues(t, "POST", link, map[string]string{ "service": fmt.Sprintf("%d", structs.GiteaService), - "clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName), + "clone_addr": fmt.Sprintf("%s/%s%s", u, ownerName, repoName), "auth_token": token, "issues": "on", "repo_name": migratedRepoName, diff --git a/tests/integration/mirror_push_test.go b/tests/integration/mirror_push_test.go index ef38846d62..398cd48b38 100644 --- a/tests/integration/mirror_push_test.go +++ b/tests/integration/mirror_push_test.go @@ -49,7 +49,7 @@ func testMirrorPush(t *testing.T, u *url.URL) { session := loginUser(t, user.Name) - pushMirrorURL := fmt.Sprintf("%s%s/%s", u.String(), url.PathEscape(user.Name), url.PathEscape(mirrorRepo.Name)) + pushMirrorURL := fmt.Sprintf("%s/%s%s", u.String(), url.PathEscape(user.Name), url.PathEscape(mirrorRepo.Name)) testCreatePushMirror(t, session, user.Name, srcRepo.Name, pushMirrorURL, user.LowerName, userPassword, "0") mirrors, _, err := repo_model.GetPushMirrorsByRepoID(t.Context(), srcRepo.ID, db.ListOptions{}) diff --git a/tests/integration/privateactivity_test.go b/tests/integration/privateactivity_test.go index ecfc8808c0..e90432f775 100644 --- a/tests/integration/privateactivity_test.go +++ b/tests/integration/privateactivity_test.go @@ -35,7 +35,7 @@ func testPrivateActivityDoSomethingForActionEntries(t *testing.T) { session := loginUser(t, privateActivityTestUser) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) - urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues?state=all", owner.Name, repoBefore.GroupID, repoBefore.Name) + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s%s/issues?state=all", owner.Name, maybeGroupSegment(repoBefore.GroupID), repoBefore.Name) req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{ Body: "test", Title: "test", diff --git a/tests/integration/repo_generate_test.go b/tests/integration/repo_generate_test.go index be4d5a036b..e91ee2a1e7 100644 --- a/tests/integration/repo_generate_test.go +++ b/tests/integration/repo_generate_test.go @@ -61,7 +61,7 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateID, templateOw body := fmt.Sprintf(`# %s Readme Owner: %s Link: /%s/%s -Clone URL: %s%s/%s.git`, +Clone URL: %s/%s%s.git`, generateRepoName, strings.ToUpper(generateOwnerName), generateOwnerName, diff --git a/tests/integration/repo_merge_upstream_test.go b/tests/integration/repo_merge_upstream_test.go index d1438ec01d..0a7444b4b7 100644 --- a/tests/integration/repo_merge_upstream_test.go +++ b/tests/integration/repo_merge_upstream_test.go @@ -40,7 +40,7 @@ func TestRepoMergeUpstream(t *testing.T) { token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) // create a fork - req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/forks", baseUser.Name, baseRepo.GroupID, baseRepo.Name), &api.CreateForkOption{ + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/forks", baseUser.Name, maybeGroupSegment(baseRepo.GroupID), baseRepo.Name), &api.CreateForkOption{ Name: new("test-repo-fork"), }).AddTokenAuth(token) MakeRequest(t, req, http.StatusAccepted) diff --git a/tests/integration/utils.go b/tests/integration/utils.go new file mode 100644 index 0000000000..38cf18d991 --- /dev/null +++ b/tests/integration/utils.go @@ -0,0 +1,18 @@ +package integration + +import "fmt" + +func maybeGroupSegment(gid int64) string { + if gid > 0 { + return fmt.Sprintf("%d/", gid) + } + return "" +} + +func maybeWebGroupSegment(gid int64) string { + gs := maybeGroupSegment(gid) + if gs != "" { + return "group/" + gs + } + return "" +}