Skip to content

Commit 6a3c037

Browse files
awwalkerbkcsoft
authored andcommitted
API: support '/orgs/:org/repos' (#2047)
* API: support '/orgs/:org/repos'
1 parent f011d6d commit 6a3c037

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

integrations/api_repo_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,24 @@ func TestAPIViewRepo(t *testing.T) {
6363
assert.EqualValues(t, 1, repo.ID)
6464
assert.EqualValues(t, "repo1", repo.Name)
6565
}
66+
67+
func TestAPIOrgRepos(t *testing.T) {
68+
prepareTestEnv(t)
69+
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
70+
// User3 is an Org. Check their repos.
71+
sourceOrg := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
72+
// Login as User2.
73+
session := loginUser(t, user.Name)
74+
75+
req := NewRequestf(t, "GET", "/api/v1/orgs/%s/repos", sourceOrg.Name)
76+
resp := session.MakeRequest(t, req, http.StatusOK)
77+
78+
var apiRepos []*api.Repository
79+
DecodeJSON(t, resp, &apiRepos)
80+
expectedLen := models.GetCount(t, models.Repository{OwnerID: sourceOrg.ID},
81+
models.Cond("is_private = ?", false))
82+
assert.Len(t, apiRepos, expectedLen)
83+
for _, repo := range apiRepos {
84+
assert.False(t, repo.Private)
85+
}
86+
}

public/swagger.v1.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@
187187
}
188188
}
189189
},
190+
"/orgs/{org}/repos": {
191+
"get": {
192+
"produces": [
193+
"application/json"
194+
],
195+
"operationId": "orgListRepos",
196+
"responses": {
197+
"200": {
198+
"$ref": "#/responses/RepositoryList"
199+
},
200+
"500": {
201+
"$ref": "#/responses/error"
202+
}
203+
}
204+
}
205+
},
190206
"/repos/search": {
191207
"get": {
192208
"produces": [
@@ -1357,4 +1373,4 @@
13571373
}
13581374
}
13591375
}
1360-
}
1376+
}

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ func RegisterRoutes(m *macaron.Macaron) {
458458
m.Get("/user/orgs", reqToken(), org.ListMyOrgs)
459459
m.Get("/users/:username/orgs", org.ListUserOrgs)
460460
m.Group("/orgs/:orgname", func() {
461+
m.Get("/repos", user.ListOrgRepos)
461462
m.Combo("").Get(org.Get).
462463
Patch(reqToken(), reqOrgOwnership(), bind(api.EditOrgOption{}), org.Edit)
463464
m.Group("/members", func() {

routers/api/v1/user/repo.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package user
26

37
import (
@@ -80,3 +84,17 @@ func ListMyRepos(ctx *context.APIContext) {
8084
}
8185
ctx.JSON(200, &apiRepos)
8286
}
87+
88+
// ListOrgRepos - list the repositories of an organization.
89+
func ListOrgRepos(ctx *context.APIContext) {
90+
// swagger:route GET /orgs/{org}/repos orgListRepos
91+
//
92+
// Produces:
93+
// - application/json
94+
//
95+
// Responses:
96+
// 200: RepositoryList
97+
// 500: error
98+
99+
listUserRepos(ctx, ctx.Org.Organization)
100+
}

0 commit comments

Comments
 (0)