diff --git a/github/event_types.go b/github/event_types.go index c9e97ffa291..64bbde122a3 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -165,8 +165,10 @@ type DeployKeyEvent struct { // // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#deployment type DeploymentEvent struct { - Deployment *Deployment `json:"deployment,omitempty"` - Repo *Repository `json:"repository,omitempty"` + Deployment *Deployment `json:"deployment,omitempty"` + Repo *Repository `json:"repository,omitempty"` + Workflow *Workflow `json:"workflow,omitempty"` + WorkflowRun *WorkflowRun `json:"workflow_run,omitempty"` // The following fields are only populated by Webhook events. Sender *User `json:"sender,omitempty"` diff --git a/github/event_types_test.go b/github/event_types_test.go index c1cb4d9636f..653671b8685 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -5674,6 +5674,98 @@ func TestDeploymentEvent_Marshal(t *testing.T) { }, SuspendedAt: &Timestamp{referenceTime}, }, + Workflow: &Workflow{ + ID: Int64(1), + NodeID: String("nid"), + Name: String("n"), + Path: String("p"), + State: String("s"), + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + URL: String("u"), + HTMLURL: String("h"), + BadgeURL: String("b"), + }, + WorkflowRun: &WorkflowRun{ + ID: Int64(1), + Name: String("n"), + NodeID: String("nid"), + HeadBranch: String("hb"), + HeadSHA: String("hs"), + RunNumber: Int(1), + RunAttempt: Int(1), + Event: String("e"), + Status: String("s"), + Conclusion: String("c"), + WorkflowID: Int64(1), + URL: String("u"), + HTMLURL: String("h"), + PullRequests: []*PullRequest{ + { + URL: String("u"), + ID: Int64(1), + Number: Int(1), + Head: &PullRequestBranch{ + Ref: String("r"), + SHA: String("s"), + Repo: &Repository{ + ID: Int64(1), + URL: String("s"), + Name: String("n"), + }, + }, + Base: &PullRequestBranch{ + Ref: String("r"), + SHA: String("s"), + Repo: &Repository{ + ID: Int64(1), + URL: String("u"), + Name: String("n"), + }, + }, + }, + }, + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + RunStartedAt: &Timestamp{referenceTime}, + JobsURL: String("j"), + LogsURL: String("l"), + CheckSuiteURL: String("c"), + ArtifactsURL: String("a"), + CancelURL: String("c"), + RerunURL: String("r"), + PreviousAttemptURL: String("p"), + HeadCommit: &HeadCommit{ + Message: String("m"), + Author: &CommitAuthor{ + Name: String("n"), + Email: String("e"), + Login: String("l"), + }, + URL: String("u"), + Distinct: Bool(false), + SHA: String("s"), + ID: String("i"), + TreeID: String("tid"), + Timestamp: &Timestamp{referenceTime}, + Committer: &CommitAuthor{ + Name: String("n"), + Email: String("e"), + Login: String("l"), + }, + }, + WorkflowURL: String("w"), + Repository: &Repository{ + ID: Int64(1), + URL: String("u"), + Name: String("n"), + }, + HeadRepository: &Repository{ + ID: Int64(1), + URL: String("u"), + Name: String("n"), + }, + }, } want := `{ @@ -5813,6 +5905,98 @@ func TestDeploymentEvent_Marshal(t *testing.T) { "url": "u" }, "suspended_at": ` + referenceTimeStr + ` + }, + "workflow": { + "id": 1, + "node_id": "nid", + "name": "n", + "path": "p", + "state": "s", + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "url": "u", + "html_url": "h", + "badge_url": "b" + }, + "workflow_run": { + "id": 1, + "name": "n", + "node_id": "nid", + "head_branch": "hb", + "head_sha": "hs", + "run_number": 1, + "run_attempt": 1, + "event": "e", + "status": "s", + "conclusion": "c", + "workflow_id": 1, + "url": "u", + "html_url": "h", + "pull_requests": [ + { + "id": 1, + "number": 1, + "url": "u", + "head": { + "ref": "r", + "sha": "s", + "repo": { + "id": 1, + "name": "n", + "url": "s" + } + }, + "base": { + "ref": "r", + "sha": "s", + "repo": { + "id": 1, + "name": "n", + "url": "u" + } + } + } + ], + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "run_started_at": ` + referenceTimeStr + `, + "jobs_url": "j", + "logs_url": "l", + "check_suite_url": "c", + "artifacts_url": "a", + "cancel_url": "c", + "rerun_url": "r", + "previous_attempt_url": "p", + "head_commit": { + "message": "m", + "author": { + "name": "n", + "email": "e", + "username": "l" + }, + "url": "u", + "distinct": false, + "sha": "s", + "id": "i", + "tree_id": "tid", + "timestamp": ` + referenceTimeStr + `, + "committer": { + "name": "n", + "email": "e", + "username": "l" + } + }, + "workflow_url": "w", + "repository": { + "id": 1, + "name": "n", + "url": "u" + }, + "head_repository": { + "id": 1, + "name": "n", + "url": "u" + } } }` diff --git a/github/github-accessors.go b/github/github-accessors.go index 06564f250c2..21d09c7b5ba 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -5366,6 +5366,22 @@ func (d *DeploymentEvent) GetSender() *User { return d.Sender } +// GetWorkflow returns the Workflow field. +func (d *DeploymentEvent) GetWorkflow() *Workflow { + if d == nil { + return nil + } + return d.Workflow +} + +// GetWorkflowRun returns the WorkflowRun field. +func (d *DeploymentEvent) GetWorkflowRun() *WorkflowRun { + if d == nil { + return nil + } + return d.WorkflowRun +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (d *DeploymentProtectionRuleEvent) GetAction() string { if d == nil || d.Action == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 46716b88064..391578360cb 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -6315,6 +6315,20 @@ func TestDeploymentEvent_GetSender(tt *testing.T) { d.GetSender() } +func TestDeploymentEvent_GetWorkflow(tt *testing.T) { + d := &DeploymentEvent{} + d.GetWorkflow() + d = nil + d.GetWorkflow() +} + +func TestDeploymentEvent_GetWorkflowRun(tt *testing.T) { + d := &DeploymentEvent{} + d.GetWorkflowRun() + d = nil + d.GetWorkflowRun() +} + func TestDeploymentProtectionRuleEvent_GetAction(tt *testing.T) { var zeroValue string d := &DeploymentProtectionRuleEvent{Action: &zeroValue}