Skip to content

Commit

Permalink
refactor: use shuheiktgw/go-travis
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Apr 19, 2020
1 parent 1b5058e commit dc33248
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: go
os:
- linux
- osx
go:
- 1.14.x
before_script:
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
14 changes: 3 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
21 changes: 11 additions & 10 deletions pkg/condition/travis.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package condition

import (
"context"
"errors"
"fmt"
"github.com/christophwitzko/go-travis"
"github.com/shuheiktgw/go-travis"
"log"
"os"
"strconv"
Expand Down Expand Up @@ -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.")
}
}
Expand Down

0 comments on commit dc33248

Please sign in to comment.