Skip to content

Commit e8ea069

Browse files
6543lunnysapkzeripathlafriks
committed
[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 <[email protected]> Co-authored-by: Antoine GIRARD <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent 0752043 commit e8ea069

File tree

3 files changed

+84
-11
lines changed

3 files changed

+84
-11
lines changed

routers/api/v1/api.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -604,17 +604,15 @@ func RegisterRoutes(m *macaron.Macaron) {
604604
}, reqToken())
605605

606606
// Repositories
607-
m.Post("/org/:org/repos", reqToken(), bind(api.CreateRepoOption{}), repo.CreateOrgRepo)
607+
m.Post("/org/:org/repos", reqToken(), bind(api.CreateRepoOption{}), repo.CreateOrgRepoDeprecated)
608+
609+
m.Combo("/repositories/:id", reqToken()).Get(repo.GetByID)
608610

609611
m.Group("/repos", func() {
610612
m.Get("/search", repo.Search)
611-
})
612613

613-
m.Get("/repos/issues/search", repo.SearchIssues)
614+
m.Get("/issues/search", repo.SearchIssues)
614615

615-
m.Combo("/repositories/:id", reqToken()).Get(repo.GetByID)
616-
617-
m.Group("/repos", func() {
618616
m.Post("/migrate", reqToken(), bind(auth.MigrateRepoForm{}), repo.Migrate)
619617

620618
m.Group("/:username/:reponame", func() {
@@ -824,10 +822,11 @@ func RegisterRoutes(m *macaron.Macaron) {
824822
m.Get("/users/:username/orgs", org.ListUserOrgs)
825823
m.Post("/orgs", reqToken(), bind(api.CreateOrgOption{}), org.Create)
826824
m.Group("/orgs/:orgname", func() {
827-
m.Get("/repos", user.ListOrgRepos)
828825
m.Combo("").Get(org.Get).
829826
Patch(reqToken(), reqOrgOwnership(), bind(api.EditOrgOption{}), org.Edit).
830827
Delete(reqToken(), reqOrgOwnership(), org.Delete)
828+
m.Combo("/repos").Get(user.ListOrgRepos).
829+
Post(reqToken(), bind(api.CreateRepoOption{}), repo.CreateOrgRepo)
831830
m.Group("/members", func() {
832831
m.Get("", org.ListMembers)
833832
m.Combo("/:username").Get(org.IsMember).

routers/api/v1/repo/repo.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,12 @@ func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
283283
CreateUserRepo(ctx, ctx.User, opt)
284284
}
285285

286-
// CreateOrgRepo create one repository of the organization
287-
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
288-
// swagger:operation POST /org/{org}/repos organization createOrgRepo
286+
// CreateOrgRepoDeprecated create one repository of the organization
287+
func CreateOrgRepoDeprecated(ctx *context.APIContext, opt api.CreateRepoOption) {
288+
// swagger:operation POST /org/{org}/repos organization createOrgRepoDeprecated
289289
// ---
290290
// summary: Create a repository in an organization
291+
// deprecated: true
291292
// consumes:
292293
// - application/json
293294
// produces:
@@ -310,6 +311,37 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
310311
// "403":
311312
// "$ref": "#/responses/forbidden"
312313

314+
CreateOrgRepo(ctx, opt)
315+
}
316+
317+
// CreateOrgRepo create one repository of the organization
318+
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
319+
// swagger:operation POST /orgs/{org}/repos organization createOrgRepo
320+
// ---
321+
// summary: Create a repository in an organization
322+
// deprecated: true
323+
// consumes:
324+
// - application/json
325+
// produces:
326+
// - application/json
327+
// parameters:
328+
// - name: org
329+
// in: path
330+
// description: name of organization
331+
// type: string
332+
// required: true
333+
// - name: body
334+
// in: body
335+
// schema:
336+
// "$ref": "#/definitions/CreateRepoOption"
337+
// responses:
338+
// "201":
339+
// "$ref": "#/responses/Repository"
340+
// "404":
341+
// "$ref": "#/responses/notFound"
342+
// "403":
343+
// "$ref": "#/responses/forbidden"
344+
313345
org, err := models.GetOrgByName(ctx.Params(":org"))
314346
if err != nil {
315347
if models.IsErrOrgNotExist(err) {

templates/swagger/v1_json.tmpl

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@
574574
"organization"
575575
],
576576
"summary": "Create a repository in an organization",
577-
"operationId": "createOrgRepo",
577+
"operationId": "createOrgRepoDeprecated",
578+
"deprecated": true,
578579
"parameters": [
579580
{
580581
"type": "string",
@@ -1140,6 +1141,47 @@
11401141
"$ref": "#/responses/RepositoryList"
11411142
}
11421143
}
1144+
},
1145+
"post": {
1146+
"consumes": [
1147+
"application/json"
1148+
],
1149+
"produces": [
1150+
"application/json"
1151+
],
1152+
"tags": [
1153+
"organization"
1154+
],
1155+
"summary": "Create a repository in an organization",
1156+
"operationId": "createOrgRepo",
1157+
"deprecated": true,
1158+
"parameters": [
1159+
{
1160+
"type": "string",
1161+
"description": "name of organization",
1162+
"name": "org",
1163+
"in": "path",
1164+
"required": true
1165+
},
1166+
{
1167+
"name": "body",
1168+
"in": "body",
1169+
"schema": {
1170+
"$ref": "#/definitions/CreateRepoOption"
1171+
}
1172+
}
1173+
],
1174+
"responses": {
1175+
"201": {
1176+
"$ref": "#/responses/Repository"
1177+
},
1178+
"403": {
1179+
"$ref": "#/responses/forbidden"
1180+
},
1181+
"404": {
1182+
"$ref": "#/responses/notFound"
1183+
}
1184+
}
11431185
}
11441186
},
11451187
"/orgs/{org}/teams": {

0 commit comments

Comments
 (0)