mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:15:43 +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
|
- Gravatar and custom source support
|
||||||
- Mail service
|
- Mail service
|
||||||
- Administration panel
|
- Administration panel
|
||||||
- Drone CI integration
|
|
||||||
- Supports MySQL, PostgreSQL and SQLite3
|
- Supports MySQL, PostgreSQL and SQLite3
|
||||||
- Social account login (GitHub, Google, QQ, Weibo)
|
- Social account login (GitHub, Google, QQ, Weibo)
|
||||||
- Multi-language support ([14 languages](https://crowdin.com/project/gogs))
|
- Multi-language support ([14 languages](https://crowdin.com/project/gogs))
|
||||||
|
|
|
@ -28,7 +28,6 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自
|
||||||
- 支持 Gravatar 以及自定义源
|
- 支持 Gravatar 以及自定义源
|
||||||
- 支持邮件服务
|
- 支持邮件服务
|
||||||
- 支持后台管理面板
|
- 支持后台管理面板
|
||||||
- 支持 Drone CI 持续部署集成
|
|
||||||
- 支持 MySQL、PostgreSQL 以及 SQLite3 数据库
|
- 支持 MySQL、PostgreSQL 以及 SQLite3 数据库
|
||||||
- 支持社交帐号登录(GitHub、Google、QQ、微博)
|
- 支持社交帐号登录(GitHub、Google、QQ、微博)
|
||||||
- 支持多语言本地化([14 种语言]([more](https://crowdin.com/project/gogs)))
|
- 支持多语言本地化([14 种语言]([more](https://crowdin.com/project/gogs)))
|
||||||
|
|
|
@ -100,13 +100,46 @@ 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) {
|
func createRepo(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,
|
||||||
Gitignores: opt.Gitignore,
|
Gitignores: opt.Gitignores,
|
||||||
License: opt.License,
|
License: opt.License,
|
||||||
// Readme: form.Readme,
|
Readme: opt.Readme,
|
||||||
IsPrivate: opt.Private,
|
IsPrivate: opt.Private,
|
||||||
AutoInit: opt.AutoInit,
|
AutoInit: opt.AutoInit,
|
||||||
})
|
})
|
||||||
|
@ -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}))
|
ctx.JSON(201, ToApiRepository(owner, repo, api.Permission{true, true, true}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /user/repos
|
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
|
||||||
// https://developer.github.com/v3/repos/#create
|
|
||||||
func CreateRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
|
func CreateRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
|
||||||
// Shouldn't reach this condition, but just in case.
|
// Shouldn't reach this condition, but just in case.
|
||||||
if ctx.User.IsOrganization() {
|
if ctx.User.IsOrganization() {
|
||||||
|
@ -141,8 +173,6 @@ func CreateRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
|
||||||
createRepo(ctx, ctx.User, opt)
|
createRepo(ctx, ctx.User, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /orgs/:org/repos
|
|
||||||
// https://developer.github.com/v3/repos/#create
|
|
||||||
func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
|
func CreateOrgRepo(ctx *middleware.Context, opt api.CreateRepoOption) {
|
||||||
org, err := models.GetOrgByName(ctx.Params(":org"))
|
org, err := models.GetOrgByName(ctx.Params(":org"))
|
||||||
if err != nil {
|
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)
|
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
||||||
ctx.WriteHeader(200)
|
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