gitea源码

watch.go 978B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2025 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "net/http"
  6. repo_model "code.gitea.io/gitea/models/repo"
  7. "code.gitea.io/gitea/modules/templates"
  8. "code.gitea.io/gitea/services/context"
  9. )
  10. const tplWatchUnwatch templates.TplName = "repo/watch_unwatch"
  11. func ActionWatch(ctx *context.Context) {
  12. err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, ctx.PathParam("action") == "watch")
  13. if err != nil {
  14. handleActionError(ctx, err)
  15. return
  16. }
  17. ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
  18. ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name)
  19. if err != nil {
  20. ctx.ServerError("GetRepositoryByName", err)
  21. return
  22. }
  23. ctx.RespHeader().Add("hx-trigger", "refreshUserCards") // see the `hx-trigger="refreshUserCards ..."` comments in tmpl
  24. ctx.HTML(http.StatusOK, tplWatchUnwatch)
  25. }