mirror of https://code.forgejo.org/forgejo/runner
get token
parent
2442cdd8ad
commit
93c8de3ec4
|
@ -105,6 +105,17 @@ func demoPlatforms() map[string]string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getToken(task *runnerv1.Task) string {
|
||||||
|
token := task.Secrets["GITHUB_TOKEN"]
|
||||||
|
if task.Secrets["GITEA_TOKEN"] != "" {
|
||||||
|
token = task.Secrets["GITEA_TOKEN"]
|
||||||
|
}
|
||||||
|
if task.Context.Fields["token"].GetStringValue() != "" {
|
||||||
|
token = task.Context.Fields["token"].GetStringValue()
|
||||||
|
}
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error {
|
func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -159,6 +170,9 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token := getToken(task)
|
||||||
|
log.Infof("task %v token is %v", task.Id, token)
|
||||||
|
|
||||||
dataContext := task.Context.Fields
|
dataContext := task.Context.Fields
|
||||||
preset := &model.GithubContext{
|
preset := &model.GithubContext{
|
||||||
Event: dataContext["event"].GetStructValue().AsMap(),
|
Event: dataContext["event"].GetStructValue().AsMap(),
|
||||||
|
@ -173,7 +187,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error {
|
||||||
RefType: dataContext["ref_type"].GetStringValue(),
|
RefType: dataContext["ref_type"].GetStringValue(),
|
||||||
HeadRef: dataContext["head_ref"].GetStringValue(),
|
HeadRef: dataContext["head_ref"].GetStringValue(),
|
||||||
BaseRef: dataContext["base_ref"].GetStringValue(),
|
BaseRef: dataContext["base_ref"].GetStringValue(),
|
||||||
Token: dataContext["token"].GetStringValue(),
|
Token: token,
|
||||||
RepositoryOwner: dataContext["repository_owner"].GetStringValue(),
|
RepositoryOwner: dataContext["repository_owner"].GetStringValue(),
|
||||||
RetentionDays: dataContext["retention_days"].GetStringValue(),
|
RetentionDays: dataContext["retention_days"].GetStringValue(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue