Repository: google/go-github
Pull request #2583 (2022-11-29 18:57:04)

Add new field for issue state reason
Adds new field `state_reason` for GitHub Issue struct.
reference on the field: https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#update-an-issue

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

```diff
@@           Coverage Diff           @@
##           master    #2583   +/-   ##
=======================================
  Coverage   97.98%   97.98%           
=======================================
  Files         125      125           
  Lines       10875    10875           
=======================================
  Hits        10656    10656           
  Misses        150      150           
  Partials       69       69           
```


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

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)

ganeshkumarsv: Thanks for the suggestion @gmlewis! I committed your suggestion
ganeshkumarsv: @gmlewis once the PR gets approved and merged, can we have a new release?
gmlewis: > @gmlewis once the PR gets approved and merged, can we have a new release?

I would really like to get #2581 in before releasing `v48.2.0`.  Hopefully that can happen today.


Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 33de4b7e..c348e1a3 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -7470,6 +7470,14 @@ func (i *Issue) GetState() string {
 	return *i.State
 }
 
+// GetStateReason returns the StateReason field if it's non-nil, zero value otherwise.
+func (i *Issue) GetStateReason() string {
+	if i == nil || i.StateReason == nil {
+		return ""
+	}
+	return *i.StateReason
+}
+
 // GetTitle returns the Title field if it's non-nil, zero value otherwise.
 func (i *Issue) GetTitle() string {
 	if i == nil || i.Title == nil {
diff --git a/github/issues.go b/github/issues.go
index 351ec09c..571a7211 100644
--- a/github/issues.go
+++ b/github/issues.go
@@ -25,9 +25,11 @@ type IssuesService service
 // this is an issue, and if PullRequestLinks is not nil, this is a pull request.
 // The IsPullRequest helper method can be used to check that.
 type Issue struct {
-	ID                *int64            `json:"id,omitempty"`
-	Number            *int              `json:"number,omitempty"`
-	State             *string           `json:"state,omitempty"`
+	ID     *int64  `json:"id,omitempty"`
+	Number *int    `json:"number,omitempty"`
+	State  *string `json:"state,omitempty"`
+	// StateReason can be one of: "completed", "not_planned", "reopened".
+	StateReason       *string           `json:"state_reason,omitempty"`
 	Locked            *bool             `json:"locked,omitempty"`
 	Title             *string           `json:"title,omitempty"`
 	Body              *string           `json:"body,omitempty"`


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index ecc0d761..05fa1961 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -8780,6 +8780,16 @@ func TestIssue_GetState(tt *testing.T) {
 	i.GetState()
 }
 
+func TestIssue_GetStateReason(tt *testing.T) {
+	var zeroValue string
+	i := &Issue{StateReason: &zeroValue}
+	i.GetStateReason()
+	i = &Issue{}
+	i.GetStateReason()
+	i = nil
+	i.GetStateReason()
+}
+
 func TestIssue_GetTitle(tt *testing.T) {
 	var zeroValue string
 	i := &Issue{Title: &zeroValue}
diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go
index b83ff237..d4093a09 100644
--- a/github/github-stringify_test.go
+++ b/github/github-stringify_test.go
@@ -713,6 +713,7 @@ func TestIssue_String(t *testing.T) {
 		ID:                Int64(0),
 		Number:            Int(0),
 		State:             String(""),
+		StateReason:       String(""),
 		Locked:            Bool(false),
 		Title:             String(""),
 		Body:              String(""),
@@ -734,7 +735,7 @@ func TestIssue_String(t *testing.T) {
 		NodeID:            String(""),
 		ActiveLockReason:  String(""),
 	}
-	want := `github.Issue{ID:0, Number:0, State:"", Locked:false, Title:"", Body:"", AuthorAssociation:"", User:github.User{}, Assignee:github.User{}, Comments:0, ClosedBy:github.User{}, URL:"", HTMLURL:"", CommentsURL:"", EventsURL:"", LabelsURL:"", RepositoryURL:"", Milestone:github.Milestone{}, PullRequestLinks:github.PullRequestLinks{}, Repository:github.Repository{}, Reactions:github.Reactions{}, NodeID:"", ActiveLockReason:""}`
+	want := `github.Issue{ID:0, Number:0, State:"", StateReason:"", Locked:false, Title:"", Body:"", AuthorAssociation:"", User:github.User{}, Assignee:github.User{}, Comments:0, ClosedBy:github.User{}, URL:"", HTMLURL:"", CommentsURL:"", EventsURL:"", LabelsURL:"", RepositoryURL:"", Milestone:github.Milestone{}, PullRequestLinks:github.PullRequestLinks{}, Repository:github.Repository{}, Reactions:github.Reactions{}, NodeID:"", ActiveLockReason:""}`
 	if got := v.String(); got != want {
 		t.Errorf("Issue.String = %v, want %v", got, want)
 	}