From 1c9dd11ba71ff261f52bf1d31aba6812d0680179 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 17 Dec 2015 22:57:41 -0500 Subject: [PATCH] #1692 API: admin create repo --- routers/api/v1/admin/repos.go | 23 +++++++++++++++++++++++ routers/api/v1/api.go | 1 + routers/api/v1/repo/repo.go | 6 +++--- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 routers/api/v1/admin/repos.go diff --git a/routers/api/v1/admin/repos.go b/routers/api/v1/admin/repos.go new file mode 100644 index 0000000000..7a6b2af20b --- /dev/null +++ b/routers/api/v1/admin/repos.go @@ -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) +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index bc7c14006e..cc169f708d 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -198,6 +198,7 @@ func RegisterRoutes(m *macaron.Macaron) { Delete(admin.DeleteUser) m.Post("/keys", admin.CreatePublicKey) m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg) + m.Post("/repos", bind(api.CreateRepoOption{}), admin.CreateRepo) }) }) }, ReqAdmin()) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 7790377910..eb00aa886f 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -113,7 +113,7 @@ func ListMyRepos(ctx *middleware.Context) { 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{ Name: opt.Name, Description: opt.Description, @@ -149,7 +149,7 @@ func Create(ctx *middleware.Context, opt api.CreateRepoOption) { ctx.APIError(422, "", "not allowed creating repository for organization") return } - createRepo(ctx, ctx.User, opt) + CreateUserRepo(ctx, ctx.User, opt) } 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.") return } - createRepo(ctx, org, opt) + CreateUserRepo(ctx, org, opt) } // https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate