mirror of
https://github.com/go-gitea/gitea
synced 2024-11-21 21:11:33 +01:00
new create repo options
This commit is contained in:
parent
d07033a0f0
commit
f2de4d5c04
3 changed files with 38 additions and 44 deletions
|
@ -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))
|
||||
|
|
|
@ -28,7 +28,6 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自
|
|||
- 支持 Gravatar 以及自定义源
|
||||
- 支持邮件服务
|
||||
- 支持后台管理面板
|
||||
- 支持 Drone CI 持续部署集成
|
||||
- 支持 MySQL、PostgreSQL 以及 SQLite3 数据库
|
||||
- 支持社交帐号登录(GitHub、Google、QQ、微博)
|
||||
- 支持多语言本地化([14 种语言]([more](https://crowdin.com/project/gogs)))
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue