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.

186 lines
4.5 KiB

API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
4 years ago
  1. // Copyright 2016 The Gitea 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 org
  5. import (
  6. "net/http"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/convert"
  10. api "code.gitea.io/gitea/modules/structs"
  11. "code.gitea.io/gitea/routers/api/v1/utils"
  12. )
  13. // ListHooks list an organziation's webhooks
  14. func ListHooks(ctx *context.APIContext) {
  15. // swagger:operation GET /orgs/{org}/hooks organization orgListHooks
  16. // ---
  17. // summary: List an organization's webhooks
  18. // produces:
  19. // - application/json
  20. // parameters:
  21. // - name: org
  22. // in: path
  23. // description: name of the organization
  24. // type: string
  25. // required: true
  26. // - name: page
  27. // in: query
  28. // description: page number of results to return (1-based)
  29. // type: integer
  30. // - name: limit
  31. // in: query
  32. // description: page size of results
  33. // type: integer
  34. // responses:
  35. // "200":
  36. // "$ref": "#/responses/HookList"
  37. org := ctx.Org.Organization
  38. orgHooks, err := models.GetWebhooksByOrgID(org.ID, utils.GetListOptions(ctx))
  39. if err != nil {
  40. ctx.Error(http.StatusInternalServerError, "GetWebhooksByOrgID", err)
  41. return
  42. }
  43. hooks := make([]*api.Hook, len(orgHooks))
  44. for i, hook := range orgHooks {
  45. hooks[i] = convert.ToHook(org.HomeLink(), hook)
  46. }
  47. ctx.JSON(http.StatusOK, hooks)
  48. }
  49. // GetHook get an organization's hook by id
  50. func GetHook(ctx *context.APIContext) {
  51. // swagger:operation GET /orgs/{org}/hooks/{id} organization orgGetHook
  52. // ---
  53. // summary: Get a hook
  54. // produces:
  55. // - application/json
  56. // parameters:
  57. // - name: org
  58. // in: path
  59. // description: name of the organization
  60. // type: string
  61. // required: true
  62. // - name: id
  63. // in: path
  64. // description: id of the hook to get
  65. // type: integer
  66. // format: int64
  67. // required: true
  68. // responses:
  69. // "200":
  70. // "$ref": "#/responses/Hook"
  71. org := ctx.Org.Organization
  72. hookID := ctx.ParamsInt64(":id")
  73. hook, err := utils.GetOrgHook(ctx, org.ID, hookID)
  74. if err != nil {
  75. return
  76. }
  77. ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), hook))
  78. }
  79. // CreateHook create a hook for an organization
  80. func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
  81. // swagger:operation POST /orgs/{org}/hooks/ organization orgCreateHook
  82. // ---
  83. // summary: Create a hook
  84. // consumes:
  85. // - application/json
  86. // produces:
  87. // - application/json
  88. // parameters:
  89. // - name: org
  90. // in: path
  91. // description: name of the organization
  92. // type: string
  93. // required: true
  94. // - name: body
  95. // in: body
  96. // required: true
  97. // schema:
  98. // "$ref": "#/definitions/CreateHookOption"
  99. // responses:
  100. // "201":
  101. // "$ref": "#/responses/Hook"
  102. //TODO in body params
  103. if !utils.CheckCreateHookOption(ctx, &form) {
  104. return
  105. }
  106. utils.AddOrgHook(ctx, &form)
  107. }
  108. // EditHook modify a hook of a repository
  109. func EditHook(ctx *context.APIContext, form api.EditHookOption) {
  110. // swagger:operation PATCH /orgs/{org}/hooks/{id} organization orgEditHook
  111. // ---
  112. // summary: Update a hook
  113. // consumes:
  114. // - application/json
  115. // produces:
  116. // - application/json
  117. // parameters:
  118. // - name: org
  119. // in: path
  120. // description: name of the organization
  121. // type: string
  122. // required: true
  123. // - name: id
  124. // in: path
  125. // description: id of the hook to update
  126. // type: integer
  127. // format: int64
  128. // required: true
  129. // - name: body
  130. // in: body
  131. // schema:
  132. // "$ref": "#/definitions/EditHookOption"
  133. // responses:
  134. // "200":
  135. // "$ref": "#/responses/Hook"
  136. //TODO in body params
  137. hookID := ctx.ParamsInt64(":id")
  138. utils.EditOrgHook(ctx, &form, hookID)
  139. }
  140. // DeleteHook delete a hook of an organization
  141. func DeleteHook(ctx *context.APIContext) {
  142. // swagger:operation DELETE /orgs/{org}/hooks/{id} organization orgDeleteHook
  143. // ---
  144. // summary: Delete a hook
  145. // produces:
  146. // - application/json
  147. // parameters:
  148. // - name: org
  149. // in: path
  150. // description: name of the organization
  151. // type: string
  152. // required: true
  153. // - name: id
  154. // in: path
  155. // description: id of the hook to delete
  156. // type: integer
  157. // format: int64
  158. // required: true
  159. // responses:
  160. // "204":
  161. // "$ref": "#/responses/empty"
  162. org := ctx.Org.Organization
  163. hookID := ctx.ParamsInt64(":id")
  164. if err := models.DeleteWebhookByOrgID(org.ID, hookID); err != nil {
  165. if models.IsErrWebhookNotExist(err) {
  166. ctx.NotFound()
  167. } else {
  168. ctx.Error(http.StatusInternalServerError, "DeleteWebhookByOrgID", err)
  169. }
  170. return
  171. }
  172. ctx.Status(http.StatusNoContent)
  173. }