forked from farhoodlabs/skills
refactor: Consolidate error handling into a new die function.
This commit is contained in:
@@ -8,24 +8,26 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
if [[ -z "${GITHUB_APP_ID:-}" ]]; then
|
die() {
|
||||||
echo "error: GITHUB_APP_ID is not set" >&2
|
echo "error: $1" >&2
|
||||||
|
echo "return 1 2>/dev/null || false"
|
||||||
exit 1
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ -z "${GITHUB_APP_ID:-}" ]]; then
|
||||||
|
die "GITHUB_APP_ID is not set"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "${GITHUB_APP_INSTALLATION_ID:-}" ]]; then
|
if [[ -z "${GITHUB_APP_INSTALLATION_ID:-}" ]]; then
|
||||||
echo "error: GITHUB_APP_INSTALLATION_ID is not set" >&2
|
die "GITHUB_APP_INSTALLATION_ID is not set"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "${GITHUB_APP_PEM_FILE:-}" ]]; then
|
if [[ -z "${GITHUB_APP_PEM_FILE:-}" ]]; then
|
||||||
echo "error: GITHUB_APP_PEM_FILE is not set" >&2
|
die "GITHUB_APP_PEM_FILE is not set"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "${GITHUB_APP_PEM_FILE}" ]]; then
|
if [[ ! -f "${GITHUB_APP_PEM_FILE}" ]]; then
|
||||||
echo "error: PEM file not found: ${GITHUB_APP_PEM_FILE}" >&2
|
die "PEM file not found: ${GITHUB_APP_PEM_FILE}"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to base64 encode with URL-safe characters
|
# Function to base64 encode with URL-safe characters
|
||||||
@@ -57,9 +59,7 @@ RESPONSE=$(curl -s -X POST \
|
|||||||
INSTALL_TOKEN=$(printf '%s' "${RESPONSE}" | jq -r '.token // empty')
|
INSTALL_TOKEN=$(printf '%s' "${RESPONSE}" | jq -r '.token // empty')
|
||||||
|
|
||||||
if [[ -z "${INSTALL_TOKEN}" ]]; then
|
if [[ -z "${INSTALL_TOKEN}" ]]; then
|
||||||
echo "error: failed to generate installation token" >&2
|
die "failed to generate installation token. Response: ${RESPONSE}"
|
||||||
echo "${RESPONSE}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Output the export command so it can be eval'd by the caller
|
# Output the export command so it can be eval'd by the caller
|
||||||
|
|||||||
Reference in New Issue
Block a user