Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow GitHub enterprise #6

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions hooks/pre-command
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/pre-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down