feat: change github context parsing

This commit is contained in:
Louis Seubert 2024-11-01 23:38:54 +01:00
commit 6a3a41374e
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
3 changed files with 44 additions and 60 deletions

View file

@ -37,6 +37,7 @@ func TestAction_Context(t *testing.T) {
APIURL: "https://api.github.com",
ServerURL: "https://github.com",
GraphqlURL: "https://api.github.com/graphql",
event: map[string]any{},
},
},
{
@ -70,12 +71,13 @@ func TestAction_Context(t *testing.T) {
"GITHUB_STEP_SUMMARY": "/path/to/summary",
"GITHUB_WORKFLOW": "test",
"GITHUB_WORKSPACE": "/path/to/workspace",
"GITHUB_TOKEN": "somerandomtoken",
},
exp: &GitHubContext{
Action: "__repo-owner_name-of-action-repo",
ActionPath: "/path/to/action",
ActionRepository: "repo-owner/name-of-action-repo",
Actions: true,
Actions: "true",
Actor: "sethvargo",
APIURL: "https://foo.com",
BaseRef: "main",
@ -88,19 +90,21 @@ func TestAction_Context(t *testing.T) {
Path: "/path/to/path",
Ref: "refs/tags/v1.0",
RefName: "v1.0",
RefProtected: true,
RefProtected: "true",
RefType: "tag",
Repository: "sethvargo/baz",
RepositoryOwner: "sethvargo",
RetentionDays: 90,
RunAttempt: 6,
RunID: 56,
RunNumber: 34,
RetentionDays: "90",
RunAttempt: "6",
RunID: "56",
RunNumber: "34",
ServerURL: "https://bar.com",
SHA: "abcd1234",
StepSummary: "/path/to/summary",
Workflow: "test",
Workspace: "/path/to/workspace",
Token: "somerandomtoken",
event: map[string]any{},
},
},
{
@ -116,7 +120,7 @@ func TestAction_Context(t *testing.T) {
ServerURL: "https://github.com",
GraphqlURL: "https://api.github.com/graphql",
Event: map[string]any{
event: map[string]any{
"foo": "bar",
},
},
@ -131,7 +135,8 @@ func TestAction_Context(t *testing.T) {
a := New()
a.env = func(s string) string { return tc.env[s] }
got, err := a.Context()
got := a.Context()
_, err := got.Event()
if err != nil {
t.Fatal(err)
}