Repository: google/go-github
Pull request #990 (2018-09-01 17:15:27)

Support changes to the Checks REST API
This PR updates `CheckService` and `CheckSuiteAnnotation` to account for the [recent changes to the GitHub API](https://developer.github.com/changes/2018-08-16-changes-to-the-checks-rest-api/):

* `filename` is being renamed to `path`
* `blob_href` is no longer necessary (no changes required, as responses continue to provide this value)
* `warning_level` is being renamed to `annotation_level`
* `POST /repos/:owner/:repo/check-suite-requests` is being removed
* `POST /repos/:owner/:repo/check-suites/:check_suite_id/rerequest` is being added

Fixes https://github.com/google/go-github/issues/980

jnewland: Thanks for the review, @gmlewis! I've pushed up changes that I believe address your comments.
gmlewis: Thank you, @gauntface!
Merging.

Patch:
diff --git a/github/checks.go b/github/checks.go
index ac924ac4..9c057e0b 100644
--- a/github/checks.go
+++ b/github/checks.go
@@ -47,14 +47,14 @@ type CheckRunOutput struct {
 
 // CheckRunAnnotation represents an annotation object for a CheckRun output.
 type CheckRunAnnotation struct {
-	FileName     *string `json:"filename,omitempty"`
-	BlobHRef     *string `json:"blob_href,omitempty"`
-	StartLine    *int    `json:"start_line,omitempty"`
-	EndLine      *int    `json:"end_line,omitempty"`
-	WarningLevel *string `json:"warning_level,omitempty"`
-	Message      *string `json:"message,omitempty"`
-	Title        *string `json:"title,omitempty"`
-	RawDetails   *string `json:"raw_details,omitempty"`
+	Path            *string `json:"path,omitempty"`
+	BlobHRef        *string `json:"blob_href,omitempty"`
+	StartLine       *int    `json:"start_line,omitempty"`
+	EndLine         *int    `json:"end_line,omitempty"`
+	AnnotationLevel *string `json:"annotation_level,omitempty"`
+	Message         *string `json:"message,omitempty"`
+	Title           *string `json:"title,omitempty"`
+	RawDetails      *string `json:"raw_details,omitempty"`
 }
 
 // CheckRunImage represents an image object for a CheckRun output.
@@ -401,18 +401,13 @@ func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string
 	return checkSuite, resp, nil
 }
 
-// RequestCheckSuiteOptions sets up the parameters for a request check suite endpoint.
-type RequestCheckSuiteOptions struct {
-	HeadSHA string `json:"head_sha"` // The sha of the head commit. (Required.)
-}
-
-// RequestCheckSuite triggers GitHub to create a new check suite, without pushing new code to a repository.
+// ReRequestCheckSuite triggers GitHub to rerequest an existing check suite, without pushing new code to a repository.
 //
-// GitHub API docs: https://developer.github.com/v3/checks/suites/#request-check-suites
-func (s *ChecksService) RequestCheckSuite(ctx context.Context, owner, repo string, opt RequestCheckSuiteOptions) (*Response, error) {
-	u := fmt.Sprintf("repos/%v/%v/check-suite-requests", owner, repo)
+// GitHub API docs: https://developer.github.com/v3/checks/suites/#rerequest-check-suite
+func (s *ChecksService) ReRequestCheckSuite(ctx context.Context, owner, repo string, checkSuiteID int64) (*Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/check-suites/%v/rerequest", owner, repo, checkSuiteID)
 
-	req, err := s.client.NewRequest("POST", u, opt)
+	req, err := s.client.NewRequest("POST", u, nil)
 	if err != nil {
 		return nil, err
 	}
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 00a5e06f..8dc27454 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -564,6 +564,14 @@ func (c *CheckRun) GetURL() string {
 	return *c.URL
 }
 
+// GetAnnotationLevel returns the AnnotationLevel field if it's non-nil, zero value otherwise.
+func (c *CheckRunAnnotation) GetAnnotationLevel() string {
+	if c == nil || c.AnnotationLevel == nil {
+		return ""
+	}
+	return *c.AnnotationLevel
+}
+
 // GetBlobHRef returns the BlobHRef field if it's non-nil, zero value otherwise.
 func (c *CheckRunAnnotation) GetBlobHRef() string {
 	if c == nil || c.BlobHRef == nil {
@@ -580,14 +588,6 @@ func (c *CheckRunAnnotation) GetEndLine() int {
 	return *c.EndLine
 }
 
-// GetFileName returns the FileName field if it's non-nil, zero value otherwise.
-func (c *CheckRunAnnotation) GetFileName() string {
-	if c == nil || c.FileName == nil {
-		return ""
-	}
-	return *c.FileName
-}
-
 // GetMessage returns the Message field if it's non-nil, zero value otherwise.
 func (c *CheckRunAnnotation) GetMessage() string {
 	if c == nil || c.Message == nil {
@@ -596,6 +596,14 @@ func (c *CheckRunAnnotation) GetMessage() string {
 	return *c.Message
 }
 
+// GetPath returns the Path field if it's non-nil, zero value otherwise.
+func (c *CheckRunAnnotation) GetPath() string {
+	if c == nil || c.Path == nil {
+		return ""
+	}
+	return *c.Path
+}
+
 // GetRawDetails returns the RawDetails field if it's non-nil, zero value otherwise.
 func (c *CheckRunAnnotation) GetRawDetails() string {
 	if c == nil || c.RawDetails == nil {
@@ -620,14 +628,6 @@ func (c *CheckRunAnnotation) GetTitle() string {
 	return *c.Title
 }
 
-// GetWarningLevel returns the WarningLevel field if it's non-nil, zero value otherwise.
-func (c *CheckRunAnnotation) GetWarningLevel() string {
-	if c == nil || c.WarningLevel == nil {
-		return ""
-	}
-	return *c.WarningLevel
-}
-
 // GetAction returns the Action field if it's non-nil, zero value otherwise.
 func (c *CheckRunEvent) GetAction() string {
 	if c == nil || c.Action == nil {


Test patch:
diff --git a/github/checks_test.go b/github/checks_test.go
index 40516f46..3170f70d 100644
--- a/github/checks_test.go
+++ b/github/checks_test.go
@@ -147,11 +147,11 @@ func TestChecksService_ListCheckRunAnnotations(t *testing.T) {
 			"page": "1",
 		})
 		fmt.Fprint(w, `[{
-		                           "filename": "README.md",
+		                           "path": "README.md",
 		                           "blob_href": "https://github.com/octocat/Hello-World/blob/837db83be4137ca555d9a5598d0a1ea2987ecfee/README.md",
 		                           "start_line": 2,
 		                           "end_line": 2,
-		                           "warning_level": "warning",
+		                           "annotation_level": "warning",
 		                           "message": "Check your spelling for 'banaas'.",
                                            "title": "Spell check",
 		                           "raw_details": "Do you mean 'bananas' or 'banana'?"}]`,
@@ -164,14 +164,14 @@ func TestChecksService_ListCheckRunAnnotations(t *testing.T) {
 	}
 
 	want := []*CheckRunAnnotation{{
-		FileName:     String("README.md"),
-		BlobHRef:     String("https://github.com/octocat/Hello-World/blob/837db83be4137ca555d9a5598d0a1ea2987ecfee/README.md"),
-		StartLine:    Int(2),
-		EndLine:      Int(2),
-		WarningLevel: String("warning"),
-		Message:      String("Check your spelling for 'banaas'."),
-		RawDetails:   String("Do you mean 'bananas' or 'banana'?"),
-		Title:        String("Spell check"),
+		Path:            String("README.md"),
+		BlobHRef:        String("https://github.com/octocat/Hello-World/blob/837db83be4137ca555d9a5598d0a1ea2987ecfee/README.md"),
+		StartLine:       Int(2),
+		EndLine:         Int(2),
+		AnnotationLevel: String("warning"),
+		Message:         String("Check your spelling for 'banaas'."),
+		RawDetails:      String("Do you mean 'bananas' or 'banana'?"),
+		Title:           String("Spell check"),
 	}}
 
 	if !reflect.DeepEqual(checkRunAnnotations, want) {
@@ -460,23 +460,20 @@ func TestChecksService_CreateCheckSuite(t *testing.T) {
 	}
 }
 
-func TestChecksService_RequestCheckSuite(t *testing.T) {
+func TestChecksService_ReRequestCheckSuite(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
 
-	mux.HandleFunc("/repos/o/r/check-suite-requests", func(w http.ResponseWriter, r *http.Request) {
+	mux.HandleFunc("/repos/o/r/check-suites/1/rerequest", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "POST")
 		testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
-		testBody(t, r, `{"head_sha":"deadbeef"}`+"\n")
+		w.WriteHeader(http.StatusCreated)
 	})
-	opt := RequestCheckSuiteOptions{
-		HeadSHA: "deadbeef",
-	}
-	resp, err := client.Checks.RequestCheckSuite(context.Background(), "o", "r", opt)
+	resp, err := client.Checks.ReRequestCheckSuite(context.Background(), "o", "r", 1)
 	if err != nil {
-		t.Errorf("Checks.RequestCheckSuite return error: %v", err)
+		t.Errorf("Checks.ReRequestCheckSuite return error: %v", err)
 	}
-	if resp.StatusCode != 200 {
-		t.Errorf("Checks.RequestCheckSuite return %+v, want 200", resp.StatusCode)
+	if got, want := resp.StatusCode, http.StatusCreated; got != want {
+		t.Errorf("Checks.ReRequestCheckSuite = %v, want %v", got, want)
 	}
 }