Repository: google/go-github
Pull request #978 (2018-08-15 16:20:12)

Fix RequestCheckSuite
Previously, `RequestCheckSuite` appended the contents of the `ops RequestCheckSuiteOptions` parameter as query string parameters, resulting in requests like `https://api.github.com/repos/$owner/$repo/check-suite-requests?HeadSHA=$sha`. These sorts of requests result in `422 Invalid request` errors from the GitHub API.

This PR passes the contents of the `ops RequestCheckSuiteOptions` parameter through to `(c *Client) NewRequest` as the body instead, resulting in requests that GitHub's API accepts.

gmlewis: Thank you, @jnewland!  Your changes LGTM.
When you sign the CLA we can proceed with merging this change.

Patch:
diff --git a/.travis.yml b/.travis.yml
index ab63e63c..096ca213 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,13 +1,16 @@
 sudo: false
 language: go
 go:
+  - "1.11.x"
   - "1.10.x"
   - "1.9.x"
-  - "1.8.x"
-  - master
+  - tip
+env:
+  global:
+    - GO111MODULE=on
 matrix:
   allow_failures:
-    - go: master
+    - go: tip
   fast_finish: true
 env:
   secure: "IrnPmy/rkIP6Nrbqji+u7MCAibQlA6WvPLEllmDQ2yZP/uIe3wLwwYbTu9BOkgzoLA+f8PA6u3pp/RhY/rtaM4NzHAO2nVfGIv9UHUQ3NGq0DYS6rODjVKhq7vkhELoagRewyqFVN4rE0LnExkknRMgjQfRke6/DA7u7Xm8JyhY=" # COVERALLS_TOKEN
diff --git a/AUTHORS b/AUTHORS
index 56622a4c..7c2f1291 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -26,14 +26,17 @@ Andy Lindeman <andy@lindeman.io>
 Anshuman Bhartiya <anshuman.bhartiya@gmail.com>
 Antoine Pelisse <apelisse@gmail.com>
 Anubha Kushwaha <anubha_bt2k14@dtu.ac.in>
+appilon <apilon@hashicorp.com>
 Aravind <aravindkp@outlook.in>
 Arıl Bozoluk <arilbozoluk@hotmail.com>
 Austin Dizzy <dizzy@wow.com>
+Ben Batha <bhbatha@gmail.com>
 Beshr Kayali <beshrkayali@gmail.com>
 Beyang Liu <beyang.liu@gmail.com>
 Billy Lynch <wlynch92@gmail.com>
 Björn Häuser <b.haeuser@rebuy.de>
 Brad Harris <bmharris@gmail.com>
+Brad Moylan <moylan.brad@gmail.com>
 Bradley Falzon <brad@teambrad.net>
 Brian Egizi <brian@mojotech.com>
 Bryan Boreham <bryan@weave.works>
@@ -54,7 +57,10 @@ Daniel Leavitt <daniel.leavitt@gmail.com>
 Dave Du Cros <davidducros@gmail.com>
 Dave Henderson <dhenderson@gmail.com>
 David Deng <daviddengcn@gmail.com>
+David Jannotta <djannotta@gmail.com>
+Davide Zipeto <dawez1@gmail.com>
 Dennis Webb <dennis@bluesentryit.com>
+Dhi Aurrahman <diorahman@rockybars.com>
 Diego Lapiduz <diego.lapiduz@cfpb.gov>
 Dmitri Shuralyov <shurcooL@gmail.com>
 dmnlk <seikima2demon@gmail.com>
@@ -63,6 +69,7 @@ Doug Turner <doug.turner@gmail.com>
 Drew Fradette <drew.fradette@gmail.com>
 Eli Uriegas <seemethere101@gmail.com>
 Elliott Beach <elliott2.71828@gmail.com>
+Emerson Wood <emersonwood94@gmail.com>
 erwinvaneyk <erwinvaneyk@gmail.com>
 Fabrice <fabrice.vaillant@student.ecp.fr>
 Filippo Valsorda <hi@filippo.io>
@@ -75,7 +82,9 @@ Georgy Buranov <gburanov@gmail.com>
 Gnahz <p@oath.pl>
 Google Inc.
 griffin_stewie <panterathefamilyguy@gmail.com>
+Guillaume Jacquet <guillaume.jacquet@gmail.com>
 Guz Alexander <kalimatas@gmail.com>
+Guðmundur Bjarni Ólafsson <gudmundur@github.com>
 Hanno Hecker <hanno.hecker@zalando.de>
 Hari haran <hariharan.uno@gmail.com>
 haya14busa <hayabusa1419@gmail.com>
@@ -89,6 +98,7 @@ Jan Kosecki <jan.kosecki91@gmail.com>
 Jeremy Morris <jeremylevanmorris@gmail.com>
 Jihoon Chung <j.c@navercorp.com>
 Jimmi Dyson <jimmidyson@gmail.com>
+Joan Saum <joan.saum@epitech.eu>
 Joe Tsai <joetsai@digital-static.net>
 John Barton <jrbarton@gmail.com>
 John Engelman <john.r.engelman@gmail.com>
@@ -96,6 +106,7 @@ jpbelanger-mtl <jp.belanger@gmail.com>
 Juan Basso <jrbasso@gmail.com>
 Julien Rostand <jrostand@users.noreply.github.com>
 Justin Abrahms <justin@abrah.ms>
+Jusung Lee <e.jusunglee@gmail.com>
 jzhoucliqr <jzhou@cliqr.com>
 Katrina Owen <kytrinyx@github.com>
 Keita Urashima <ursm@ursm.jp>
@@ -113,9 +124,11 @@ Luke Young <luke@hydrantlabs.org>
 Maksim Zhylinski <uzzable@gmail.com>
 Martin-Louis Bright <mlbright@gmail.com>
 Mat Geist <matgeist@gmail.com>
+Matt <alpmatthew@gmail.com>
 Matt Brender <mjbrender@gmail.com>
 Matt Landis <landis.matt@gmail.com>
 Maxime Bury <maxime.bury@gmail.com>
+Michael Spiegel <michael.m.spiegel@gmail.com>
 Michael Tiller <michael.tiller@gmail.com>
 Michał Glapa <michal.glapa@gmail.com>
 Nathan VanBenschoten <nvanbenschoten@gmail.com>
@@ -125,15 +138,19 @@ Nick Spragg <nick.spragg@bbc.co.uk>
 Nikhita Raghunath <nikitaraghunath@gmail.com>
 Noah Zoschke <noah+sso2@convox.com>
 ns-cweber <cweber@narrativescience.com>
+Oleg Kovalov <iamolegkovalov@gmail.com>
 Ondřej Kupka <ondra.cap@gmail.com>
 Panagiotis Moustafellos <pmoust@gmail.com>
+Parham Alvani <parham.alvani@gmail.com>
 Parker Moore <parkrmoore@gmail.com>
+parkhyukjun89 <park.hyukjun89@gmail.com>
 Pavel Shtanko <pavel.shtanko@gmail.com>
 Petr Shevtsov <petr.shevtsov@gmail.com>
 Pierre Carrier <pierre@meteor.com>
 Piotr Zurek <p.zurek@gmail.com>
 Quinn Slack <qslack@qslack.com>
 Rackspace US, Inc.
+Radek Simko <radek.simko@gmail.com>
 Rajendra arora <rajendraarora16@yahoo.com>
 RaviTeja Pothana <ravi-teja@live.com>
 rc1140 <jameel@republiccommandos.co.za>
@@ -145,6 +162,7 @@ Ryan Lower <rpjlower@gmail.com>
 Sahil Dua <sahildua2305@gmail.com>
 saisi <saisi@users.noreply.github.com>
 Sam Minnée <sam@silverstripe.com>
+Sandeep Sukhani <sandeep.d.sukhani@gmail.com>
 Sander van Harmelen <svanharmelen@schubergphilis.com>
 Sanket Payghan <sanket.payghan8@gmail.com>
 Sarasa Kisaragi <lingsamuelgrace@gmail.com>
@@ -152,6 +170,7 @@ Sean Wang <sean@decrypted.org>
 Sebastian Mandrean <sebastian.mandrean@gmail.com>
 Sebastian Mæland Pedersen <sem.pedersen@stud.uis.no>
 Sevki <s@sevki.org>
+Shagun Khemka <shagun.khemka60@gmail.com>
 Shawn Catanzarite <me@shawncatz.com>
 Shawn Smith <shawnpsmith@gmail.com>
 sona-tar <sona.zip@gmail.com>
diff --git a/README.md b/README.md
index 5f20bf85..9ec4bd18 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
 
 go-github is a Go client library for accessing the [GitHub API v3][].
 
-go-github requires Go version 1.8 or greater.
+go-github requires Go version 1.9 or greater.
 
 If you're interested in using the [GraphQL API v4][], the recommended library is
 [shurcooL/githubv4][].
@@ -12,7 +12,7 @@ If you're interested in using the [GraphQL API v4][], the recommended library is
 ## Usage ##
 
 ```go
-import "github.com/google/go-github/github"
+import "github.com/google/go-github/github/v18"
 ```
 
 Construct a new GitHub client, then use the various services on the client to
diff --git a/example/appengine/app.go b/example/appengine/app.go
index 4d6cc30c..38f24e4e 100644
--- a/example/appengine/app.go
+++ b/example/appengine/app.go
@@ -12,7 +12,7 @@ import (
 	"net/http"
 	"os"
 
-	"github.com/google/go-github/github"
+	"github.com/google/go-github/v18/github"
 	"golang.org/x/oauth2"
 	"google.golang.org/appengine"
 	"google.golang.org/appengine/log"
diff --git a/example/basicauth/main.go b/example/basicauth/main.go
index f67c3d66..8dfd68a6 100644
--- a/example/basicauth/main.go
+++ b/example/basicauth/main.go
@@ -16,7 +16,7 @@ import (
 	"strings"
 	"syscall"
 
-	"github.com/google/go-github/github"
+	"github.com/google/go-github/v18/github"
 	"golang.org/x/crypto/ssh/terminal"
 )
 
diff --git a/example/commitpr/main.go b/example/commitpr/main.go
index 3eb53c5c..80ac88e8 100644
--- a/example/commitpr/main.go
+++ b/example/commitpr/main.go
@@ -31,7 +31,7 @@ import (
 	"strings"
 	"time"
 
-	"github.com/google/go-github/github"
+	"github.com/google/go-github/v18/github"
 	"golang.org/x/oauth2"
 )
 
diff --git a/example/migrations/main.go b/example/migrations/main.go
index 3607d085..d8266068 100644
--- a/example/migrations/main.go
+++ b/example/migrations/main.go
@@ -11,7 +11,7 @@ package main
 import (
 	"context"
 	"fmt"
-	"github.com/google/go-github/github"
+	"github.com/google/go-github/v18/github"
 	"golang.org/x/oauth2"
 )
 
diff --git a/example/newrepo/main.go b/example/newrepo/main.go
index da357d5c..49fba776 100644
--- a/example/newrepo/main.go
+++ b/example/newrepo/main.go
@@ -16,7 +16,7 @@ import (
 	"log"
 	"os"
 
-	"github.com/google/go-github/github"
+	"github.com/google/go-github/v18/github"
 	"golang.org/x/oauth2"
 )
 
diff --git a/example/simple/main.go b/example/simple/main.go
index 64a2e6f5..5f2ce20a 100644
--- a/example/simple/main.go
+++ b/example/simple/main.go
@@ -12,7 +12,7 @@ import (
 	"context"
 	"fmt"
 
-	"github.com/google/go-github/github"
+	"github.com/google/go-github/v18/github"
 )
 
 // Fetch all the public organizations' membership of a user.
diff --git a/github/apps.go b/github/apps.go
index e25de2c5..32d4f2f4 100644
--- a/github/apps.go
+++ b/github/apps.go
@@ -197,6 +197,13 @@ func (s *AppsService) FindRepositoryInstallation(ctx context.Context, owner, rep
 	return s.getInstallation(ctx, fmt.Sprintf("repos/%v/%v/installation", owner, repo))
 }
 
+// FindRepositoryInstallationByID finds the repository's installation information.
+//
+// Note: FindRepositoryInstallationByID uses the undocumented GitHub API endpoint /repositories/:id/installation.
+func (s *AppsService) FindRepositoryInstallationByID(ctx context.Context, id int64) (*Installation, *Response, error) {
+	return s.getInstallation(ctx, fmt.Sprintf("repositories/%d/installation", id))
+}
+
 // FindUserInstallation finds the user's installation information.
 //
 // GitHub API docs: https://developer.github.com/v3/apps/#find-repository-installation
diff --git a/github/checks.go b/github/checks.go
index 35490899..ac924ac4 100644
--- a/github/checks.go
+++ b/github/checks.go
@@ -411,12 +411,8 @@ type RequestCheckSuiteOptions struct {
 // 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)
-	u, err := addOptions(u, opt)
-	if err != nil {
-		return nil, err
-	}
 
-	req, err := s.client.NewRequest("POST", u, nil)
+	req, err := s.client.NewRequest("POST", u, opt)
 	if err != nil {
 		return nil, err
 	}
diff --git a/go.mod b/go.mod
new file mode 100644
index 00000000..6e09a506
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,11 @@
+module github.com/google/go-github/v18
+
+require (
+	github.com/golang/protobuf v1.2.0 // indirect
+	github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135
+	golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac
+	golang.org/x/net v0.0.0-20180826012351-8a410e7b638d // indirect
+	golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
+	golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87 // indirect
+	google.golang.org/appengine v1.1.0
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 00000000..64309118
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,14 @@
+github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 h1:zLTLjkaOFEFIOxY5BWLFLwh+cL8vOBW4XJ2aqLE/Tf0=
+github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
+golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac h1:7d7lG9fHOLdL6jZPtnV4LpI41SbohIJ1Atq7U991dMg=
+golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87 h1:GqwDwfvIpC33dK9bA1fD+JiDUNsuAiQiEkpHqUKze4o=
+golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=


Test patch:
diff --git a/github/apps_test.go b/github/apps_test.go
index b4d63016..f56c1c44 100644
--- a/github/apps_test.go
+++ b/github/apps_test.go
@@ -227,6 +227,27 @@ func TestAppsService_FindRepositoryInstallation(t *testing.T) {
 	}
 }
 
+func TestAppsService_FindRepositoryInstallationByID(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repositories/1/installation", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		testHeader(t, r, "Accept", mediaTypeIntegrationPreview)
+		fmt.Fprint(w, `{"id":1, "app_id":1, "target_id":1, "target_type": "Organization"}`)
+	})
+
+	installation, _, err := client.Apps.FindRepositoryInstallationByID(context.Background(), 1)
+	if err != nil {
+		t.Errorf("Apps.FindRepositoryInstallationByID returned error: %v", err)
+	}
+
+	want := &Installation{ID: Int64(1), AppID: Int64(1), TargetID: Int64(1), TargetType: String("Organization")}
+	if !reflect.DeepEqual(installation, want) {
+		t.Errorf("Apps.FindRepositoryInstallationByID returned %+v, want %+v", installation, want)
+	}
+}
+
 func TestAppsService_FindUserInstallation(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()
diff --git a/github/checks_test.go b/github/checks_test.go
index 6c87fbcf..40516f46 100644
--- a/github/checks_test.go
+++ b/github/checks_test.go
@@ -467,6 +467,7 @@ func TestChecksService_RequestCheckSuite(t *testing.T) {
 	mux.HandleFunc("/repos/o/r/check-suite-requests", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "POST")
 		testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
+		testBody(t, r, `{"head_sha":"deadbeef"}`+"\n")
 	})
 	opt := RequestCheckSuiteOptions{
 		HeadSHA: "deadbeef",
diff --git a/github/examples_test.go b/github/examples_test.go
index 261d710c..942b0b7d 100644
--- a/github/examples_test.go
+++ b/github/examples_test.go
@@ -10,7 +10,7 @@ import (
 	"fmt"
 	"log"
 
-	"github.com/google/go-github/github"
+	"github.com/google/go-github/v18/github"
 )
 
 func ExampleClient_Markdown() {
diff --git a/github/projects_test.go b/github/projects_test.go
index 2d574c66..9f12272a 100644
--- a/github/projects_test.go
+++ b/github/projects_test.go
@@ -20,11 +20,12 @@ func TestProjectsService_UpdateProject(t *testing.T) {
 	defer teardown()
 
 	input := &ProjectOptions{
-		Name:  String("Project Name"),
-		Body:  String("Project body."),
-		State: String("open"),
+		Name:   String("Project Name"),
+		Body:   String("Project body."),
+		State:  String("open"),
+		Public: Bool(true),
+
 		OrganizationPermission: String("read"),
-		Public:                 Bool(true),
 	}
 
 	mux.HandleFunc("/projects/1", func(w http.ResponseWriter, r *http.Request) {
diff --git a/test/fields/fields.go b/test/fields/fields.go
index 7ee1f6e0..1a75a4c6 100644
--- a/test/fields/fields.go
+++ b/test/fields/fields.go
@@ -25,7 +25,7 @@ import (
 	"reflect"
 	"strings"
 
-	"github.com/google/go-github/github"
+	"github.com/google/go-github/v18/github"
 	"golang.org/x/oauth2"
 )