Repository: google/go-github
Pull request #2755 (2023-04-14 00:08:04)

Add WorkflowRun and Workflow to DeploymentEvent

gmlewis: @google-ospo-team - here is another PR where the googlebot has failed to comment.  Please address.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/2755?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2755](https://app.codecov.io/gh/google/go-github/pull/2755?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (7fe93f2) into [master](https://app.codecov.io/gh/google/go-github/commit/0c10d670aa824453a404505438e8881c41763cc7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (0c10d67) will **not change** coverage.
> The diff coverage is `n/a`.

> :exclamation: Current head 7fe93f2 differs from pull request most recent head 66d940c. Consider uploading reports for the commit 66d940c to get more accurate results

```diff
@@           Coverage Diff           @@
##           master    #2755   +/-   ##
=======================================
  Coverage   98.07%   98.07%           
=======================================
  Files         139      139           
  Lines       12357    12357           
=======================================
  Hits        12119    12119           
  Misses        162      162           
  Partials       76       76           
```


| [Files Changed](https://app.codecov.io/gh/google/go-github/pull/2755?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/event\_types.go](https://app.codecov.io/gh/google/go-github/pull/2755?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2V2ZW50X3R5cGVzLmdv) | `100.00% <ø> (ø)` | |


gmlewis: Ah!  We now have the cla/google check - @soniachikh - please follow the instructions to sign the Google CLA and then we can merge this PR.  Thank you!

Patch:
diff --git a/github/event_types.go b/github/event_types.go
index c9e97ffa..64bbde12 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/github-accessors.go b/github/github-accessors.go
index 06564f25..21d09c7b 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 {


Test patch:
diff --git a/github/event_types_test.go b/github/event_types_test.go
index c1cb4d96..653671b8 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_test.go b/github/github-accessors_test.go
index 46716b88..39157836 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}