From 41749a62809298f29d8bdf8b21d946853972ec44 Mon Sep 17 00:00:00 2001 From: Andy Grunwald Date: Wed, 21 Sep 2022 18:10:59 +0200 Subject: [PATCH] GitHub Actions: Raise Go versions to v1.18 and v1.19 (#125) * GitHub Actions: Raise Go versions to v1.18 and v1.19 * GitHub Actions: Only run once on a Pull Request * Fix "package io/ioutil is deprecated" package io/ioutil is deprecated: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details. (SA1019) * go fmt --- .github/workflows/testing.yml | 11 +++++++---- changes.go | 4 ++-- changes_attention.go | 1 - events.go | 4 ++-- gerrit.go | 7 +++---- gerrit_test.go | 6 +++--- go.mod | 2 +- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b009a78..80b8b8c 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -2,7 +2,10 @@ name: Testing on: push: + branches: + - main pull_request: + workflow_dispatch: schedule: - cron: "5 1 * * *" @@ -12,7 +15,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - go: [ '1.18', '1.17' ] + go: [ '1.19', '1.18' ] steps: - uses: actions/checkout@v3 @@ -37,7 +40,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - go: [ '1.18', '1.17' ] + go: [ '1.19', '1.18' ] steps: - uses: actions/checkout@v3 @@ -61,7 +64,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - go: [ '1.18', '1.17' ] + go: [ '1.19', '1.18' ] steps: - uses: actions/checkout@v3 @@ -89,7 +92,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - go: [ '1.18', '1.17' ] + go: [ '1.19', '1.18' ] steps: - uses: actions/checkout@v3 diff --git a/changes.go b/changes.go index 788dfe4..6d1e8d5 100644 --- a/changes.go +++ b/changes.go @@ -3,7 +3,7 @@ package gerrit import ( "errors" "fmt" - "io/ioutil" + "io" "net/http" ) @@ -911,7 +911,7 @@ func (s *ChangesService) change(tail string, changeID string, input interface{}) return nil, resp, err } if resp.StatusCode == http.StatusConflict { - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return v, resp, err } diff --git a/changes_attention.go b/changes_attention.go index 5b489b7..d4d7c3c 100644 --- a/changes_attention.go +++ b/changes_attention.go @@ -29,7 +29,6 @@ type AttentionSetInput struct { } // RemoveAttention deletes a single user from the attention set of a change. -// // AttentionSetInput.Input must be provided // // https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#remove-from-attention-set diff --git a/events.go b/events.go index 4850ba4..0a8be74 100644 --- a/events.go +++ b/events.go @@ -3,7 +3,7 @@ package gerrit import ( "bytes" "encoding/json" - "io/ioutil" + "io" "net/url" "time" ) @@ -142,7 +142,7 @@ func (events *EventsLogService) GetEvents(options *EventsLogOptions) ([]EventInf return info, response, failures, err } - body, err := ioutil.ReadAll(response.Body) + body, err := io.ReadAll(response.Body) defer response.Body.Close() // nolint: errcheck if err != nil { return info, response, failures, err diff --git a/gerrit.go b/gerrit.go index 8d3b075..aaba962 100644 --- a/gerrit.go +++ b/gerrit.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "reflect" @@ -372,7 +371,7 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) { } } else { var body []byte - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) if err != nil { // even though there was an error, we still return the response // in case the caller wants to inspect it further @@ -430,8 +429,8 @@ func (c *Client) addAuthentication(req *http.Request) error { // When the function exits discard the rest of the // body and close it. This should cause go to // reuse the connection. - defer io.Copy(ioutil.Discard, response.Body) // nolint: errcheck - defer response.Body.Close() // nolint: errcheck + defer io.Copy(io.Discard, response.Body) // nolint: errcheck + defer response.Body.Close() // nolint: errcheck if response.StatusCode == http.StatusUnauthorized { authorization, err := c.Authentication.digestAuthHeader(response) diff --git a/gerrit_test.go b/gerrit_test.go index 8dc4ba4..b1e7936 100644 --- a/gerrit_test.go +++ b/gerrit_test.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -405,7 +405,7 @@ func TestNewRequest(t *testing.T) { } // Test that body was JSON encoded - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) if got, want := string(body), outBody; got != want { t.Errorf("NewRequest Body is %v, want %v", got, want) } @@ -426,7 +426,7 @@ func TestNewRawPutRequest(t *testing.T) { } // Test that body was JSON encoded - body, _ := ioutil.ReadAll(req.Body) + body, _ := io.ReadAll(req.Body) if got, want := string(body), "test raw PUT contents"; got != want { t.Errorf("NewRequest Body is %v, want %v", got, want) } diff --git a/go.mod b/go.mod index 994f772..6c6352c 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/andygrunwald/go-gerrit -go 1.15 +go 1.16 require github.com/google/go-querystring v1.1.0