diff --git a/hooks/pre-command b/hooks/pre-command index 885dcd4..984f161 100755 --- a/hooks/pre-command +++ b/hooks/pre-command @@ -1,8 +1,8 @@ #!/bin/bash set -euo pipefail -if [[ "${BUILDKITE_PIPELINE_PROVIDER:-}" != "github" ]] ; then - echo "⛔️ this plugin can only be used on piplines associated with github repositories" >&2 +if [ "${BUILDKITE_PIPELINE_PROVIDER:-}" != "github" ] && [ "${BUILDKITE_PIPELINE_PROVIDER:-}" != "github_enterprise" ] ; then + echo "⛔️ this plugin can only be used on pipelines associated with github repositories" >&2 exit 1 fi @@ -12,8 +12,15 @@ if [[ "${BUILDKITE_PULL_REQUEST:-false}" == "false" ]] ; then fi pullReqNo="${BUILDKITE_PULL_REQUEST}" +regexRepo="" +if [ "${BUILDKITE_PIPELINE_PROVIDER:-}" = "github" ] ; then + regexRepo="github.com[:/](.*).git[/]?" +elif [ "${BUILDKITE_PIPELINE_PROVIDER:-}" = "github_enterprise" ]; then + regexRepo="git@${BUILDKITE_REPO_SSH_HOST:-}[:/](.*).git[/]?" +fi + repoFq="" -if [[ "${BUILDKITE_REPO:-}" =~ github.com[:/](.*).git[/]? ]]; then +if [[ "${BUILDKITE_REPO:-}" =~ $regexRepo ]]; then repoFq="${BASH_REMATCH[1]}" else echo "⛔️ the BUILDKITE_REPO variable has an unexpected format" >&2 diff --git a/tests/pre-command.bats b/tests/pre-command.bats index c67bd3b..c2fabee 100644 --- a/tests/pre-command.bats +++ b/tests/pre-command.bats @@ -8,7 +8,7 @@ load '/usr/local/lib/bats/load.bash' run "$PWD/hooks/pre-command" assert_failure - assert_output --partial "this plugin can only be used on piplines associated with" + assert_output --partial "this plugin can only be used on pipelines associated with" } @test "ensure early exit if not a PR-build" {