diff options
author | 6543 <6543@obermui.de> | 2021-06-17 16:02:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-17 16:02:34 +0200 |
commit | b3fbd37e992cf3f9f42f49818087c67d464000eb (patch) | |
tree | ddb4aee79d6dfafaa3ff64acffed6f119c222acd /routers | |
parent | 0db1048c3ab0b0802779fd84b86c4335c37e54b3 (diff) | |
download | gitea-b3fbd37e992cf3f9f42f49818087c67d464000eb.tar.gz gitea-b3fbd37e992cf3f9f42f49818087c67d464000eb.zip |
[API] expose repo.GetReviewers() & repo.GetAssignees() (#16168)
* API: expose repo.GetReviewers() & repo.GetAssignees()
* Add tests
* fix unrelated swagger query type
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/api.go | 2 | ||||
-rw-r--r-- | routers/api/v1/notify/repo.go | 2 | ||||
-rw-r--r-- | routers/api/v1/notify/user.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/collaborators.go | 60 | ||||
-rw-r--r-- | routers/api/v1/user/user.go | 8 |
5 files changed, 65 insertions, 9 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index acee6329af..0b47953e58 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -746,6 +746,8 @@ func Routes() *web.Route { Put(reqAdmin(), bind(api.AddCollaboratorOption{}), repo.AddCollaborator). Delete(reqAdmin(), repo.DeleteCollaborator) }, reqToken()) + m.Get("/assignees", reqToken(), reqAnyRepoReader(), repo.GetAssignees) + m.Get("/reviewers", reqToken(), reqAnyRepoReader(), repo.GetReviewers) m.Group("/teams", func() { m.Get("", reqAnyRepoReader(), repo.ListTeams) m.Combo("/{team}").Get(reqAnyRepoReader(), repo.IsTeam). diff --git a/routers/api/v1/notify/repo.go b/routers/api/v1/notify/repo.go index 4deb16a227..af55d1d49c 100644 --- a/routers/api/v1/notify/repo.go +++ b/routers/api/v1/notify/repo.go @@ -65,7 +65,7 @@ func ListRepoNotifications(ctx *context.APIContext) { // - name: all // in: query // description: If true, show notifications marked as read. Default value is false - // type: string + // type: boolean // - name: status-types // in: query // description: "Show notifications with the provided status types. Options are: unread, read and/or pinned. Defaults to unread & pinned" diff --git a/routers/api/v1/notify/user.go b/routers/api/v1/notify/user.go index 1ff62622b0..475a541bdc 100644 --- a/routers/api/v1/notify/user.go +++ b/routers/api/v1/notify/user.go @@ -27,7 +27,7 @@ func ListNotifications(ctx *context.APIContext) { // - name: all // in: query // description: If true, show notifications marked as read. Default value is false - // type: string + // type: boolean // - name: status-types // in: query // description: "Show notifications with the provided status types. Options are: unread, read and/or pinned. Defaults to unread & pinned." diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index d0936019fa..078af1f6ff 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -221,3 +221,63 @@ func DeleteCollaborator(ctx *context.APIContext) { } ctx.Status(http.StatusNoContent) } + +// GetReviewers return all users that can be requested to review in this repo +func GetReviewers(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/reviewers repository repoGetReviewers + // --- + // summary: Return all users that can be requested to review in this repo + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // responses: + // "200": + // "$ref": "#/responses/UserList" + + reviewers, err := ctx.Repo.Repository.GetReviewers(ctx.User.ID, 0) + if err != nil { + ctx.Error(http.StatusInternalServerError, "ListCollaborators", err) + return + } + ctx.JSON(http.StatusOK, convert.ToUsers(ctx.User, reviewers)) +} + +// GetAssignees return all users that have write access and can be assigned to issues +func GetAssignees(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/assignees repository repoGetAssignees + // --- + // summary: Return all users that have write access and can be assigned to issues + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // responses: + // "200": + // "$ref": "#/responses/UserList" + + assignees, err := ctx.Repo.Repository.GetAssignees() + if err != nil { + ctx.Error(http.StatusInternalServerError, "ListCollaborators", err) + return + } + ctx.JSON(http.StatusOK, convert.ToUsers(ctx.User, assignees)) +} diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index 6e811bf0f8..4adae532fd 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -13,7 +13,6 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" - api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/utils" ) @@ -73,18 +72,13 @@ func Search(ctx *context.APIContext) { return } - results := make([]*api.User, len(users)) - for i := range users { - results[i] = convert.ToUser(users[i], ctx.User) - } - ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults)) ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link") ctx.JSON(http.StatusOK, map[string]interface{}{ "ok": true, - "data": results, + "data": convert.ToUsers(ctx.User, users), }) } |