Skip to content

Commit

Permalink
Merge pull request #139 from dvonthenen/feature/workflowjob
Browse files Browse the repository at this point in the history
Implement github workflow events (Dispatch, Job, Run)
  • Loading branch information
Toshik1978 authored Nov 16, 2021
2 parents a920656 + ffc40ad commit 9c954e2
Show file tree
Hide file tree
Showing 6 changed files with 1,345 additions and 0 deletions.
15 changes: 15 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ const (
TeamEvent Event = "team"
TeamAddEvent Event = "team_add"
WatchEvent Event = "watch"
WorkflowDispatchEvent Event = "workflow_dispatch"
WorkflowJobEvent Event = "workflow_job"
WorkflowRunEvent Event = "workflow_run"
)

// EventSubtype defines a GitHub Hook Event subtype
Expand Down Expand Up @@ -325,6 +328,18 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
var pl WatchPayload
err = json.Unmarshal([]byte(payload), &pl)
return pl, err
case WorkflowDispatchEvent:
var pl WorkflowDispatchPayload
err = json.Unmarshal([]byte(payload), &pl)
return pl, err
case WorkflowJobEvent:
var pl WorkflowJobPayload
err = json.Unmarshal([]byte(payload), &pl)
return pl, err
case WorkflowRunEvent:
var pl WorkflowRunPayload
err = json.Unmarshal([]byte(payload), &pl)
return pl, err
default:
return nil, fmt.Errorf("unknown event %s", gitHubEvent)
}
Expand Down
30 changes: 30 additions & 0 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,36 @@ func TestWebhooks(t *testing.T) {
"X-Hub-Signature": []string{"sha1=a317bcfe69ccb8bece74c20c7378e5413c4772f1"},
},
},
{
name: "WorkflowDispatchEvent",
event: WorkflowDispatchEvent,
typ: WorkflowDispatchPayload{},
filename: "../testdata/github/workflow_dispatch.json",
headers: http.Header{
"X-Github-Event": []string{"workflow_dispatch"},
"X-Hub-Signature": []string{"sha1=58db5b3c7e2391b34275d42256e0eda67e4997b9"},
},
},
{
name: "WorkflowJobEvent",
event: WorkflowJobEvent,
typ: WorkflowJobPayload{},
filename: "../testdata/github/workflow_job.json",
headers: http.Header{
"X-Github-Event": []string{"workflow_job"},
"X-Hub-Signature": []string{"sha1=2f22091ecf169313c9991f5f98ef3dffb069841b"},
},
},
{
name: "WorkflowRunEvent",
event: WorkflowRunEvent,
typ: WorkflowRunPayload{},
filename: "../testdata/github/workflow_run.json",
headers: http.Header{
"X-Github-Event": []string{"workflow_run"},
"X-Hub-Signature": []string{"sha1=c54d046b1ce440bc3434c8de5ad73e0a630d7cbe"},
},
},
}

for _, tt := range tests {
Expand Down
Loading

0 comments on commit 9c954e2

Please sign in to comment.