issue_milestone.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2016 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 repo
  5. import (
  6. api "github.com/gogits/go-gogs-client"
  7. "github.com/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/context"
  9. "github.com/gogits/gogs/routers/api/v1/convert"
  10. )
  11. func GetIssueMilestone(ctx *context.APIContext) {
  12. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  13. if err != nil {
  14. if models.IsErrIssueNotExist(err) {
  15. ctx.Status(404)
  16. } else {
  17. ctx.Error(500, "GetIssueByIndex", err)
  18. }
  19. return
  20. }
  21. apiMilestone := convert.ToMilestone(issue.Milestone)
  22. ctx.JSON(200, &apiMilestone)
  23. }
  24. func SetIssueMilestone(ctx *context.APIContext, form api.SetIssueMilestoneOption) {
  25. if !ctx.Repo.IsWriter() {
  26. ctx.Status(403)
  27. return
  28. }
  29. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  30. if err != nil {
  31. if models.IsErrIssueNotExist(err) {
  32. ctx.Status(404)
  33. } else {
  34. ctx.Error(500, "GetIssueByIndex", err)
  35. }
  36. return
  37. }
  38. oldMid := issue.MilestoneID
  39. if oldMid != form.ID {
  40. issue.MilestoneID = form.ID
  41. if err = models.ChangeMilestoneAssign(oldMid, issue); err != nil {
  42. ctx.Error(500, "ChangeMilestoneAssign", err)
  43. return
  44. }
  45. }
  46. // Refresh issue to return updated milestone
  47. issue, err = models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
  48. if err != nil {
  49. if models.IsErrIssueNotExist(err) {
  50. ctx.Status(404)
  51. } else {
  52. ctx.Error(500, "GetIssueByIndex", err)
  53. }
  54. return
  55. }
  56. apiMilestone := convert.ToMilestone(issue.Milestone)
  57. ctx.JSON(200, &apiMilestone)
  58. }
  59. func DeleteIssueMilestone(ctx *context.APIContext) {
  60. form := api.SetIssueMilestoneOption{
  61. ID: 0,
  62. }
  63. SetIssueMilestone(ctx, form)
  64. }