Skip to content

Commit 67cc3c3

Browse files
committed
explicitly convert GiteaContext ToGitHubContext()
1 parent 2b0939e commit 67cc3c3

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

services/actions/context.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"code.gitea.io/gitea/modules/container"
1515
"code.gitea.io/gitea/modules/git"
1616
"code.gitea.io/gitea/modules/json"
17-
"code.gitea.io/gitea/modules/log"
1817
"code.gitea.io/gitea/modules/setting"
1918

2019
"github.com/nektos/act/pkg/model"
@@ -167,17 +166,35 @@ func mergeTwoOutputs(o1, o2 map[string]string) map[string]string {
167166
}
168167

169168
func (g *GiteaContext) ToGitHubContext() *model.GithubContext {
170-
ghCtx := &model.GithubContext{}
171-
172-
gitCtxRaw, err := json.Marshal(g)
173-
if err != nil {
174-
log.Error("ToGitHubContext.json.Marshal: %v", err)
175-
}
176-
177-
err = json.Unmarshal(gitCtxRaw, ghCtx)
178-
if err != nil {
179-
log.Error("ToGitHubContext.json.Unmarshal: %v", err)
169+
return &model.GithubContext{
170+
Event: (*g)["event"].(map[string]interface{}),
171+
EventPath: (*g)["event_path"].(string),
172+
Workflow: (*g)["workflow"].(string),
173+
RunID: (*g)["run_id"].(string),
174+
RunNumber: (*g)["run_number"].(string),
175+
Actor: (*g)["actor"].(string),
176+
Repository: (*g)["repository"].(string),
177+
EventName: (*g)["event_name"].(string),
178+
Sha: (*g)["sha"].(string),
179+
Ref: (*g)["ref"].(string),
180+
RefName: (*g)["ref_name"].(string),
181+
RefType: (*g)["ref_type"].(string),
182+
HeadRef: (*g)["head_ref"].(string),
183+
BaseRef: (*g)["base_ref"].(string),
184+
Token: "", // deliberately omitted for security
185+
Workspace: (*g)["workspace"].(string),
186+
Action: (*g)["action"].(string),
187+
ActionPath: (*g)["action_path"].(string),
188+
ActionRef: (*g)["action_ref"].(string),
189+
ActionRepository: (*g)["action_repository"].(string),
190+
Job: (*g)["job"].(string),
191+
JobName: "", // not present in GiteaContext
192+
RepositoryOwner: (*g)["repository_owner"].(string),
193+
RetentionDays: (*g)["retention_days"].(string),
194+
RunnerPerflog: "", // not present in GiteaContext
195+
RunnerTrackingID: "", // not present in GiteaContext
196+
ServerURL: (*g)["server_url"].(string),
197+
APIURL: (*g)["api_url"].(string),
198+
GraphQLURL: (*g)["graphql_url"].(string),
180199
}
181-
182-
return ghCtx
183200
}

0 commit comments

Comments
 (0)