From 376973256e2b76c03316e441f5b44082e3ba8b81 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Thu, 19 Sep 2024 14:02:13 +0200 Subject: [PATCH] Use regex to support both ssh and https formats of repo address --- bin/upload_sarif_to_github | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/upload_sarif_to_github b/bin/upload_sarif_to_github index aecbdc5..72a74db 100755 --- a/bin/upload_sarif_to_github +++ b/bin/upload_sarif_to_github @@ -3,8 +3,12 @@ set -euo pipefail sarif_file="${1:-}" -owner=$(echo "$BUILDKITE_REPO" | awk -F'[:/]' '{print $2}') -repo=$(echo "$BUILDKITE_REPO" | awk -F'[/.]' '{print $(NF-1)}') + +[[ $BUILDKITE_REPO =~ ^(https?://|git@)([^/:]+)[/:](.*)$ ]] && slug=${BASH_REMATCH[3]%%.git} +if [[ -z "${slug:-}" ]]; then + echo "Unable to determine the repo slug from the repo URL" + exit 1 +fi if [ -z "$sarif_file" ]; then echo "Not enough arguments provided. Usage: ./upload_sarif_to_gh.sh " @@ -64,4 +68,4 @@ curl -L \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ --data-binary "@$sarif_json_temp_file" \ - https://api.github.com/repos/"$owner"/"$repo"/code-scanning/sarifs + https://api.github.com/repos/"$slug"/code-scanning/sarifs