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.

251 lines
6.7 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
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 Gogs Authors. All rights reserved.
  2. // Copyright 2020 The Gitea Authors.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package repo
  6. import (
  7. "net/http"
  8. "time"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/context"
  11. "code.gitea.io/gitea/modules/convert"
  12. api "code.gitea.io/gitea/modules/structs"
  13. "code.gitea.io/gitea/modules/timeutil"
  14. "code.gitea.io/gitea/routers/api/v1/utils"
  15. )
  16. // ListMilestones list milestones for a repository
  17. func ListMilestones(ctx *context.APIContext) {
  18. // swagger:operation GET /repos/{owner}/{repo}/milestones issue issueGetMilestonesList
  19. // ---
  20. // summary: Get all of a repository's opened milestones
  21. // produces:
  22. // - application/json
  23. // parameters:
  24. // - name: owner
  25. // in: path
  26. // description: owner of the repo
  27. // type: string
  28. // required: true
  29. // - name: repo
  30. // in: path
  31. // description: name of the repo
  32. // type: string
  33. // required: true
  34. // - name: state
  35. // in: query
  36. // description: Milestone state, Recognised values are open, closed and all. Defaults to "open"
  37. // type: string
  38. // - name: page
  39. // in: query
  40. // description: page number of results to return (1-based)
  41. // type: integer
  42. // - name: limit
  43. // in: query
  44. // description: page size of results, maximum page size is 50
  45. // type: integer
  46. // responses:
  47. // "200":
  48. // "$ref": "#/responses/MilestoneList"
  49. milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")), utils.GetListOptions(ctx))
  50. if err != nil {
  51. ctx.Error(http.StatusInternalServerError, "GetMilestonesByRepoID", err)
  52. return
  53. }
  54. apiMilestones := make([]*api.Milestone, len(milestones))
  55. for i := range milestones {
  56. apiMilestones[i] = convert.ToAPIMilestone(milestones[i])
  57. }
  58. ctx.JSON(http.StatusOK, &apiMilestones)
  59. }
  60. // GetMilestone get a milestone for a repository
  61. func GetMilestone(ctx *context.APIContext) {
  62. // swagger:operation GET /repos/{owner}/{repo}/milestones/{id} issue issueGetMilestone
  63. // ---
  64. // summary: Get a milestone
  65. // produces:
  66. // - application/json
  67. // parameters:
  68. // - name: owner
  69. // in: path
  70. // description: owner of the repo
  71. // type: string
  72. // required: true
  73. // - name: repo
  74. // in: path
  75. // description: name of the repo
  76. // type: string
  77. // required: true
  78. // - name: id
  79. // in: path
  80. // description: id of the milestone
  81. // type: integer
  82. // format: int64
  83. // required: true
  84. // responses:
  85. // "200":
  86. // "$ref": "#/responses/Milestone"
  87. milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  88. if err != nil {
  89. if models.IsErrMilestoneNotExist(err) {
  90. ctx.NotFound()
  91. } else {
  92. ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
  93. }
  94. return
  95. }
  96. ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone))
  97. }
  98. // CreateMilestone create a milestone for a repository
  99. func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
  100. // swagger:operation POST /repos/{owner}/{repo}/milestones issue issueCreateMilestone
  101. // ---
  102. // summary: Create a milestone
  103. // consumes:
  104. // - application/json
  105. // produces:
  106. // - application/json
  107. // parameters:
  108. // - name: owner
  109. // in: path
  110. // description: owner of the repo
  111. // type: string
  112. // required: true
  113. // - name: repo
  114. // in: path
  115. // description: name of the repo
  116. // type: string
  117. // required: true
  118. // - name: body
  119. // in: body
  120. // schema:
  121. // "$ref": "#/definitions/CreateMilestoneOption"
  122. // responses:
  123. // "201":
  124. // "$ref": "#/responses/Milestone"
  125. if form.Deadline == nil {
  126. defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local)
  127. form.Deadline = &defaultDeadline
  128. }
  129. milestone := &models.Milestone{
  130. RepoID: ctx.Repo.Repository.ID,
  131. Name: form.Title,
  132. Content: form.Description,
  133. DeadlineUnix: timeutil.TimeStamp(form.Deadline.Unix()),
  134. }
  135. if err := models.NewMilestone(milestone); err != nil {
  136. ctx.Error(http.StatusInternalServerError, "NewMilestone", err)
  137. return
  138. }
  139. ctx.JSON(http.StatusCreated, convert.ToAPIMilestone(milestone))
  140. }
  141. // EditMilestone modify a milestone for a repository
  142. func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
  143. // swagger:operation PATCH /repos/{owner}/{repo}/milestones/{id} issue issueEditMilestone
  144. // ---
  145. // summary: Update a milestone
  146. // consumes:
  147. // - application/json
  148. // produces:
  149. // - application/json
  150. // parameters:
  151. // - name: owner
  152. // in: path
  153. // description: owner of the repo
  154. // type: string
  155. // required: true
  156. // - name: repo
  157. // in: path
  158. // description: name of the repo
  159. // type: string
  160. // required: true
  161. // - name: id
  162. // in: path
  163. // description: id of the milestone
  164. // type: integer
  165. // format: int64
  166. // required: true
  167. // - name: body
  168. // in: body
  169. // schema:
  170. // "$ref": "#/definitions/EditMilestoneOption"
  171. // responses:
  172. // "200":
  173. // "$ref": "#/responses/Milestone"
  174. milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
  175. if err != nil {
  176. if models.IsErrMilestoneNotExist(err) {
  177. ctx.NotFound()
  178. } else {
  179. ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
  180. }
  181. return
  182. }
  183. if len(form.Title) > 0 {
  184. milestone.Name = form.Title
  185. }
  186. if form.Description != nil {
  187. milestone.Content = *form.Description
  188. }
  189. if form.Deadline != nil && !form.Deadline.IsZero() {
  190. milestone.DeadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
  191. }
  192. var oldIsClosed = milestone.IsClosed
  193. if form.State != nil {
  194. milestone.IsClosed = *form.State == string(api.StateClosed)
  195. }
  196. if err := models.UpdateMilestone(milestone, oldIsClosed); err != nil {
  197. ctx.ServerError("UpdateMilestone", err)
  198. return
  199. }
  200. ctx.JSON(http.StatusOK, convert.ToAPIMilestone(milestone))
  201. }
  202. // DeleteMilestone delete a milestone for a repository
  203. func DeleteMilestone(ctx *context.APIContext) {
  204. // swagger:operation DELETE /repos/{owner}/{repo}/milestones/{id} issue issueDeleteMilestone
  205. // ---
  206. // summary: Delete a milestone
  207. // parameters:
  208. // - name: owner
  209. // in: path
  210. // description: owner of the repo
  211. // type: string
  212. // required: true
  213. // - name: repo
  214. // in: path
  215. // description: name of the repo
  216. // type: string
  217. // required: true
  218. // - name: id
  219. // in: path
  220. // description: id of the milestone to delete
  221. // type: integer
  222. // format: int64
  223. // required: true
  224. // responses:
  225. // "204":
  226. // "$ref": "#/responses/empty"
  227. if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
  228. ctx.Error(http.StatusInternalServerError, "DeleteMilestoneByRepoID", err)
  229. return
  230. }
  231. ctx.Status(http.StatusNoContent)
  232. }