Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Expose allowed Reactions #11735

Merged
merged 7 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions integrations/api_issue_reaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,27 @@ import (
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"

"github.com/stretchr/testify/assert"
)

func TestAPIAllowedReactions(t *testing.T) {
defer prepareTestEnv(t)()

type allowed []string

a := new(allowed)

req := NewRequest(t, "GET", "/api/v1/settings/allowed_reactions")
resp := MakeRequest(t, req, http.StatusOK)

DecodeJSON(t, resp, &a)
assert.Len(t, *a, len(setting.UI.Reactions))
assert.ElementsMatch(t, setting.UI.Reactions, *a)
}

func TestAPIIssuesReactions(t *testing.T) {
defer prepareTestEnv(t)()

Expand Down
3 changes: 3 additions & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/signing-key.gpg", misc.SigningKey)
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
m.Post("/markdown/raw", misc.MarkdownRaw)
m.Group("/settings", func() {
m.Get("/allowed_reactions", misc.SettingGetsAllowedReactions)
})

// Notifications
m.Group("/notifications", func() {
Expand Down
23 changes: 23 additions & 0 deletions routers/api/v1/misc/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package misc

import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
)

// SettingGetsAllowedReactions return allowed reactions
func SettingGetsAllowedReactions(ctx *context.APIContext) {
// swagger:operation GET /settings/allowed_reactions miscellaneous getAllowedReactions
// ---
// summary: Returns string array of allowed reactions
6543 marked this conversation as resolved.
Show resolved Hide resolved
// produces:
// - application/json
// responses:
// "200":
// "$ref": "#/responses/StringSlice"
ctx.JSON(200, setting.UI.Reactions)
}
7 changes: 7 additions & 0 deletions routers/api/v1/swagger/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ type swaggerResponseServerVersion struct {
// in:body
Body api.ServerVersion `json:"body"`
}

// StringSlice
// swagger:response StringSlice
type swaggerResponseStringSlice struct {
// in:body
Body []string `json:"body"`
}
26 changes: 26 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8343,6 +8343,23 @@
}
}
},
"/settings/allowed_reactions": {
"get": {
"produces": [
"application/json"
],
"tags": [
"miscellaneous"
],
"summary": "Returns string array of allowed reactions",
"operationId": "getAllowedReactions",
"responses": {
"200": {
"$ref": "#/responses/StringSlice"
}
}
}
},
"/signing-key.gpg": {
"get": {
"produces": [
Expand Down Expand Up @@ -15042,6 +15059,15 @@
}
}
},
"StringSlice": {
"description": "StringSlice",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
"Tag": {
"description": "Tag",
"schema": {
Expand Down