loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added instance-level variables (#28115)

This PR adds instance-level variables, and so closes #27726



![gitea_instance_variables_1](https://github.com/go-gitea/gitea/assets/8344487/ad409cd4-ce36-4c84-a764-34451b0fb63a)

![gitea_instance_variables_2](https://github.com/go-gitea/gitea/assets/8344487/426f0965-dec6-4560-948c-067cdeddd720)

![gitea_instance_variables_3](https://github.com/go-gitea/gitea/assets/8344487/cf1d7776-4938-4825-922e-cbbbf28a5f33)

authored by

Jean-Baptiste Gomond and committed by
GitHub
d0f24ff4 0407a402

+42 -18
+4 -8
models/actions/variable.go
··· 31 31 } 32 32 33 33 func (v *ActionVariable) Validate() error { 34 - if v.OwnerID == 0 && v.RepoID == 0 { 35 - return errors.New("the variable is not bound to any scope") 34 + if v.OwnerID != 0 && v.RepoID != 0 { 35 + return errors.New("a variable should not be bound to an owner and a repository at the same time") 36 36 } 37 37 return nil 38 38 } ··· 58 58 59 59 func (opts FindVariablesOpts) ToConds() builder.Cond { 60 60 cond := builder.NewCond() 61 - if opts.OwnerID > 0 { 62 - cond = cond.And(builder.Eq{"owner_id": opts.OwnerID}) 63 - } 64 - if opts.RepoID > 0 { 65 - cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) 66 - } 61 + cond = cond.And(builder.Eq{"owner_id": opts.OwnerID}) 62 + cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) 67 63 return cond 68 64 } 69 65
+8 -2
routers/api/actions/runner/utils.go
··· 94 94 func getVariablesOfTask(ctx context.Context, task *actions_model.ActionTask) map[string]string { 95 95 variables := map[string]string{} 96 96 97 + // Global 98 + globalVariables, err := db.Find[actions_model.ActionVariable](ctx, actions_model.FindVariablesOpts{}) 99 + if err != nil { 100 + log.Error("find global variables: %v", err) 101 + } 102 + 97 103 // Org / User level 98 104 ownerVariables, err := db.Find[actions_model.ActionVariable](ctx, actions_model.FindVariablesOpts{OwnerID: task.Job.Run.Repo.OwnerID}) 99 105 if err != nil { ··· 106 112 log.Error("find variables of repo: %d, error: %v", task.Job.Run.RepoID, err) 107 113 } 108 114 109 - // Level precedence: Repo > Org / User 110 - for _, v := range append(ownerVariables, repoVariables...) { 115 + // Level precedence: Repo > Org / User > Global 116 + for _, v := range append(globalVariables, append(ownerVariables, repoVariables...)...) { 111 117 variables[v.Name] = v.Data 112 118 } 113 119
+18 -3
routers/web/repo/setting/variables.go
··· 15 15 ) 16 16 17 17 const ( 18 - tplRepoVariables base.TplName = "repo/settings/actions" 19 - tplOrgVariables base.TplName = "org/settings/actions" 20 - tplUserVariables base.TplName = "user/settings/actions" 18 + tplRepoVariables base.TplName = "repo/settings/actions" 19 + tplOrgVariables base.TplName = "org/settings/actions" 20 + tplUserVariables base.TplName = "user/settings/actions" 21 + tplAdminVariables base.TplName = "admin/actions" 21 22 ) 22 23 23 24 type variablesCtx struct { ··· 26 27 IsRepo bool 27 28 IsOrg bool 28 29 IsUser bool 30 + IsGlobal bool 29 31 VariablesTemplate base.TplName 30 32 RedirectLink string 31 33 } ··· 33 35 func getVariablesCtx(ctx *context.Context) (*variablesCtx, error) { 34 36 if ctx.Data["PageIsRepoSettings"] == true { 35 37 return &variablesCtx{ 38 + OwnerID: 0, 36 39 RepoID: ctx.Repo.Repository.ID, 37 40 IsRepo: true, 38 41 VariablesTemplate: tplRepoVariables, ··· 48 51 } 49 52 return &variablesCtx{ 50 53 OwnerID: ctx.ContextUser.ID, 54 + RepoID: 0, 51 55 IsOrg: true, 52 56 VariablesTemplate: tplOrgVariables, 53 57 RedirectLink: ctx.Org.OrgLink + "/settings/actions/variables", ··· 57 61 if ctx.Data["PageIsUserSettings"] == true { 58 62 return &variablesCtx{ 59 63 OwnerID: ctx.Doer.ID, 64 + RepoID: 0, 60 65 IsUser: true, 61 66 VariablesTemplate: tplUserVariables, 62 67 RedirectLink: setting.AppSubURL + "/user/settings/actions/variables", 68 + }, nil 69 + } 70 + 71 + if ctx.Data["PageIsAdmin"] == true { 72 + return &variablesCtx{ 73 + OwnerID: 0, 74 + RepoID: 0, 75 + IsGlobal: true, 76 + VariablesTemplate: tplAdminVariables, 77 + RedirectLink: setting.AppSubURL + "/admin/actions/variables", 63 78 }, nil 64 79 } 65 80
+5 -4
routers/web/web.go
··· 417 417 m.Post("/packagist/{id}", web.Bind(forms.NewPackagistHookForm{}), repo_setting.PackagistHooksEditPost) 418 418 } 419 419 420 - addSettingVariablesRoutes := func() { 420 + addSettingsVariablesRoutes := func() { 421 421 m.Group("/variables", func() { 422 422 m.Get("", repo_setting.Variables) 423 423 m.Post("/new", web.Bind(forms.EditVariableForm{}), repo_setting.VariableCreate) ··· 618 618 m.Get("", user_setting.RedirectToDefaultSetting) 619 619 addSettingsRunnersRoutes() 620 620 addSettingsSecretsRoutes() 621 - addSettingVariablesRoutes() 621 + addSettingsVariablesRoutes() 622 622 }, actions.MustEnableActions) 623 623 624 624 m.Get("/organization", user_setting.Organization) ··· 763 763 m.Group("/actions", func() { 764 764 m.Get("", admin.RedirectToDefaultSetting) 765 765 addSettingsRunnersRoutes() 766 + addSettingsVariablesRoutes() 766 767 }) 767 768 }, adminReq, ctxDataSet("EnableOAuth2", setting.OAuth2.Enable, "EnablePackages", setting.Packages.Enabled)) 768 769 // ***** END: Admin ***** ··· 905 906 m.Get("", org_setting.RedirectToDefaultSetting) 906 907 addSettingsRunnersRoutes() 907 908 addSettingsSecretsRoutes() 908 - addSettingVariablesRoutes() 909 + addSettingsVariablesRoutes() 909 910 }, actions.MustEnableActions) 910 911 911 912 m.Methods("GET,POST", "/delete", org.SettingsDelete) ··· 1084 1085 m.Get("", repo_setting.RedirectToDefaultSetting) 1085 1086 addSettingsRunnersRoutes() 1086 1087 addSettingsSecretsRoutes() 1087 - addSettingVariablesRoutes() 1088 + addSettingsVariablesRoutes() 1088 1089 }, actions.MustEnableActions) 1089 1090 // the follow handler must be under "settings", otherwise this incomplete repo can't be accessed 1090 1091 m.Group("/migrate", func() {
+3
templates/admin/actions.tmpl
··· 3 3 {{if eq .PageType "runners"}} 4 4 {{template "shared/actions/runner_list" .}} 5 5 {{end}} 6 + {{if eq .PageType "variables"}} 7 + {{template "shared/variables/variable_list" .}} 8 + {{end}} 6 9 </div> 7 10 {{template "admin/layout_footer" .}}
+4 -1
templates/admin/navbar.tmpl
··· 60 60 {{end}} 61 61 {{end}} 62 62 {{if .EnableActions}} 63 - <details class="item toggleable-item" {{if .PageIsSharedSettingsRunners}}open{{end}}> 63 + <details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsVariables}}open{{end}}> 64 64 <summary>{{ctx.Locale.Tr "actions.actions"}}</summary> 65 65 <div class="menu"> 66 66 <a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{AppSubUrl}}/admin/actions/runners"> 67 67 {{ctx.Locale.Tr "actions.runners"}} 68 + </a> 69 + <a class="{{if .PageIsSharedSettingsVariables}}active {{end}}item" href="{{AppSubUrl}}/admin/actions/variables"> 70 + {{ctx.Locale.Tr "actions.variables"}} 68 71 </a> 69 72 </div> 70 73 </details>