aboutsummaryrefslogtreecommitdiffstats
path: root/services/actions/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/actions/context.go')
-rw-r--r--services/actions/context.go42
1 files changed, 40 insertions, 2 deletions
diff --git a/services/actions/context.go b/services/actions/context.go
index 2667e18337..8f686a688a 100644
--- a/services/actions/context.go
+++ b/services/actions/context.go
@@ -15,11 +15,15 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
+
+ "github.com/nektos/act/pkg/model"
)
+type GiteaContext map[string]any
+
// GenerateGiteaContext generate the gitea context without token and gitea_runtime_token
// job can be nil when generating a context for parsing workflow-level expressions
-func GenerateGiteaContext(run *actions_model.ActionRun, job *actions_model.ActionRunJob) map[string]any {
+func GenerateGiteaContext(run *actions_model.ActionRun, job *actions_model.ActionRunJob) GiteaContext {
event := map[string]any{}
_ = json.Unmarshal([]byte(run.EventPayload), &event)
@@ -42,7 +46,7 @@ func GenerateGiteaContext(run *actions_model.ActionRun, job *actions_model.Actio
refName := git.RefName(ref)
- gitContext := map[string]any{
+ gitContext := GiteaContext{
// standard contexts, see https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
"action": "", // string, The name of the action currently running, or the id of a step. GitHub removes special characters, and uses the name __run when the current step runs a script without an id. If you use the same action more than once in the same job, the name will include a suffix with the sequence number with underscore before it. For example, the first script you run will have the name __run, and the second script will be named __run_2. Similarly, the second invocation of actions/checkout will be actionscheckout2.
"action_path": "", // string, The path where an action is located. This property is only supported in composite actions. You can use this path to access files located in the same repository as the action.
@@ -160,3 +164,37 @@ func mergeTwoOutputs(o1, o2 map[string]string) map[string]string {
}
return ret
}
+
+func (g *GiteaContext) ToGitHubContext() *model.GithubContext {
+ return &model.GithubContext{
+ Event: (*g)["event"].(map[string]any),
+ EventPath: (*g)["event_path"].(string),
+ Workflow: (*g)["workflow"].(string),
+ RunID: (*g)["run_id"].(string),
+ RunNumber: (*g)["run_number"].(string),
+ Actor: (*g)["actor"].(string),
+ Repository: (*g)["repository"].(string),
+ EventName: (*g)["event_name"].(string),
+ Sha: (*g)["sha"].(string),
+ Ref: (*g)["ref"].(string),
+ RefName: (*g)["ref_name"].(string),
+ RefType: (*g)["ref_type"].(string),
+ HeadRef: (*g)["head_ref"].(string),
+ BaseRef: (*g)["base_ref"].(string),
+ Token: "", // deliberately omitted for security
+ Workspace: (*g)["workspace"].(string),
+ Action: (*g)["action"].(string),
+ ActionPath: (*g)["action_path"].(string),
+ ActionRef: (*g)["action_ref"].(string),
+ ActionRepository: (*g)["action_repository"].(string),
+ Job: (*g)["job"].(string),
+ JobName: "", // not present in GiteaContext
+ RepositoryOwner: (*g)["repository_owner"].(string),
+ RetentionDays: (*g)["retention_days"].(string),
+ RunnerPerflog: "", // not present in GiteaContext
+ RunnerTrackingID: "", // not present in GiteaContext
+ ServerURL: (*g)["server_url"].(string),
+ APIURL: (*g)["api_url"].(string),
+ GraphQLURL: (*g)["graphql_url"].(string),
+ }
+}