Add default bot url

This commit is contained in:
Lunny Xiao 2022-11-16 13:33:13 +08:00 committed by Jason Song
parent 1a55d39adc
commit fc2c70033a
4 changed files with 46 additions and 27 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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
}

View File

@ -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 {