API: support '/orgs/:org/repos' (#2047)
* API: support '/orgs/:org/repos'
This commit is contained in:
		
							parent
							
								
									f011d6d4d7
								
							
						
					
					
						commit
						6a3c03762a
					
				
					 4 changed files with 57 additions and 1 deletions
				
			
		|  | @ -63,3 +63,24 @@ func TestAPIViewRepo(t *testing.T) { | ||||||
| 	assert.EqualValues(t, 1, repo.ID) | 	assert.EqualValues(t, 1, repo.ID) | ||||||
| 	assert.EqualValues(t, "repo1", repo.Name) | 	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
									
								
								public/swagger.v1.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								public/swagger.v1.json
									
									
									
									
										vendored
									
									
								
							|  | @ -187,6 +187,22 @@ | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  |     "/orgs/{org}/repos": { | ||||||
|  |       "get": { | ||||||
|  |         "produces": [ | ||||||
|  |           "application/json" | ||||||
|  |         ], | ||||||
|  |         "operationId": "orgListRepos", | ||||||
|  |         "responses": { | ||||||
|  |           "200": { | ||||||
|  |             "$ref": "#/responses/RepositoryList" | ||||||
|  |           }, | ||||||
|  |           "500": { | ||||||
|  |             "$ref": "#/responses/error" | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     "/repos/search": { |     "/repos/search": { | ||||||
|       "get": { |       "get": { | ||||||
|         "produces": [ |         "produces": [ | ||||||
|  | @ -1357,4 +1373,4 @@ | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -458,6 +458,7 @@ func RegisterRoutes(m *macaron.Macaron) { | ||||||
| 		m.Get("/user/orgs", reqToken(), org.ListMyOrgs) | 		m.Get("/user/orgs", reqToken(), org.ListMyOrgs) | ||||||
| 		m.Get("/users/:username/orgs", org.ListUserOrgs) | 		m.Get("/users/:username/orgs", org.ListUserOrgs) | ||||||
| 		m.Group("/orgs/:orgname", func() { | 		m.Group("/orgs/:orgname", func() { | ||||||
|  | 			m.Get("/repos", user.ListOrgRepos) | ||||||
| 			m.Combo("").Get(org.Get). | 			m.Combo("").Get(org.Get). | ||||||
| 				Patch(reqToken(), reqOrgOwnership(), bind(api.EditOrgOption{}), org.Edit) | 				Patch(reqToken(), reqOrgOwnership(), bind(api.EditOrgOption{}), org.Edit) | ||||||
| 			m.Group("/members", func() { | 			m.Group("/members", func() { | ||||||
|  |  | ||||||
|  | @ -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 | package user | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | @ -80,3 +84,17 @@ func ListMyRepos(ctx *context.APIContext) { | ||||||
| 	} | 	} | ||||||
| 	ctx.JSON(200, &apiRepos) | 	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) | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue