1
0
Fork 0

[API] creat org repo call same as github (#9186)

* deprecate /api/v1/org/{org}/repos in favour of /api/v1/orgs/{org}/repos + cleanup api repository routes a bit

* remove redundant code

* use upstream function for api cal

* make generate-swagger

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
6543 2020-01-09 17:40:01 +01:00 committed by zeripath
parent 07520431ae
commit e8ea0695b0
3 changed files with 85 additions and 12 deletions

View file

@ -604,17 +604,15 @@ func RegisterRoutes(m *macaron.Macaron) {
}, reqToken()) }, reqToken())
// Repositories // Repositories
m.Post("/org/:org/repos", reqToken(), bind(api.CreateRepoOption{}), repo.CreateOrgRepo) m.Post("/org/:org/repos", reqToken(), bind(api.CreateRepoOption{}), repo.CreateOrgRepoDeprecated)
m.Group("/repos", func() {
m.Get("/search", repo.Search)
})
m.Get("/repos/issues/search", repo.SearchIssues)
m.Combo("/repositories/:id", reqToken()).Get(repo.GetByID) m.Combo("/repositories/:id", reqToken()).Get(repo.GetByID)
m.Group("/repos", func() { m.Group("/repos", func() {
m.Get("/search", repo.Search)
m.Get("/issues/search", repo.SearchIssues)
m.Post("/migrate", reqToken(), bind(auth.MigrateRepoForm{}), repo.Migrate) m.Post("/migrate", reqToken(), bind(auth.MigrateRepoForm{}), repo.Migrate)
m.Group("/:username/:reponame", func() { m.Group("/:username/:reponame", func() {
@ -824,10 +822,11 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/users/:username/orgs", org.ListUserOrgs) m.Get("/users/:username/orgs", org.ListUserOrgs)
m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create) m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create)
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).
Delete(reqToken(), reqOrgOwnership(), org.Delete) Delete(reqToken(), reqOrgOwnership(), org.Delete)
m.Combo("/repos").Get(user.ListOrgRepos).
Post(reqToken(), bind(api.CreateRepoOption{}), repo.CreateOrgRepo)
m.Group("/members", func() { m.Group("/members", func() {
m.Get("", org.ListMembers) m.Get("", org.ListMembers)
m.Combo("/:username").Get(org.IsMember). m.Combo("/:username").Get(org.IsMember).

View file

@ -283,11 +283,12 @@ func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
CreateUserRepo(ctx, ctx.User, opt) CreateUserRepo(ctx, ctx.User, opt)
} }
// CreateOrgRepo create one repository of the organization // CreateOrgRepoDeprecated create one repository of the organization
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) { func CreateOrgRepoDeprecated(ctx *context.APIContext, opt api.CreateRepoOption) {
// swagger:operation POST /org/{org}/repos organization createOrgRepo // swagger:operation POST /org/{org}/repos organization createOrgRepoDeprecated
// --- // ---
// summary: Create a repository in an organization // summary: Create a repository in an organization
// deprecated: true
// consumes: // consumes:
// - application/json // - application/json
// produces: // produces:
@ -310,6 +311,37 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
// "403": // "403":
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
CreateOrgRepo(ctx, opt)
}
// CreateOrgRepo create one repository of the organization
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
// swagger:operation POST /orgs/{org}/repos organization createOrgRepo
// ---
// summary: Create a repository in an organization
// deprecated: true
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: org
// in: path
// description: name of organization
// type: string
// required: true
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/CreateRepoOption"
// responses:
// "201":
// "$ref": "#/responses/Repository"
// "404":
// "$ref": "#/responses/notFound"
// "403":
// "$ref": "#/responses/forbidden"
org, err := models.GetOrgByName(ctx.Params(":org")) org, err := models.GetOrgByName(ctx.Params(":org"))
if err != nil { if err != nil {
if models.IsErrOrgNotExist(err) { if models.IsErrOrgNotExist(err) {

View file

@ -574,7 +574,8 @@
"organization" "organization"
], ],
"summary": "Create a repository in an organization", "summary": "Create a repository in an organization",
"operationId": "createOrgRepo", "operationId": "createOrgRepoDeprecated",
"deprecated": true,
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
@ -1140,6 +1141,47 @@
"$ref": "#/responses/RepositoryList" "$ref": "#/responses/RepositoryList"
} }
} }
},
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"organization"
],
"summary": "Create a repository in an organization",
"operationId": "createOrgRepo",
"deprecated": true,
"parameters": [
{
"type": "string",
"description": "name of organization",
"name": "org",
"in": "path",
"required": true
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/CreateRepoOption"
}
}
],
"responses": {
"201": {
"$ref": "#/responses/Repository"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
}
}
} }
}, },
"/orgs/{org}/teams": { "/orgs/{org}/teams": {