Skip to content

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

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

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/:username").Get(org.IsMember).
Delete(reqOrgOwnership(), org.DeleteMember)
})
m.Group("/repos", func() {
m.Get("", org.ListRepos)
})
m.Group("/public_members", func() {
m.Get("", org.ListPublicMembers)
m.Combo("/:username").Get(org.IsPublicMember).
Expand Down
46 changes: 46 additions & 0 deletions routers/api/v1/org/repo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org
Copy link
Member

Choose a reason for hiding this comment

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

Needs a copyright


import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/sdk/gitea"
)

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

var apiRepos []*api.Repository
if ctx.User != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I don't like quietly returning a empty list of repositories for unauthenticated users. Either we should have a 401 (like we do for GET /repos/:owner/:reponame), or show the unauthenticated users the organization's public repos.

// Find all repos a user has access to within an org.
org := ctx.Org.Organization
reposEnv, err := org.AccessibleReposEnv(ctx.User.ID)
if err != nil {
ctx.Error(500, "AccessibleReposEnv", err)
return
}
repos, err := reposEnv.Repos(1, org.NumRepos)
if err != nil {
ctx.Error(500, "Repos", err)
return
}
// Convert to API repos.
apiRepos = make([]*api.Repository, len(repos))
for i, repo := range repos {
accessLevel, err := models.AccessLevel(ctx.User.ID, repo)
if err != nil {
ctx.Error(500, "AccessLevel", err)
return
}
apiRepos[i] = repo.APIFormat(accessLevel)
}
}
ctx.JSON(200, &apiRepos)
}