Files
computer-playbook/scripts/meta/resolve/repository/owner.sh
kevinveenbirkenbach 003a3a0b84 Merge branch 'main' into feature/lint
Resolve merge conflicts, keep the cleanup script move to scripts/image, and fix the resulting lint regressions.
2026-03-21 01:36:58 +01:00

40 lines
941 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [[ -n "${OWNER:-}" ]]; then
printf '%s\n' "${OWNER,,}"
exit 0
fi
if [[ -n "${GITHUB_REPOSITORY_OWNER:-}" ]]; then
printf '%s\n' "${GITHUB_REPOSITORY_OWNER,,}"
exit 0
fi
if [[ -n "${GITHUB_REPOSITORY:-}" ]]; then
owner="${GITHUB_REPOSITORY%%/*}"
printf '%s\n' "${owner,,}"
exit 0
fi
if remote_url="$(git config --get remote.origin.url 2>/dev/null)" && [[ -n "${remote_url}" ]]; then
remote_path="${remote_url%.git}"
if [[ "${remote_path}" == *://* ]]; then
remote_path="${remote_path#*://}"
remote_path="${remote_path#*@}"
remote_path="${remote_path#*/}"
elif [[ "${remote_path}" == *:* ]]; then
remote_path="${remote_path#*:}"
fi
if [[ "${remote_path}" == */* ]]; then
owner="${remote_path%%/*}"
printf '%s\n' "${owner,,}"
exit 0
fi
fi
echo "ERROR: Could not resolve repository owner from OWNER, GITHUB_REPOSITORY_OWNER, GITHUB_REPOSITORY or git remote." >&2
exit 1