You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_hooks.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package v1
  5. import (
  6. "github.com/gogits/gogs/models"
  7. "github.com/gogits/gogs/modules/middleware"
  8. )
  9. type apiHookConfig struct {
  10. Url string `json:"url"`
  11. ContentType string `json:"content_type"`
  12. }
  13. type ApiHook struct {
  14. Id int64 `json:"id"`
  15. Type string `json:"type"`
  16. Events []string `json:"events"`
  17. Active bool `json:"active"`
  18. Config apiHookConfig `json:"config"`
  19. }
  20. // /repos/:username/:reponame/hooks: https://developer.github.com/v3/repos/hooks/#list-hooks
  21. func ListRepoHooks(ctx *middleware.Context) {
  22. hooks, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.Id)
  23. if err != nil {
  24. ctx.JSON(500, map[string]interface{}{
  25. "ok": false,
  26. "error": err.Error(),
  27. })
  28. return
  29. }
  30. apiHooks := make([]*ApiHook, len(hooks))
  31. for i := range hooks {
  32. apiHooks[i] = &ApiHook{
  33. Id: hooks[i].Id,
  34. Type: hooks[i].HookTaskType.Name(),
  35. Active: hooks[i].IsActive,
  36. Config: apiHookConfig{hooks[i].Url, hooks[i].ContentType.Name()},
  37. }
  38. // Currently, onle have push event.
  39. apiHooks[i].Events = []string{"push"}
  40. }
  41. ctx.JSON(200, &apiHooks)
  42. }