Repository: google/go-github (go)

Issue:
Support state_reason in IssuesService.Edit

I would like to be able to use the API to close an issue with a reason why like you can in the UI (https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/ , https://github.blog/changelog/2022-03-10-the-new-github-issues-march-10th-update/ ). I looked at the Issues API documentation and couldn't find reference to these closing reasons (https://docs.github.com/en/rest/issues/issues#update-an-issue) but I contacted support and they stated:

> The API now supports closing issues with state reasons. I'd reach out to the docs team to help update this in the API documentation.
> 
> Here is a sample query you can run:
>
> ```text
> curl -X PATCH -H "Accept: application/vnd.github.v3+json" -H "Authorization: token {TOKEN}" https://api.github.com/repos/{org_name}/{repo_name}/issues/{issue-id} -d '{"state":"closed","state_reason":"not_planned"}'
> ```
>
> `"state_reason"` can either be `completed` or `not_planned`.

Pull request:
Add state_reason to IssuesService.Edit 
`state_reason` can be 'completed' or 'not_planned'.

I believe we let GitHub document these values, but let me know if you need me to modify this change. Thank you!

Fixes #2393.

/cc @gmlewis 

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 0092c588..da146bcb 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -7630,6 +7630,14 @@ func (i *IssueRequest) GetState() string {
 	return *i.State
 }
 
+// GetStateReason returns the StateReason field if it's non-nil, zero value otherwise.
+func (i *IssueRequest) 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 *IssueRequest) GetTitle() string {
 	if i == nil || i.Title == nil {
diff --git a/github/issues.go b/github/issues.go
index 12488f98..351ec09c 100644
--- a/github/issues.go
+++ b/github/issues.go
@@ -77,13 +77,15 @@ func (i Issue) IsPullRequest() bool {
 // It is separate from Issue above because otherwise Labels
 // and Assignee fail to serialize to the correct JSON.
 type IssueRequest struct {
-	Title     *string   `json:"title,omitempty"`
-	Body      *string   `json:"body,omitempty"`
-	Labels    *[]string `json:"labels,omitempty"`
-	Assignee  *string   `json:"assignee,omitempty"`
-	State     *string   `json:"state,omitempty"`
-	Milestone *int      `json:"milestone,omitempty"`
-	Assignees *[]string `json:"assignees,omitempty"`
+	Title    *string   `json:"title,omitempty"`
+	Body     *string   `json:"body,omitempty"`
+	Labels   *[]string `json:"labels,omitempty"`
+	Assignee *string   `json:"assignee,omitempty"`
+	State    *string   `json:"state,omitempty"`
+	// StateReason can be 'completed' or 'not_planned'.
+	StateReason *string   `json:"state_reason,omitempty"`
+	Milestone   *int      `json:"milestone,omitempty"`
+	Assignees   *[]string `json:"assignees,omitempty"`
 }
 
 // IssueListOptions specifies the optional parameters to the IssuesService.List


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index bf5008f5..5d30ec96 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -8938,6 +8938,16 @@ func TestIssueRequest_GetState(tt *testing.T) {
 	i.GetState()
 }
 
+func TestIssueRequest_GetStateReason(tt *testing.T) {
+	var zeroValue string
+	i := &IssueRequest{StateReason: &zeroValue}
+	i.GetStateReason()
+	i = &IssueRequest{}
+	i.GetStateReason()
+	i = nil
+	i.GetStateReason()
+}
+
 func TestIssueRequest_GetTitle(tt *testing.T) {
 	var zeroValue string
 	i := &IssueRequest{Title: &zeroValue}