From f2de4d5c04fe5cd090fd448ec44658d8dd0ea5e4 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 28 Aug 2015 19:06:18 +0800 Subject: [PATCH] new create repo options --- README.md | 1 - README_ZH.md | 1 - routers/api/v1/repo.go | 80 ++++++++++++++++++++---------------------- 3 files changed, 38 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 1296265b66..6d526b40a2 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,6 @@ The goal of this project is to make the easiest, fastest, and most painless way - Gravatar and custom source support - Mail service - Administration panel -- Drone CI integration - Supports MySQL, PostgreSQL and SQLite3 - Social account login (GitHub, Google, QQ, Weibo) - Multi-language support ([14 languages](https://crowdin.com/project/gogs)) diff --git a/README_ZH.md b/README_ZH.md index cd72a0ce9e..a5241c556e 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -28,7 +28,6 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自 - 支持 Gravatar 以及自定义源 - 支持邮件服务 - 支持后台管理面板 -- 支持 Drone CI 持续部署集成 - 支持 MySQL、PostgreSQL 以及 SQLite3 数据库 - 支持社交帐号登录(GitHub、Google、QQ、微博) - 支持多语言本地化([14 种语言]([more](https://crowdin.com/project/gogs))) diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go index 1ac3e22559..9126ba3769 100644 --- a/routers/api/v1/repo.go +++ b/routers/api/v1/repo.go @@ -100,15 +100,48 @@ func SearchRepos(ctx *middleware.Context) { }) } +// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories +func ListMyRepos(ctx *middleware.Context) { + ownRepos, err := models.GetRepositories(ctx.User.Id, true) + if err != nil { + ctx.JSON(500, &base.ApiJsonErr{"GetRepositories: " + err.Error(), base.DOC_URL}) + return + } + numOwnRepos := len(ownRepos) + + accessibleRepos, err := ctx.User.GetAccessibleRepositories() + if err != nil { + ctx.JSON(500, &base.ApiJsonErr{"GetAccessibleRepositories: " + err.Error(), base.DOC_URL}) + return + } + + repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos)) + for i := range ownRepos { + repos[i] = ToApiRepository(ctx.User, ownRepos[i], api.Permission{true, true, true}) + } + i := numOwnRepos + + for repo, access := range accessibleRepos { + repos[i] = ToApiRepository(repo.Owner, repo, api.Permission{ + Admin: access >= models.ACCESS_MODE_ADMIN, + Push: access >= models.ACCESS_MODE_WRITE, + Pull: true, + }) + i++ + } + + ctx.JSON(200, &repos) +} + func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoOption) { repo, err := models.CreateRepository(owner, models.CreateRepoOptions{ Name: opt.Name, Description: opt.Description, - Gitignores: opt.Gitignore, + Gitignores: opt.Gitignores, License: opt.License, - // Readme: form.Readme, - IsPrivate: opt.Private, - AutoInit: opt.AutoInit, + Readme: opt.Readme, + IsPrivate: opt.Private, + AutoInit: opt.AutoInit, }) if err != nil { if models.IsErrRepoAlreadyExist(err) || @@ -130,8 +163,7 @@ func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoO ctx.JSON(201, ToApiRepository(owner, repo, api.Permission{true, true, true})) } -// POST /user/repos -// https://developer.github.com/v3/repos/#create +// https://github.com/gogits/go-gogs-client/wiki/Repositories#create func CreateRepo(ctx *middleware.Context, opt api.CreateRepoOption) { // Shouldn't reach this condition, but just in case. if ctx.User.IsOrganization() { @@ -141,8 +173,6 @@ func CreateRepo(ctx *middleware.Context, opt api.CreateRepoOption) { createRepo(ctx, ctx.User, opt) } -// POST /orgs/:org/repos -// https://developer.github.com/v3/repos/#create func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) { org, err := models.GetOrgByName(ctx.Params(":org")) if err != nil { @@ -237,37 +267,3 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) { log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) ctx.WriteHeader(200) } - -// GET /user/repos -// https://developer.github.com/v3/repos/#list-your-repositories -func ListMyRepos(ctx *middleware.Context) { - ownRepos, err := models.GetRepositories(ctx.User.Id, true) - if err != nil { - ctx.JSON(500, &base.ApiJsonErr{"GetRepositories: " + err.Error(), base.DOC_URL}) - return - } - numOwnRepos := len(ownRepos) - - accessibleRepos, err := ctx.User.GetAccessibleRepositories() - if err != nil { - ctx.JSON(500, &base.ApiJsonErr{"GetAccessibleRepositories: " + err.Error(), base.DOC_URL}) - return - } - - repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos)) - for i := range ownRepos { - repos[i] = ToApiRepository(ctx.User, ownRepos[i], api.Permission{true, true, true}) - } - i := numOwnRepos - - for repo, access := range accessibleRepos { - repos[i] = ToApiRepository(repo.Owner, repo, api.Permission{ - Admin: access >= models.ACCESS_MODE_ADMIN, - Push: access >= models.ACCESS_MODE_WRITE, - Pull: true, - }) - i++ - } - - ctx.JSON(200, &repos) -}