From e4b1f351966d5f05da0295759571e08374b14964 Mon Sep 17 00:00:00 2001 From: Sonia Chikh Date: Thu, 13 Apr 2023 20:07:40 -0400 Subject: [PATCH 1/4] add workflow run and workflow to deployment event --- github/event_types.go | 7 +- github/event_types_test.go | 184 +++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 3 deletions(-) diff --git a/github/event_types.go b/github/event_types.go index 2340a60156f..4be3440f2ee 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"` @@ -183,7 +185,6 @@ type DeploymentStatusEvent struct { Deployment *Deployment `json:"deployment,omitempty"` DeploymentStatus *DeploymentStatus `json:"deployment_status,omitempty"` Repo *Repository `json:"repository,omitempty"` - // The following fields are only populated by Webhook events. Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` diff --git a/github/event_types_test.go b/github/event_types_test.go index cdbaee5542b..4e4e3e016d9 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -5338,6 +5338,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 := `{ @@ -5477,6 +5569,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" + } } }` From 103b1c04f7b1c4c7d7dc7c4b9e342bd937a35f33 Mon Sep 17 00:00:00 2001 From: Aaron Stockmeister Date: Tue, 15 Aug 2023 16:18:07 -0400 Subject: [PATCH 2/4] go generate and address review comment --- github/event_types.go | 3 ++- github/github-accessors.go | 16 ++++++++++++++++ github/github-accessors_test.go | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/github/event_types.go b/github/event_types.go index 4be3440f2ee..872c6859fe8 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -184,7 +184,8 @@ type DeploymentEvent struct { type DeploymentStatusEvent struct { Deployment *Deployment `json:"deployment,omitempty"` DeploymentStatus *DeploymentStatus `json:"deployment_status,omitempty"` - Repo *Repository `json:"repository,omitempty"` + + Repo *Repository `json:"repository,omitempty"` // The following fields are only populated by Webhook events. Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` diff --git a/github/github-accessors.go b/github/github-accessors.go index eea7518cbab..e47561106c1 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4598,6 +4598,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 +} + // GetAutoMerge returns the AutoMerge field if it's non-nil, zero value otherwise. func (d *DeploymentRequest) GetAutoMerge() bool { if d == nil || d.AutoMerge == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 5b2054bfeb4..500631b8667 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -5382,6 +5382,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 TestDeploymentRequest_GetAutoMerge(tt *testing.T) { var zeroValue bool d := &DeploymentRequest{AutoMerge: &zeroValue} From 7fe93f2ef6c6a94e03511c660244df3f158e401c Mon Sep 17 00:00:00 2001 From: Aaron Stockmeister Date: Tue, 15 Aug 2023 16:27:30 -0400 Subject: [PATCH 3/4] go generate again --- github/github-accessors.go | 32 ++++++++++++++++---------------- github/github-accessors_test.go | 28 ++++++++++++++-------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 3169d88a716..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 { @@ -5438,22 +5454,6 @@ func (d *DeploymentProtectionRuleEvent) 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 -} - // GetAutoMerge returns the AutoMerge field if it's non-nil, zero value otherwise. func (d *DeploymentRequest) GetAutoMerge() bool { if d == nil || d.AutoMerge == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index f0e3bb6c103..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} @@ -6390,20 +6404,6 @@ func TestDeploymentProtectionRuleEvent_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 TestDeploymentRequest_GetAutoMerge(tt *testing.T) { var zeroValue bool d := &DeploymentRequest{AutoMerge: &zeroValue} From 66d940cc7298867e67240f6e3781fc73c9614ae6 Mon Sep 17 00:00:00 2001 From: Aaron Stockmeister Date: Tue, 15 Aug 2023 16:30:10 -0400 Subject: [PATCH 4/4] fix blank line --- github/event_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/event_types.go b/github/event_types.go index 32ca85b649a..64bbde122a3 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -203,8 +203,8 @@ type DeploymentProtectionRuleEvent struct { type DeploymentStatusEvent struct { Deployment *Deployment `json:"deployment,omitempty"` DeploymentStatus *DeploymentStatus `json:"deployment_status,omitempty"` + Repo *Repository `json:"repository,omitempty"` - Repo *Repository `json:"repository,omitempty"` // The following fields are only populated by Webhook events. Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"`