0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-11 04:55:34 +02:00

update FullName method to show group id if it's non-zero

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2025-08-17 21:48:29 -04:00
parent 11ab4445a0
commit 7a8db72e63
No known key found for this signature in database
GPG Key ID: 924A5F6AF051E87C
51 changed files with 342 additions and 342 deletions

View File

@ -365,7 +365,7 @@ func (repo *Repository) LoadAttributes(ctx context.Context) error {
// FullName returns the repository full name // FullName returns the repository full name
func (repo *Repository) FullName() string { func (repo *Repository) FullName() string {
return repo.OwnerName + "/" + repo.Name return repo.OwnerName + "/" + groupSegmentWithTrailingSlash(repo.GroupID) + repo.Name
} }
// HTMLURL returns the repository HTML URL // HTMLURL returns the repository HTML URL

View File

@ -259,7 +259,7 @@ a,"quoted ""text"" with
new lines new lines
in second column",c`, in second column",c`,
expectedText: `col1,col2,col3 expectedText: `col1,col2,col3
a,,c`, a,c`,
}, },
// case 2 - quoted text with escaped quotes in last column // case 2 - quoted text with escaped quotes in last column
{ {
@ -279,9 +279,9 @@ a,bb,c,d,ee ,"f
f" f"
a,b,"c "" a,b,"c ""
c",d,e,f`, c",d,e,f`,
expectedText: `a,,c,d,,f expectedText: `a,c,d,f
a,bb,c,d,ee , a,bb,c,d,ee ,
a,b,,d,e,f`, a,b,d,e,f`,
}, },
// case 4 - csv with pipes and quotes // case 4 - csv with pipes and quotes
{ {
@ -394,17 +394,17 @@ f" | 4.56 | 789`,
// In the previous bestScore algorithm, this would have picked comma as the delimiter, but now it should guess tab // In the previous bestScore algorithm, this would have picked comma as the delimiter, but now it should guess tab
{ {
csv: `c1 c2 c3 c4 c5 c6 csv: `c1 c2 c3 c4 c5 c6
v,k,x,v ym,f,oa,qn,uqijh,n,s,wvygpo uj,kt,j,w,i,fvv,tm,f,ddt,b,mwt,e,t,teq,rd,p,a e,wfuae,t,h,q,im,ix,y h,mrlu,l,dz,ff,zi,af,emh ,gov,bmfelvb,axp,f,u,i,cni,x,z,v,sh,w,jo,,m,h v,k,x,v ym,f,oa,qn,uqijh,n,s,wvygpo uj,kt,j,w,i,fvv,tm,f,ddt,b,mwt,e,t,teq,rd,p,a e,wfuae,t,h,q,im,ix,y h,mrlu,l,dz,ff,zi,af,emh ,gov,bmfelvb,axp,f,u,i,cni,x,z,v,sh,w,jo,m,h
k,ohf,pgr,tde,m,s te,ek,,v,,ic,kqc,dv,w,oi,j,w,gojjr,ug,,l,j,zl g,qziq,bcajx,zfow,ka,j,re,ohbc k,nzm,qm,ts,auf th,elb,lx,l,q,e,qf asbr,z,k,y,tltobga k,ohf,pgr,tde,m,s te,ek,v,ic,kqc,dv,w,oi,j,w,gojjr,ug,l,j,zl g,qziq,bcajx,zfow,ka,j,re,ohbc k,nzm,qm,ts,auf th,elb,lx,l,q,e,qf asbr,z,k,y,tltobga
g,m,bu,el h,l,jwi,o,wge,fy,rure,c,g,lcxu,fxte,uns,cl,s,o,t,h,rsoy,f bq,s,uov,z,ikkhgyg,,sabs,c,hzue mc,b,,j,t,n sp,mn,,m,t,dysi,eq,pigb,rfa,z w,rfli,sg,,o,wjjjf,f,wxdzfk,x,t,p,zy,p,mg,r,l,h g,m,bu,el h,l,jwi,o,wge,fy,rure,c,g,lcxu,fxte,uns,cl,s,o,t,h,rsoy,f bq,s,uov,z,ikkhgyg,sabs,c,hzue mc,b,j,t,n sp,mn,m,t,dysi,eq,pigb,rfa,z w,rfli,sg,o,wjjjf,f,wxdzfk,x,t,p,zy,p,mg,r,l,h
e,ewbkc,nugd,jj,sf,ih,i,n,jo,b,poem,kw,q,i,x,t,e,uug,k j,xm,sch,ux,h,,fb,f,pq,,mh,,f,v,,oba,w,h,v,eiz,yzd,o,a,c,e,dhp,q a,pbef,epc,k,rdpuw,cw k,j,e,d xf,dz,sviv,w,sqnzew,t,b v,yg,f,cq,ti,g,m,ta,hm,ym,ii,hxy,p,z,r,e,ga,sfs,r,p,l,aar,w,kox,j e,ewbkc,nugd,jj,sf,ih,i,n,jo,b,poem,kw,q,i,x,t,e,uug,k j,xm,sch,ux,h,fb,f,pq,mh,f,v,oba,w,h,v,eiz,yzd,o,a,c,e,dhp,q a,pbef,epc,k,rdpuw,cw k,j,e,d xf,dz,sviv,w,sqnzew,t,b v,yg,f,cq,ti,g,m,ta,hm,ym,ii,hxy,p,z,r,e,ga,sfs,r,p,l,aar,w,kox,j
l,d,v,pp,q,j,bxip,w,i,im,qa,o e,o h,w,a,a,qzj,nt,qfn,ut,fvhu,ts hu,q,g,p,q,ofpje,fsqa,frp,p,vih,j,w,k,jx, ln,th,ka,l,b,vgk,rv,hkx rj,v,y,cwm,rao,e,l,wvr,ptc,lm,yg,u,k,i,b,zk,b,gv,fls l,d,v,pp,q,j,bxip,w,i,im,qa,o e,o h,w,a,a,qzj,nt,qfn,ut,fvhu,ts hu,q,g,p,q,ofpje,fsqa,frp,p,vih,j,w,k,jx, ln,th,ka,l,b,vgk,rv,hkx rj,v,y,cwm,rao,e,l,wvr,ptc,lm,yg,u,k,i,b,zk,b,gv,fls
velxtnhlyuysbnlchosqlhkozkdapjaueexjwrndwb nglvnv kqiv pbshwlmcexdzipopxjyrxhvjalwp pydvipwlkkpdvbtepahskwuornbsb qwbacgq velxtnhlyuysbnlchosqlhkozkdapjaueexjwrndwb nglvnv kqiv pbshwlmcexdzipopxjyrxhvjalwp pydvipwlkkpdvbtepahskwuornbsb qwbacgq
l,y,u,bf,y,m,eals,n,cop,h,g,vs,jga,opt x,b,zwmn,hh,b,n,pdj,t,d px yn,vtd,u,y,b,ps,yo,qqnem,mxg,m,al,rd,c,k,d,q,f ilxdxa,m,y,,p,p,y,prgmg,q,n,etj,k,ns b,pl,z,jq,hk l,y,u,bf,y,m,eals,n,cop,h,g,vs,jga,opt x,b,zwmn,hh,b,n,pdj,t,d px yn,vtd,u,y,b,ps,yo,qqnem,mxg,m,al,rd,c,k,d,q,f ilxdxa,m,y,p,p,y,prgmg,q,n,etj,k,ns b,pl,z,jq,hk
p,gc jn,mzr,bw sb,e,r,dy,ur,wzy,r,c,n,yglr,jbdu,r,pqk,k q,d,,,p,l,euhl,dc,rwh,t,tq,z,h,p,s,t,x,fugr,h wi,zxb,jcig,o,t,k mfh,ym,h,e,p,cnvx,uv,zx,x,pq,blt,v,r,u,tr,g,g,xt p,gc jn,mzr,bw sb,e,r,dy,ur,wzy,r,c,n,yglr,jbdu,r,pqk,k q,d,,p,l,euhl,dc,rwh,t,tq,z,h,p,s,t,x,fugr,h wi,zxb,jcig,o,t,k mfh,ym,h,e,p,cnvx,uv,zx,x,pq,blt,v,r,u,tr,g,g,xt
nri,p,,t,if,,y,ptlqq a,i w,ovli,um,w,f,re,k,sb,w,jy,zf i,g,p,q,mii,nr,jm,cc i,szl,k,eg,l,d ,ah,w,b,vh nri,p,t,if,y,ptlqq a,i w,ovli,um,w,f,re,k,sb,w,jy,zf i,g,p,q,mii,nr,jm,cc i,szl,k,eg,l,d ,ah,w,b,vh
,,sh,wx,mn,xm,u,d,yy,u,t,m,j,s,b ogadq,g,y,y,i,h,ln,jda,g,cz,s,rv,r,s,s,le,r, y,nu,f,nagj o,h,,adfy,o,nf,ns,gvsvnub,k,b,xyz v,h,g,ef,y,gb c,x,cw,x,go,h,t,x,cu,u,qgrqzrcmn,kq,cd,g,rejp,zcq ,sh,wx,mn,xm,u,d,yy,u,t,m,j,s,b ogadq,g,y,y,i,h,ln,jda,g,cz,s,rv,r,s,s,le,r, y,nu,f,nagj o,h,adfy,o,nf,ns,gvsvnub,k,b,xyz v,h,g,ef,y,gb c,x,cw,x,go,h,t,x,cu,u,qgrqzrcmn,kq,cd,g,rejp,zcq
skxg,t,vay,d,wug,d,xg,sexc rt g,ag,mjq,fjnyji,iwa,m,ml,b,ua,b,qjxeoc be,s,sh,n,jbzxs,g,n,i,h,y,r,be,mfo,u,p cw,r,,u,zn,eg,r,yac,m,l,edkr,ha,x,g,b,c,tg,c j,ye,u,ejd,maj,ea,bm,u,iy`, skxg,t,vay,d,wug,d,xg,sexc rt g,ag,mjq,fjnyji,iwa,m,ml,b,ua,b,qjxeoc be,s,sh,n,jbzxs,g,n,i,h,y,r,be,mfo,u,p cw,r,u,zn,eg,r,yac,m,l,edkr,ha,x,g,b,c,tg,c j,ye,u,ejd,maj,ea,bm,u,iy`,
expectedDelimiter: '\t', expectedDelimiter: '\t',
}, },
// case 13 - a CSV with more than 10 lines and since we only use the first 10 lines, it should still get the delimiter as semicolon // case 13 - a CSV with more than 10 lines and since we only use the first 10 lines, it should still get the delimiter as semicolon

View File

@ -312,7 +312,7 @@ func convertResult(searchResult *elastic.SearchResult, kw string, pageSize int)
// <em> and </em> tags? If elastic search has handled that? // <em> and </em> tags? If elastic search has handled that?
startIndex, endIndex = contentMatchIndexPos(c[0], "<em>", "</em>") startIndex, endIndex = contentMatchIndexPos(c[0], "<em>", "</em>")
if startIndex == -1 { if startIndex == -1 {
panic(fmt.Sprintf("1===%s,,,%#v,,,%s", kw, hit.Highlight, c[0])) panic(fmt.Sprintf("1===%s,,%#v,,%s", kw, hit.Highlight, c[0]))
} }
} else { } else {
panic(fmt.Sprintf("2===%#v", hit.Highlight)) panic(fmt.Sprintf("2===%#v", hit.Highlight))

View File

@ -662,7 +662,7 @@ body:
name: Name name: Name
title: Title title: Title
about: About about: About
labels: label1,label2,,label3 ,, labels: label1,label2,label3 ,
ref: Ref ref: Ref
body: body:
- type: markdown - type: markdown
@ -731,7 +731,7 @@ body:
name: Name name: Name
title: Title title: Title
about: About about: About
labels: label1,label2,,label3 ,, labels: label1,label2,label3 ,
ref: Ref ref: Ref
--- ---
Content Content

View File

@ -144,7 +144,7 @@ func repoAssignment() func(ctx *context.APIContext) {
if group != "" { if group != "" {
gid, _ = strconv.ParseInt(group, 10, 64) gid, _ = strconv.ParseInt(group, 10, 64)
if gid == 0 { if gid == 0 {
ctx.Redirect(strings.Replace(ctx.Req.URL.RequestURI(), "/0/", "/", 1)) ctx.Redirect(strings.Replace(ctx.Req.URL.RequestURI(), "/0/", "/", 1), 307)
return return
} }
group += "/" group += "/"

View File

@ -1778,7 +1778,7 @@ func buildSignature(endp string, expires, artifactID int64) []byte {
} }
func buildDownloadRawEndpoint(repo *repo_model.Repository, artifactID int64) string { func buildDownloadRawEndpoint(repo *repo_model.Repository, artifactID int64) string {
return fmt.Sprintf("api/v1/repos/%s/%s/actions/artifacts/%d/zip/raw", url.PathEscape(repo.OwnerName), url.PathEscape(repo.Name), artifactID) return fmt.Sprintf("api/v1/repos/%s/%d/%s/actions/artifacts/%d/zip/raw", url.PathEscape(repo.OwnerName), repo.GroupID, url.PathEscape(repo.Name), artifactID)
} }
func buildSigURL(ctx go_context.Context, endPoint string, artifactID int64) string { func buildSigURL(ctx go_context.Context, endPoint string, artifactID int64) string {

View File

@ -479,7 +479,7 @@ func RepoAssignment(ctx *Context) {
if q != "" { if q != "" {
q = "?" + q q = "?" + q
} }
ctx.Redirect(strings.Replace(ctx.Link, "/0/", "/", 1) + q) ctx.Redirect(strings.Replace(ctx.Link, "/0/", "/", 1)+q, 307)
return return
} }
group += "/" group += "/"

View File

@ -120,7 +120,7 @@ jobs:
runner.registerAsRepoRunner(t, user2.Name, apiRepo.Name, "mock-runner", []string{"ubuntu-latest"}, false) runner.registerAsRepoRunner(t, user2.Name, apiRepo.Name, "mock-runner", []string{"ubuntu-latest"}, false)
opts := getWorkflowCreateFileOptions(user2, apiRepo.DefaultBranch, "create "+testCase.treePath, testCase.fileContent) opts := getWorkflowCreateFileOptions(user2, apiRepo.DefaultBranch, "create "+testCase.treePath, testCase.fileContent)
createWorkflowFile(t, token, user2.Name, apiRepo.Name, testCase.treePath, opts) createWorkflowFile(t, token, user2.Name, apiRepo.Name, testCase.treePath, apiRepo.GroupID, opts)
var runID int64 var runID int64
for i := 0; i < len(testCase.outcomes); i++ { for i := 0; i < len(testCase.outcomes); i++ {

View File

@ -142,7 +142,7 @@ jobs:
t.Run("test "+tc.treePath, func(t *testing.T) { t.Run("test "+tc.treePath, func(t *testing.T) {
// create the workflow file // create the workflow file
opts := getWorkflowCreateFileOptions(user2, apiRepo.DefaultBranch, "create "+tc.treePath, tc.fileContent) opts := getWorkflowCreateFileOptions(user2, apiRepo.DefaultBranch, "create "+tc.treePath, tc.fileContent)
fileResp := createWorkflowFile(t, token, user2.Name, apiRepo.Name, tc.treePath, opts) fileResp := createWorkflowFile(t, token, user2.Name, apiRepo.Name, tc.treePath, apiRepo.GroupID, opts)
// fetch and execute task // fetch and execute task
for i := 0; i < len(tc.outcomes); i++ { for i := 0; i < len(tc.outcomes); i++ {
@ -154,7 +154,7 @@ jobs:
} }
// check result // check result
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/tasks", user2.Name, apiRepo.Name)). req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/actions/tasks", user2.Name, apiRepo.GroupID, apiRepo.Name)).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var actionTaskRespAfter api.ActionTaskResponse var actionTaskRespAfter api.ActionTaskResponse
@ -324,7 +324,7 @@ jobs:
for _, tc := range testCases { for _, tc := range testCases {
t.Run("test "+tc.treePath, func(t *testing.T) { t.Run("test "+tc.treePath, func(t *testing.T) {
opts := getWorkflowCreateFileOptions(user2, apiRepo.DefaultBranch, "create "+tc.treePath, tc.fileContent) opts := getWorkflowCreateFileOptions(user2, apiRepo.DefaultBranch, "create "+tc.treePath, tc.fileContent)
createWorkflowFile(t, token, user2.Name, apiRepo.Name, tc.treePath, opts) createWorkflowFile(t, token, user2.Name, apiRepo.Name, tc.treePath, apiRepo.GroupID, opts)
for i := 0; i < len(tc.outcomes); i++ { for i := 0; i < len(tc.outcomes); i++ {
task := runner.fetchTask(t) task := runner.fetchTask(t)
@ -490,7 +490,7 @@ jobs:
- run: echo 'test the pull' - run: echo 'test the pull'
` `
opts := getWorkflowCreateFileOptions(user2, baseRepo.DefaultBranch, "create "+wfTreePath, wfFileContent) opts := getWorkflowCreateFileOptions(user2, baseRepo.DefaultBranch, "create "+wfTreePath, wfFileContent)
createWorkflowFile(t, user2Token, baseRepo.OwnerName, baseRepo.Name, wfTreePath, opts) createWorkflowFile(t, user2Token, baseRepo.OwnerName, baseRepo.Name, wfTreePath, baseRepo.GroupID, opts)
// user2 creates a pull request // user2 creates a pull request
doAPICreateFile(user2APICtx, "user2-patch.txt", &api.CreateFileOptions{ doAPICreateFile(user2APICtx, "user2-patch.txt", &api.CreateFileOptions{
FileOptions: api.FileOptions{ FileOptions: api.FileOptions{
@ -582,7 +582,7 @@ jobs:
- run: echo 'test the pull' - run: echo 'test the pull'
` `
opts := getWorkflowCreateFileOptions(user2, baseRepo.DefaultBranch, "create "+wfTreePath, wfFileContent) opts := getWorkflowCreateFileOptions(user2, baseRepo.DefaultBranch, "create "+wfTreePath, wfFileContent)
createWorkflowFile(t, user2Token, baseRepo.OwnerName, baseRepo.Name, wfTreePath, opts) createWorkflowFile(t, user2Token, baseRepo.OwnerName, baseRepo.Name, wfTreePath, baseRepo.GroupID, opts)
// user2 creates a pull request // user2 creates a pull request
doAPICreateFile(user2APICtx, "user2-patch.txt", &api.CreateFileOptions{ doAPICreateFile(user2APICtx, "user2-patch.txt", &api.CreateFileOptions{
FileOptions: api.FileOptions{ FileOptions: api.FileOptions{
@ -734,8 +734,8 @@ func getWorkflowCreateFileOptions(u *user_model.User, branch, msg, content strin
} }
} }
func createWorkflowFile(t *testing.T, authToken, ownerName, repoName, treePath string, opts *api.CreateFileOptions) *api.FileResponse { func createWorkflowFile(t *testing.T, authToken, ownerName, repoName, treePath string, groupID int64, opts *api.CreateFileOptions) *api.FileResponse {
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", ownerName, repoName, treePath), opts). req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", ownerName, groupID, repoName, treePath), opts).
AddTokenAuth(authToken) AddTokenAuth(authToken)
resp := MakeRequest(t, req, http.StatusCreated) resp := MakeRequest(t, req, http.StatusCreated)
var fileResponse api.FileResponse var fileResponse api.FileResponse

View File

@ -166,7 +166,7 @@ jobs:
// create the workflow file // create the workflow file
opts := getWorkflowCreateFileOptions(user2, repo.DefaultBranch, "create "+tc.treePath, tc.fileContent) opts := getWorkflowCreateFileOptions(user2, repo.DefaultBranch, "create "+tc.treePath, tc.fileContent)
createWorkflowFile(t, token, user2.Name, repo.Name, tc.treePath, opts) createWorkflowFile(t, token, user2.Name, repo.Name, tc.treePath, repo.GroupID, opts)
// fetch and execute tasks // fetch and execute tasks
for _, outcome := range tc.outcome { for _, outcome := range tc.outcome {
@ -198,7 +198,7 @@ jobs:
} }
// download task logs from API and check content // download task logs from API and check content
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/jobs/%d/logs", user2.Name, repo.Name, job.ID)). req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/actions/jobs/%d/logs", user2.Name, repo.GroupID, repo.Name, job.ID)).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n") logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n")

View File

@ -1560,10 +1560,10 @@ jobs:
- run: echo 'Hello World' - run: echo 'Hello World'
` `
opts1 := getWorkflowCreateFileOptions(user2, baseRepo.DefaultBranch, "create "+wfTreePath, wfFileContent) opts1 := getWorkflowCreateFileOptions(user2, baseRepo.DefaultBranch, "create "+wfTreePath, wfFileContent)
createWorkflowFile(t, user2Token, baseRepo.OwnerName, baseRepo.Name, wfTreePath, opts1) createWorkflowFile(t, user2Token, baseRepo.OwnerName, baseRepo.Name, wfTreePath, baseRepo.GroupID, opts1)
// user4 forks the repo // user4 forks the repo
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/forks", baseRepo.OwnerName, baseRepo.Name), req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/forks", baseRepo.OwnerName, baseRepo.GroupID, baseRepo.Name),
&api.CreateForkOption{ &api.CreateForkOption{
Name: new("close-pull-request-with-path-fork"), Name: new("close-pull-request-with-path-fork"),
}).AddTokenAuth(user4Token) }).AddTokenAuth(user4Token)

View File

@ -36,17 +36,17 @@ func TestAPIGetCommentAttachment(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.Name, comment.ID, attachment.ID). 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).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
}) })
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.Name, comment.ID, attachment.ID). 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).
AddTokenAuth(token) AddTokenAuth(token)
session.MakeRequest(t, req, http.StatusOK) session.MakeRequest(t, req, http.StatusOK)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.Name, comment.ID, attachment.ID). 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).
AddTokenAuth(token) AddTokenAuth(token)
resp := session.MakeRequest(t, req, http.StatusOK) resp := session.MakeRequest(t, req, http.StatusOK)
@ -71,7 +71,7 @@ func TestAPIListCommentAttachments(t *testing.T) {
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d/assets", repoOwner.Name, repo.Name, comment.ID). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, comment.ID).
AddTokenAuth(token) AddTokenAuth(token)
resp := session.MakeRequest(t, req, http.StatusOK) resp := session.MakeRequest(t, req, http.StatusOK)
@ -105,7 +105,7 @@ func TestAPICreateCommentAttachment(t *testing.T) {
err = writer.Close() err = writer.Close()
assert.NoError(t, err) assert.NoError(t, err)
req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets", repoOwner.Name, repo.Name, comment.ID), body). 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).
AddTokenAuth(token). AddTokenAuth(token).
SetHeader("Content-Type", writer.FormDataContentType()) SetHeader("Content-Type", writer.FormDataContentType())
resp := session.MakeRequest(t, req, http.StatusCreated) resp := session.MakeRequest(t, req, http.StatusCreated)
@ -137,7 +137,7 @@ func TestAPICreateCommentAttachmentWithUnallowedFile(t *testing.T) {
err = writer.Close() err = writer.Close()
assert.NoError(t, err) assert.NoError(t, err)
req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets", repoOwner.Name, repo.Name, comment.ID), body). 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).
AddTokenAuth(token). AddTokenAuth(token).
SetHeader("Content-Type", writer.FormDataContentType()) SetHeader("Content-Type", writer.FormDataContentType())
@ -202,7 +202,7 @@ func TestAPIDeleteCommentAttachment(t *testing.T) {
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/assets/%d", repoOwner.Name, repo.Name, comment.ID, attachment.ID)). 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)).
AddTokenAuth(token) AddTokenAuth(token)
session.MakeRequest(t, req, http.StatusNoContent) session.MakeRequest(t, req, http.StatusNoContent)

View File

@ -30,7 +30,7 @@ func TestAPIListRepoComments(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments", repoOwner.Name, repo.Name)) link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/comments", repoOwner.Name, repo.GroupID, repo.Name))
req := NewRequest(t, "GET", link.String()) req := NewRequest(t, "GET", link.String())
resp := MakeRequest(t, req, http.StatusOK) 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}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeReadIssue) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeReadIssue)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments", repoOwner.Name, repo.Name, issue.Index). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/%d/comments", repoOwner.Name, repo.GroupID, repo.Name, issue.Index).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -115,7 +115,7 @@ func TestAPICreateComment(t *testing.T) {
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
req := NewRequestWithValues(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", repo.OwnerName, repo.Name, issue.Index), map[string]string{ 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{
"body": commentBody, "body": commentBody,
}).AddTokenAuth(getUserToken(t, user34.Name, auth_model.AccessTokenScopeWriteRepository)) }).AddTokenAuth(getUserToken(t, user34.Name, auth_model.AccessTokenScopeWriteRepository))
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
@ -128,7 +128,7 @@ func TestAPICreateComment(t *testing.T) {
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 13}) issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 13})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
req := NewRequestWithValues(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", repo.OwnerName, repo.Name, issue.Index), map[string]string{ 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{
"body": commentBody, "body": commentBody,
}).AddTokenAuth(getUserToken(t, user34.Name, auth_model.AccessTokenScopeWriteRepository)) }).AddTokenAuth(getUserToken(t, user34.Name, auth_model.AccessTokenScopeWriteRepository))
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
@ -144,9 +144,9 @@ func TestAPIGetComment(t *testing.T) {
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeReadIssue) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeReadIssue)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID) req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -183,7 +183,7 @@ func TestAPIGetSystemUserComment(t *testing.T) {
}) })
assert.NoError(t, err) assert.NoError(t, err)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID) req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var apiComment api.Comment var apiComment api.Comment
@ -251,13 +251,13 @@ func TestAPIDeleteComment(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue)
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID). req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
}) })
token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue)
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID). req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/issues/comments/%d", repoOwner.Name, repo.GroupID, repo.Name, comment.ID).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
@ -273,7 +273,7 @@ func TestAPIListIssueTimeline(t *testing.T) {
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
// make request // make request
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/timeline", repoOwner.Name, repo.Name, issue.Index) req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/issues/%d/timeline", repoOwner.Name, repo.GroupID, repo.Name, issue.Index)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
// check if lens of list returned by API and // check if lens of list returned by API and

View File

@ -32,7 +32,7 @@ func TestAPIGetIssueAttachment(t *testing.T) {
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets/%d", repoOwner.Name, repo.Name, issue.Index, attachment.ID)). 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)).
AddTokenAuth(token) AddTokenAuth(token)
resp := session.MakeRequest(t, req, http.StatusOK) resp := session.MakeRequest(t, req, http.StatusOK)
apiAttachment := new(api.Attachment) apiAttachment := new(api.Attachment)
@ -52,7 +52,7 @@ func TestAPIListIssueAttachments(t *testing.T) {
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets", repoOwner.Name, repo.Name, issue.Index)). req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, issue.Index)).
AddTokenAuth(token) AddTokenAuth(token)
resp := session.MakeRequest(t, req, http.StatusOK) resp := session.MakeRequest(t, req, http.StatusOK)
apiAttachment := new([]api.Attachment) apiAttachment := new([]api.Attachment)
@ -82,7 +82,7 @@ func TestAPICreateIssueAttachment(t *testing.T) {
err = writer.Close() err = writer.Close()
assert.NoError(t, err) assert.NoError(t, err)
req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets", repoOwner.Name, repo.Name, issue.Index), body). req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, issue.Index), body).
AddTokenAuth(token) AddTokenAuth(token)
req.Header.Add("Content-Type", writer.FormDataContentType()) req.Header.Add("Content-Type", writer.FormDataContentType())
resp := session.MakeRequest(t, req, http.StatusCreated) resp := session.MakeRequest(t, req, http.StatusCreated)
@ -113,7 +113,7 @@ func TestAPICreateIssueAttachmentWithUnallowedFile(t *testing.T) {
err = writer.Close() err = writer.Close()
assert.NoError(t, err) assert.NoError(t, err)
req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets", repoOwner.Name, repo.Name, issue.Index), body). req := NewRequestWithBody(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets", repoOwner.Name, repo.GroupID, repo.Name, issue.Index), body).
AddTokenAuth(token) AddTokenAuth(token)
req.Header.Add("Content-Type", writer.FormDataContentType()) req.Header.Add("Content-Type", writer.FormDataContentType())
@ -156,7 +156,7 @@ func TestAPIEditIssueAttachmentWithUnallowedFile(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
filename := "file.bad" filename := "file.bad"
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets/%d", repoOwner.Name, repo.Name, issue.Index, attachment.ID) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, issue.Index, attachment.ID)
req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
"name": filename, "name": filename,
}).AddTokenAuth(token) }).AddTokenAuth(token)
@ -175,7 +175,7 @@ func TestAPIDeleteIssueAttachment(t *testing.T) {
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/assets/%d", repoOwner.Name, repo.Name, issue.Index, attachment.ID)). 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)).
AddTokenAuth(token) AddTokenAuth(token)
session.MakeRequest(t, req, http.StatusNoContent) session.MakeRequest(t, req, http.StatusNoContent)

View File

@ -150,7 +150,7 @@ func TestAPIRepoValidateIssueConfig(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 49}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 49})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issue_config/validate", owner.Name, repo.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issue_config/validate", owner.Name, repo.GroupID, repo.Name)
t.Run("Valid", func(t *testing.T) { t.Run("Valid", func(t *testing.T) {
req := NewRequest(t, "GET", urlStr) req := NewRequest(t, "GET", urlStr)

View File

@ -26,7 +26,7 @@ func TestAPIModifyLabels(t *testing.T) {
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/labels", owner.Name, repo.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/labels", owner.Name, repo.GroupID, repo.Name)
// CreateLabel // CreateLabel
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateLabelOption{ req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateLabelOption{
@ -62,7 +62,7 @@ func TestAPIModifyLabels(t *testing.T) {
assert.Len(t, apiLabels, 2) assert.Len(t, apiLabels, 2)
// GetLabel // GetLabel
singleURLStr := fmt.Sprintf("/api/v1/repos/%s/%s/labels/%d", owner.Name, repo.Name, dbLabel.ID) singleURLStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/labels/%d", owner.Name, repo.GroupID, repo.Name, dbLabel.ID)
req = NewRequest(t, "GET", singleURLStr). req = NewRequest(t, "GET", singleURLStr).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
@ -127,7 +127,7 @@ func TestAPIAddIssueLabelsWithLabelNames(t *testing.T) {
token := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeWriteIssue)
// add the org label and the repo label to the issue // add the org label and the repo label to the issue
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels", owner.Name, repo.Name, issue.Index) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/labels", owner.Name, repo.GroupID, repo.Name, issue.Index)
req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{ req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{
Labels: []any{repoLabel.Name, orgLabel.Name}, Labels: []any{repoLabel.Name, orgLabel.Name},
}).AddTokenAuth(token) }).AddTokenAuth(token)

View File

@ -27,7 +27,7 @@ func TestAPILockIssue(t *testing.T) {
assert.False(t, issueBefore.IsLocked) assert.False(t, issueBefore.IsLocked)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/lock", owner.Name, repo.Name, issueBefore.Index) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/lock", owner.Name, repo.GroupID, repo.Name, issueBefore.Index)
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) 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}) issueBefore := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/lock", owner.Name, repo.Name, issueBefore.Index) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/lock", owner.Name, repo.GroupID, repo.Name, issueBefore.Index)
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)

View File

@ -34,7 +34,7 @@ func TestAPIIssuesMilestone(t *testing.T) {
// update values of issue // update values of issue
milestoneState := "closed" milestoneState := "closed"
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%d", owner.Name, repo.Name, milestone.ID) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones/%d", owner.Name, repo.GroupID, repo.Name, milestone.ID)
req := NewRequestWithJSON(t, "PATCH", urlStr, structs.EditMilestoneOption{ req := NewRequestWithJSON(t, "PATCH", urlStr, structs.EditMilestoneOption{
State: &milestoneState, State: &milestoneState,
}).AddTokenAuth(token) }).AddTokenAuth(token)
@ -50,7 +50,7 @@ func TestAPIIssuesMilestone(t *testing.T) {
DecodeJSON(t, resp, &apiMilestone2) DecodeJSON(t, resp, &apiMilestone2)
assert.EqualValues(t, "closed", apiMilestone2.State) assert.EqualValues(t, "closed", apiMilestone2.State)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/milestones", owner.Name, repo.Name), structs.CreateMilestoneOption{ req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones", owner.Name, repo.GroupID, repo.Name), structs.CreateMilestoneOption{
Title: "wow", Title: "wow",
Description: "closed one", Description: "closed one",
State: "closed", State: "closed",
@ -62,27 +62,27 @@ func TestAPIIssuesMilestone(t *testing.T) {
assert.Nil(t, apiMilestone.Deadline) assert.Nil(t, apiMilestone.Deadline)
var apiMilestones []structs.Milestone var apiMilestones []structs.Milestone
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/milestones?state=%s", owner.Name, repo.Name, "all")). req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones?state=%s", owner.Name, repo.GroupID, repo.Name, "all")).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiMilestones) DecodeJSON(t, resp, &apiMilestones)
assert.Len(t, apiMilestones, 4) assert.Len(t, apiMilestones, 4)
assert.Nil(t, apiMilestones[0].Deadline) assert.Nil(t, apiMilestones[0].Deadline)
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%s", owner.Name, repo.Name, apiMilestones[2].Title)). req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones/%s", owner.Name, repo.GroupID, repo.Name, apiMilestones[2].Title)).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiMilestone) DecodeJSON(t, resp, &apiMilestone)
assert.Equal(t, apiMilestones[2], apiMilestone) assert.Equal(t, apiMilestones[2], apiMilestone)
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/milestones?state=%s&name=%s", owner.Name, repo.Name, "all", "milestone2")). 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")).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiMilestones) DecodeJSON(t, resp, &apiMilestones)
assert.Len(t, apiMilestones, 1) assert.Len(t, apiMilestones, 1)
assert.Equal(t, int64(2), apiMilestones[0].ID) assert.Equal(t, int64(2), apiMilestones[0].ID)
req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%d", owner.Name, repo.Name, apiMilestone.ID)). req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/milestones/%d", owner.Name, repo.GroupID, repo.Name, apiMilestone.ID)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
} }

View File

@ -32,12 +32,12 @@ func TestAPIPinIssue(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
// Pin the Issue // Pin the Issue
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/pin", repo.OwnerName, repo.Name, issue.Index)). req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Check if the Issue is pinned // Check if the Issue is pinned
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", repo.OwnerName, repo.Name, issue.Index)) req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index))
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var issueAPI api.Issue var issueAPI api.Issue
DecodeJSON(t, resp, &issueAPI) DecodeJSON(t, resp, &issueAPI)
@ -57,24 +57,24 @@ func TestAPIUnpinIssue(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
// Pin the Issue // Pin the Issue
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/pin", repo.OwnerName, repo.Name, issue.Index)). req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Check if the Issue is pinned // Check if the Issue is pinned
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", repo.OwnerName, repo.Name, issue.Index)) req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index))
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var issueAPI api.Issue var issueAPI api.Issue
DecodeJSON(t, resp, &issueAPI) DecodeJSON(t, resp, &issueAPI)
assert.Equal(t, 1, issueAPI.PinOrder) assert.Equal(t, 1, issueAPI.PinOrder)
// Unpin the Issue // Unpin the Issue
req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/pin", repo.OwnerName, repo.Name, issue.Index)). req = NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Check if the Issue is no longer pinned // Check if the Issue is no longer pinned
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", repo.OwnerName, repo.Name, issue.Index)) req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index))
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &issueAPI) DecodeJSON(t, resp, &issueAPI)
assert.Equal(t, 0, issueAPI.PinOrder) assert.Equal(t, 0, issueAPI.PinOrder)
@ -94,36 +94,36 @@ func TestAPIMoveIssuePin(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
// Pin the first Issue // Pin the first Issue
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/pin", repo.OwnerName, repo.Name, issue.Index)). req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Check if the first Issue is pinned at position 1 // Check if the first Issue is pinned at position 1
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", repo.OwnerName, repo.Name, issue.Index)) req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index))
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var issueAPI api.Issue var issueAPI api.Issue
DecodeJSON(t, resp, &issueAPI) DecodeJSON(t, resp, &issueAPI)
assert.Equal(t, 1, issueAPI.PinOrder) assert.Equal(t, 1, issueAPI.PinOrder)
// Pin the second Issue // Pin the second Issue
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/pin", repo.OwnerName, repo.Name, issue2.Index)). req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue2.Index)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Move the first Issue to position 2 // Move the first Issue to position 2
req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/pin/2", repo.OwnerName, repo.Name, issue.Index)). req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin/2", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Check if the first Issue is pinned at position 2 // Check if the first Issue is pinned at position 2
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", repo.OwnerName, repo.Name, issue.Index)) req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue.Index))
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
var issueAPI3 api.Issue var issueAPI3 api.Issue
DecodeJSON(t, resp, &issueAPI3) DecodeJSON(t, resp, &issueAPI3)
assert.Equal(t, 2, issueAPI3.PinOrder) assert.Equal(t, 2, issueAPI3.PinOrder)
// Check if the second Issue is pinned at position 1 // Check if the second Issue is pinned at position 1
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", repo.OwnerName, repo.Name, issue2.Index)) req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", repo.OwnerName, repo.GroupID, repo.Name, issue2.Index))
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
var issueAPI4 api.Issue var issueAPI4 api.Issue
DecodeJSON(t, resp, &issueAPI4) DecodeJSON(t, resp, &issueAPI4)
@ -143,12 +143,12 @@ func TestAPIListPinnedIssues(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
// Pin the Issue // Pin the Issue
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/pin", repo.OwnerName, repo.Name, issue.Index)). req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/pin", repo.OwnerName, repo.GroupID, repo.Name, issue.Index)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Check if the Issue is in the List // Check if the Issue is in the List
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/pinned", repo.OwnerName, repo.Name)) req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/pinned", repo.OwnerName, repo.GroupID, repo.Name))
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var issueList []api.Issue var issueList []api.Issue
DecodeJSON(t, resp, &issueList) DecodeJSON(t, resp, &issueList)
@ -164,7 +164,7 @@ func TestAPIListPinnedPullrequests(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/pulls/pinned", repo.OwnerName, repo.Name)) req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls/pinned", repo.OwnerName, repo.GroupID, repo.Name))
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var prList []api.PullRequest var prList []api.PullRequest
DecodeJSON(t, resp, &prList) DecodeJSON(t, resp, &prList)
@ -178,7 +178,7 @@ func TestAPINewPinAllowed(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/new_pin_allowed", owner.Name, repo.Name)) req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/new_pin_allowed", owner.Name, repo.GroupID, repo.Name))
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var newPinsAllowed api.NewIssuePinsAllowed var newPinsAllowed api.NewIssuePinsAllowed

View File

@ -118,7 +118,7 @@ func TestAPICommentReactions(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/reactions", repoOwner.Name, repo.Name, comment.ID) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/comments/%d/reactions", repoOwner.Name, repo.GroupID, repo.Name, comment.ID)
req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{ req = NewRequestWithJSON(t, "POST", urlStr, &api.EditReactionOption{
Reaction: "+1", Reaction: "+1",
}).AddTokenAuth(token) }).AddTokenAuth(token)

View File

@ -36,7 +36,7 @@ func TestAPIIssueSubscriptions(t *testing.T) {
testSubscription := func(issue *issues_model.Issue, isWatching bool) { testSubscription := func(issue *issues_model.Issue, isWatching bool) {
issueRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) issueRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/check", issueRepo.OwnerName, issueRepo.Name, issue.Index)). req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/subscriptions/check", issueRepo.OwnerName, issueRepo.GroupID, issueRepo.Name, issue.Index)).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
wi := new(api.WatchInfo) wi := new(api.WatchInfo)
@ -56,7 +56,7 @@ func TestAPIIssueSubscriptions(t *testing.T) {
testSubscription(issue5, false) testSubscription(issue5, false)
issue1Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue1.RepoID}) issue1Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue1.RepoID})
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s", issue1Repo.OwnerName, issue1Repo.Name, issue1.Index, owner.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/subscriptions/%s", issue1Repo.OwnerName, issue1Repo.GroupID, issue1Repo.Name, issue1.Index, owner.Name)
req := NewRequest(t, "DELETE", urlStr). req := NewRequest(t, "DELETE", urlStr).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -68,7 +68,7 @@ func TestAPIIssueSubscriptions(t *testing.T) {
testSubscription(issue1, false) testSubscription(issue1, false)
issue5Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue5.RepoID}) issue5Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue5.RepoID})
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s", issue5Repo.OwnerName, issue5Repo.Name, issue5.Index, owner.Name) urlStr = fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d/subscriptions/%s", issue5Repo.OwnerName, issue5Repo.GroupID, issue5Repo.Name, issue5.Index, owner.Name)
req = NewRequest(t, "PUT", urlStr). req = NewRequest(t, "PUT", urlStr).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)

View File

@ -43,7 +43,7 @@ func testAPIListIssues(t *testing.T) {
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner.Name, repo.Name)) link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner.Name, repo.GroupID, repo.Name))
link.RawQuery = url.Values{"token": {token}, "state": {"all"}}.Encode() link.RawQuery = url.Values{"token": {token}, "state": {"all"}}.Encode()
resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
@ -91,7 +91,7 @@ func testAPIListIssuesPublicOnly(t *testing.T) {
session := loginUser(t, owner1.Name) session := loginUser(t, owner1.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner1.Name, repo1.Name)) link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner1.Name, repo1.GroupID, repo1.Name))
link.RawQuery = url.Values{"state": {"all"}}.Encode() link.RawQuery = url.Values{"state": {"all"}}.Encode()
req := NewRequest(t, "GET", link.String()).AddTokenAuth(token) req := NewRequest(t, "GET", link.String()).AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
@ -101,7 +101,7 @@ func testAPIListIssuesPublicOnly(t *testing.T) {
session = loginUser(t, owner2.Name) session = loginUser(t, owner2.Name)
token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue) token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner2.Name, repo2.Name)) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner2.Name, repo2.GroupID, repo2.Name))
link.RawQuery = url.Values{"state": {"all"}}.Encode() link.RawQuery = url.Values{"state": {"all"}}.Encode()
req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) req = NewRequest(t, "GET", link.String()).AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
@ -119,7 +119,7 @@ func testAPICreateIssue(t *testing.T) {
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner.Name, repoBefore.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner.Name, repoBefore.GroupID, repoBefore.Name)
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{ req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
Body: body, Body: body,
Title: title, Title: title,
@ -168,7 +168,7 @@ func testAPICreateIssueParallel(t *testing.T) {
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner.Name, repoBefore.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues", owner.Name, repoBefore.GroupID, repoBefore.Name)
var wg sync.WaitGroup var wg sync.WaitGroup
for i := range 10 { for i := range 10 {
@ -220,7 +220,7 @@ func testAPIEditIssue(t *testing.T) {
body := "new content!" body := "new content!"
title := "new title from api set" title := "new title from api set"
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d", owner.Name, repoBefore.Name, issueBefore.Index) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues/%d", owner.Name, repoBefore.GroupID, repoBefore.Name, issueBefore.Index)
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{ req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
State: &issueState, State: &issueState,
RemoveDeadline: &removeDeadline, RemoveDeadline: &removeDeadline,

View File

@ -55,7 +55,7 @@ func TestCreateReadOnlyDeployKey(t *testing.T) {
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
keysURL := fmt.Sprintf("/api/v1/repos/%s/%s/keys", repoOwner.Name, repo.Name) keysURL := fmt.Sprintf("/api/v1/repos/%s/%d/%s/keys", repoOwner.Name, repo.GroupID, repo.Name)
rawKeyBody := api.CreateKeyOption{ rawKeyBody := api.CreateKeyOption{
Title: "read-only", Title: "read-only",
Key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n", 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 // 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/%s/keys/%d", repoOwner.Name, repo.Name, newDeployKey.ID)). req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/keys/%d", repoOwner.Name, repo.GroupID, repo.Name, newDeployKey.ID)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
@ -95,7 +95,7 @@ func TestCreateReadWriteDeployKey(t *testing.T) {
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
keysURL := fmt.Sprintf("/api/v1/repos/%s/%s/keys", repoOwner.Name, repo.Name) keysURL := fmt.Sprintf("/api/v1/repos/%s/%d/%s/keys", repoOwner.Name, repo.GroupID, repo.Name)
rawKeyBody := api.CreateKeyOption{ rawKeyBody := api.CreateKeyOption{
Title: "read-write", Title: "read-write",
Key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n", Key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n",

View File

@ -63,7 +63,7 @@ func TestAPINotification(t *testing.T) {
assert.False(t, apiNL[2].Pinned) assert.False(t, apiNL[2].Pinned)
// -- GET /repos/{owner}/{repo}/notifications -- // -- GET /repos/{owner}/{repo}/notifications --
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread", user2.Name, repo1.Name)). req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/notifications?status-types=unread", user2.Name, repo1.GroupID, repo1.Name)).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL) DecodeJSON(t, resp, &apiNL)
@ -72,7 +72,7 @@ func TestAPINotification(t *testing.T) {
assert.EqualValues(t, 4, apiNL[0].ID) assert.EqualValues(t, 4, apiNL[0].ID)
// -- GET /repos/{owner}/{repo}/notifications -- multiple status-types // -- GET /repos/{owner}/{repo}/notifications -- multiple status-types
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/notifications?status-types=unread&status-types=pinned", user2.Name, repo1.Name)). 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)).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiNL) DecodeJSON(t, resp, &apiNL)
@ -129,7 +129,7 @@ func TestAPINotification(t *testing.T) {
assert.Len(t, apiNL, 2) assert.Len(t, apiNL, 2)
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ... 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/%s/notifications?last_read_at=%s", user2.Name, repo1.Name, lastReadAt)). req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/notifications?last_read_at=%s", user2.Name, repo1.GroupID, repo1.Name, lastReadAt)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusResetContent) MakeRequest(t, req, http.StatusResetContent)

View File

@ -23,7 +23,7 @@ func TestAPIPullCommits(t *testing.T) {
assert.NoError(t, pr.LoadIssue(t.Context())) assert.NoError(t, pr.LoadIssue(t.Context()))
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pr.HeadRepoID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pr.HeadRepoID})
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pr.Index) req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%d/%s/pulls/%d/commits", repo.OwnerName, repo.GroupID, repo.Name, pr.Index)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var commits []*api.Commit var commits []*api.Commit

View File

@ -36,7 +36,7 @@ func TestAPIPullReview(t *testing.T) {
// test ListPullReviews // test ListPullReviews
session := loginUser(t, "user2") session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index). req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo.OwnerName, repo.GroupID, repo.Name, pullIssue.Index).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -61,14 +61,14 @@ func TestAPIPullReview(t *testing.T) {
assert.True(t, reviews[5].Official) assert.True(t, reviews[5].Official)
// test GetPullReview // test GetPullReview
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d", repo.OwnerName, repo.Name, pullIssue.Index, reviews[3].ID). 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).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
var review api.PullReview var review api.PullReview
DecodeJSON(t, resp, &review) DecodeJSON(t, resp, &review)
assert.Equal(t, *reviews[3], review) assert.Equal(t, *reviews[3], review)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls/%d/reviews/%d", repo.OwnerName, repo.Name, pullIssue.Index, reviews[5].ID). 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).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &review) DecodeJSON(t, resp, &review)
@ -76,7 +76,7 @@ func TestAPIPullReview(t *testing.T) {
// test GetPullReviewComments // test GetPullReviewComments
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 7}) comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 7})
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d/comments", repo.OwnerName, repo.Name, pullIssue.Index, 10). 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).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
var reviewComments []*api.PullReviewComment var reviewComments []*api.PullReviewComment
@ -89,7 +89,7 @@ func TestAPIPullReview(t *testing.T) {
assert.Equal(t, comment.HTMLURL(t.Context()), reviewComments[0].HTMLURL) assert.Equal(t, comment.HTMLURL(t.Context()), reviewComments[0].HTMLURL)
// test CreatePullReview // test CreatePullReview
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ 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{
Body: "body1", Body: "body1",
// Event: "" # will result in PENDING // Event: "" # will result in PENDING
Comments: []api.CreatePullReviewComment{ Comments: []api.CreatePullReviewComment{
@ -118,7 +118,7 @@ func TestAPIPullReview(t *testing.T) {
assert.Equal(t, 3, review.CodeCommentsCount) assert.Equal(t, 3, review.CodeCommentsCount)
// test SubmitPullReview // test SubmitPullReview
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d", repo.OwnerName, repo.Name, pullIssue.Index, review.ID), &api.SubmitPullReviewOptions{ 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{
Event: "APPROVED", Event: "APPROVED",
Body: "just two nits", Body: "just two nits",
}).AddTokenAuth(token) }).AddTokenAuth(token)
@ -129,7 +129,7 @@ func TestAPIPullReview(t *testing.T) {
assert.Equal(t, 3, review.CodeCommentsCount) assert.Equal(t, 3, review.CodeCommentsCount)
// test dismiss review // test dismiss review
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d/dismissals", repo.OwnerName, repo.Name, pullIssue.Index, review.ID), &api.DismissPullReviewOptions{ 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{
Message: "test", Message: "test",
}).AddTokenAuth(token) }).AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
@ -138,7 +138,7 @@ func TestAPIPullReview(t *testing.T) {
assert.True(t, review.Dismissed) assert.True(t, review.Dismissed)
// test dismiss review // test dismiss review
req = NewRequest(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews/%d/undismissals", repo.OwnerName, repo.Name, pullIssue.Index, review.ID)). 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)).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &review) DecodeJSON(t, resp, &review)
@ -146,7 +146,7 @@ func TestAPIPullReview(t *testing.T) {
assert.False(t, review.Dismissed) assert.False(t, review.Dismissed)
// test DeletePullReview // test DeletePullReview
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ 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{
Body: "just a comment", Body: "just a comment",
Event: "COMMENT", Event: "COMMENT",
}).AddTokenAuth(token) }).AddTokenAuth(token)
@ -154,12 +154,12 @@ func TestAPIPullReview(t *testing.T) {
DecodeJSON(t, resp, &review) DecodeJSON(t, resp, &review)
assert.EqualValues(t, "COMMENT", review.State) assert.EqualValues(t, "COMMENT", review.State)
assert.Equal(t, 0, review.CodeCommentsCount) assert.Equal(t, 0, review.CodeCommentsCount)
req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d", repo.OwnerName, repo.Name, pullIssue.Index, review.ID). 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).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// test CreatePullReview Comment without body but with comments // test CreatePullReview Comment without body but with comments
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ 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{
// Body: "", // Body: "",
Event: "COMMENT", Event: "COMMENT",
Comments: []api.CreatePullReviewComment{ Comments: []api.CreatePullReviewComment{
@ -187,7 +187,7 @@ func TestAPIPullReview(t *testing.T) {
// test CreatePullReview Comment with body but without comments // test CreatePullReview Comment with body but without comments
commentBody := "This is a body of the comment." commentBody := "This is a body of the comment."
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ 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{
Body: commentBody, Body: commentBody,
Event: "COMMENT", Event: "COMMENT",
Comments: []api.CreatePullReviewComment{}, Comments: []api.CreatePullReviewComment{},
@ -201,7 +201,7 @@ func TestAPIPullReview(t *testing.T) {
assert.False(t, commentReview.Dismissed) assert.False(t, commentReview.Dismissed)
// test CreatePullReview Comment without body and no comments // test CreatePullReview Comment without body and no comments
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ 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{
Body: "", Body: "",
Event: "COMMENT", Event: "COMMENT",
Comments: []api.CreatePullReviewComment{}, Comments: []api.CreatePullReviewComment{},
@ -217,7 +217,7 @@ func TestAPIPullReview(t *testing.T) {
assert.NoError(t, pullIssue12.LoadAttributes(t.Context())) assert.NoError(t, pullIssue12.LoadAttributes(t.Context()))
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID}) repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID})
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews", repo3.OwnerName, repo3.Name, pullIssue12.Index). req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%d/%s/pulls/%d/reviews", repo3.OwnerName, repo3.GroupID, repo3.Name, pullIssue12.Index).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &reviews) DecodeJSON(t, resp, &reviews)
@ -245,19 +245,19 @@ func TestAPIPullReviewRequest(t *testing.T) {
// Test add Review Request // Test add Review Request
session := loginUser(t, "user2") session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user4@example.com", "user8"}, Reviewers: []string{"user4@example.com", "user8"},
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
// poster of pr can't be reviewer // poster of pr can't be reviewer
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user1"}, Reviewers: []string{"user1"},
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusUnprocessableEntity) MakeRequest(t, req, http.StatusUnprocessableEntity)
// test user not exist // test user not exist
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"testOther"}, Reviewers: []string{"testOther"},
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
@ -266,18 +266,18 @@ func TestAPIPullReviewRequest(t *testing.T) {
session2 := loginUser(t, "user4") session2 := loginUser(t, "user4")
token2 := getTokenForLoggedInUser(t, session2, auth_model.AccessTokenScopeWriteRepository) token2 := getTokenForLoggedInUser(t, session2, auth_model.AccessTokenScopeWriteRepository)
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user4"}, Reviewers: []string{"user4"},
}).AddTokenAuth(token2) }).AddTokenAuth(token2)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// doer is not admin // doer is not admin
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user8"}, Reviewers: []string{"user8"},
}).AddTokenAuth(token2) }).AddTokenAuth(token2)
MakeRequest(t, req, http.StatusUnprocessableEntity) MakeRequest(t, req, http.StatusUnprocessableEntity)
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user8"}, Reviewers: []string{"user8"},
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) 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 pull21Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue21.RepoID}) // repo60
user38Session := loginUser(t, "user38") user38Session := loginUser(t, "user38")
user38Token := getTokenForLoggedInUser(t, user38Session, auth_model.AccessTokenScopeWriteRepository) user38Token := getTokenForLoggedInUser(t, user38Session, auth_model.AccessTokenScopeWriteRepository)
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user4@example.com"}, Reviewers: []string{"user4@example.com"},
}).AddTokenAuth(user38Token) }).AddTokenAuth(user38Token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user4@example.com"}, Reviewers: []string{"user4@example.com"},
}).AddTokenAuth(user38Token) }).AddTokenAuth(user38Token)
MakeRequest(t, req, http.StatusNoContent) 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 // the poster of the PR can add/remove a review request
user39Session := loginUser(t, "user39") user39Session := loginUser(t, "user39")
user39Token := getTokenForLoggedInUser(t, user39Session, auth_model.AccessTokenScopeWriteRepository) user39Token := getTokenForLoggedInUser(t, user39Session, auth_model.AccessTokenScopeWriteRepository)
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user8"}, Reviewers: []string{"user8"},
}).AddTokenAuth(user39Token) }).AddTokenAuth(user39Token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull21Repo.OwnerName, pull21Repo.Name, pullIssue21.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user8"}, Reviewers: []string{"user8"},
}).AddTokenAuth(user39Token) }).AddTokenAuth(user39Token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
@ -315,12 +315,12 @@ func TestAPIPullReviewRequest(t *testing.T) {
pullIssue22 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 22}) pullIssue22 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 22})
assert.NoError(t, pullIssue22.LoadAttributes(t.Context())) assert.NoError(t, pullIssue22.LoadAttributes(t.Context()))
pull22Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue22.RepoID}) // repo61 pull22Repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue22.RepoID}) // repo61
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user38"}, Reviewers: []string{"user38"},
}).AddTokenAuth(user39Token) // user39 is from a team with read permission on pull requests unit }).AddTokenAuth(user39Token) // user39 is from a team with read permission on pull requests unit
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", pull22Repo.OwnerName, pull22Repo.Name, pullIssue22.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{"user38"}, Reviewers: []string{"user38"},
}).AddTokenAuth(user39Token) // user39 is from a team with read permission on pull requests unit }).AddTokenAuth(user39Token) // user39 is from a team with read permission on pull requests unit
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
@ -331,35 +331,35 @@ func TestAPIPullReviewRequest(t *testing.T) {
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID}) repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pullIssue12.RepoID})
// Test add Team Review Request // Test add Team Review Request
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ 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{
TeamReviewers: []string{"team1", "owners"}, TeamReviewers: []string{"team1", "owners"},
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
// Test add Team Review Request to not allowned // Test add Team Review Request to not allowned
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ 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{
TeamReviewers: []string{"test_team"}, TeamReviewers: []string{"test_team"},
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusUnprocessableEntity) MakeRequest(t, req, http.StatusUnprocessableEntity)
// Test add Team Review Request to not exist // Test add Team Review Request to not exist
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ 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{
TeamReviewers: []string{"not_exist_team"}, TeamReviewers: []string{"not_exist_team"},
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test Remove team Review Request // Test Remove team Review Request
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{ 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{
TeamReviewers: []string{"team1"}, TeamReviewers: []string{"team1"},
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// empty request test // empty request test
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{}). 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{}).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
req = NewRequestWithJSON(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo3.OwnerName, repo3.Name, pullIssue12.Index), &api.PullReviewRequestOptions{}). 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{}).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
} }
@ -452,7 +452,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
token8 := getTokenForLoggedInUser(t, session8, auth_model.AccessTokenScopeWriteRepository) token8 := getTokenForLoggedInUser(t, session8, auth_model.AccessTokenScopeWriteRepository)
// user2 request user8 // user2 request user8
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{user8.LoginName}, Reviewers: []string{user8.LoginName},
}).AddTokenAuth(token2) }).AddTokenAuth(token2)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -462,7 +462,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
pullIssue.ID, user8.ID, 0, 1, 1, false) pullIssue.ID, user8.ID, 0, 1, 1, false)
// user2 request user8 again, it is expected to be ignored // user2 request user8 again, it is expected to be ignored
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{user8.LoginName}, Reviewers: []string{user8.LoginName},
}).AddTokenAuth(token2) }).AddTokenAuth(token2)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -472,7 +472,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
pullIssue.ID, user8.ID, 0, 1, 1, false) pullIssue.ID, user8.ID, 0, 1, 1, false)
// user8 reviews it as accept // user8 reviews it as accept
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ 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{
Event: "APPROVED", Event: "APPROVED",
Body: "lgtm", Body: "lgtm",
}).AddTokenAuth(token8) }).AddTokenAuth(token8)
@ -488,7 +488,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// user2 request user8 again // user2 request user8 again
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers", repo.OwnerName, repo.Name, pullIssue.Index), &api.PullReviewRequestOptions{ 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{
Reviewers: []string{user8.LoginName}, Reviewers: []string{user8.LoginName},
}).AddTokenAuth(token2) }).AddTokenAuth(token2)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -508,7 +508,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
pullIssue.ID, user8.ID, 1, 0, 1, false) pullIssue.ID, user8.ID, 1, 0, 1, false)
// add a new valid approval // add a new valid approval
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ 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{
Event: "APPROVED", Event: "APPROVED",
Body: "lgtm", Body: "lgtm",
}).AddTokenAuth(token8) }).AddTokenAuth(token8)
@ -519,7 +519,7 @@ func TestAPIPullReviewStayDismissed(t *testing.T) {
pullIssue.ID, user8.ID, 1, 0, 2, true) pullIssue.ID, user8.ID, 1, 0, 2, true)
// now add a change request witch should dismiss the approval // now add a change request witch should dismiss the approval
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews", repo.OwnerName, repo.Name, pullIssue.Index), &api.CreatePullReviewOptions{ 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{
Event: "REQUEST_CHANGES", Event: "REQUEST_CHANGES",
Body: "please change XYZ", Body: "please change XYZ",
}).AddTokenAuth(token8) }).AddTokenAuth(token8)

View File

@ -43,7 +43,7 @@ func TestAPIViewPulls(t *testing.T) {
ctx := NewAPITestContext(t, "user2", repo.Name, auth_model.AccessTokenScopeReadRepository) ctx := NewAPITestContext(t, "user2", repo.Name, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls?state=all", owner.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/pulls?state=all", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(ctx.Token) AddTokenAuth(ctx.Token)
resp := ctx.Session.MakeRequest(t, req, http.StatusOK) resp := ctx.Session.MakeRequest(t, req, http.StatusOK)
@ -152,7 +152,7 @@ func TestAPIViewPullsByBaseHead(t *testing.T) {
ctx := NewAPITestContext(t, "user2", repo.Name, auth_model.AccessTokenScopeReadRepository) ctx := NewAPITestContext(t, "user2", repo.Name, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls/master/branch2", owner.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/pulls/master/branch2", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(ctx.Token) AddTokenAuth(ctx.Token)
resp := ctx.Session.MakeRequest(t, req, http.StatusOK) 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, 3, pull.Index)
assert.EqualValues(t, 2, pull.ID) assert.EqualValues(t, 2, pull.ID)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/pulls/master/branch-not-exist", owner.Name, repo.Name). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/pulls/master/branch-not-exist", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(ctx.Token) AddTokenAuth(ctx.Token)
ctx.Session.MakeRequest(t, req, http.StatusNotFound) ctx.Session.MakeRequest(t, req, http.StatusNotFound)
} }
@ -182,7 +182,7 @@ func TestAPIMergePullWIP(t *testing.T) {
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge", owner.Name, repo.Name, pr.Index), &forms.MergePullRequestForm{ 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{
MergeMessageField: pr.Issue.Title, MergeMessageField: pr.Issue.Title,
Do: string(repo_model.MergeStyleMerge), Do: string(repo_model.MergeStyleMerge),
}).AddTokenAuth(token) }).AddTokenAuth(token)
@ -272,7 +272,7 @@ func TestAPICreatePullSuccess(t *testing.T) {
session := loginUser(t, owner11.Name) session := loginUser(t, owner11.Name)
prTitle := "test pull request title " + time.Now().String() prTitle := "test pull request title " + time.Now().String()
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), &api.CreatePullRequestOption{ req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &api.CreatePullRequestOption{
Head: owner11.Name + ":master", Head: owner11.Name + ":master",
Base: "master", Base: "master",
Title: prTitle, Title: prTitle,
@ -306,7 +306,7 @@ func TestAPICreatePullBasePermission(t *testing.T) {
AllowMaintainerEdit: new(false), AllowMaintainerEdit: new(false),
} }
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), &opts).AddTokenAuth(token) req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
// add user4 to be a collaborator to base repo // 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)) t.Run("AddUser4AsCollaborator", doAPIAddCollaborator(ctx, user4.Name, perm.AccessModeRead))
// create again // create again
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), &opts).AddTokenAuth(token) req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
// Also test that AllowMaintainerEdit is set to false, the default "true" case is covered by TestAPICreatePullSuccess // 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", Base: "master",
Title: "create a failure pr", Title: "create a failure pr",
} }
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), &opts).AddTokenAuth(token) req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
// add user4 to be a collaborator to head repo with read permission // add user4 to be a collaborator to head repo with read permission
ctx := NewAPITestContext(t, repo11.OwnerName, repo11.Name, auth_model.AccessTokenScopeWriteRepository) ctx := NewAPITestContext(t, repo11.OwnerName, repo11.Name, auth_model.AccessTokenScopeWriteRepository)
t.Run("AddUser4AsCollaboratorWithRead", doAPIAddCollaborator(ctx, user4.Name, perm.AccessModeRead)) t.Run("AddUser4AsCollaboratorWithRead", doAPIAddCollaborator(ctx, user4.Name, perm.AccessModeRead))
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), &opts).AddTokenAuth(token) req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
// add user4 to be a collaborator to head repo with write permission // add user4 to be a collaborator to head repo with write permission
t.Run("AddUser4AsCollaboratorWithWrite", doAPIAddCollaborator(ctx, user4.Name, perm.AccessModeWrite)) t.Run("AddUser4AsCollaboratorWithWrite", doAPIAddCollaborator(ctx, user4.Name, perm.AccessModeWrite))
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), &opts).AddTokenAuth(token) req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &opts).AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
} }
@ -362,7 +362,7 @@ func TestAPICreatePullSameRepoSuccess(t *testing.T) {
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner.Name, repo.Name), &api.CreatePullRequestOption{ req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner.Name, repo.GroupID, repo.Name), &api.CreatePullRequestOption{
Head: owner.Name + ":pr-to-update", Head: owner.Name + ":pr-to-update",
Base: "master", Base: "master",
Title: "successfully create a PR between branches of the same repository", Title: "successfully create a PR between branches of the same repository",
@ -393,7 +393,7 @@ func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
Labels: []int64{5}, Labels: []int64{5},
} }
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), opts). req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), opts).
AddTokenAuth(token) AddTokenAuth(token)
res := MakeRequest(t, req, http.StatusCreated) res := MakeRequest(t, req, http.StatusCreated)
@ -426,7 +426,7 @@ func TestAPICreatePullWithFieldsFailure(t *testing.T) {
Base: "master", Base: "master",
} }
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), opts). req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), opts).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusUnprocessableEntity) MakeRequest(t, req, http.StatusUnprocessableEntity)
opts.Title = "is required" opts.Title = "is required"
@ -452,7 +452,7 @@ func TestAPIEditPull(t *testing.T) {
session := loginUser(t, owner10.Name) session := loginUser(t, owner10.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
title := "create a success pr" title := "create a success pr"
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls", owner10.Name, repo10.Name), &api.CreatePullRequestOption{ req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%d/%s/pulls", owner10.Name, repo10.GroupID, repo10.Name), &api.CreatePullRequestOption{
Head: "develop", Head: "develop",
Base: "master", Base: "master",
Title: title, Title: title,
@ -463,7 +463,7 @@ func TestAPIEditPull(t *testing.T) {
newTitle := "edit a this pr" newTitle := "edit a this pr"
newBody := "edited body" newBody := "edited body"
req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d", owner10.Name, repo10.Name, apiPull.Index), &api.EditPullRequestOption{ 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{
Base: "feature/1", Base: "feature/1",
Title: newTitle, Title: newTitle,
Body: &newBody, 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.Comment{IssueID: pull.Issue.ID, OldTitle: title, NewTitle: newTitle})
unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{IssueID: pull.Issue.ID, ContentText: newBody, IsFirstCreated: false}) 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/%s/pulls/%d", owner10.Name, repo10.Name, pull.Index), &api.EditPullRequestOption{ 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{
Base: "not-exist", Base: "not-exist",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
@ -567,11 +567,11 @@ func TestAPICommitPullRequest(t *testing.T) {
ctx := NewAPITestContext(t, "user2", repo.Name, auth_model.AccessTokenScopeReadRepository) ctx := NewAPITestContext(t, "user2", repo.Name, auth_model.AccessTokenScopeReadRepository)
mergedCommitSHA := "1a8823cd1a9549fde083f992f6b9b87a7ab74fb3" mergedCommitSHA := "1a8823cd1a9549fde083f992f6b9b87a7ab74fb3"
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/commits/%s/pull", owner.Name, repo.Name, mergedCommitSHA).AddTokenAuth(ctx.Token) req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/commits/%s/pull", owner.Name, repo.GroupID, repo.Name, mergedCommitSHA).AddTokenAuth(ctx.Token)
ctx.Session.MakeRequest(t, req, http.StatusOK) ctx.Session.MakeRequest(t, req, http.StatusOK)
invalidCommitSHA := "abcd1234abcd1234abcd1234abcd1234abcd1234" invalidCommitSHA := "abcd1234abcd1234abcd1234abcd1234abcd1234"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/commits/%s/pull", owner.Name, repo.Name, invalidCommitSHA).AddTokenAuth(ctx.Token) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/commits/%s/pull", owner.Name, repo.GroupID, repo.Name, invalidCommitSHA).AddTokenAuth(ctx.Token)
ctx.Session.MakeRequest(t, req, http.StatusNotFound) ctx.Session.MakeRequest(t, req, http.StatusNotFound)
} }

View File

@ -31,7 +31,7 @@ func testAPIEditReleaseAttachmentWithUnallowedFile(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
filename := "file.bad" filename := "file.bad"
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d/assets/%d", repoOwner.Name, repo.Name, release.ID, attachment.ID) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/%d/assets/%d", repoOwner.Name, repo.GroupID, repo.Name, release.ID, attachment.ID)
req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{
"name": filename, "name": filename,
}).AddTokenAuth(token) }).AddTokenAuth(token)

View File

@ -46,7 +46,7 @@ func testAPIListReleasesWithWriteToken(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository) token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/releases", user2.Name, repo.Name)) link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases", user2.Name, repo.GroupID, repo.Name))
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
var apiReleases []*api.Release var apiReleases []*api.Release
DecodeJSON(t, resp, &apiReleases) 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 { 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/%s/releases", owner.Name, repo.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases", owner.Name, repo.GroupID, repo.Name)
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{ req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{
TagName: name, TagName: name,
Title: title, 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") newRelease := createNewReleaseUsingAPI(t, token, owner, repo, "v0.0.1", target, "v0.0.1", "test")
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d", owner.Name, repo.Name, newRelease.ID) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/%d", owner.Name, repo.GroupID, repo.Name, newRelease.ID)
req := NewRequest(t, "GET", urlStr). req := NewRequest(t, "GET", urlStr).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -249,7 +249,7 @@ func TestAPICreateProtectedTagRelease(t *testing.T) {
commit, err := gitRepo.GetBranchCommit("master") commit, err := gitRepo.GetBranchCommit("master")
assert.NoError(t, err) assert.NoError(t, err)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/releases", repo.OwnerName, repo.Name), &api.CreateReleaseOption{ req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases", repo.OwnerName, repo.GroupID, repo.Name), &api.CreateReleaseOption{
TagName: "v0.0.1", TagName: "v0.0.1",
Title: "v0.0.1", Title: "v0.0.1",
IsDraft: false, IsDraft: false,
@ -296,7 +296,7 @@ func TestAPICreateReleaseGivenInvalidTarget(t *testing.T) {
session := loginUser(t, owner.LowerName) session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases", owner.Name, repo.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases", owner.Name, repo.GroupID, repo.Name)
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{ req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{
TagName: "i-point-to-an-invalid-target", TagName: "i-point-to-an-invalid-target",
Title: "Invalid Target", Title: "Invalid Target",
@ -310,7 +310,7 @@ func testAPIGetLatestRelease(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/releases/latest", owner.Name, repo.Name)) req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/latest", owner.Name, repo.GroupID, repo.Name))
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var release *api.Release var release *api.Release
@ -325,7 +325,7 @@ func testAPIGetReleaseByTag(t *testing.T) {
tag := "v1.1" tag := "v1.1"
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/%s", owner.Name, repo.Name, tag)) req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/tags/%s", owner.Name, repo.GroupID, repo.Name, tag))
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var release *api.Release var release *api.Release
@ -335,7 +335,7 @@ func testAPIGetReleaseByTag(t *testing.T) {
nonexistingtag := "nonexistingtag" nonexistingtag := "nonexistingtag"
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/%s", owner.Name, repo.Name, nonexistingtag)) req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/tags/%s", owner.Name, repo.GroupID, repo.Name, nonexistingtag))
resp = MakeRequest(t, req, http.StatusNotFound) resp = MakeRequest(t, req, http.StatusNotFound)
var err *api.APIError var err *api.APIError
@ -388,17 +388,17 @@ func TestAPIDeleteReleaseByTagName(t *testing.T) {
createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test") createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test")
// delete release // delete release
req := NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/releases/tags/release-tag", owner.Name, repo.Name). req := NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%d/%s/releases/tags/release-tag", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
_ = MakeRequest(t, req, http.StatusNoContent) _ = MakeRequest(t, req, http.StatusNoContent)
// make sure release is deleted // make sure release is deleted
req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/releases/tags/release-tag", owner.Name, repo.Name). req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%d/%s/releases/tags/release-tag", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
_ = MakeRequest(t, req, http.StatusNotFound) _ = MakeRequest(t, req, http.StatusNotFound)
// delete release tag too // delete release tag too
req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/tags/release-tag", owner.Name, repo.Name). req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%d/%s/tags/release-tag", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
_ = MakeRequest(t, req, http.StatusNoContent) _ = MakeRequest(t, req, http.StatusNoContent)
} }
@ -416,7 +416,7 @@ func TestAPIUploadAssetRelease(t *testing.T) {
bufLargeBytes := bytes.Repeat([]byte{' '}, 2*1024*1024) bufLargeBytes := bytes.Repeat([]byte{' '}, 2*1024*1024)
release := createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test") release := createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test")
assetURL := fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d/assets", owner.Name, repo.Name, release.ID) assetURL := fmt.Sprintf("/api/v1/repos/%s/%d/%s/releases/%d/assets", owner.Name, repo.GroupID, repo.Name, release.ID)
t.Run("multipart/form-data", func(t *testing.T) { t.Run("multipart/form-data", func(t *testing.T) {
defer tests.PrintCurrentTest(t)() defer tests.PrintCurrentTest(t)()

View File

@ -30,13 +30,13 @@ func TestAPIDownloadArchive(t *testing.T) {
session := loginUser(t, user2.LowerName) session := loginUser(t, user2.LowerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.zip", user2.Name, repo.Name)) link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/archive/master.zip", user2.Name, repo.GroupID, repo.Name))
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err := io.ReadAll(resp.Body) bs, err := io.ReadAll(resp.Body)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, bs, 320) assert.Len(t, bs, 320)
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name)) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/archive/master.tar.gz", user2.Name, repo.GroupID, repo.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body) bs, err = io.ReadAll(resp.Body)
assert.NoError(t, err) 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 // The locked URL should give the same bytes as the non-locked one
assert.Equal(t, bs, bs2) assert.Equal(t, bs, bs2)
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name)) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/archive/master.bundle", user2.Name, repo.GroupID, repo.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body) bs, err = io.ReadAll(resp.Body)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, bs, 382) assert.Len(t, bs, 382)
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name)) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/archive/master", user2.Name, repo.GroupID, repo.Name))
MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest) MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest)
t.Run("GitHubStyle", testAPIDownloadArchiveGitHubStyle) t.Run("GitHubStyle", testAPIDownloadArchiveGitHubStyle)
@ -73,13 +73,13 @@ func testAPIDownloadArchiveGitHubStyle(t *testing.T) {
session := loginUser(t, user2.LowerName) session := loginUser(t, user2.LowerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/zipball/master", user2.Name, repo.Name)) link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/zipball/master", user2.Name, repo.GroupID, repo.Name))
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err := io.ReadAll(resp.Body) bs, err := io.ReadAll(resp.Body)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, bs, 320) assert.Len(t, bs, 320)
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/tarball/master", user2.Name, repo.Name)) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/tarball/master", user2.Name, repo.GroupID, repo.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body) bs, err = io.ReadAll(resp.Body)
assert.NoError(t, err) 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 // The locked URL should give the same bytes as the non-locked one
assert.Equal(t, bs, bs2) assert.Equal(t, bs, bs2)
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/bundle/master", user2.Name, repo.Name)) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%d/%s/bundle/master", user2.Name, repo.GroupID, repo.Name))
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK) resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
bs, err = io.ReadAll(resp.Body) bs, err = io.ReadAll(resp.Body)
assert.NoError(t, err) assert.NoError(t, err)

View File

@ -38,7 +38,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) {
Image: base64.StdEncoding.EncodeToString(avatar), Image: base64.StdEncoding.EncodeToString(avatar),
} }
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/avatar", repo.OwnerName, repo.Name), &opts). req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/avatar", repo.OwnerName, repo.GroupID, repo.Name), &opts).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
@ -47,7 +47,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) {
Image: "Invalid", Image: "Invalid",
} }
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/avatar", repo.OwnerName, repo.Name), &opts). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/avatar", repo.OwnerName, repo.GroupID, repo.Name), &opts).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusBadRequest) MakeRequest(t, req, http.StatusBadRequest)
@ -62,7 +62,7 @@ func TestAPIUpdateRepoAvatar(t *testing.T) {
Image: base64.StdEncoding.EncodeToString(text), Image: base64.StdEncoding.EncodeToString(text),
} }
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/avatar", repo.OwnerName, repo.Name), &opts). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/avatar", repo.OwnerName, repo.GroupID, repo.Name), &opts).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusInternalServerError) MakeRequest(t, req, http.StatusInternalServerError)
} }
@ -74,7 +74,7 @@ func TestAPIDeleteRepoAvatar(t *testing.T) {
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository) token := getUserToken(t, user2.LowerName, auth_model.AccessTokenScopeWriteRepository)
req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/avatar", repo.OwnerName, repo.Name)). req := NewRequest(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/avatar", repo.OwnerName, repo.GroupID, repo.Name)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
} }

View File

@ -32,7 +32,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
testCtx := NewAPITestContext(t, repo2Owner.Name, repo2.Name, auth_model.AccessTokenScopeWriteRepository) testCtx := NewAPITestContext(t, repo2Owner.Name, repo2.Name, auth_model.AccessTokenScopeWriteRepository)
t.Run("RepoOwnerShouldBeOwner", func(t *testing.T) { t.Run("RepoOwnerShouldBeOwner", func(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, repo2Owner.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, repo2Owner.Name).
AddTokenAuth(testCtx.Token) AddTokenAuth(testCtx.Token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -45,7 +45,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
t.Run("CollaboratorWithReadAccess", func(t *testing.T) { t.Run("CollaboratorWithReadAccess", func(t *testing.T) {
t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeRead)) t.Run("AddUserAsCollaboratorWithReadAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeRead))
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, user4.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user4.Name).
AddTokenAuth(testCtx.Token) AddTokenAuth(testCtx.Token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -58,7 +58,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
t.Run("CollaboratorWithWriteAccess", func(t *testing.T) { t.Run("CollaboratorWithWriteAccess", func(t *testing.T) {
t.Run("AddUserAsCollaboratorWithWriteAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeWrite)) t.Run("AddUserAsCollaboratorWithWriteAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeWrite))
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, user4.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user4.Name).
AddTokenAuth(testCtx.Token) AddTokenAuth(testCtx.Token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -71,7 +71,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
t.Run("CollaboratorWithAdminAccess", func(t *testing.T) { t.Run("CollaboratorWithAdminAccess", func(t *testing.T) {
t.Run("AddUserAsCollaboratorWithAdminAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeAdmin)) t.Run("AddUserAsCollaboratorWithAdminAccess", doAPIAddCollaborator(testCtx, user4.Name, perm.AccessModeAdmin))
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, user4.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user4.Name).
AddTokenAuth(testCtx.Token) AddTokenAuth(testCtx.Token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
@ -82,7 +82,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
}) })
t.Run("CollaboratorNotFound", func(t *testing.T) { t.Run("CollaboratorNotFound", func(t *testing.T) {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, "non-existent-user"). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, "non-existent-user").
AddTokenAuth(testCtx.Token) AddTokenAuth(testCtx.Token)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
}) })
@ -99,7 +99,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
_session := loginUser(t, user5.Name) _session := loginUser(t, user5.Name)
_testCtx := NewAPITestContext(t, user5.Name, repo2.Name, auth_model.AccessTokenScopeReadRepository) _testCtx := NewAPITestContext(t, user5.Name, repo2.Name, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, user5.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user5.Name).
AddTokenAuth(_testCtx.Token) AddTokenAuth(_testCtx.Token)
resp := _session.MakeRequest(t, req, http.StatusOK) resp := _session.MakeRequest(t, req, http.StatusOK)
@ -112,7 +112,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
session := loginUser(t, user5.Name) session := loginUser(t, user5.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, user5.Name).AddTokenAuth(token) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user5.Name).AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
repoCollPerm := api.RepoCollaboratorPermission{} repoCollPerm := api.RepoCollaboratorPermission{}
@ -128,7 +128,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
_session := loginUser(t, user5.Name) _session := loginUser(t, user5.Name)
_testCtx := NewAPITestContext(t, user5.Name, repo2.Name, auth_model.AccessTokenScopeReadRepository) _testCtx := NewAPITestContext(t, user5.Name, repo2.Name, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, user5.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user5.Name).
AddTokenAuth(_testCtx.Token) AddTokenAuth(_testCtx.Token)
resp := _session.MakeRequest(t, req, http.StatusOK) resp := _session.MakeRequest(t, req, http.StatusOK)
@ -145,7 +145,7 @@ func TestAPIRepoCollaboratorPermission(t *testing.T) {
_session := loginUser(t, user10.Name) _session := loginUser(t, user10.Name)
_testCtx := NewAPITestContext(t, user10.Name, repo2.Name, auth_model.AccessTokenScopeReadRepository) _testCtx := NewAPITestContext(t, user10.Name, repo2.Name, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/collaborators/%s/permission", repo2Owner.Name, repo2.Name, user11.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/collaborators/%s/permission", repo2Owner.Name, repo2.GroupID, repo2.Name, user11.Name).
AddTokenAuth(_testCtx.Token) AddTokenAuth(_testCtx.Token)
resp := _session.MakeRequest(t, req, http.StatusOK) resp := _session.MakeRequest(t, req, http.StatusOK)

View File

@ -179,7 +179,7 @@ func TestAPICreateFile(t *testing.T) {
createFileOptions.BranchName = branch createFileOptions.BranchName = branch
fileID++ fileID++
treePath := fmt.Sprintf("new/file%d.txt", fileID) treePath := fmt.Sprintf("new/file%d.txt", fileID)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions). req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusCreated) resp := MakeRequest(t, req, http.StatusCreated)
gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1) gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
@ -214,7 +214,7 @@ func TestAPICreateFile(t *testing.T) {
createFileOptions.NewBranchName = "new_branch" createFileOptions.NewBranchName = "new_branch"
fileID++ fileID++
treePath := fmt.Sprintf("new/file%d.txt", fileID) treePath := fmt.Sprintf("new/file%d.txt", fileID)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions). req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusCreated) resp := MakeRequest(t, req, http.StatusCreated)
var fileResponse api.FileResponse var fileResponse api.FileResponse
@ -232,7 +232,7 @@ func TestAPICreateFile(t *testing.T) {
createFileOptions.Message = "" createFileOptions.Message = ""
fileID++ fileID++
treePath = fmt.Sprintf("new/file%d.txt", fileID) treePath = fmt.Sprintf("new/file%d.txt", fileID)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusCreated) resp = MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, &fileResponse) DecodeJSON(t, resp, &fileResponse)
@ -242,7 +242,7 @@ func TestAPICreateFile(t *testing.T) {
// Test trying to create a file that already exists, should fail // Test trying to create a file that already exists, should fail
createFileOptions = getCreateFileOptions() createFileOptions = getCreateFileOptions()
treePath = "README.md" treePath = "README.md"
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusUnprocessableEntity) resp = MakeRequest(t, req, http.StatusUnprocessableEntity)
expectedAPIError := context.APIError{ expectedAPIError := context.APIError{
@ -257,7 +257,7 @@ func TestAPICreateFile(t *testing.T) {
createFileOptions = getCreateFileOptions() createFileOptions = getCreateFileOptions()
fileID++ fileID++
treePath = fmt.Sprintf("new/file%d.txt", fileID) treePath = fmt.Sprintf("new/file%d.txt", fileID)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &createFileOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &createFileOptions).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
@ -265,14 +265,14 @@ func TestAPICreateFile(t *testing.T) {
createFileOptions = getCreateFileOptions() createFileOptions = getCreateFileOptions()
fileID++ fileID++
treePath = fmt.Sprintf("new/file%d.txt", fileID) treePath = fmt.Sprintf("new/file%d.txt", fileID)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &createFileOptions) req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &createFileOptions)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns // Test using access token for a private repo that the user of the token owns
createFileOptions = getCreateFileOptions() createFileOptions = getCreateFileOptions()
fileID++ fileID++
treePath = fmt.Sprintf("new/file%d.txt", fileID) treePath = fmt.Sprintf("new/file%d.txt", fileID)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &createFileOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &createFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -280,7 +280,7 @@ func TestAPICreateFile(t *testing.T) {
createFileOptions = getCreateFileOptions() createFileOptions = getCreateFileOptions()
fileID++ fileID++
treePath = fmt.Sprintf("new/file%d.txt", fileID) treePath = fmt.Sprintf("new/file%d.txt", fileID)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", org3.Name, repo3.Name, treePath), &createFileOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &createFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -288,14 +288,14 @@ func TestAPICreateFile(t *testing.T) {
createFileOptions = getCreateFileOptions() createFileOptions = getCreateFileOptions()
fileID++ fileID++
treePath = fmt.Sprintf("new/file%d.txt", fileID) treePath = fmt.Sprintf("new/file%d.txt", fileID)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", org3.Name, repo3.Name, treePath), &createFileOptions) req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &createFileOptions)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator // Test using repo "user2/repo1" where user4 is a NOT collaborator
createFileOptions = getCreateFileOptions() createFileOptions = getCreateFileOptions()
fileID++ fileID++
treePath = fmt.Sprintf("new/file%d.txt", fileID) treePath = fmt.Sprintf("new/file%d.txt", fileID)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &createFileOptions).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)

View File

@ -64,7 +64,7 @@ func TestAPIDeleteFile(t *testing.T) {
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
deleteFileOptions := getDeleteFileOptions() deleteFileOptions := getDeleteFileOptions()
deleteFileOptions.BranchName = branch deleteFileOptions.BranchName = branch
req := NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &deleteFileOptions). req := NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var fileResponse api.FileResponse var fileResponse api.FileResponse
@ -80,7 +80,7 @@ func TestAPIDeleteFile(t *testing.T) {
deleteFileOptions := getDeleteFileOptions() deleteFileOptions := getDeleteFileOptions()
deleteFileOptions.BranchName = repo1.DefaultBranch deleteFileOptions.BranchName = repo1.DefaultBranch
deleteFileOptions.NewBranchName = "new_branch" deleteFileOptions.NewBranchName = "new_branch"
req := NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &deleteFileOptions). req := NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var fileResponse api.FileResponse var fileResponse api.FileResponse
@ -95,7 +95,7 @@ func TestAPIDeleteFile(t *testing.T) {
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
deleteFileOptions = getDeleteFileOptions() deleteFileOptions = getDeleteFileOptions()
deleteFileOptions.Message = "" deleteFileOptions.Message = ""
req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &deleteFileOptions). req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fileResponse) DecodeJSON(t, resp, &fileResponse)
@ -108,7 +108,7 @@ func TestAPIDeleteFile(t *testing.T) {
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
deleteFileOptions = getDeleteFileOptions() deleteFileOptions = getDeleteFileOptions()
deleteFileOptions.SHA = "badsha" deleteFileOptions.SHA = "badsha"
req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &deleteFileOptions). req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusUnprocessableEntity) MakeRequest(t, req, http.StatusUnprocessableEntity)
@ -117,7 +117,7 @@ func TestAPIDeleteFile(t *testing.T) {
treePath = fmt.Sprintf("delete/file%d.txt", fileID) treePath = fmt.Sprintf("delete/file%d.txt", fileID)
createFile(user2, repo16, treePath) createFile(user2, repo16, treePath)
deleteFileOptions = getDeleteFileOptions() deleteFileOptions = getDeleteFileOptions()
req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &deleteFileOptions). req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &deleteFileOptions).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
@ -126,7 +126,7 @@ func TestAPIDeleteFile(t *testing.T) {
treePath = fmt.Sprintf("delete/file%d.txt", fileID) treePath = fmt.Sprintf("delete/file%d.txt", fileID)
createFile(user2, repo16, treePath) createFile(user2, repo16, treePath)
deleteFileOptions = getDeleteFileOptions() deleteFileOptions = getDeleteFileOptions()
req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &deleteFileOptions) req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &deleteFileOptions)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns // 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) treePath = fmt.Sprintf("delete/file%d.txt", fileID)
createFile(user2, repo16, treePath) createFile(user2, repo16, treePath)
deleteFileOptions = getDeleteFileOptions() deleteFileOptions = getDeleteFileOptions()
req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &deleteFileOptions). req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &deleteFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
@ -143,7 +143,7 @@ func TestAPIDeleteFile(t *testing.T) {
treePath = fmt.Sprintf("delete/file%d.txt", fileID) treePath = fmt.Sprintf("delete/file%d.txt", fileID)
createFile(org3, repo3, treePath) createFile(org3, repo3, treePath)
deleteFileOptions = getDeleteFileOptions() deleteFileOptions = getDeleteFileOptions()
req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", org3.Name, repo3.Name, treePath), &deleteFileOptions). req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &deleteFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
@ -152,7 +152,7 @@ func TestAPIDeleteFile(t *testing.T) {
treePath = fmt.Sprintf("delete/file%d.txt", fileID) treePath = fmt.Sprintf("delete/file%d.txt", fileID)
createFile(org3, repo3, treePath) createFile(org3, repo3, treePath)
deleteFileOptions = getDeleteFileOptions() deleteFileOptions = getDeleteFileOptions()
req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", org3.Name, repo3.Name, treePath), &deleteFileOptions) req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &deleteFileOptions)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator // 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) treePath = fmt.Sprintf("delete/file%d.txt", fileID)
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
deleteFileOptions = getDeleteFileOptions() deleteFileOptions = getDeleteFileOptions()
req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &deleteFileOptions). req = NewRequestWithJSON(t, "DELETE", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &deleteFileOptions).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
}) })

View File

@ -133,7 +133,7 @@ func TestAPIUpdateFile(t *testing.T) {
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
updateFileOptions := getUpdateFileOptions() updateFileOptions := getUpdateFileOptions()
updateFileOptions.BranchName = branch updateFileOptions.BranchName = branch
req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions). req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1) gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
@ -164,7 +164,7 @@ func TestAPIUpdateFile(t *testing.T) {
fileID++ fileID++
treePath := fmt.Sprintf("update/file%d.txt", fileID) treePath := fmt.Sprintf("update/file%d.txt", fileID)
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions). req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var fileResponse api.FileResponse var fileResponse api.FileResponse
@ -194,7 +194,7 @@ func TestAPIUpdateFile(t *testing.T) {
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
updateFileOptions.FromPath = treePath updateFileOptions.FromPath = treePath
treePath = "rename/" + treePath treePath = "rename/" + treePath
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions). req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fileResponse) DecodeJSON(t, resp, &fileResponse)
@ -212,7 +212,7 @@ func TestAPIUpdateFile(t *testing.T) {
fileID++ fileID++
treePath = fmt.Sprintf("update/file%d.txt", fileID) treePath = fmt.Sprintf("update/file%d.txt", fileID)
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions). req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &fileResponse) DecodeJSON(t, resp, &fileResponse)
@ -226,7 +226,7 @@ func TestAPIUpdateFile(t *testing.T) {
updateFileOptions = getUpdateFileOptions() updateFileOptions = getUpdateFileOptions()
correctSHA := updateFileOptions.SHA correctSHA := updateFileOptions.SHA
updateFileOptions.SHA = "badsha" updateFileOptions.SHA = "badsha"
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions). req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusUnprocessableEntity) resp = MakeRequest(t, req, http.StatusUnprocessableEntity)
expectedAPIError := context.APIError{ expectedAPIError := context.APIError{
@ -242,7 +242,7 @@ func TestAPIUpdateFile(t *testing.T) {
treePath = fmt.Sprintf("update/file%d.txt", fileID) treePath = fmt.Sprintf("update/file%d.txt", fileID)
createFile(user2, repo16, treePath) createFile(user2, repo16, treePath)
updateFileOptions = getUpdateFileOptions() updateFileOptions = getUpdateFileOptions()
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &updateFileOptions). req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &updateFileOptions).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
@ -251,7 +251,7 @@ func TestAPIUpdateFile(t *testing.T) {
treePath = fmt.Sprintf("update/file%d.txt", fileID) treePath = fmt.Sprintf("update/file%d.txt", fileID)
createFile(user2, repo16, treePath) createFile(user2, repo16, treePath)
updateFileOptions = getUpdateFileOptions() updateFileOptions = getUpdateFileOptions()
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &updateFileOptions) req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &updateFileOptions)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns // 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) treePath = fmt.Sprintf("update/file%d.txt", fileID)
createFile(user2, repo16, treePath) createFile(user2, repo16, treePath)
updateFileOptions = getUpdateFileOptions() updateFileOptions = getUpdateFileOptions()
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath), &updateFileOptions). req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath), &updateFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
@ -268,7 +268,7 @@ func TestAPIUpdateFile(t *testing.T) {
treePath = fmt.Sprintf("update/file%d.txt", fileID) treePath = fmt.Sprintf("update/file%d.txt", fileID)
createFile(org3, repo3, treePath) createFile(org3, repo3, treePath)
updateFileOptions = getUpdateFileOptions() updateFileOptions = getUpdateFileOptions()
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", org3.Name, repo3.Name, treePath), &updateFileOptions). req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &updateFileOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
@ -277,7 +277,7 @@ func TestAPIUpdateFile(t *testing.T) {
treePath = fmt.Sprintf("update/file%d.txt", fileID) treePath = fmt.Sprintf("update/file%d.txt", fileID)
createFile(org3, repo3, treePath) createFile(org3, repo3, treePath)
updateFileOptions = getUpdateFileOptions() updateFileOptions = getUpdateFileOptions()
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", org3.Name, repo3.Name, treePath), &updateFileOptions) req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath), &updateFileOptions)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator // 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) treePath = fmt.Sprintf("update/file%d.txt", fileID)
createFile(user2, repo1, treePath) createFile(user2, repo1, treePath)
updateFileOptions = getUpdateFileOptions() updateFileOptions = getUpdateFileOptions()
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions). req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath), &updateFileOptions).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
}) })

View File

@ -90,7 +90,7 @@ func TestAPIChangeFiles(t *testing.T) {
changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[0].Path = createTreePath
changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[1].Path = updateTreePath
changeFilesOptions.Files[2].Path = deleteTreePath changeFilesOptions.Files[2].Path = deleteTreePath
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo1.Name), &changeFilesOptions). req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo1.GroupID, repo1.Name), &changeFilesOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusCreated) resp := MakeRequest(t, req, http.StatusCreated)
gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1) gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo1)
@ -142,7 +142,7 @@ func TestAPIChangeFiles(t *testing.T) {
changeFilesOptions.Files[2].Path = deleteTreePath changeFilesOptions.Files[2].Path = deleteTreePath
createFile(user2, repo1, updateTreePath) createFile(user2, repo1, updateTreePath)
createFile(user2, repo1, deleteTreePath) createFile(user2, repo1, deleteTreePath)
url := fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo1.Name) url := fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo1.GroupID, repo1.Name)
req := NewRequestWithJSON(t, "POST", url, &changeFilesOptions). req := NewRequestWithJSON(t, "POST", url, &changeFilesOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusCreated) resp := MakeRequest(t, req, http.StatusCreated)
@ -314,7 +314,7 @@ func TestAPIChangeFiles(t *testing.T) {
changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[0].Path = createTreePath
changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[1].Path = updateTreePath
changeFilesOptions.Files[2].Path = deleteTreePath changeFilesOptions.Files[2].Path = deleteTreePath
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo16.Name), &changeFilesOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo16.GroupID, repo16.Name), &changeFilesOptions).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
@ -329,7 +329,7 @@ func TestAPIChangeFiles(t *testing.T) {
changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[0].Path = createTreePath
changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[1].Path = updateTreePath
changeFilesOptions.Files[2].Path = deleteTreePath changeFilesOptions.Files[2].Path = deleteTreePath
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo16.Name), &changeFilesOptions) req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo16.GroupID, repo16.Name), &changeFilesOptions)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns // 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[0].Path = createTreePath
changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[1].Path = updateTreePath
changeFilesOptions.Files[2].Path = deleteTreePath changeFilesOptions.Files[2].Path = deleteTreePath
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo16.Name), &changeFilesOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo16.GroupID, repo16.Name), &changeFilesOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -358,7 +358,7 @@ func TestAPIChangeFiles(t *testing.T) {
changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[0].Path = createTreePath
changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[1].Path = updateTreePath
changeFilesOptions.Files[2].Path = deleteTreePath changeFilesOptions.Files[2].Path = deleteTreePath
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", org3.Name, repo3.Name), &changeFilesOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", org3.Name, repo3.GroupID, repo3.Name), &changeFilesOptions).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -373,7 +373,7 @@ func TestAPIChangeFiles(t *testing.T) {
changeFilesOptions.Files[0].Path = createTreePath changeFilesOptions.Files[0].Path = createTreePath
changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[1].Path = updateTreePath
changeFilesOptions.Files[2].Path = deleteTreePath changeFilesOptions.Files[2].Path = deleteTreePath
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", org3.Name, repo3.Name), &changeFilesOptions) req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", org3.Name, repo3.GroupID, repo3.Name), &changeFilesOptions)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using repo "user2/repo1" where user4 is a NOT collaborator // 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[0].Path = createTreePath
changeFilesOptions.Files[1].Path = updateTreePath changeFilesOptions.Files[1].Path = updateTreePath
changeFilesOptions.Files[2].Path = deleteTreePath changeFilesOptions.Files[2].Path = deleteTreePath
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo1.Name), &changeFilesOptions). req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/contents", user2.Name, repo1.GroupID, repo1.Name), &changeFilesOptions).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
}) })

View File

@ -95,13 +95,13 @@ func TestAPIGetRequestedFiles(t *testing.T) {
t.Run("PermissionCheck", func(t *testing.T) { t.Run("PermissionCheck", func(t *testing.T) {
filesOptions := &api.GetFilesOptions{Files: []string{"README.md"}} filesOptions := &api.GetFilesOptions{Files: []string{"README.md"}}
// Test accessing private ref with user token that does not have access - should fail // Test accessing private ref with user token that does not have access - should fail
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/file-contents", user2.Name, repo16.Name), &filesOptions).AddTokenAuth(token4) req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/file-contents", user2.Name, repo16.GroupID, repo16.Name), &filesOptions).AddTokenAuth(token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test access private ref of owner of token // Test access private ref of owner of token
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/file-contents", user2.Name, repo16.Name), &filesOptions).AddTokenAuth(token2) req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/file-contents", user2.Name, repo16.GroupID, repo16.Name), &filesOptions).AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
// Test access of org org3 private repo file by owner user2 // Test access of org org3 private repo file by owner user2
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/file-contents", org3.Name, repo3.Name), &filesOptions).AddTokenAuth(token2) req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/file-contents", org3.Name, repo3.GroupID, repo3.Name), &filesOptions).AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
}) })

View File

@ -92,7 +92,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
// ref is default ref // ref is default ref
ref := repo1.DefaultBranch ref := repo1.DefaultBranch
refType := "branch" refType := "branch"
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents?ref=%s", user2.Name, repo1.Name, ref) req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var contentsListResponse []*api.ContentsResponse var contentsListResponse []*api.ContentsResponse
DecodeJSON(t, resp, &contentsListResponse) DecodeJSON(t, resp, &contentsListResponse)
@ -104,7 +104,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
// No ref // No ref
refType = "branch" refType = "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/", user2.Name, repo1.Name) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/", user2.Name, repo1.GroupID, repo1.Name)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsListResponse) DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, 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 is the branch we created above in setup
ref = newBranch ref = newBranch
refType = "branch" refType = "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents?ref=%s", user2.Name, repo1.Name, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsListResponse) DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, 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 is the new tag we created above in setup
ref = newTag ref = newTag
refType = "tag" refType = "tag"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/?ref=%s", user2.Name, repo1.Name, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsListResponse) DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, contentsListResponse) assert.NotNil(t, contentsListResponse)
@ -143,7 +143,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
// ref is a commit // ref is a commit
ref = commitID ref = commitID
refType = "commit" refType = "commit"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/?ref=%s", user2.Name, repo1.Name, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsListResponse) DecodeJSON(t, resp, &contentsListResponse)
assert.NotNil(t, 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 // Test file contents a file with a bad ref
ref = "badref" ref = "badref"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/?ref=%s", user2.Name, repo1.Name, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/?ref=%s", user2.Name, repo1.GroupID, repo1.Name, ref)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test accessing private ref with user token that does not have access - should fail // Test accessing private ref with user token that does not have access - should fail
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/", user2.Name, repo16.Name). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/", user2.Name, repo16.GroupID, repo16.Name).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test access private ref of owner of token // Test access private ref of owner of token
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/", user2.Name, repo16.Name). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/", user2.Name, repo16.GroupID, repo16.Name).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
// Test access of org org3 private repo file by owner user2 // Test access of org org3 private repo file by owner user2
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/", org3.Name, repo3.Name). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/", org3.Name, repo3.GroupID, repo3.Name).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
} }

View File

@ -96,14 +96,14 @@ func testAPIGetContents(t *testing.T, _ *url.URL) {
/*** END SETUP ***/ /*** END SETUP ***/
// not found // not found
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/no-such/file.md", user2.Name, repo1.Name) req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/no-such/file.md", user2.Name, repo1.GroupID, repo1.Name)
resp := MakeRequest(t, req, http.StatusNotFound) resp := MakeRequest(t, req, http.StatusNotFound)
assert.Contains(t, resp.Body.String(), "object does not exist [id: , rel_path: no-such]") assert.Contains(t, resp.Body.String(), "object does not exist [id: , rel_path: no-such]")
// ref is default ref // ref is default ref
ref := repo1.DefaultBranch ref := repo1.DefaultBranch
refType := "branch" refType := "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
var contentsResponse api.ContentsResponse var contentsResponse api.ContentsResponse
DecodeJSON(t, resp, &contentsResponse) DecodeJSON(t, resp, &contentsResponse)
@ -113,7 +113,7 @@ func testAPIGetContents(t *testing.T, _ *url.URL) {
// No ref // No ref
refType = "branch" refType = "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo1.GroupID, repo1.Name, treePath)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsResponse) DecodeJSON(t, resp, &contentsResponse)
expectedContentsResponse = getExpectedContentsResponseForContents(repo1.DefaultBranch, refType, lastCommit.ID.String()) 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 is the branch we created above in setup
ref = newBranch ref = newBranch
refType = "branch" refType = "branch"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsResponse) DecodeJSON(t, resp, &contentsResponse)
branchCommit, _ := gitRepo.GetBranchCommit(ref) 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 is the new tag we created above in setup
ref = newTag ref = newTag
refType = "tag" refType = "tag"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsResponse) DecodeJSON(t, resp, &contentsResponse)
tagCommit, _ := gitRepo.GetTagCommit(ref) tagCommit, _ := gitRepo.GetTagCommit(ref)
@ -144,7 +144,7 @@ func testAPIGetContents(t *testing.T, _ *url.URL) {
// ref is a commit // ref is a commit
ref = commitID ref = commitID
refType = "commit" refType = "commit"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &contentsResponse) DecodeJSON(t, resp, &contentsResponse)
expectedContentsResponse = getExpectedContentsResponseForContents(ref, refType, commitID) 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 // Test file contents a file with a bad ref
ref = "badref" ref = "badref"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s?ref=%s", user2.Name, repo1.GroupID, repo1.Name, treePath, ref)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test accessing private ref with user token that does not have access - should fail // Test accessing private ref with user token that does not have access - should fail
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s", user2.Name, repo16.Name, treePath). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s", user2.Name, repo16.GroupID, repo16.Name, treePath).
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test access private ref of owner of token // Test access private ref of owner of token
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/readme.md", user2.Name, repo16.Name). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/readme.md", user2.Name, repo16.GroupID, repo16.Name).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
// Test access of org org3 private repo file by owner user2 // Test access of org org3 private repo file by owner user2
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s", org3.Name, repo3.Name, treePath). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/contents/%s", org3.Name, repo3.GroupID, repo3.Name, treePath).
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
} }

View File

@ -35,7 +35,7 @@ func TestAPIReposGitBlobs(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
// Test a public repo that anyone can GET the blob of // Test a public repo that anyone can GET the blob of
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo1.Name, repo1ReadmeSHA) req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", user2.Name, repo1.GroupID, repo1.Name, repo1ReadmeSHA)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var gitBlobResponse api.GitBlobResponse var gitBlobResponse api.GitBlobResponse
DecodeJSON(t, resp, &gitBlobResponse) DecodeJSON(t, resp, &gitBlobResponse)
@ -44,30 +44,30 @@ func TestAPIReposGitBlobs(t *testing.T) {
assert.Equal(t, expectedContent, *gitBlobResponse.Content) assert.Equal(t, expectedContent, *gitBlobResponse.Content)
// Tests a private repo with no token so will fail // Tests a private repo with no token so will fail
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo16.Name, repo16ReadmeSHA) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", user2.Name, repo16.GroupID, repo16.Name, repo16ReadmeSHA)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Test using access token for a private repo that the user of the token owns // Test using access token for a private repo that the user of the token owns
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo16.Name, repo16ReadmeSHA). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", user2.Name, repo16.GroupID, repo16.Name, repo16ReadmeSHA).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
// Test using bad sha // Test using bad sha
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", user2.Name, repo1.Name, badSHA) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", user2.Name, repo1.GroupID, repo1.Name, badSHA)
MakeRequest(t, req, http.StatusBadRequest) MakeRequest(t, req, http.StatusBadRequest)
// Test using org repo "org3/repo3" where user2 is a collaborator // Test using org repo "org3/repo3" where user2 is a collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", org3.Name, repo3.Name, repo3ReadmeSHA). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", org3.Name, repo3.GroupID, repo3.Name, repo3ReadmeSHA).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
// Test using org repo "org3/repo3" where user2 is a collaborator // Test using org repo "org3/repo3" where user2 is a collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", org3.Name, repo3.Name, repo3ReadmeSHA). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", org3.Name, repo3.GroupID, repo3.Name, repo3ReadmeSHA).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
// Test using org repo "org3/repo3" with no user token // Test using org repo "org3/repo3" with no user token
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/%s", org3.Name, repo3ReadmeSHA, repo3.Name) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/%s", org3.Name, repo3ReadmeSHA, repo3.GroupID, repo3.Name)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Login as User4. // Login as User4.
@ -75,6 +75,6 @@ func TestAPIReposGitBlobs(t *testing.T) {
token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAll) token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAll)
// Test using org repo "org3/repo3" where user4 is a NOT collaborator // Test using org repo "org3/repo3" where user4 is a NOT collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/blobs/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", org3.Name, repo3.Name, token4) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/blobs/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", org3.Name, repo3.GroupID, repo3.Name, token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
} }

View File

@ -37,7 +37,7 @@ echo "TestGitHookScript"
// user1 is an admin user // user1 is an admin user
session := loginUser(t, "user1") session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var apiGitHooks []*api.GitHook var apiGitHooks []*api.GitHook
@ -63,7 +63,7 @@ echo "TestGitHookScript"
// user1 is an admin user // user1 is an admin user
session := loginUser(t, "user1") session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var apiGitHooks []*api.GitHook var apiGitHooks []*api.GitHook
@ -83,7 +83,7 @@ echo "TestGitHookScript"
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git", owner.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
}) })
@ -97,7 +97,7 @@ echo "TestGitHookScript"
// user1 is an admin user // user1 is an admin user
session := loginUser(t, "user1") session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var apiGitHook *api.GitHook var apiGitHook *api.GitHook
@ -113,7 +113,7 @@ echo "TestGitHookScript"
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
}) })
@ -139,7 +139,7 @@ echo "TestGitHookScript"
assert.True(t, apiGitHook.IsActive) assert.True(t, apiGitHook.IsActive)
assert.Equal(t, testHookContent, apiGitHook.Content) assert.Equal(t, testHookContent, apiGitHook.Content)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
var apiGitHook2 *api.GitHook var apiGitHook2 *api.GitHook
@ -156,7 +156,7 @@ echo "TestGitHookScript"
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name)
req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditGitHookOption{ req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditGitHookOption{
Content: testHookContent, Content: testHookContent,
}).AddTokenAuth(token) }).AddTokenAuth(token)
@ -173,11 +173,11 @@ echo "TestGitHookScript"
session := loginUser(t, "user1") session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name). req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var apiGitHook2 *api.GitHook var apiGitHook2 *api.GitHook
@ -194,7 +194,7 @@ echo "TestGitHookScript"
session := loginUser(t, owner.Name) session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/hooks/git/pre-receive", owner.Name, repo.Name). req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/hooks/git/pre-receive", owner.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
}) })

View File

@ -44,7 +44,7 @@ func TestAPIGitTags(t *testing.T) {
aTag, _ := gitRepo.GetTag(aTagName) aTag, _ := gitRepo.GetTag(aTagName)
// SHOULD work for annotated tags // SHOULD work for annotated tags
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/tags/%s", user.Name, repo.Name, aTag.ID.String()). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/tags/%s", user.Name, repo.GroupID, repo.Name, aTag.ID.String()).
AddTokenAuth(token) AddTokenAuth(token)
res := MakeRequest(t, req, http.StatusOK) 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) assert.Equal(t, repo.APIURL()+"/git/tags/"+aTag.ID.String(), tag.URL)
// Should NOT work for lightweight tags // Should NOT work for lightweight tags
badReq := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/tags/%s", user.Name, repo.Name, commit.ID.String()). badReq := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/tags/%s", user.Name, repo.GroupID, repo.Name, commit.ID.String()).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, badReq, http.StatusBadRequest) MakeRequest(t, badReq, http.StatusBadRequest)
} }
@ -73,14 +73,14 @@ func TestAPIDeleteTagByName(t *testing.T) {
session := loginUser(t, owner.LowerName) session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequest(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/tags/delete-tag", owner.Name, repo.Name)). req := NewRequest(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/tags/delete-tag", owner.Name, repo.GroupID, repo.Name)).
AddTokenAuth(token) AddTokenAuth(token)
_ = MakeRequest(t, req, http.StatusNoContent) _ = MakeRequest(t, req, http.StatusNoContent)
// Make sure that actual releases can't be deleted outright // Make sure that actual releases can't be deleted outright
createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test") createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test")
req = NewRequest(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/tags/release-tag", owner.Name, repo.Name)). req = NewRequest(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%d/%s/tags/release-tag", owner.Name, repo.GroupID, repo.Name)).
AddTokenAuth(token) AddTokenAuth(token)
_ = MakeRequest(t, req, http.StatusConflict) _ = MakeRequest(t, req, http.StatusConflict)
} }

View File

@ -57,26 +57,26 @@ func TestAPIReposGitTrees(t *testing.T) {
"master", // Branch "master", // Branch
repo1TreeSHA, // Tag repo1TreeSHA, // Tag
} { } {
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", user2.Name, repo16.Name, ref) req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", user2.Name, repo16.GroupID, repo16.Name, ref)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
} }
// Test using access token for a private repo that the user of the token owns // Test using access token for a private repo that the user of the token owns
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", user2.Name, repo16.Name, repo16TreeSHA). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", user2.Name, repo16.GroupID, repo16.Name, repo16TreeSHA).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
// Test using bad sha // Test using bad sha
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", user2.Name, repo1.Name, badSHA) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", user2.Name, repo1.GroupID, repo1.Name, badSHA)
MakeRequest(t, req, http.StatusBadRequest) MakeRequest(t, req, http.StatusBadRequest)
// Test using org repo "org3/repo3" where user2 is a collaborator // Test using org repo "org3/repo3" where user2 is a collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", org3.Name, repo3.Name, repo3TreeSHA). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", org3.Name, repo3.GroupID, repo3.Name, repo3TreeSHA).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusOK) MakeRequest(t, req, http.StatusOK)
// Test using org repo "org3/repo3" with no user token // Test using org repo "org3/repo3" with no user token
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", org3.Name, repo3TreeSHA, repo3.Name) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/%s", org3.Name, repo3TreeSHA, repo3.GroupID, repo3.Name)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
// Login as User4. // Login as User4.
@ -84,6 +84,6 @@ func TestAPIReposGitTrees(t *testing.T) {
token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAll) token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAll)
// Test using org repo "org3/repo3" where user4 is a NOT collaborator // Test using org repo "org3/repo3" where user4 is a NOT collaborator
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", org3.Name, repo3.Name, token4) req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/git/trees/d56a3073c1dbb7b15963110a049d50cdb5db99fc?access=%s", org3.Name, repo3.GroupID, repo3.Name, token4)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
} }

View File

@ -27,7 +27,7 @@ func TestAPICreateHook(t *testing.T) {
// user1 is an admin user // user1 is an admin user
session := loginUser(t, "user1") session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/%s", owner.Name, repo.Name, "hooks"), api.CreateHookOption{ req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/%s", owner.Name, repo.GroupID, repo.Name, "hooks"), api.CreateHookOption{
Type: "gitea", Type: "gitea",
Config: api.CreateHookOptionConfig{ Config: api.CreateHookOptionConfig{
"content_type": "json", "content_type": "json",

View File

@ -56,7 +56,7 @@ func TestAPIRepoTags(t *testing.T) {
} }
// get created tag // get created tag
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/tags/%s", user.Name, repoName, newTag.Name). req = NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/tags/%s", user.Name, repoName, newTag.GroupID, newTag.Name).
AddTokenAuth(token) AddTokenAuth(token)
resp = MakeRequest(t, req, http.StatusOK) resp = MakeRequest(t, req, http.StatusOK)
var tag *api.Tag var tag *api.Tag
@ -64,7 +64,7 @@ func TestAPIRepoTags(t *testing.T) {
assert.Equal(t, newTag, tag) assert.Equal(t, newTag, tag)
// delete tag // delete tag
delReq := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/tags/%s", user.Name, repoName, newTag.Name). delReq := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/tags/%s", user.Name, repoName, newTag.GroupID, newTag.Name).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, delReq, http.StatusNoContent) MakeRequest(t, delReq, http.StatusNoContent)

View File

@ -82,66 +82,66 @@ func TestAPISearchRepo(t *testing.T) {
}{ }{
{ {
name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{
nil: {count: 36}, nil: {count: 36},
user: {count: 36}, user: {count: 36},
user2: {count: 36}, user2: {count: 36},
}, },
}, },
{ {
name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10&private=false", expectedResults: expectedResults{ name: "RepositoriesMax10", requestURL: "/api/v1/repos/search?limit=10&private=false", expectedResults: expectedResults{
nil: {count: 10}, nil: {count: 10},
user: {count: 10}, user: {count: 10},
user2: {count: 10}, user2: {count: 10},
}, },
}, },
{ {
name: "RepositoriesDefault", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{ name: "RepositoriesDefault", requestURL: "/api/v1/repos/search?default&private=false", expectedResults: expectedResults{
nil: {count: 10}, nil: {count: 10},
user: {count: 10}, user: {count: 10},
user2: {count: 10}, user2: {count: 10},
}, },
}, },
{ {
name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s&private=false", "big_test_"), expectedResults: expectedResults{ name: "RepositoriesByName", requestURL: fmt.Sprintf("/api/v1/repos/search?q=%s&private=false", "big_test_"), expectedResults: expectedResults{
nil: {count: 7, repoName: "big_test_"}, nil: {count: 7, repoName: "big_test_"},
user: {count: 7, repoName: "big_test_"}, user: {count: 7, repoName: "big_test_"},
user2: {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{ 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{ name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{
nil: {count: 5}, nil: {count: 5},
user: {count: 9, includesPrivate: true}, user: {count: 9, includesPrivate: true},
user2: {count: 6, includesPrivate: true}, user2: {count: 6, includesPrivate: true},
}, },
}, },
{ {
name: "RepositoriesAccessibleAndRelatedToUser2", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user2.ID), expectedResults: expectedResults{ name: "RepositoriesAccessibleAndRelatedToUser2", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user2.ID), expectedResults: expectedResults{
nil: {count: 1}, nil: {count: 1},
user: {count: 2, includesPrivate: true}, user: {count: 2, includesPrivate: true},
user2: {count: 2, includesPrivate: true}, user2: {count: 2, includesPrivate: true},
user4: {count: 1}, user4: {count: 1},
}, },
}, },
{ {
name: "RepositoriesAccessibleAndRelatedToUser3", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", org3.ID), expectedResults: expectedResults{ name: "RepositoriesAccessibleAndRelatedToUser3", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", org3.ID), expectedResults: expectedResults{
nil: {count: 1}, nil: {count: 1},
user: {count: 4, includesPrivate: true}, user: {count: 4, includesPrivate: true},
user2: {count: 3, includesPrivate: true}, user2: {count: 3, includesPrivate: true},
org3: {count: 4, includesPrivate: true}, org3: {count: 4, includesPrivate: true},
}, },
}, },
{ {
name: "RepositoriesOwnedByOrganization", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", orgUser.ID), expectedResults: expectedResults{ name: "RepositoriesOwnedByOrganization", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", orgUser.ID), expectedResults: expectedResults{
nil: {count: 1, repoOwnerID: orgUser.ID}, nil: {count: 1, repoOwnerID: orgUser.ID},
user: {count: 2, repoOwnerID: orgUser.ID, includesPrivate: true}, user: {count: 2, repoOwnerID: orgUser.ID, includesPrivate: true},
user2: {count: 1, repoOwnerID: orgUser.ID}, user2: {count: 1, repoOwnerID: orgUser.ID},
}, },
}, },
{name: "RepositoriesAccessibleAndRelatedToUser4", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user4.ID), expectedResults: expectedResults{ {name: "RepositoriesAccessibleAndRelatedToUser4", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user4.ID), expectedResults: expectedResults{
nil: {count: 3}, nil: {count: 3},
@ -565,7 +565,7 @@ func TestAPIRepoTransfer(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID})
session = loginUser(t, user.Name) session = loginUser(t, user.Name)
token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer", repo.OwnerName, repo.Name), &api.TransferRepoOption{ req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer", repo.OwnerName, repo.GroupID, repo.Name), &api.TransferRepoOption{
NewOwner: testCase.newOwner, NewOwner: testCase.newOwner,
TeamIDs: testCase.teams, TeamIDs: testCase.teams,
}).AddTokenAuth(token) }).AddTokenAuth(token)
@ -596,7 +596,7 @@ func transfer(t *testing.T) *repo_model.Repository {
DecodeJSON(t, resp, apiRepo) DecodeJSON(t, resp, apiRepo)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiRepo.ID})
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer", repo.OwnerName, repo.Name), &api.TransferRepoOption{ req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer", repo.OwnerName, repo.GroupID, repo.Name), &api.TransferRepoOption{
NewOwner: "user4", NewOwner: "user4",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusCreated) MakeRequest(t, req, http.StatusCreated)
@ -612,7 +612,7 @@ func TestAPIAcceptTransfer(t *testing.T) {
// try to accept with not authorized user // try to accept with not authorized user
session := loginUser(t, "user2") session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject", repo.OwnerName, repo.Name)). req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer/reject", repo.OwnerName, repo.GroupID, repo.Name)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
@ -625,7 +625,7 @@ func TestAPIAcceptTransfer(t *testing.T) {
session = loginUser(t, "user4") session = loginUser(t, "user4")
token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/accept", repo.OwnerName, repo.Name)). req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer/accept", repo.OwnerName, repo.GroupID, repo.Name)).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusAccepted) resp := MakeRequest(t, req, http.StatusAccepted)
apiRepo := new(api.Repository) apiRepo := new(api.Repository)
@ -641,7 +641,7 @@ func TestAPIRejectTransfer(t *testing.T) {
// try to reject with not authorized user // try to reject with not authorized user
session := loginUser(t, "user2") session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject", repo.OwnerName, repo.Name)). req := NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer/reject", repo.OwnerName, repo.GroupID, repo.Name)).
AddTokenAuth(token) AddTokenAuth(token)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
@ -654,7 +654,7 @@ func TestAPIRejectTransfer(t *testing.T) {
session = loginUser(t, "user4") session = loginUser(t, "user4")
token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer/reject", repo.OwnerName, repo.Name)). req = NewRequest(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/transfer/reject", repo.OwnerName, repo.GroupID, repo.Name)).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
apiRepo := new(api.Repository) apiRepo := new(api.Repository)
@ -673,7 +673,7 @@ func TestAPIGenerateRepo(t *testing.T) {
// user // user
repo := new(api.Repository) repo := new(api.Repository)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/generate", templateRepo.OwnerName, templateRepo.Name), &api.GenerateRepoOption{ req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/generate", templateRepo.OwnerName, templateRepo.GroupID, templateRepo.Name), &api.GenerateRepoOption{
Owner: user.Name, Owner: user.Name,
Name: "new-repo", Name: "new-repo",
Description: "test generate repo", Description: "test generate repo",
@ -686,7 +686,7 @@ func TestAPIGenerateRepo(t *testing.T) {
assert.Equal(t, "new-repo", repo.Name) assert.Equal(t, "new-repo", repo.Name)
// org // org
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/generate", templateRepo.OwnerName, templateRepo.Name), &api.GenerateRepoOption{ req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/generate", templateRepo.OwnerName, templateRepo.GroupID, templateRepo.Name), &api.GenerateRepoOption{
Owner: "org3", Owner: "org3",
Name: "new-repo", Name: "new-repo",
Description: "test generate repo", Description: "test generate repo",
@ -706,7 +706,7 @@ func TestAPIRepoGetReviewers(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/reviewers", user.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/reviewers", user.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var reviewers []*api.User var reviewers []*api.User
@ -723,7 +723,7 @@ func TestAPIRepoGetAssignees(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/assignees", user.Name, repo.Name). req := NewRequestf(t, "GET", "/api/v1/repos/%s/%d/%s/assignees", user.Name, repo.GroupID, repo.Name).
AddTokenAuth(token) AddTokenAuth(token)
resp := MakeRequest(t, req, http.StatusOK) resp := MakeRequest(t, req, http.StatusOK)
var assignees []*api.User var assignees []*api.User

View File

@ -83,7 +83,7 @@ func TestAPIRepoTopic(t *testing.T) {
token2 := getUserToken(t, user2.Name, auth_model.AccessTokenScopeWriteRepository) token2 := getUserToken(t, user2.Name, auth_model.AccessTokenScopeWriteRepository)
// Test read topics using login // Test read topics using login
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/topics", user2.Name, repo2.Name)). req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/topics", user2.Name, repo2.GroupID, repo2.Name)).
AddTokenAuth(token2) AddTokenAuth(token2)
res := MakeRequest(t, req, http.StatusOK) res := MakeRequest(t, req, http.StatusOK)
var topics *api.TopicName var topics *api.TopicName
@ -91,21 +91,21 @@ func TestAPIRepoTopic(t *testing.T) {
assert.ElementsMatch(t, []string{"topicname1", "topicname2"}, topics.TopicNames) assert.ElementsMatch(t, []string{"topicname1", "topicname2"}, topics.TopicNames)
// Test delete a topic // Test delete a topic
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/topics/%s", user2.Name, repo2.Name, "Topicname1"). req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "Topicname1").
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Test add an existing topic // Test add an existing topic
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s", user2.Name, repo2.Name, "Golang"). req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "Golang").
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
// Test add a topic // Test add a topic
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s", user2.Name, repo2.Name, "topicName3"). req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "topicName3").
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)
url := fmt.Sprintf("/api/v1/repos/%s/%s/topics", user2.Name, repo2.Name) url := fmt.Sprintf("/api/v1/repos/%s/%d/%s/topics", user2.Name, repo2.GroupID, repo2.Name)
// Test read topics using token // Test read topics using token
req = NewRequest(t, "GET", url). req = NewRequest(t, "GET", url).
@ -158,12 +158,12 @@ func TestAPIRepoTopic(t *testing.T) {
MakeRequest(t, req, http.StatusUnprocessableEntity) MakeRequest(t, req, http.StatusUnprocessableEntity)
// Test add a topic when there is already maximum // Test add a topic when there is already maximum
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s", user2.Name, repo2.Name, "t26"). req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "t26").
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusUnprocessableEntity) MakeRequest(t, req, http.StatusUnprocessableEntity)
// Test delete a topic that repo doesn't have // Test delete a topic that repo doesn't have
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/topics/%s", user2.Name, repo2.Name, "Topicname1"). req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%d/%s/topics/%s", user2.Name, repo2.GroupID, repo2.Name, "Topicname1").
AddTokenAuth(token2) AddTokenAuth(token2)
MakeRequest(t, req, http.StatusNotFound) MakeRequest(t, req, http.StatusNotFound)
@ -171,14 +171,14 @@ func TestAPIRepoTopic(t *testing.T) {
token4 := getUserToken(t, user4.Name, auth_model.AccessTokenScopeWriteRepository) token4 := getUserToken(t, user4.Name, auth_model.AccessTokenScopeWriteRepository)
// Test read topics with write access // Test read topics with write access
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/topics", org3.Name, repo3.Name)). req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%d/%s/topics", org3.Name, repo3.GroupID, repo3.Name)).
AddTokenAuth(token4) AddTokenAuth(token4)
res = MakeRequest(t, req, http.StatusOK) res = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, res, &topics) DecodeJSON(t, res, &topics)
assert.Empty(t, topics.TopicNames) assert.Empty(t, topics.TopicNames)
// Test add a topic to repo with write access (requires repo admin access) // Test add a topic to repo with write access (requires repo admin access)
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s", org3.Name, repo3.Name, "topicName"). req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%d/%s/topics/%s", org3.Name, repo3.GroupID, repo3.Name, "topicName").
AddTokenAuth(token4) AddTokenAuth(token4)
MakeRequest(t, req, http.StatusForbidden) MakeRequest(t, req, http.StatusForbidden)
} }

View File

@ -72,7 +72,7 @@ func TestEventSourceManagerRun(t *testing.T) {
assert.Len(t, apiNL, 2) assert.Len(t, apiNL, 2)
lastReadAt := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801 <- only Notification 4 is in this filter ... 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/%s/notifications?last_read_at=%s", user2.Name, repo1.Name, lastReadAt)). req = NewRequest(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%d/%s/notifications?last_read_at=%s", user2.Name, repo1.GroupID, repo1.Name, lastReadAt)).
AddTokenAuth(token) AddTokenAuth(token)
session.MakeRequest(t, req, http.StatusResetContent) session.MakeRequest(t, req, http.StatusResetContent)

View File

@ -35,7 +35,7 @@ func testPrivateActivityDoSomethingForActionEntries(t *testing.T) {
session := loginUser(t, privateActivityTestUser) session := loginUser(t, privateActivityTestUser)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues?state=all", owner.Name, repoBefore.Name) urlStr := fmt.Sprintf("/api/v1/repos/%s/%d/%s/issues?state=all", owner.Name, repoBefore.GroupID, repoBefore.Name)
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{ req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
Body: "test", Body: "test",
Title: "test", Title: "test",

View File

@ -40,7 +40,7 @@ func TestRepoMergeUpstream(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
// create a fork // create a fork
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/forks", baseUser.Name, baseRepo.Name), &api.CreateForkOption{ req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%d/%s/forks", baseUser.Name, baseRepo.GroupID, baseRepo.Name), &api.CreateForkOption{
Name: new("test-repo-fork"), Name: new("test-repo-fork"),
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusAccepted) MakeRequest(t, req, http.StatusAccepted)

View File

@ -1021,7 +1021,7 @@ jobs:
- run: echo 'cmd 2' - run: echo 'cmd 2'
` `
opts := getWorkflowCreateFileOptions(user2, repo1.DefaultBranch, "create "+wfTreePath, wfFileContent) opts := getWorkflowCreateFileOptions(user2, repo1.DefaultBranch, "create "+wfTreePath, wfFileContent)
createWorkflowFile(t, token, "user2", "repo1", wfTreePath, opts) createWorkflowFile(t, token, "user2", "repo1", wfTreePath, repo1.GroupID, opts)
commitID, err := gitRepo1.GetBranchCommitID(repo1.DefaultBranch) commitID, err := gitRepo1.GetBranchCommitID(repo1.DefaultBranch)
assert.NoError(t, err) assert.NoError(t, err)
@ -1720,7 +1720,7 @@ jobs:
steps: steps:
- run: echo 'test the webhook' - run: echo 'test the webhook'
`) `)
createWorkflowFile(t, token, "user2", "repo1", ".gitea/workflows/dispatch.yml", opts) createWorkflowFile(t, token, "user2", "repo1", ".gitea/workflows/dispatch.yml", repo1.GroupID, opts)
// 2.2 trigger the webhooks // 2.2 trigger the webhooks
@ -1742,7 +1742,7 @@ jobs:
- run: echo 'cmd 2' - run: echo 'cmd 2'
` `
opts = getWorkflowCreateFileOptions(user2, repo1.DefaultBranch, "create "+wfTreePath, wfFileContent) opts = getWorkflowCreateFileOptions(user2, repo1.DefaultBranch, "create "+wfTreePath, wfFileContent)
createWorkflowFile(t, token, "user2", "repo1", wfTreePath, opts) createWorkflowFile(t, token, "user2", "repo1", wfTreePath, repo1.GroupID, opts)
commitID, err := gitRepo1.GetBranchCommitID(repo1.DefaultBranch) commitID, err := gitRepo1.GetBranchCommitID(repo1.DefaultBranch)
assert.NoError(t, err) assert.NoError(t, err)
@ -1822,7 +1822,7 @@ jobs:
- run: echo 'test the webhook' - run: echo 'test the webhook'
` `
opts := getWorkflowCreateFileOptions(user2, repo1.DefaultBranch, "create "+wfTreePath, wfFileContent) opts := getWorkflowCreateFileOptions(user2, repo1.DefaultBranch, "create "+wfTreePath, wfFileContent)
createWorkflowFile(t, token, "user2", "repo1", wfTreePath, opts) createWorkflowFile(t, token, "user2", "repo1", wfTreePath, repo1.GroupID, opts)
commitID, err := gitRepo1.GetBranchCommitID(repo1.DefaultBranch) commitID, err := gitRepo1.GetBranchCommitID(repo1.DefaultBranch)
assert.NoError(t, err) assert.NoError(t, err)