Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: support '/orgs/:org/repos' #2047

Merged
merged 9 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions integrations/api_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,24 @@ func TestAPIViewRepo(t *testing.T) {
assert.EqualValues(t, 1, repo.ID)
assert.EqualValues(t, "repo1", repo.Name)
}

func TestAPIOrgRepos(t *testing.T) {
prepareTestEnv(t)
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// User3 is an Org. Check their repos.
sourceOrg := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)

req := NewRequestf(t, "GET", "/api/v1/orgs/%s/repos", sourceOrg.Name)
resp := session.MakeRequest(t, req, http.StatusOK)

var apiRepos []*api.Repository
DecodeJSON(t, resp, &apiRepos)
expectedLen := models.GetCount(t, models.Repository{OwnerID: sourceOrg.ID},
models.Cond("is_private = ?", false))
assert.Len(t, apiRepos, expectedLen)
for _, repo := range apiRepos {
assert.False(t, repo.Private)
}
}
18 changes: 17 additions & 1 deletion public/swagger.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@
}
}
},
"/orgs/{org}/repos": {
"get": {
"produces": [
"application/json"
],
"operationId": "orgListRepos",
"responses": {
"200": {
"$ref": "#/responses/RepositoryList"
},
"500": {
"$ref": "#/responses/error"
}
}
}
},
"/repos/search": {
"get": {
"produces": [
Expand Down Expand Up @@ -1357,4 +1373,4 @@
}
}
}
}
}
1 change: 1 addition & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/user/orgs", reqToken(), org.ListMyOrgs)
m.Get("/users/:username/orgs", org.ListUserOrgs)
m.Group("/orgs/:orgname", func() {
m.Get("/repos", user.ListOrgRepos)
m.Combo("").Get(org.Get).
Patch(reqToken(), reqOrgOwnership(), bind(api.EditOrgOption{}), org.Edit)
m.Group("/members", func() {
Expand Down
18 changes: 18 additions & 0 deletions routers/api/v1/user/repo.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package user

import (
Expand Down Expand Up @@ -80,3 +84,17 @@ func ListMyRepos(ctx *context.APIContext) {
}
ctx.JSON(200, &apiRepos)
}

// ListOrgRepos - list the repositories of an organization.
func ListOrgRepos(ctx *context.APIContext) {
// swagger:route GET /orgs/{org}/repos orgListRepos
//
// Produces:
// - application/json
//
// Responses:
// 200: RepositoryList
// 500: error

listUserRepos(ctx, ctx.Org.Organization)
Copy link
Member

@sapk sapk Jul 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made a PR #2117 to enforce that ctx.Org.Organization is an org. So this detail could be ignore and the check up under /users/{username}/repo could be make in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks

}