diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index e7ddda4b8a..23f2ad8bdb 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2478,3 +2478,18 @@ ROUTER = console ;PROXY_URL = ;; Comma separated list of host names requiring proxy. Glob patterns (*) are accepted; use ** to match all hosts. ;PROXY_HOSTS = + +; [bots] +;; Enable/Disable bots capabilities +;ENABLED = false +;DEFAULT_BOTS_URL = https://gitea.com + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; settings for packages, will override storage setting +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;[storage.bots_log] +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; storage type +;STORAGE_TYPE = local diff --git a/modules/setting/build.go b/modules/setting/bot.go similarity index 55% rename from modules/setting/build.go rename to modules/setting/bot.go index 7d93271b4c..417bc0a809 100644 --- a/modules/setting/build.go +++ b/modules/setting/bot.go @@ -8,21 +8,23 @@ import ( "code.gitea.io/gitea/modules/log" ) -// Builds settings +// Bots settings var ( - Builds = struct { + Bots = struct { Storage - Enabled bool + Enabled bool + DefaultBotsURL string }{ - Enabled: true, + Enabled: false, + DefaultBotsURL: "https://gitea.com", } ) func newBuilds() { - sec := Cfg.Section("builds") - if err := sec.MapTo(&Builds); err != nil { + sec := Cfg.Section("bots") + if err := sec.MapTo(&Bots); err != nil { log.Fatal("Failed to map Builds settings: %v", err) } - Builds.Storage = getStorage("builds", "", nil) + Bots.Storage = getStorage("bots_log", "", nil) } diff --git a/modules/storage/storage.go b/modules/storage/storage.go index c91d9a6938..a261fc215c 100644 --- a/modules/storage/storage.go +++ b/modules/storage/storage.go @@ -140,7 +140,7 @@ func Init() error { initLFS, initRepoArchives, initPackages, - initBuilds, + initBots, } { if err := f(); err != nil { return err @@ -198,8 +198,8 @@ func initPackages() (err error) { return err } -func initBuilds() (err error) { - log.Info("Initialising Builds storage with type: %s", setting.Builds.Storage.Type) - Builds, err = NewStorage(setting.Builds.Storage.Type, &setting.Builds.Storage) +func initBots() (err error) { + log.Info("Initialising Bots storage with type: %s", setting.Bots.Storage.Type) + Builds, err = NewStorage(setting.Bots.Storage.Type, &setting.Bots.Storage) return err } diff --git a/routers/api/bots/runner/runner.go b/routers/api/bots/runner/runner.go index 9ac51301ab..7db973a01e 100644 --- a/routers/api/bots/runner/runner.go +++ b/routers/api/bots/runner/runner.go @@ -18,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/bots" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" secret_service "code.gitea.io/gitea/services/secrets" @@ -305,22 +306,23 @@ func pickTask(ctx context.Context, runner *bots_model.Runner) (*runnerv1.Task, b // TODO: more context in https://docs.github.com/cn/actions/learn-github-actions/contexts#github-context taskContext, _ := structpb.NewStruct(map[string]interface{}{ - "event": event, - "run_id": fmt.Sprint(t.Job.ID), - "run_number": fmt.Sprint(t.Job.Run.Index), - "run_attempt": fmt.Sprint(t.Job.Attempt), - "actor": fmt.Sprint(t.Job.Run.TriggerUser.Name), - "repository": fmt.Sprint(t.Job.Run.Repo.OwnerName) + "/" + fmt.Sprint(t.Job.Run.Repo.Name), - "event_name": fmt.Sprint(t.Job.Run.Event.Event()), - "sha": fmt.Sprint(t.Job.Run.CommitSHA), - "ref": fmt.Sprint(t.Job.Run.Ref), - "ref_name": "", - "ref_type": "", - "head_ref": "", - "base_ref": "", - "token": t.Token, - "repository_owner": fmt.Sprint(t.Job.Run.Repo.OwnerName), - "retention_days": "", + "event": event, + "run_id": fmt.Sprint(t.Job.ID), + "run_number": fmt.Sprint(t.Job.Run.Index), + "run_attempt": fmt.Sprint(t.Job.Attempt), + "actor": fmt.Sprint(t.Job.Run.TriggerUser.Name), + "repository": fmt.Sprint(t.Job.Run.Repo.OwnerName) + "/" + fmt.Sprint(t.Job.Run.Repo.Name), + "event_name": fmt.Sprint(t.Job.Run.Event.Event()), + "sha": fmt.Sprint(t.Job.Run.CommitSHA), + "ref": fmt.Sprint(t.Job.Run.Ref), + "ref_name": "", + "ref_type": "", + "head_ref": "", + "base_ref": "", + "token": t.Token, + "repository_owner": fmt.Sprint(t.Job.Run.Repo.OwnerName), + "retention_days": "", + "gitea_default_bots_url": setting.Bots.DefaultBotsURL, }) secrets := getSecretsOfTask(ctx, t) if _, ok := secrets["GITHUB_TOKEN"]; !ok {