Skip to content

Commit 68a2af6

Browse files
6543proton-ab
andauthored
API expose usefull General Repo settings settings (#11758)
* GeneralRepoSettings expose MirrorsDisabled, HTTPGitDisabled, MaxCreationLimit * Apply suggestions from code review Co-authored-by: proton <[email protected]> * lint Co-authored-by: proton <[email protected]>
1 parent 1ac4618 commit 68a2af6

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

modules/structs/settings.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2020 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+
5+
package structs
6+
7+
// GeneralRepoSettings contains global repository settings exposed by API
8+
type GeneralRepoSettings struct {
9+
MirrorsDisabled bool `json:"mirrors_disabled"`
10+
HTTPGitDisabled bool `json:"http_git_disabled"`
11+
}

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ func RegisterRoutes(m *macaron.Macaron) {
514514
m.Post("/markdown/raw", misc.MarkdownRaw)
515515
m.Group("/settings", func() {
516516
m.Get("/allowed_reactions", misc.SettingGetsAllowedReactions)
517+
m.Get("/repository", misc.GetGeneralRepoSettings)
517518
})
518519

519520
// Notifications

routers/api/v1/misc/settings.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"code.gitea.io/gitea/modules/context"
1111
"code.gitea.io/gitea/modules/setting"
12+
api "code.gitea.io/gitea/modules/structs"
1213
)
1314

1415
// SettingGetsAllowedReactions return allowed reactions
@@ -23,3 +24,19 @@ func SettingGetsAllowedReactions(ctx *context.APIContext) {
2324
// "$ref": "#/responses/StringSlice"
2425
ctx.JSON(http.StatusOK, setting.UI.Reactions)
2526
}
27+
28+
// GetGeneralRepoSettings returns instance's global settings for repositories
29+
func GetGeneralRepoSettings(ctx *context.APIContext) {
30+
// swagger:operation GET /settings/repository miscellaneous getGeneralRepositorySettings
31+
// ---
32+
// summary: Get instance's global settings for repositories
33+
// produces:
34+
// - application/json
35+
// responses:
36+
// "200":
37+
// "$ref": "#/responses/GeneralRepoSettings"
38+
ctx.JSON(http.StatusOK, api.GeneralRepoSettings{
39+
MirrorsDisabled: setting.Repository.DisableMirrors,
40+
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
41+
})
42+
}

routers/api/v1/swagger/misc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ type swaggerResponseStringSlice struct {
2121
// in:body
2222
Body []string `json:"body"`
2323
}
24+
25+
// GeneralRepoSettings
26+
// swagger:response GeneralRepoSettings
27+
type swaggerResponseGeneralRepoSettings struct {
28+
// in:body
29+
Body api.GeneralRepoSettings `json:"body"`
30+
}

templates/swagger/v1_json.tmpl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8487,6 +8487,23 @@
84878487
}
84888488
}
84898489
},
8490+
"/settings/repository": {
8491+
"get": {
8492+
"produces": [
8493+
"application/json"
8494+
],
8495+
"tags": [
8496+
"miscellaneous"
8497+
],
8498+
"summary": "Get instance's global settings for repositories",
8499+
"operationId": "getGeneralRepositorySettings",
8500+
"responses": {
8501+
"200": {
8502+
"$ref": "#/responses/GeneralRepoSettings"
8503+
}
8504+
}
8505+
}
8506+
},
84908507
"/signing-key.gpg": {
84918508
"get": {
84928509
"produces": [
@@ -12721,6 +12738,21 @@
1272112738
},
1272212739
"x-go-package": "code.gitea.io/gitea/modules/structs"
1272312740
},
12741+
"GeneralRepoSettings": {
12742+
"description": "GeneralRepoSettings contains global repository settings exposed by API",
12743+
"type": "object",
12744+
"properties": {
12745+
"http_git_disabled": {
12746+
"type": "boolean",
12747+
"x-go-name": "HTTPGitDisabled"
12748+
},
12749+
"mirrors_disabled": {
12750+
"type": "boolean",
12751+
"x-go-name": "MirrorsDisabled"
12752+
}
12753+
},
12754+
"x-go-package": "code.gitea.io/gitea/modules/structs"
12755+
},
1272412756
"GitBlobResponse": {
1272512757
"description": "GitBlobResponse represents a git blob",
1272612758
"type": "object",
@@ -14890,6 +14922,12 @@
1489014922
}
1489114923
}
1489214924
},
14925+
"GeneralRepoSettings": {
14926+
"description": "GeneralRepoSettings",
14927+
"schema": {
14928+
"$ref": "#/definitions/GeneralRepoSettings"
14929+
}
14930+
},
1489314931
"GitBlobResponse": {
1489414932
"description": "GitBlobResponse",
1489514933
"schema": {

0 commit comments

Comments
 (0)