Skip to content

Commit 765b2c6

Browse files
committed
Store remote name in config database
1 parent c483167 commit 765b2c6

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

modules/setting/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func DefaultOpenWithEditorApps() OpenWithEditorAppsType {
4949

5050
type RepositoryStruct struct {
5151
OpenWithEditorApps *config.Value[OpenWithEditorAppsType]
52+
SnippetRemoteName *config.Value[string]
5253
}
5354

5455
type ConfigStruct struct {
@@ -70,6 +71,7 @@ func initDefaultConfig() {
7071
},
7172
Repository: &RepositoryStruct{
7273
OpenWithEditorApps: config.ValueJSON[OpenWithEditorAppsType]("repository.open-with.editor-apps"),
74+
SnippetRemoteName: config.ValueJSON[string]("repository.snippet-remote-name").WithDefault("origin"),
7375
},
7476
}
7577
}

modules/setting/config/value.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func (value *Value[T]) DynKey() string {
7979
return value.dynKey
8080
}
8181

82+
func (value *Value[T]) Def() T {
83+
return value.def
84+
}
85+
8286
func (value *Value[T]) WithDefault(def T) *Value[T] {
8387
value.def = def
8488
return value

modules/setting/repository.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ var (
4848
DisableMigrations bool
4949
DisableStars bool `ini:"DISABLE_STARS"`
5050
DefaultBranch string
51-
SnippetRemoteName string
5251
AllowAdoptionOfUnadoptedRepositories bool
5352
AllowDeleteOfUnadoptedRepositories bool
5453
DisableDownloadSourceArchives bool
@@ -167,7 +166,6 @@ var (
167166
DisableMigrations: false,
168167
DisableStars: false,
169168
DefaultBranch: "main",
170-
SnippetRemoteName: "origin",
171169
AllowForkWithoutMaximumLimit: true,
172170

173171
// Repository editor settings

routers/web/admin/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ func ChangeConfig(ctx *context.Context) {
206206
}
207207
return "false", nil
208208
}
209+
210+
marshalStringWithDefault := func(def string) func(v string) (string, error) {
211+
return func(v string) (string, error) {
212+
if strings.TrimSpace(v) == "" {
213+
v = def
214+
}
215+
b, err := json.Marshal(v)
216+
if err != nil {
217+
return "", err
218+
}
219+
return string(b), nil
220+
}
221+
}
222+
209223
marshalOpenWithApps := func(value string) (string, error) {
210224
lines := strings.Split(value, "\n")
211225
var openWithEditorApps setting.OpenWithEditorAppsType
@@ -234,6 +248,7 @@ func ChangeConfig(ctx *context.Context) {
234248
cfg.Picture.DisableGravatar.DynKey(): marshalBool,
235249
cfg.Picture.EnableFederatedAvatar.DynKey(): marshalBool,
236250
cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps,
251+
cfg.Repository.SnippetRemoteName.DynKey(): marshalStringWithDefault(cfg.Repository.SnippetRemoteName.Def()),
237252
}
238253
marshaller, hasMarshaller := marshallers[key]
239254
if !hasMarshaller {

routers/web/repo/issue_view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func ViewPullMergeBox(ctx *context.Context) {
446446

447447
// TODO: it should use a dedicated struct to render the pull merge box, to make sure all data is prepared correctly
448448
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.Doer.ID)
449-
ctx.Data["SnippetRemoteName"] = setting.Repository.SnippetRemoteName
449+
ctx.Data["SnippetRemoteName"] = setting.Config().Repository.SnippetRemoteName.Value(ctx)
450450
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
451451
ctx.HTML(http.StatusOK, tplPullMergeBox)
452452
}

services/context/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ func RepoAssignment(ctx *Context) {
542542
ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(unit_model.TypeIssues)
543543
ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(unit_model.TypePullRequests)
544544
ctx.Data["CanWriteActions"] = ctx.Repo.CanWrite(unit_model.TypeActions)
545-
ctx.Data["SnippetRemoteName"] = setting.Repository.SnippetRemoteName
545+
ctx.Data["SnippetRemoteName"] = setting.Config().Repository.SnippetRemoteName.Value(ctx)
546546

547547
canSignedUserFork, err := repo_module.CanUserForkRepo(ctx, ctx.Doer, ctx.Repo.Repository)
548548
if err != nil {

templates/admin/config_settings.tmpl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,19 @@
3939
</div>
4040
</form>
4141
</div>
42+
43+
<h4 class="ui top attached header">
44+
{{ctx.Locale.Tr "admin.config.repository_snippets"}}
45+
</h4>
46+
<div class="ui attached segment">
47+
<form class="ui form form-fetch-action" method="post" action="{{AppSubUrl}}/-/admin/config?key={{.SystemConfig.Repository.SnippetRemoteName.DynKey}}">
48+
<div class="field" data-field-patched="true">
49+
<label for="remote_name">{{ctx.Locale.Tr "admin.config.repository_snippets.remote_name"}}</label>
50+
<input id="remote_name" name="value" value="{{.SystemConfig.Repository.SnippetRemoteName.Value ctx}}" maxlength="100" dir="auto" placeholder="{{.SystemConfig.Repository.SnippetRemoteName.Def}}">
51+
</div>
52+
<div class="field">
53+
<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>
54+
</div>
55+
</form>
56+
</div>
4257
{{template "admin/layout_footer" .}}

0 commit comments

Comments
 (0)