Repository: google/go-github
Pull request #2764 (2023-04-18 10:51:02)

Add HeadBranch field to WorkflowJob
The `workflow_job` events contain the branch information (`head_branch`) but it's missing from the `WorkflowJob` object. This change adds the missing field and updates the corresponding tests.

Fixes: #2762.

codecov[bot]: ## [Codecov](https://codecov.io/gh/google/go-github/pull/2764?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2764](https://codecov.io/gh/google/go-github/pull/2764?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (50e1105) into [master](https://codecov.io/gh/google/go-github/commit/a888f0ce6a3ded0f042787812ea94b13c79ffd3a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (a888f0c) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2764   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files         132      132           
  Lines       11638    11638           
=======================================
  Hits        11412    11412           
  Misses        154      154           
  Partials       72       72           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2764?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/actions\_workflow\_jobs.go](https://codecov.io/gh/google/go-github/pull/2764?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2FjdGlvbnNfd29ya2Zsb3dfam9icy5nbw==) | `100.00% <ø> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)


Patch:
diff --git a/github/actions_workflow_jobs.go b/github/actions_workflow_jobs.go
index b7130916..1f018b3e 100644
--- a/github/actions_workflow_jobs.go
+++ b/github/actions_workflow_jobs.go
@@ -28,6 +28,7 @@ type WorkflowJob struct {
 	RunID       *int64      `json:"run_id,omitempty"`
 	RunURL      *string     `json:"run_url,omitempty"`
 	NodeID      *string     `json:"node_id,omitempty"`
+	HeadBranch  *string     `json:"head_branch,omitempty"`
 	HeadSHA     *string     `json:"head_sha,omitempty"`
 	URL         *string     `json:"url,omitempty"`
 	HTMLURL     *string     `json:"html_url,omitempty"`
diff --git a/github/github-accessors.go b/github/github-accessors.go
index eea7518c..0e25c7e8 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -21798,6 +21798,14 @@ func (w *WorkflowJob) GetCreatedAt() Timestamp {
 	return *w.CreatedAt
 }
 
+// GetHeadBranch returns the HeadBranch field if it's non-nil, zero value otherwise.
+func (w *WorkflowJob) GetHeadBranch() string {
+	if w == nil || w.HeadBranch == nil {
+		return ""
+	}
+	return *w.HeadBranch
+}
+
 // GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise.
 func (w *WorkflowJob) GetHeadSHA() string {
 	if w == nil || w.HeadSHA == nil {


Test patch:
diff --git a/github/actions_workflow_jobs_test.go b/github/actions_workflow_jobs_test.go
index 521e4011..8cea9545 100644
--- a/github/actions_workflow_jobs_test.go
+++ b/github/actions_workflow_jobs_test.go
@@ -246,6 +246,7 @@ func TestWorkflowJob_Marshal(t *testing.T) {
 		RunID:       Int64(1),
 		RunURL:      String("r"),
 		NodeID:      String("n"),
+		HeadBranch:  String("b"),
 		HeadSHA:     String("h"),
 		URL:         String("u"),
 		HTMLURL:     String("h"),
@@ -274,6 +275,7 @@ func TestWorkflowJob_Marshal(t *testing.T) {
 		"run_id": 1,
 		"run_url": "r",
 		"node_id": "n",
+		"head_branch": "b",
 		"head_sha": "h",
 		"url": "u",
 		"html_url": "h",
@@ -309,6 +311,7 @@ func TestJobs_Marshal(t *testing.T) {
 				RunID:       Int64(1),
 				RunURL:      String("r"),
 				NodeID:      String("n"),
+				HeadBranch:  String("b"),
 				HeadSHA:     String("h"),
 				URL:         String("u"),
 				HTMLURL:     String("h"),
@@ -342,6 +345,7 @@ func TestJobs_Marshal(t *testing.T) {
 			"run_id": 1,
 			"run_url": "r",
 			"node_id": "n",
+			"head_branch": "b",
 			"head_sha": "h",
 			"url": "u",
 			"html_url": "h",
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 5b2054bf..8560b276 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -25481,6 +25481,16 @@ func TestWorkflowJob_GetCreatedAt(tt *testing.T) {
 	w.GetCreatedAt()
 }
 
+func TestWorkflowJob_GetHeadBranch(tt *testing.T) {
+	var zeroValue string
+	w := &WorkflowJob{HeadBranch: &zeroValue}
+	w.GetHeadBranch()
+	w = &WorkflowJob{}
+	w.GetHeadBranch()
+	w = nil
+	w.GetHeadBranch()
+}
+
 func TestWorkflowJob_GetHeadSHA(tt *testing.T) {
 	var zeroValue string
 	w := &WorkflowJob{HeadSHA: &zeroValue}