#12, use go-gogs-client
This commit is contained in:
parent
437dd5272f
commit
52d66ba6c8
11 changed files with 48 additions and 74 deletions
|
@ -13,6 +13,7 @@ github.com/codegangsta/cli = commit:7381bc4e62
|
||||||
github.com/go-sql-driver/mysql = commit:8111ee3ec3
|
github.com/go-sql-driver/mysql = commit:8111ee3ec3
|
||||||
github.com/go-xorm/core =
|
github.com/go-xorm/core =
|
||||||
github.com/go-xorm/xorm =
|
github.com/go-xorm/xorm =
|
||||||
|
github.com/gogits/go-gogs-client =
|
||||||
github.com/gogits/oauth2 = commit:99cbec870a
|
github.com/gogits/oauth2 = commit:99cbec870a
|
||||||
github.com/lib/pq = commit:b021d0ef20
|
github.com/lib/pq = commit:b021d0ef20
|
||||||
github.com/macaron-contrib/binding =
|
github.com/macaron-contrib/binding =
|
||||||
|
|
|
@ -184,7 +184,7 @@ func runWeb(*cli.Context) {
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Any("/*", func(ctx *middleware.Context) {
|
m.Any("/*", func(ctx *middleware.Context) {
|
||||||
ctx.JSON(404, &base.ApiJsonErr{"Not Found", v1.DOC_URL})
|
ctx.JSON(404, &base.ApiJsonErr{"Not Found", base.DOC_URL})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.5.8.1113 Beta"
|
const APP_VER = "0.5.8.1114 Beta"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -72,6 +72,8 @@ type Webhook struct {
|
||||||
HookTaskType HookTaskType
|
HookTaskType HookTaskType
|
||||||
Meta string `xorm:"TEXT"` // store hook-specific attributes
|
Meta string `xorm:"TEXT"` // store hook-specific attributes
|
||||||
OrgId int64
|
OrgId int64
|
||||||
|
Created time.Time `xorm:"CREATED"`
|
||||||
|
Updated time.Time `xorm:"UPDATED"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEvent handles conversion from Events to HookEvent.
|
// GetEvent handles conversion from Events to HookEvent.
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
package base
|
package base
|
||||||
|
|
||||||
|
const DOC_URL = "http://gogs.io/docs"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
TplName string
|
TplName string
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,12 @@ import (
|
||||||
"github.com/Unknwon/macaron"
|
"github.com/Unknwon/macaron"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
|
"github.com/gogits/gogs/modules/base"
|
||||||
"github.com/gogits/gogs/modules/git"
|
"github.com/gogits/gogs/modules/git"
|
||||||
"github.com/gogits/gogs/modules/log"
|
"github.com/gogits/gogs/modules/log"
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FIXME: response error in JSON.
|
|
||||||
func ApiRepoAssignment() macaron.Handler {
|
func ApiRepoAssignment() macaron.Handler {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
userName := ctx.Params(":username")
|
userName := ctx.Params(":username")
|
||||||
|
@ -33,7 +33,7 @@ func ApiRepoAssignment() macaron.Handler {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
ctx.Repo.IsOwner, err = models.HasAccess(ctx.User.Name, userName+"/"+repoName, models.WRITABLE)
|
ctx.Repo.IsOwner, err = models.HasAccess(ctx.User.Name, userName+"/"+repoName, models.WRITABLE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "HasAccess", err)
|
ctx.JSON(500, &base.ApiJsonErr{"HasAccess: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Repo.IsTrueOwner = ctx.User.LowerName == strings.ToLower(userName)
|
ctx.Repo.IsTrueOwner = ctx.User.LowerName == strings.ToLower(userName)
|
||||||
|
@ -45,7 +45,7 @@ func ApiRepoAssignment() macaron.Handler {
|
||||||
if err == models.ErrUserNotExist {
|
if err == models.ErrUserNotExist {
|
||||||
ctx.Error(404)
|
ctx.Error(404)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "GetUserByName", err)
|
ctx.JSON(500, &base.ApiJsonErr{"GetUserByName: " + err.Error(), base.DOC_URL})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,10 @@ func ApiRepoAssignment() macaron.Handler {
|
||||||
ctx.Error(404)
|
ctx.Error(404)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Handle(500, "GetRepositoryByName", err)
|
ctx.JSON(500, &base.ApiJsonErr{"GetRepositoryByName: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
} else if err = repo.GetOwner(); err != nil {
|
} else if err = repo.GetOwner(); err != nil {
|
||||||
ctx.Handle(500, "GetOwner", err)
|
ctx.JSON(500, &base.ApiJsonErr{"GetOwner: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ func ApiRepoAssignment() macaron.Handler {
|
||||||
if u.IsOrganization() {
|
if u.IsOrganization() {
|
||||||
auth, err := models.GetHighestAuthorize(u.Id, ctx.User.Id, repo.Id, 0)
|
auth, err := models.GetHighestAuthorize(u.Id, ctx.User.Id, repo.Id, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "GetHighestAuthorize", err)
|
ctx.JSON(500, &base.ApiJsonErr{"GetHighestAuthorize: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if auth == models.ORG_ADMIN {
|
if auth == models.ORG_ADMIN {
|
||||||
|
@ -101,7 +101,7 @@ func ApiRepoAssignment() macaron.Handler {
|
||||||
|
|
||||||
hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+repo.Name, models.READABLE)
|
hasAccess, err := models.HasAccess(ctx.User.Name, ctx.Repo.Owner.Name+"/"+repo.Name, models.READABLE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "HasAccess", err)
|
ctx.JSON(500, &base.ApiJsonErr{"HasAccess: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
} else if !hasAccess {
|
} else if !hasAccess {
|
||||||
ctx.Error(404)
|
ctx.Error(404)
|
||||||
|
|
|
@ -13,12 +13,10 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DOC_URL = "http://gogs.io/docs"
|
|
||||||
|
|
||||||
// Render an arbitrary Markdown document.
|
// Render an arbitrary Markdown document.
|
||||||
func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) {
|
func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) {
|
||||||
if ctx.HasApiError() {
|
if ctx.HasApiError() {
|
||||||
ctx.JSON(422, base.ApiJsonErr{ctx.GetErrMsg(), DOC_URL})
|
ctx.JSON(422, base.ApiJsonErr{ctx.GetErrMsg(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +33,7 @@ func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) {
|
||||||
func MarkdownRaw(ctx *middleware.Context) {
|
func MarkdownRaw(ctx *middleware.Context) {
|
||||||
body, err := ctx.Req.Body().Bytes()
|
body, err := ctx.Req.Body().Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(422, base.ApiJsonErr{err.Error(), DOC_URL})
|
ctx.JSON(422, base.ApiJsonErr{err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Write(base.RenderRawMarkdown(body, ""))
|
ctx.Write(base.RenderRawMarkdown(body, ""))
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
|
|
||||||
|
api "github.com/gogits/go-gogs-client"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/auth"
|
"github.com/gogits/gogs/modules/auth"
|
||||||
"github.com/gogits/gogs/modules/log"
|
"github.com/gogits/gogs/modules/log"
|
||||||
|
@ -18,24 +20,6 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ApiPermission struct {
|
|
||||||
Admin bool `json:"admin"`
|
|
||||||
Push bool `json:"push"`
|
|
||||||
Pull bool `json:"pull"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ApiRepository struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Owner ApiUser `json:"owner"`
|
|
||||||
FullName string `json:"full_name"`
|
|
||||||
Private bool `json:"private"`
|
|
||||||
Fork bool `json:"fork"`
|
|
||||||
HtmlUrl string `json:"html_url"`
|
|
||||||
CloneUrl string `json:"clone_url"`
|
|
||||||
SshUrl string `json:"ssh_url"`
|
|
||||||
Permissions ApiPermission `json:"permissions"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func SearchRepos(ctx *middleware.Context) {
|
func SearchRepos(ctx *middleware.Context) {
|
||||||
opt := models.SearchOption{
|
opt := models.SearchOption{
|
||||||
Keyword: path.Base(ctx.Query("q")),
|
Keyword: path.Base(ctx.Query("q")),
|
||||||
|
@ -75,7 +59,7 @@ func SearchRepos(ctx *middleware.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]*ApiRepository, len(repos))
|
results := make([]*api.Repository, len(repos))
|
||||||
for i := range repos {
|
for i := range repos {
|
||||||
if err = repos[i].GetOwner(); err != nil {
|
if err = repos[i].GetOwner(); err != nil {
|
||||||
ctx.JSON(500, map[string]interface{}{
|
ctx.JSON(500, map[string]interface{}{
|
||||||
|
@ -84,7 +68,7 @@ func SearchRepos(ctx *middleware.Context) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
results[i] = &ApiRepository{
|
results[i] = &api.Repository{
|
||||||
Id: repos[i].Id,
|
Id: repos[i].Id,
|
||||||
FullName: path.Join(repos[i].Owner.Name, repos[i].Name),
|
FullName: path.Join(repos[i].Owner.Name, repos[i].Name),
|
||||||
}
|
}
|
||||||
|
@ -199,12 +183,12 @@ func ListMyRepos(ctx *middleware.Context) {
|
||||||
sshUrlFmt = "ssh://%s@%s:%d/%s/%s.git"
|
sshUrlFmt = "ssh://%s@%s:%d/%s/%s.git"
|
||||||
}
|
}
|
||||||
|
|
||||||
repos := make([]*ApiRepository, numOwnRepos+len(collaRepos))
|
repos := make([]*api.Repository, numOwnRepos+len(collaRepos))
|
||||||
// FIXME: make only one loop
|
// FIXME: make only one loop
|
||||||
for i := range ownRepos {
|
for i := range ownRepos {
|
||||||
repos[i] = &ApiRepository{
|
repos[i] = &api.Repository{
|
||||||
Id: ownRepos[i].Id,
|
Id: ownRepos[i].Id,
|
||||||
Owner: ApiUser{
|
Owner: api.User{
|
||||||
Id: ctx.User.Id,
|
Id: ctx.User.Id,
|
||||||
UserName: ctx.User.Name,
|
UserName: ctx.User.Name,
|
||||||
AvatarUrl: string(setting.Protocol) + ctx.User.AvatarLink(),
|
AvatarUrl: string(setting.Protocol) + ctx.User.AvatarLink(),
|
||||||
|
@ -214,7 +198,7 @@ func ListMyRepos(ctx *middleware.Context) {
|
||||||
Fork: ownRepos[i].IsFork,
|
Fork: ownRepos[i].IsFork,
|
||||||
HtmlUrl: setting.AppUrl + ctx.User.Name + "/" + ownRepos[i].Name,
|
HtmlUrl: setting.AppUrl + ctx.User.Name + "/" + ownRepos[i].Name,
|
||||||
SshUrl: fmt.Sprintf(sshUrlFmt, setting.RunUser, setting.Domain, ctx.User.LowerName, ownRepos[i].LowerName),
|
SshUrl: fmt.Sprintf(sshUrlFmt, setting.RunUser, setting.Domain, ctx.User.LowerName, ownRepos[i].LowerName),
|
||||||
Permissions: ApiPermission{true, true, true},
|
Permissions: api.Permission{true, true, true},
|
||||||
}
|
}
|
||||||
repos[i].CloneUrl = repos[i].HtmlUrl + ".git"
|
repos[i].CloneUrl = repos[i].HtmlUrl + ".git"
|
||||||
}
|
}
|
||||||
|
@ -227,9 +211,9 @@ func ListMyRepos(ctx *middleware.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
j := i + numOwnRepos
|
j := i + numOwnRepos
|
||||||
repos[j] = &ApiRepository{
|
repos[j] = &api.Repository{
|
||||||
Id: collaRepos[i].Id,
|
Id: collaRepos[i].Id,
|
||||||
Owner: ApiUser{
|
Owner: api.User{
|
||||||
Id: collaRepos[i].Owner.Id,
|
Id: collaRepos[i].Owner.Id,
|
||||||
UserName: collaRepos[i].Owner.Name,
|
UserName: collaRepos[i].Owner.Name,
|
||||||
AvatarUrl: string(setting.Protocol) + collaRepos[i].Owner.AvatarLink(),
|
AvatarUrl: string(setting.Protocol) + collaRepos[i].Owner.AvatarLink(),
|
||||||
|
@ -239,7 +223,7 @@ func ListMyRepos(ctx *middleware.Context) {
|
||||||
Fork: collaRepos[i].IsFork,
|
Fork: collaRepos[i].IsFork,
|
||||||
HtmlUrl: setting.AppUrl + collaRepos[i].Owner.Name + "/" + collaRepos[i].Name,
|
HtmlUrl: setting.AppUrl + collaRepos[i].Owner.Name + "/" + collaRepos[i].Name,
|
||||||
SshUrl: fmt.Sprintf(sshUrlFmt, setting.RunUser, setting.Domain, collaRepos[i].Owner.LowerName, collaRepos[i].LowerName),
|
SshUrl: fmt.Sprintf(sshUrlFmt, setting.RunUser, setting.Domain, collaRepos[i].Owner.LowerName, collaRepos[i].LowerName),
|
||||||
Permissions: ApiPermission{false, collaRepos[i].CanPush, true},
|
Permissions: api.Permission{false, collaRepos[i].CanPush, true},
|
||||||
}
|
}
|
||||||
repos[j].CloneUrl = repos[j].HtmlUrl + ".git"
|
repos[j].CloneUrl = repos[j].HtmlUrl + ".git"
|
||||||
|
|
||||||
|
|
|
@ -7,34 +7,25 @@ package v1
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
api "github.com/gogits/go-gogs-client"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ApiHook struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Events []string `json:"events"`
|
|
||||||
Active bool `json:"active"`
|
|
||||||
Config map[string]string `json:"config"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET /repos/:username/:reponame/hooks
|
// GET /repos/:username/:reponame/hooks
|
||||||
// https://developer.github.com/v3/repos/hooks/#list-hooks
|
// https://developer.github.com/v3/repos/hooks/#list-hooks
|
||||||
func ListRepoHooks(ctx *middleware.Context) {
|
func ListRepoHooks(ctx *middleware.Context) {
|
||||||
hooks, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.Id)
|
hooks, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, map[string]interface{}{
|
ctx.JSON(500, &base.ApiJsonErr{"GetWebhooksByRepoId: " + err.Error(), base.DOC_URL})
|
||||||
"ok": false,
|
|
||||||
"error": err.Error(),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiHooks := make([]*ApiHook, len(hooks))
|
apiHooks := make([]*api.Hook, len(hooks))
|
||||||
for i := range hooks {
|
for i := range hooks {
|
||||||
h := &ApiHook{
|
h := &api.Hook{
|
||||||
Id: hooks[i].Id,
|
Id: hooks[i].Id,
|
||||||
Type: hooks[i].HookTaskType.Name(),
|
Type: hooks[i].HookTaskType.Name(),
|
||||||
Active: hooks[i].IsActive,
|
Active: hooks[i].IsActive,
|
||||||
|
@ -67,17 +58,17 @@ type CreateRepoHookForm struct {
|
||||||
// https://developer.github.com/v3/repos/hooks/#create-a-hook
|
// https://developer.github.com/v3/repos/hooks/#create-a-hook
|
||||||
func CreateRepoHook(ctx *middleware.Context, form CreateRepoHookForm) {
|
func CreateRepoHook(ctx *middleware.Context, form CreateRepoHookForm) {
|
||||||
if !models.IsValidHookTaskType(form.Type) {
|
if !models.IsValidHookTaskType(form.Type) {
|
||||||
ctx.JSON(422, &base.ApiJsonErr{"invalid hook type", DOC_URL})
|
ctx.JSON(422, &base.ApiJsonErr{"invalid hook type", base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, name := range []string{"url", "content_type"} {
|
for _, name := range []string{"url", "content_type"} {
|
||||||
if _, ok := form.Config[name]; !ok {
|
if _, ok := form.Config[name]; !ok {
|
||||||
ctx.JSON(422, &base.ApiJsonErr{"missing config option: " + name, DOC_URL})
|
ctx.JSON(422, &base.ApiJsonErr{"missing config option: " + name, base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !models.IsValidHookContentType(form.Config["content_type"]) {
|
if !models.IsValidHookContentType(form.Config["content_type"]) {
|
||||||
ctx.JSON(422, &base.ApiJsonErr{"invalid content type", DOC_URL})
|
ctx.JSON(422, &base.ApiJsonErr{"invalid content type", base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,24 +86,24 @@ func CreateRepoHook(ctx *middleware.Context, form CreateRepoHookForm) {
|
||||||
if w.HookTaskType == models.SLACK {
|
if w.HookTaskType == models.SLACK {
|
||||||
channel, ok := form.Config["channel"]
|
channel, ok := form.Config["channel"]
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.JSON(422, &base.ApiJsonErr{"missing config option: channel", DOC_URL})
|
ctx.JSON(422, &base.ApiJsonErr{"missing config option: channel", base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
meta, err := json.Marshal(&models.Slack{
|
meta, err := json.Marshal(&models.Slack{
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, &base.ApiJsonErr{"slack: JSON marshal failed: " + err.Error(), DOC_URL})
|
ctx.JSON(500, &base.ApiJsonErr{"slack: JSON marshal failed: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Meta = string(meta)
|
w.Meta = string(meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := w.UpdateEvent(); err != nil {
|
if err := w.UpdateEvent(); err != nil {
|
||||||
ctx.JSON(500, &base.ApiJsonErr{"UpdateEvent: " + err.Error(), DOC_URL})
|
ctx.JSON(500, &base.ApiJsonErr{"UpdateEvent: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
} else if err := models.CreateWebhook(w); err != nil {
|
} else if err := models.CreateWebhook(w); err != nil {
|
||||||
ctx.JSON(500, &base.ApiJsonErr{"CreateWebhook: " + err.Error(), DOC_URL})
|
ctx.JSON(500, &base.ApiJsonErr{"CreateWebhook: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +122,7 @@ type EditRepoHookForm struct {
|
||||||
func EditRepoHook(ctx *middleware.Context, form EditRepoHookForm) {
|
func EditRepoHook(ctx *middleware.Context, form EditRepoHookForm) {
|
||||||
w, err := models.GetWebhookById(ctx.ParamsInt64(":id"))
|
w, err := models.GetWebhookById(ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, &base.ApiJsonErr{"GetWebhookById: " + err.Error(), DOC_URL})
|
ctx.JSON(500, &base.ApiJsonErr{"GetWebhookById: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +132,7 @@ func EditRepoHook(ctx *middleware.Context, form EditRepoHookForm) {
|
||||||
}
|
}
|
||||||
if ct, ok := form.Config["content_type"]; ok {
|
if ct, ok := form.Config["content_type"]; ok {
|
||||||
if !models.IsValidHookContentType(ct) {
|
if !models.IsValidHookContentType(ct) {
|
||||||
ctx.JSON(422, &base.ApiJsonErr{"invalid content type", DOC_URL})
|
ctx.JSON(422, &base.ApiJsonErr{"invalid content type", base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.ContentType = models.ToHookContentType(ct)
|
w.ContentType = models.ToHookContentType(ct)
|
||||||
|
@ -153,7 +144,7 @@ func EditRepoHook(ctx *middleware.Context, form EditRepoHookForm) {
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, &base.ApiJsonErr{"slack: JSON marshal failed: " + err.Error(), DOC_URL})
|
ctx.JSON(500, &base.ApiJsonErr{"slack: JSON marshal failed: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Meta = string(meta)
|
w.Meta = string(meta)
|
||||||
|
@ -167,7 +158,7 @@ func EditRepoHook(ctx *middleware.Context, form EditRepoHookForm) {
|
||||||
|
|
||||||
// FIXME: edit events
|
// FIXME: edit events
|
||||||
if err := models.UpdateWebhook(w); err != nil {
|
if err := models.UpdateWebhook(w); err != nil {
|
||||||
ctx.JSON(500, &base.ApiJsonErr{"UpdateWebhook: " + err.Error(), DOC_URL})
|
ctx.JSON(500, &base.ApiJsonErr{"UpdateWebhook: " + err.Error(), base.DOC_URL})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,12 @@ package v1
|
||||||
import (
|
import (
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
|
|
||||||
|
api "github.com/gogits/go-gogs-client"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ApiUser struct {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
UserName string `json:"username"`
|
|
||||||
AvatarUrl string `json:"avatar_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func SearchUsers(ctx *middleware.Context) {
|
func SearchUsers(ctx *middleware.Context) {
|
||||||
opt := models.SearchOption{
|
opt := models.SearchOption{
|
||||||
Keyword: ctx.Query("q"),
|
Keyword: ctx.Query("q"),
|
||||||
|
@ -35,9 +31,9 @@ func SearchUsers(ctx *middleware.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]*ApiUser, len(us))
|
results := make([]*api.User, len(us))
|
||||||
for i := range us {
|
for i := range us {
|
||||||
results[i] = &ApiUser{
|
results[i] = &api.User{
|
||||||
UserName: us[i].Name,
|
UserName: us[i].Name,
|
||||||
AvatarUrl: us[i].AvatarLink(),
|
AvatarUrl: us[i].AvatarLink(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.5.8.1113 Beta
|
0.5.8.1114 Beta
|
Reference in a new issue