From 56ef622e376fd6cefcbfdd253e3a73d87644a759 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 27 Apr 2017 13:17:56 -0400 Subject: [PATCH] travis: only run the git-validation on pull-requests Fixes #24 https://docs.travis-ci.com/user/pull-requests/ Signed-off-by: Vincent Batts --- .travis.yml | 1 + main.go | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index db33fc0..0d0cde8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ before_install: - mkdir -p $GOPATH/src/github.com/vbatts && ln -sf $(pwd) $GOPATH/src/github.com/vbatts/git-validation && go get ./... before_script: + - env - echo $TRAVIS_COMMIT_RANGE - echo $TRAVIS_COMMIT - echo $TRAVIS_BRANCH diff --git a/main.go b/main.go index be5f1a8..8b6876b 100644 --- a/main.go +++ b/main.go @@ -14,14 +14,15 @@ import ( ) var ( - flCommitRange = flag.String("range", "", "use this commit range instead (implies -no-travis)") - flListRules = flag.Bool("list-rules", false, "list the rules registered") - flRun = flag.String("run", "", "comma delimited list of rules to run. Defaults to all.") - flVerbose = flag.Bool("v", false, "verbose") - flDebug = flag.Bool("D", false, "debug output") - flQuiet = flag.Bool("q", false, "less output") - flDir = flag.String("d", ".", "git directory to validate from") - flNoTravis = flag.Bool("no-travis", false, "disables travis environment checks (when env TRAVIS=true is set)") + flCommitRange = flag.String("range", "", "use this commit range instead (implies -no-travis)") + flListRules = flag.Bool("list-rules", false, "list the rules registered") + flRun = flag.String("run", "", "comma delimited list of rules to run. Defaults to all.") + flVerbose = flag.Bool("v", false, "verbose") + flDebug = flag.Bool("D", false, "debug output") + flQuiet = flag.Bool("q", false, "less output") + flDir = flag.String("d", ".", "git directory to validate from") + flNoTravis = flag.Bool("no-travis", false, "disables travis environment checks (when env TRAVIS=true is set)") + flTravisPROnly = flag.Bool("travis-pr-only", true, "when on travis, only run validations if the CI-Build is checking pull-request build") ) func main() { @@ -41,6 +42,11 @@ func main() { return } + if *flTravisPROnly && strings.ToLower(os.Getenv("TRAVIS_PULL_REQUEST")) == "false" { + fmt.Printf("only to check travis PR builds and this not a PR build. yielding.\n") + return + } + // reduce the set being run rules := validate.RegisteredRules if *flRun != "" {