gitea源码

subscriber.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2017 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. api "code.gitea.io/gitea/modules/structs"
  8. "code.gitea.io/gitea/routers/api/v1/utils"
  9. "code.gitea.io/gitea/services/context"
  10. "code.gitea.io/gitea/services/convert"
  11. )
  12. // ListSubscribers list a repo's subscribers (i.e. watchers)
  13. func ListSubscribers(ctx *context.APIContext) {
  14. // swagger:operation GET /repos/{owner}/{repo}/subscribers repository repoListSubscribers
  15. // ---
  16. // summary: List a repo's watchers
  17. // produces:
  18. // - application/json
  19. // parameters:
  20. // - name: owner
  21. // in: path
  22. // description: owner of the repo
  23. // type: string
  24. // required: true
  25. // - name: repo
  26. // in: path
  27. // description: name of the repo
  28. // type: string
  29. // required: true
  30. // - name: page
  31. // in: query
  32. // description: page number of results to return (1-based)
  33. // type: integer
  34. // - name: limit
  35. // in: query
  36. // description: page size of results
  37. // type: integer
  38. // responses:
  39. // "200":
  40. // "$ref": "#/responses/UserList"
  41. // "404":
  42. // "$ref": "#/responses/notFound"
  43. subscribers, err := repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
  44. if err != nil {
  45. ctx.APIErrorInternal(err)
  46. return
  47. }
  48. users := make([]*api.User, len(subscribers))
  49. for i, subscriber := range subscribers {
  50. users[i] = convert.ToUser(ctx, subscriber, ctx.Doer)
  51. }
  52. ctx.SetTotalCountHeader(int64(ctx.Repo.Repository.NumWatches))
  53. ctx.JSON(http.StatusOK, users)
  54. }