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.

38 lines
1008 B

  1. // Copyright 2017 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 repo
  5. import (
  6. "fmt"
  7. "net/http"
  8. "strconv"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/context"
  11. )
  12. // IssueWatch sets issue watching
  13. func IssueWatch(c *context.Context) {
  14. watch, err := strconv.ParseBool(c.Req.PostForm.Get("watch"))
  15. if err != nil {
  16. c.Handle(http.StatusInternalServerError, "watch is not bool", err)
  17. return
  18. }
  19. issueIndex := c.ParamsInt64("index")
  20. issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, issueIndex)
  21. if err != nil {
  22. c.Handle(http.StatusInternalServerError, "GetIssueByIndex", err)
  23. return
  24. }
  25. if err := models.CreateOrUpdateIssueWatch(c.User.ID, issue.ID, watch); err != nil {
  26. c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
  27. return
  28. }
  29. url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueIndex)
  30. c.Redirect(url, http.StatusSeeOther)
  31. }