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