diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index 65c8b74e08..878b9e24d7 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -3692,6 +3692,7 @@ "secrets.deletion.success": "The secret has been removed.", "secrets.deletion.failed": "Failed to remove secret.", "secrets.management": "Secrets Management", + "secrets.overridden": "overridden by repository", "actions.actions": "Actions", "actions.unit.desc": "Manage actions", "actions.status.unknown": "Unknown", @@ -3796,6 +3797,7 @@ "actions.approve_all_success": "All workflow runs are approved successfully.", "actions.variables": "Variables", "actions.variables.management": "Variables Management", + "actions.variables.overridden": "overridden by repository", "actions.variables.creation": "Add Variable", "actions.variables.none": "There are no variables yet.", "actions.variables.deletion": "Remove variable", diff --git a/routers/web/shared/actions/variables.go b/routers/web/shared/actions/variables.go index 8a8c49f415..ec3b349475 100644 --- a/routers/web/shared/actions/variables.go +++ b/routers/web/shared/actions/variables.go @@ -107,6 +107,27 @@ func Variables(ctx *context.Context) { ctx.Data["Variables"] = variables ctx.Data["DataMaxLength"] = actions_model.VariableDataMaxLength ctx.Data["DescriptionMaxLength"] = actions_model.VariableDescriptionMaxLength + + // MokoGitea: when viewing repo variables, also show inherited org variables + if vCtx.IsRepo && ctx.Repo != nil && ctx.Repo.Repository != nil { + orgVars, err := db.Find[actions_model.ActionVariable](ctx, actions_model.FindVariablesOpts{ + OwnerID: ctx.Repo.Repository.OwnerID, + }) + if err != nil { + log.Error("FindOrgVariables failed: %v", err) + } else if len(orgVars) > 0 { + repoVarNames := make(map[string]bool, len(variables)) + for _, v := range variables { + repoVarNames[v.Name] = true + } + ctx.Data["OrgVariables"] = orgVars + ctx.Data["RepoVariableNames"] = repoVarNames + if err := ctx.Repo.Repository.LoadOwner(ctx); err == nil { + ctx.Data["OrgVariablesLink"] = ctx.Repo.Repository.Owner.HTMLURL(ctx) + "/settings/actions/variables" + } + } + } + ctx.HTML(http.StatusOK, vCtx.VariablesTemplate) } diff --git a/routers/web/shared/secrets/secrets.go b/routers/web/shared/secrets/secrets.go index c8842a67e9..87b5f86cf8 100644 --- a/routers/web/shared/secrets/secrets.go +++ b/routers/web/shared/secrets/secrets.go @@ -24,6 +24,25 @@ func SetSecretsContext(ctx *context.Context, ownerID, repoID int64) { ctx.Data["Secrets"] = secrets ctx.Data["DataMaxLength"] = secret_model.SecretDataMaxLength ctx.Data["DescriptionMaxLength"] = secret_model.SecretDescriptionMaxLength + + // MokoGitea: when viewing repo secrets, also show inherited org secrets + if repoID > 0 && ctx.Repo != nil && ctx.Repo.Repository != nil { + orgSecrets, err := db.Find[secret_model.Secret](ctx, secret_model.FindSecretsOptions{OwnerID: ctx.Repo.Repository.OwnerID}) + if err != nil { + log.Error("FindOrgSecrets failed: %v", err) + } else if len(orgSecrets) > 0 { + // Build a set of repo secret names to detect overrides + repoSecretNames := make(map[string]bool, len(secrets)) + for _, s := range secrets { + repoSecretNames[s.Name] = true + } + ctx.Data["OrgSecrets"] = orgSecrets + ctx.Data["RepoSecretNames"] = repoSecretNames + if err := ctx.Repo.Repository.LoadOwner(ctx); err == nil { + ctx.Data["OrgSecretsLink"] = ctx.Repo.Repository.Owner.HTMLURL(ctx) + "/settings/actions/secrets" + } + } + } } func PerformSecretsPost(ctx *context.Context, ownerID, repoID int64, redirectURL string) { diff --git a/templates/shared/secrets/add_list.tmpl b/templates/shared/secrets/add_list.tmpl index d99ec279dd..f28efe5741 100644 --- a/templates/shared/secrets/add_list.tmpl +++ b/templates/shared/secrets/add_list.tmpl @@ -65,6 +65,48 @@ {{end}} +{{/* Inherited organization secrets */}} +{{if .OrgSecrets}} +

+ {{ctx.Locale.Tr "secrets.management"}} — {{ctx.Locale.Tr "org.name"}} + {{if .OrgSecretsLink}} +
+ {{ctx.Locale.Tr "settings.manage"}} +
+ {{end}} +

+
+
+ {{range .OrgSecrets}} +
+
+ {{svg "octicon-organization" 32}} +
+
+
+ {{.Name}} + {{if index $.RepoSecretNames .Name}} + {{ctx.Locale.Tr "secrets.overridden"}} + {{end}} +
+
+ {{if .Description}}{{.Description}}{{else}}-{{end}} +
+
+ ****** +
+
+
+ + {{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}} + +
+
+ {{end}} +
+
+{{end}} + {{/* Add secret dialog */}} +{{/* Inherited organization variables */}} +{{if .OrgVariables}} +

+ {{ctx.Locale.Tr "actions.variables.management"}} — {{ctx.Locale.Tr "org.name"}} + {{if .OrgVariablesLink}} +
+ {{ctx.Locale.Tr "settings.manage"}} +
+ {{end}} +

+
+
+ {{range .OrgVariables}} +
+
+ {{svg "octicon-organization" 32}} +
+
+
+ {{.Name}} + {{if index $.RepoVariableNames .Name}} + {{ctx.Locale.Tr "actions.variables.overridden"}} + {{end}} +
+
+ {{if .Description}}{{.Description}}{{else}}-{{end}} +
+
+ {{.Data}} +
+
+
+ + {{ctx.Locale.Tr "settings.added_on" (DateUtils.AbsoluteShort .CreatedUnix)}} + +
+
+ {{end}} +
+
+{{end}} + {{/** Edit variable dialog */}}