Skip to content

API expose usefull General Repo settings settings #11758

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

Merged
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
11 changes: 11 additions & 0 deletions modules/structs/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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 structs

// GeneralRepoSettings contains global repository settings exposed by API
type GeneralRepoSettings struct {
MirrorsDisabled bool `json:"mirrors_disabled"`
HTTPGitDisabled bool `json:"http_git_disabled"`
}
1 change: 1 addition & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/markdown/raw", misc.MarkdownRaw)
m.Group("/settings", func() {
m.Get("/allowed_reactions", misc.SettingGetsAllowedReactions)
m.Get("/repository", misc.GetGeneralRepoSettings)
})

// Notifications
Expand Down
17 changes: 17 additions & 0 deletions routers/api/v1/misc/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
)

// SettingGetsAllowedReactions return allowed reactions
Expand All @@ -23,3 +24,19 @@ func SettingGetsAllowedReactions(ctx *context.APIContext) {
// "$ref": "#/responses/StringSlice"
ctx.JSON(http.StatusOK, setting.UI.Reactions)
}

// GetGeneralRepoSettings returns instance's global settings for repositories
func GetGeneralRepoSettings(ctx *context.APIContext) {
// swagger:operation GET /settings/repository miscellaneous getGeneralRepositorySettings
// ---
// summary: Get instance's global settings for repositories
// produces:
// - application/json
// responses:
// "200":
// "$ref": "#/responses/GeneralRepoSettings"
ctx.JSON(http.StatusOK, api.GeneralRepoSettings{
MirrorsDisabled: setting.Repository.DisableMirrors,
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
})
}
7 changes: 7 additions & 0 deletions routers/api/v1/swagger/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ type swaggerResponseStringSlice struct {
// in:body
Body []string `json:"body"`
}

// GeneralRepoSettings
// swagger:response GeneralRepoSettings
type swaggerResponseGeneralRepoSettings struct {
// in:body
Body api.GeneralRepoSettings `json:"body"`
}
38 changes: 38 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8487,6 +8487,23 @@
}
}
},
"/settings/repository": {
"get": {
"produces": [
"application/json"
],
"tags": [
"miscellaneous"
],
"summary": "Get instance's global settings for repositories",
"operationId": "getGeneralRepositorySettings",
"responses": {
"200": {
"$ref": "#/responses/GeneralRepoSettings"
}
}
}
},
"/signing-key.gpg": {
"get": {
"produces": [
Expand Down Expand Up @@ -12721,6 +12738,21 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"GeneralRepoSettings": {
"description": "GeneralRepoSettings contains global repository settings exposed by API",
"type": "object",
"properties": {
"http_git_disabled": {
"type": "boolean",
"x-go-name": "HTTPGitDisabled"
},
"mirrors_disabled": {
"type": "boolean",
"x-go-name": "MirrorsDisabled"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"GitBlobResponse": {
"description": "GitBlobResponse represents a git blob",
"type": "object",
Expand Down Expand Up @@ -14890,6 +14922,12 @@
}
}
},
"GeneralRepoSettings": {
"description": "GeneralRepoSettings",
"schema": {
"$ref": "#/definitions/GeneralRepoSettings"
}
},
"GitBlobResponse": {
"description": "GitBlobResponse",
"schema": {
Expand Down