gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package org
  4. import (
  5. "net/http"
  6. api "code.gitea.io/gitea/modules/structs"
  7. "code.gitea.io/gitea/modules/web"
  8. "code.gitea.io/gitea/routers/api/v1/utils"
  9. "code.gitea.io/gitea/services/context"
  10. webhook_service "code.gitea.io/gitea/services/webhook"
  11. )
  12. // ListHooks list an organziation's webhooks
  13. func ListHooks(ctx *context.APIContext) {
  14. // swagger:operation GET /orgs/{org}/hooks organization orgListHooks
  15. // ---
  16. // summary: List an organization's webhooks
  17. // produces:
  18. // - application/json
  19. // parameters:
  20. // - name: org
  21. // in: path
  22. // description: name of the organization
  23. // type: string
  24. // required: true
  25. // - name: page
  26. // in: query
  27. // description: page number of results to return (1-based)
  28. // type: integer
  29. // - name: limit
  30. // in: query
  31. // description: page size of results
  32. // type: integer
  33. // responses:
  34. // "200":
  35. // "$ref": "#/responses/HookList"
  36. // "404":
  37. // "$ref": "#/responses/notFound"
  38. utils.ListOwnerHooks(
  39. ctx,
  40. ctx.ContextUser,
  41. )
  42. }
  43. // GetHook get an organization's hook by id
  44. func GetHook(ctx *context.APIContext) {
  45. // swagger:operation GET /orgs/{org}/hooks/{id} organization orgGetHook
  46. // ---
  47. // summary: Get a hook
  48. // produces:
  49. // - application/json
  50. // parameters:
  51. // - name: org
  52. // in: path
  53. // description: name of the organization
  54. // type: string
  55. // required: true
  56. // - name: id
  57. // in: path
  58. // description: id of the hook to get
  59. // type: integer
  60. // format: int64
  61. // required: true
  62. // responses:
  63. // "200":
  64. // "$ref": "#/responses/Hook"
  65. // "404":
  66. // "$ref": "#/responses/notFound"
  67. hook, err := utils.GetOwnerHook(ctx, ctx.ContextUser.ID, ctx.PathParamInt64("id"))
  68. if err != nil {
  69. return
  70. }
  71. apiHook, err := webhook_service.ToHook(ctx.ContextUser.HomeLink(), hook)
  72. if err != nil {
  73. ctx.APIErrorInternal(err)
  74. return
  75. }
  76. ctx.JSON(http.StatusOK, apiHook)
  77. }
  78. // CreateHook create a hook for an organization
  79. func CreateHook(ctx *context.APIContext) {
  80. // swagger:operation POST /orgs/{org}/hooks organization orgCreateHook
  81. // ---
  82. // summary: Create a hook
  83. // consumes:
  84. // - application/json
  85. // produces:
  86. // - application/json
  87. // parameters:
  88. // - name: org
  89. // in: path
  90. // description: name of the organization
  91. // type: string
  92. // required: true
  93. // - name: body
  94. // in: body
  95. // required: true
  96. // schema:
  97. // "$ref": "#/definitions/CreateHookOption"
  98. // responses:
  99. // "201":
  100. // "$ref": "#/responses/Hook"
  101. // "404":
  102. // "$ref": "#/responses/notFound"
  103. utils.AddOwnerHook(
  104. ctx,
  105. ctx.ContextUser,
  106. web.GetForm(ctx).(*api.CreateHookOption),
  107. )
  108. }
  109. // EditHook modify a hook of an organization
  110. func EditHook(ctx *context.APIContext) {
  111. // swagger:operation PATCH /orgs/{org}/hooks/{id} organization orgEditHook
  112. // ---
  113. // summary: Update a hook
  114. // consumes:
  115. // - application/json
  116. // produces:
  117. // - application/json
  118. // parameters:
  119. // - name: org
  120. // in: path
  121. // description: name of the organization
  122. // type: string
  123. // required: true
  124. // - name: id
  125. // in: path
  126. // description: id of the hook to update
  127. // type: integer
  128. // format: int64
  129. // required: true
  130. // - name: body
  131. // in: body
  132. // schema:
  133. // "$ref": "#/definitions/EditHookOption"
  134. // responses:
  135. // "200":
  136. // "$ref": "#/responses/Hook"
  137. // "404":
  138. // "$ref": "#/responses/notFound"
  139. utils.EditOwnerHook(
  140. ctx,
  141. ctx.ContextUser,
  142. web.GetForm(ctx).(*api.EditHookOption),
  143. ctx.PathParamInt64("id"),
  144. )
  145. }
  146. // DeleteHook delete a hook of an organization
  147. func DeleteHook(ctx *context.APIContext) {
  148. // swagger:operation DELETE /orgs/{org}/hooks/{id} organization orgDeleteHook
  149. // ---
  150. // summary: Delete a hook
  151. // produces:
  152. // - application/json
  153. // parameters:
  154. // - name: org
  155. // in: path
  156. // description: name of the organization
  157. // type: string
  158. // required: true
  159. // - name: id
  160. // in: path
  161. // description: id of the hook to delete
  162. // type: integer
  163. // format: int64
  164. // required: true
  165. // responses:
  166. // "204":
  167. // "$ref": "#/responses/empty"
  168. // "404":
  169. // "$ref": "#/responses/notFound"
  170. utils.DeleteOwnerHook(
  171. ctx,
  172. ctx.ContextUser,
  173. ctx.PathParamInt64("id"),
  174. )
  175. }