Skip to content

Commit

Permalink
Merge pull request #62 from tomoasleep/fix-crash-on-travis-ci-not-pul…
Browse files Browse the repository at this point in the history
…l-request-job

Support branch builds of Travis CI
  • Loading branch information
b4b4r07 authored Feb 25, 2020
2 parents 761b0e6 + a81255a commit e74787f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ func circleci() (ci CI, err error) {
}

func travisci() (ci CI, err error) {
ci.PR.Revision = os.Getenv("TRAVIS_PULL_REQUEST_SHA")
ci.PR.Number, err = strconv.Atoi(os.Getenv("TRAVIS_PULL_REQUEST"))
ci.URL = os.Getenv("TRAVIS_BUILD_WEB_URL")
prNumber := os.Getenv("TRAVIS_PULL_REQUEST")
if prNumber == "false" {
ci.PR.Number = 0
ci.PR.Revision = os.Getenv("TRAVIS_COMMIT")
return ci, nil
}
ci.PR.Revision = os.Getenv("TRAVIS_PULL_REQUEST_SHA")
ci.PR.Number, err = strconv.Atoi(prNumber)
return ci, err
}

Expand All @@ -57,7 +63,7 @@ func codebuild() (ci CI, err error) {
if sourceVersion == "" {
return ci, nil
}
if !strings.HasPrefix(sourceVersion,"pr/") {
if !strings.HasPrefix(sourceVersion, "pr/") {
return ci, nil
}
pr := strings.Replace(sourceVersion, "pr/", "", 1)
Expand Down
7 changes: 5 additions & 2 deletions ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestTravisCI(t *testing.T) {
envs := []string{
"TRAVIS_PULL_REQUEST_SHA",
"TRAVIS_PULL_REQUEST",
"TRAVIS_COMMIT",
}
saveEnvs := make(map[string]string)
for _, key := range envs {
Expand All @@ -172,6 +173,7 @@ func TestTravisCI(t *testing.T) {
fn: func() {
os.Setenv("TRAVIS_PULL_REQUEST_SHA", "abcdefg")
os.Setenv("TRAVIS_PULL_REQUEST", "1")
os.Setenv("TRAVIS_COMMIT", "hijklmn")
},
ci: CI{
PR: PullRequest{
Expand All @@ -186,15 +188,16 @@ func TestTravisCI(t *testing.T) {
fn: func() {
os.Setenv("TRAVIS_PULL_REQUEST_SHA", "abcdefg")
os.Setenv("TRAVIS_PULL_REQUEST", "false")
os.Setenv("TRAVIS_COMMIT", "hijklmn")
},
ci: CI{
PR: PullRequest{
Revision: "abcdefg",
Revision: "hijklmn",
Number: 0,
},
URL: "",
},
ok: false,
ok: true,
},
}

Expand Down

0 comments on commit e74787f

Please sign in to comment.