From dc33248ec3ce29fde26be97d162ad95e6838525e Mon Sep 17 00:00:00 2001 From: Christoph Witzko Date: Sun, 19 Apr 2020 10:52:38 +0200 Subject: [PATCH] refactor: use shuheiktgw/go-travis --- .travis.yml | 3 +++ go.mod | 5 +---- go.sum | 14 +++----------- pkg/condition/travis.go | 21 +++++++++++---------- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b92afda..ddc22f26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: go +os: + - linux + - osx go: - 1.14.x before_script: diff --git a/go.mod b/go.mod index c84f7061..60297131 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,8 @@ go 1.14 require ( github.com/Masterminds/semver v1.5.0 - github.com/christophwitzko/go-travis v0.0.0-20180115212951-5311d81d834b - github.com/fatih/structs v1.1.0 // indirect github.com/google/go-github/v30 v30.1.0 - github.com/oleiade/reflections v1.0.0 // indirect - github.com/stretchr/testify v1.5.1 // indirect + github.com/shuheiktgw/go-travis v0.2.4 github.com/urfave/cli/v2 v2.2.0 golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d ) diff --git a/go.sum b/go.sum index 1177b6c2..5ccb62d6 100644 --- a/go.sum +++ b/go.sum @@ -2,32 +2,24 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= -github.com/christophwitzko/go-travis v0.0.0-20180115212951-5311d81d834b h1:YKFJ/MSTMtRCR7UeF4I2Ovi8HDwsVA7F/qWxwr7J6tU= -github.com/christophwitzko/go-travis v0.0.0-20180115212951-5311d81d834b/go.mod h1:0PHJRx/NZav97xUaOdeXLPZmPKBjSHVBAeiFFkaRSmc= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= -github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-github/v30 v30.1.0 h1:VLDx+UolQICEOKu2m4uAoMti1SxuEBAl7RSEG16L+Oo= github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQFEufcolZ95JfU8= +github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/oleiade/reflections v1.0.0 h1:0ir4pc6v8/PJ0yw5AEtMddfXpWBXg9cnG7SgSoJuCgY= -github.com/oleiade/reflections v1.0.0/go.mod h1:RbATFBbKYkVdqmSFtx13Bb/tVhR0lgOBXunWTZKeL4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shuheiktgw/go-travis v0.2.4 h1:IAnh/Dyv7ql87qtJWUcvR5MM8e5iCDGoENl9VzpxAHc= +github.com/shuheiktgw/go-travis v0.2.4/go.mod h1:RtODX49bvgHTvfzFvGEPFtU0dKVk0D3PyvUQR/63hT0= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= diff --git a/pkg/condition/travis.go b/pkg/condition/travis.go index 8096ba57..3cdfda90 100644 --- a/pkg/condition/travis.go +++ b/pkg/condition/travis.go @@ -1,9 +1,10 @@ package condition import ( + "context" "errors" "fmt" - "github.com/christophwitzko/go-travis" + "github.com/shuheiktgw/go-travis" "log" "os" "strconv" @@ -59,40 +60,40 @@ func (ci *TravisCI) RunCondition(config CIConfig) error { return errors.New("could not parse TRAVIS_BUILD_ID/TRAVIS_JOB_ID") } - endpoint := travis.TRAVIS_API_DEFAULT_URL + endpoint := travis.ApiOrgUrl if travisHost := os.Getenv("TRAVIS_ENTERPRISE_HOST"); travisHost != "" { logger.Printf("Using Travis CI enterprise host: %s\n", travisHost) endpoint = fmt.Sprintf("https://%s/api/", travisHost) } else if private { - endpoint = travis.TRAVIS_API_PRO_URL + endpoint = travis.ApiComUrl } client := travis.NewClient(endpoint, "") client.Headers["User-Agent"] = "Travis" - if _, _, err := client.Authentication.UsingGithubToken(token); err != nil { + if _, _, err := client.Authentication.UsingGithubToken(context.Background(), token); err != nil { return err } for i := 1; i <= 100; i++ { - jobs, _, err := client.Jobs.ListFromBuild(uint(buildId)) + jobs, _, err := client.Jobs.ListByBuild(context.Background(), uint(buildId)) if err != nil { return err } successes := 0 for _, job := range jobs { - if job.Id == uint(currentJobId) || job.AllowFailure || job.State == "passed" { + if *job.Id == uint(currentJobId) || *job.AllowFailure || *job.State == "passed" { successes++ continue } - if job.State == "created" || job.State == "started" { - logger.Printf("Aborting attempt %d, because job %s is still pending.\n", i, job.Number) + if *job.State == "created" || *job.State == "started" { + logger.Printf("Aborting attempt %d, because job %s is still pending.\n", i, *job.Number) break } - if job.State == "errored" || job.State == "failed" { - logger.Printf("Aborting attempt %d. Job %s failed.\n", i, job.Number) + if *job.State == "errored" || *job.State == "failed" { + logger.Printf("Aborting attempt %d. Job %s failed.\n", i, *job.Number) return errors.New("In this test run not all jobs passed and therefore a new version won’t be published.") } }