Skip to content

Add user level action runners #24995

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 11 commits into from
May 31, 2023
6 changes: 5 additions & 1 deletion models/actions/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ func (r *ActionRunner) BelongsToOwnerType() types.OwnerType {
return types.OwnerTypeRepository
}
if r.OwnerID != 0 {
return types.OwnerTypeOrganization
if r.Owner.Type == user_model.UserTypeOrganization {
return types.OwnerTypeOrganization
} else if r.Owner.Type == user_model.UserTypeIndividual {
return types.OwnerTypeIndividual
}
}
return types.OwnerTypeSystemGlobal
}
Expand Down
16 changes: 15 additions & 1 deletion routers/web/repo/setting/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ const (
tplRepoRunners base.TplName = "repo/settings/actions"
tplOrgRunners base.TplName = "org/settings/actions"
tplAdminRunners base.TplName = "admin/actions"
tplUserRunners base.TplName = "user/settings/actions"
tplRepoRunnerEdit base.TplName = "repo/settings/runner_edit"
tplOrgRunnerEdit base.TplName = "org/settings/runners_edit"
tplAdminRunnerEdit base.TplName = "admin/runners/edit"
tplUserRunnerEdit base.TplName = "user/settings/runner_edit"
)

type runnersCtx struct {
Expand All @@ -32,6 +34,7 @@ type runnersCtx struct {
IsRepo bool
IsOrg bool
IsAdmin bool
IsUser bool
RunnersTemplate base.TplName
RunnerEditTemplate base.TplName
RedirectLink string
Expand Down Expand Up @@ -71,6 +74,17 @@ func getRunnersCtx(ctx *context.Context) (*runnersCtx, error) {
}, nil
}

if ctx.Data["PageIsUserSettings"] == true {
return &runnersCtx{
OwnerID: ctx.Doer.ID,
RepoID: 0,
IsUser: true,
RunnersTemplate: tplUserRunners,
RunnerEditTemplate: tplUserRunnerEdit,
RedirectLink: setting.AppSubURL + "/user/settings/actions/runners/",
}, nil
}

return nil, errors.New("unable to set Runners context")
}

Expand Down Expand Up @@ -102,7 +116,7 @@ func Runners(ctx *context.Context) {
if rCtx.IsRepo {
opts.RepoID = rCtx.RepoID
opts.WithAvailable = true
} else if rCtx.IsOrg {
} else if rCtx.IsOrg || rCtx.IsUser {
opts.OwnerID = rCtx.OwnerID
opts.WithAvailable = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import (
)

func RedirectToDefaultSetting(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/actions/secrets")
ctx.Redirect(setting.AppSubURL + "/user/settings/actions/runners")
}
1 change: 1 addition & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ func registerRoutes(m *web.Route) {

m.Group("/actions", func() {
m.Get("", user_setting.RedirectToDefaultSetting)
addSettingsRunnersRoutes()
addSettingsSecretsRoutes()
}, actions.MustEnableActions)

Expand Down
2 changes: 2 additions & 0 deletions templates/user/settings/actions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<div class="user-setting-content">
{{if eq .PageType "secrets"}}
{{template "shared/secrets/add_list" .}}
{{else if eq .PageType "runners"}}
{{template "shared/actions/runner_list" .}}
{{end}}
</div>

Expand Down
3 changes: 3 additions & 0 deletions templates/user/settings/navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<div class="item">
{{.locale.Tr "actions.actions"}}
<div class="menu">
<a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{AppSubUrl}}/user/settings/actions/runners">
{{.locale.Tr "actions.runners"}}
</a>
<a class="{{if .PageIsSharedSettingsSecrets}}active {{end}}item" href="{{AppSubUrl}}/user/settings/actions/secrets">
{{.locale.Tr "secrets.secrets"}}
</a>
Expand Down
5 changes: 5 additions & 0 deletions templates/user/settings/runner_edit.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{template "user/settings/layout_head" (dict "ctxData" . "pageClass" "user settings runners")}}
<div class="user-setting-content">
{{template "shared/actions/runner_edit" .}}
</div>
{{template "user/settings/layout_footer" .}}