Created
July 8, 2026 09:29
-
-
Save mheap/5cda56880375baafe4eb38c7095ca42c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| branch="" | |
| open_flag=false | |
| skip_prefix=false | |
| for arg in "$@"; do | |
| case "$arg" in | |
| --open) | |
| open_flag=true | |
| ;; | |
| --skip-prefix) | |
| skip_prefix=true | |
| ;; | |
| -*) | |
| echo "Unknown option: $arg" >&2 | |
| exit 1 | |
| ;; | |
| *) | |
| if [[ -n "$branch" ]]; then | |
| echo "Unexpected argument: $arg (branch already specified as '$branch')" >&2 | |
| exit 1 | |
| fi | |
| branch="$arg" | |
| ;; | |
| esac | |
| done | |
| if [[ -z "$branch" ]]; then | |
| echo "Usage: docs-release-preview <branch> [--open] [--skip-prefix]" >&2 | |
| exit 1 | |
| fi | |
| if ! $skip_prefix; then | |
| branch="release/$branch" | |
| fi | |
| if ! command -v gh &>/dev/null; then | |
| echo "Error: 'gh' CLI is required but not found." >&2 | |
| exit 1 | |
| fi | |
| pr_number=$(gh pr list -R Kong/developer.konghq.com --head "$branch" --state all --json number --jq '.[0].number' 2>/dev/null || true) | |
| if [[ -z "$pr_number" ]]; then | |
| echo "Error: No pull request found for branch '$branch'." >&2 | |
| exit 1 | |
| fi | |
| url="https://deploy-preview-${pr_number}--kongdeveloper.netlify.app" | |
| if $open_flag; then | |
| if [[ "$(uname)" == "Darwin" ]]; then | |
| open "$url" | |
| elif command -v xdg-open &>/dev/null; then | |
| xdg-open "$url" | |
| else | |
| echo "Error: No browser opener found (tried 'open' and 'xdg-open')." >&2 | |
| exit 1 | |
| fi | |
| echo "Opening: $url" | |
| else | |
| echo "$url" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment