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.

subscriber.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "code.gitea.io/gitea/modules/context"
  7. "code.gitea.io/gitea/modules/convert"
  8. api "code.gitea.io/gitea/modules/structs"
  9. )
  10. // ListSubscribers list a repo's subscribers (i.e. watchers)
  11. func ListSubscribers(ctx *context.APIContext) {
  12. // swagger:operation GET /repos/{owner}/{repo}/subscribers repository repoListSubscribers
  13. // ---
  14. // summary: List a repo's watchers
  15. // produces:
  16. // - application/json
  17. // parameters:
  18. // - name: owner
  19. // in: path
  20. // description: owner of the repo
  21. // type: string
  22. // required: true
  23. // - name: repo
  24. // in: path
  25. // description: name of the repo
  26. // type: string
  27. // required: true
  28. // responses:
  29. // "200":
  30. // "$ref": "#/responses/UserList"
  31. subscribers, err := ctx.Repo.Repository.GetWatchers(0)
  32. if err != nil {
  33. ctx.Error(500, "GetWatchers", err)
  34. return
  35. }
  36. users := make([]*api.User, len(subscribers))
  37. for i, subscriber := range subscribers {
  38. users[i] = convert.ToUser(subscriber, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
  39. }
  40. ctx.JSON(200, users)
  41. }