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

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

merged 9 commits into from
Jul 13, 2017

Conversation

awwalker
Copy link
Contributor

This is in favor of #1691 in order to fix #494.

Sorry for opening a new PR, but this new approach seems to address all of the concerns brought up in #494. I also added an integration test, but was unsure of how to create a test organization in the integrations directory. If this PR is approved of over #494 I'll close that one and we can focus on this one. Otherwise I'll go back to fixing that one and close this one.

@appleboy
Copy link
Member

build fail.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 24, 2017
@appleboy appleboy added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jun 24, 2017
@appleboy appleboy added this to the 1.2.0 milestone Jun 24, 2017
// 200: RepositoryList
// 500: error

org := GetOrgByParams(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Not necessary, can just use ctx.Org (which is populated by the orgAssignment(true) handler)

@awwalker
Copy link
Contributor Author

I think build failure is due to the added test case. I need to make an org inside the integrations test somehow but wasn't sure of how to do that. Any guidance would be helpful

func TestAPIOrgReposNotLogin(t *testing.T) {
assert.NoError(t, models.LoadFixtures())

req := NewRequest(t, "GET", "/api/v1/orgs/org1/repos")
Copy link
Member

Choose a reason for hiding this comment

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

@awwalker You need to be authenticated for this API endpoint; that's why the test is failing. Use the loginUser(..) helper function, and take a look at other API integrations test (a lot of them already use loginUser(..)).

// 200: RepositoryList
// 500: error

listUserRepos(ctx, ctx.Org)
Copy link
Member

Choose a reason for hiding this comment

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

ctx.Org.Organization must be used

@lunny
Copy link
Member

lunny commented Jun 28, 2017

@awwalker See https://github.com/go-gitea/gitea/blob/master/models/fixtures/user.yml, user3, user6 and user7 are organizations and there is no user named org1. So you can use /api/v1/orgs/user3/repos and login with user2. And it should has 1 repo repo3.

@lunny lunny modified the milestones: 1.3.0, 1.2.0 Jul 1, 2017
req := NewRequest(t, "GET", "/api/v1/orgs/user3/repos")
session := loginUser(t, "user2")
resp := session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
Copy link
Member

Choose a reason for hiding this comment

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

Please check also if it returns correct repository count

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@sapk
Copy link
Member

sapk commented Jul 6, 2017

@awwalker Can you exec make generate-swagger to update the public/swagger.v1.json and commit it. It was remove from build (go generate) to limit extra work for Drone (#1791).

Copy link
Member

@sapk sapk left a comment

Choose a reason for hiding this comment

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

A little corner case to check and a little simplification. For the rest LGTM.

// 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

@@ -455,6 +455,9 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/:username").Get(org.IsMember).
Delete(reqToken(), reqOrgOwnership(), org.DeleteMember)
})
m.Group("/repos", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Why a group for only one route ? Just do m.Get("/repos", user.ListOrgRepos).

Copy link
Member

Choose a reason for hiding this comment

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

Just as a side note during review context we should use a combo and migrate https://github.com/go-gitea/gitea/blob/master/routers/api/v1/api.go#L335 that does not currently follow the normal path. Still, this will maybe break few things so I will wait for the advice of other before doing that. Maybe in an other PR.

@@ -10,6 +10,7 @@ import (

"code.gitea.io/gitea/models"

api "code.gitea.io/sdk/gitea"
Copy link
Member

Choose a reason for hiding this comment

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

Should be next to other code.gitea.io imports (see the styleguide)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm this was gofmt's choice because I aliased it. I'll edit it for the styleguide though

Copy link
Member

@ethantkoenig ethantkoenig left a comment

Choose a reason for hiding this comment

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

@awwalker The new GET /orgs/:org/repos endpoint has many of the same bugs that the GET /users/:username/repos has (see #2125)

@awwalker
Copy link
Contributor Author

awwalker commented Jul 9, 2017

This should pass drone once #2125 is in

@ethantkoenig
Copy link
Member

@awwalker #2125 has been merged, so you'll need to rebase this on top of master

@awwalker
Copy link
Contributor Author

@ethantkoenig rebased and ready for review

@bkcsoft
Copy link
Member

bkcsoft commented Jul 12, 2017

@awwalker Conflicts again :trollface:

@awwalker
Copy link
Contributor Author

@bkcsoft better....for now!

@bkcsoft
Copy link
Member

bkcsoft commented Jul 13, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jul 13, 2017
@sapk
Copy link
Member

sapk commented Jul 13, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jul 13, 2017
@bkcsoft bkcsoft merged commit 6a3c037 into go-gitea:master Jul 13, 2017
@lunny lunny added the modifies/api This PR adds API routes or modifies them label Jul 13, 2017
@lunny lunny modified the milestones: 1.2.0, 1.3.0 Jul 13, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User/org repository listing API
8 participants