mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-24 01:34:07 +01:00
#1692 API: admin create repo
This commit is contained in:
parent
1e7e092992
commit
1c9dd11ba7
3 changed files with 27 additions and 3 deletions
23
routers/api/v1/admin/repos.go
Normal file
23
routers/api/v1/admin/repos.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright 2015 The Gogs 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 admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
api "github.com/gogits/go-gogs-client"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
|
"github.com/gogits/gogs/routers/api/v1/repo"
|
||||||
|
"github.com/gogits/gogs/routers/api/v1/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// https://github.com/gogits/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
|
||||||
|
func CreateRepo(ctx *middleware.Context, form api.CreateRepoOption) {
|
||||||
|
owner := user.GetUserByParams(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.CreateUserRepo(ctx, owner, form)
|
||||||
|
}
|
|
@ -198,6 +198,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
Delete(admin.DeleteUser)
|
Delete(admin.DeleteUser)
|
||||||
m.Post("/keys", admin.CreatePublicKey)
|
m.Post("/keys", admin.CreatePublicKey)
|
||||||
m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg)
|
m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg)
|
||||||
|
m.Post("/repos", bind(api.CreateRepoOption{}), admin.CreateRepo)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}, ReqAdmin())
|
}, ReqAdmin())
|
||||||
|
|
|
@ -113,7 +113,7 @@ func ListMyRepos(ctx *middleware.Context) {
|
||||||
ctx.JSON(200, &repos)
|
ctx.JSON(200, &repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoOption) {
|
func CreateUserRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoOption) {
|
||||||
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{
|
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{
|
||||||
Name: opt.Name,
|
Name: opt.Name,
|
||||||
Description: opt.Description,
|
Description: opt.Description,
|
||||||
|
@ -149,7 +149,7 @@ func Create(ctx *middleware.Context, opt api.CreateRepoOption) {
|
||||||
ctx.APIError(422, "", "not allowed creating repository for organization")
|
ctx.APIError(422, "", "not allowed creating repository for organization")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
createRepo(ctx, ctx.User, opt)
|
CreateUserRepo(ctx, ctx.User, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
|
func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
|
||||||
|
@ -167,7 +167,7 @@ func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
|
||||||
ctx.APIError(403, "", "Given user is not owner of organization.")
|
ctx.APIError(403, "", "Given user is not owner of organization.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
createRepo(ctx, org, opt)
|
CreateUserRepo(ctx, org, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
|
// https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
|
||||||
|
|
Loading…
Reference in a new issue