Skip to content

Commit ac417aa

Browse files
authored
Merge branch 'main' into speedup-highlight
2 parents 397c1e7 + b3fbd37 commit ac417aa

File tree

8 files changed

+170
-11
lines changed

8 files changed

+170
-11
lines changed

integrations/api_repo_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,31 @@ func TestAPIRepoTransfer(t *testing.T) {
494494
repo = models.AssertExistsAndLoadBean(t, &models.Repository{ID: repo.ID}).(*models.Repository)
495495
_ = models.DeleteRepository(user, repo.OwnerID, repo.ID)
496496
}
497+
498+
func TestAPIRepoGetReviewers(t *testing.T) {
499+
defer prepareTestEnv(t)()
500+
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
501+
session := loginUser(t, user.Name)
502+
token := getTokenForLoggedInUser(t, session)
503+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
504+
505+
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/reviewers?token=%s", user.Name, repo.Name, token)
506+
resp := session.MakeRequest(t, req, http.StatusOK)
507+
var reviewers []*api.User
508+
DecodeJSON(t, resp, &reviewers)
509+
assert.Len(t, reviewers, 4)
510+
}
511+
512+
func TestAPIRepoGetAssignees(t *testing.T) {
513+
defer prepareTestEnv(t)()
514+
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
515+
session := loginUser(t, user.Name)
516+
token := getTokenForLoggedInUser(t, session)
517+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
518+
519+
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/assignees?token=%s", user.Name, repo.Name, token)
520+
resp := session.MakeRequest(t, req, http.StatusOK)
521+
var assignees []*api.User
522+
DecodeJSON(t, resp, &assignees)
523+
assert.Len(t, assignees, 1)
524+
}

modules/convert/user.go

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ func ToUser(user, doer *models.User) *api.User {
2525
return toUser(user, signed, authed)
2626
}
2727

28+
// ToUsers convert list of models.User to list of api.User
29+
func ToUsers(doer *models.User, users []*models.User) []*api.User {
30+
result := make([]*api.User, len(users))
31+
for i := range users {
32+
result[i] = ToUser(users[i], doer)
33+
}
34+
return result
35+
}
36+
2837
// ToUserWithAccessMode convert models.User to api.User
2938
// AccessMode is not none show add some more information
3039
func ToUserWithAccessMode(user *models.User, accessMode models.AccessMode) *api.User {

routers/api/v1/api.go

+2
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ func Routes() *web.Route {
746746
Put(reqAdmin(), bind(api.AddCollaboratorOption{}), repo.AddCollaborator).
747747
Delete(reqAdmin(), repo.DeleteCollaborator)
748748
}, reqToken())
749+
m.Get("/assignees", reqToken(), reqAnyRepoReader(), repo.GetAssignees)
750+
m.Get("/reviewers", reqToken(), reqAnyRepoReader(), repo.GetReviewers)
749751
m.Group("/teams", func() {
750752
m.Get("", reqAnyRepoReader(), repo.ListTeams)
751753
m.Combo("/{team}").Get(reqAnyRepoReader(), repo.IsTeam).

routers/api/v1/notify/repo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func ListRepoNotifications(ctx *context.APIContext) {
6565
// - name: all
6666
// in: query
6767
// description: If true, show notifications marked as read. Default value is false
68-
// type: string
68+
// type: boolean
6969
// - name: status-types
7070
// in: query
7171
// description: "Show notifications with the provided status types. Options are: unread, read and/or pinned. Defaults to unread & pinned"

routers/api/v1/notify/user.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func ListNotifications(ctx *context.APIContext) {
2727
// - name: all
2828
// in: query
2929
// description: If true, show notifications marked as read. Default value is false
30-
// type: string
30+
// type: boolean
3131
// - name: status-types
3232
// in: query
3333
// description: "Show notifications with the provided status types. Options are: unread, read and/or pinned. Defaults to unread & pinned."

routers/api/v1/repo/collaborators.go

+60
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,63 @@ func DeleteCollaborator(ctx *context.APIContext) {
221221
}
222222
ctx.Status(http.StatusNoContent)
223223
}
224+
225+
// GetReviewers return all users that can be requested to review in this repo
226+
func GetReviewers(ctx *context.APIContext) {
227+
// swagger:operation GET /repos/{owner}/{repo}/reviewers repository repoGetReviewers
228+
// ---
229+
// summary: Return all users that can be requested to review in this repo
230+
// produces:
231+
// - application/json
232+
// parameters:
233+
// - name: owner
234+
// in: path
235+
// description: owner of the repo
236+
// type: string
237+
// required: true
238+
// - name: repo
239+
// in: path
240+
// description: name of the repo
241+
// type: string
242+
// required: true
243+
// responses:
244+
// "200":
245+
// "$ref": "#/responses/UserList"
246+
247+
reviewers, err := ctx.Repo.Repository.GetReviewers(ctx.User.ID, 0)
248+
if err != nil {
249+
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
250+
return
251+
}
252+
ctx.JSON(http.StatusOK, convert.ToUsers(ctx.User, reviewers))
253+
}
254+
255+
// GetAssignees return all users that have write access and can be assigned to issues
256+
func GetAssignees(ctx *context.APIContext) {
257+
// swagger:operation GET /repos/{owner}/{repo}/assignees repository repoGetAssignees
258+
// ---
259+
// summary: Return all users that have write access and can be assigned to issues
260+
// produces:
261+
// - application/json
262+
// parameters:
263+
// - name: owner
264+
// in: path
265+
// description: owner of the repo
266+
// type: string
267+
// required: true
268+
// - name: repo
269+
// in: path
270+
// description: name of the repo
271+
// type: string
272+
// required: true
273+
// responses:
274+
// "200":
275+
// "$ref": "#/responses/UserList"
276+
277+
assignees, err := ctx.Repo.Repository.GetAssignees()
278+
if err != nil {
279+
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
280+
return
281+
}
282+
ctx.JSON(http.StatusOK, convert.ToUsers(ctx.User, assignees))
283+
}

routers/api/v1/user/user.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"code.gitea.io/gitea/models"
1414
"code.gitea.io/gitea/modules/context"
1515
"code.gitea.io/gitea/modules/convert"
16-
api "code.gitea.io/gitea/modules/structs"
1716
"code.gitea.io/gitea/routers/api/v1/utils"
1817
)
1918

@@ -73,18 +72,13 @@ func Search(ctx *context.APIContext) {
7372
return
7473
}
7574

76-
results := make([]*api.User, len(users))
77-
for i := range users {
78-
results[i] = convert.ToUser(users[i], ctx.User)
79-
}
80-
8175
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
8276
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", maxResults))
8377
ctx.Header().Set("Access-Control-Expose-Headers", "X-Total-Count, Link")
8478

8579
ctx.JSON(http.StatusOK, map[string]interface{}{
8680
"ok": true,
87-
"data": results,
81+
"data": convert.ToUsers(ctx.User, users),
8882
})
8983
}
9084

templates/swagger/v1_json.tmpl

+68-2
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@
630630
"operationId": "notifyGetList",
631631
"parameters": [
632632
{
633-
"type": "string",
633+
"type": "boolean",
634634
"description": "If true, show notifications marked as read. Default value is false",
635635
"name": "all",
636636
"in": "query"
@@ -2277,6 +2277,39 @@
22772277
}
22782278
}
22792279
},
2280+
"/repos/{owner}/{repo}/assignees": {
2281+
"get": {
2282+
"produces": [
2283+
"application/json"
2284+
],
2285+
"tags": [
2286+
"repository"
2287+
],
2288+
"summary": "Return all users that have write access and can be assigned to issues",
2289+
"operationId": "repoGetAssignees",
2290+
"parameters": [
2291+
{
2292+
"type": "string",
2293+
"description": "owner of the repo",
2294+
"name": "owner",
2295+
"in": "path",
2296+
"required": true
2297+
},
2298+
{
2299+
"type": "string",
2300+
"description": "name of the repo",
2301+
"name": "repo",
2302+
"in": "path",
2303+
"required": true
2304+
}
2305+
],
2306+
"responses": {
2307+
"200": {
2308+
"$ref": "#/responses/UserList"
2309+
}
2310+
}
2311+
}
2312+
},
22802313
"/repos/{owner}/{repo}/branch_protections": {
22812314
"get": {
22822315
"produces": [
@@ -6844,7 +6877,7 @@
68446877
"required": true
68456878
},
68466879
{
6847-
"type": "string",
6880+
"type": "boolean",
68486881
"description": "If true, show notifications marked as read. Default value is false",
68496882
"name": "all",
68506883
"in": "query"
@@ -8629,6 +8662,39 @@
86298662
}
86308663
}
86318664
},
8665+
"/repos/{owner}/{repo}/reviewers": {
8666+
"get": {
8667+
"produces": [
8668+
"application/json"
8669+
],
8670+
"tags": [
8671+
"repository"
8672+
],
8673+
"summary": "Return all users that can be requested to review in this repo",
8674+
"operationId": "repoGetReviewers",
8675+
"parameters": [
8676+
{
8677+
"type": "string",
8678+
"description": "owner of the repo",
8679+
"name": "owner",
8680+
"in": "path",
8681+
"required": true
8682+
},
8683+
{
8684+
"type": "string",
8685+
"description": "name of the repo",
8686+
"name": "repo",
8687+
"in": "path",
8688+
"required": true
8689+
}
8690+
],
8691+
"responses": {
8692+
"200": {
8693+
"$ref": "#/responses/UserList"
8694+
}
8695+
}
8696+
}
8697+
},
86328698
"/repos/{owner}/{repo}/signing-key.gpg": {
86338699
"get": {
86348700
"produces": [

0 commit comments

Comments
 (0)