Skip to content

Commit

Permalink
Use regex to support both ssh and https formats of repo address
Browse files Browse the repository at this point in the history
  • Loading branch information
wzieba committed Sep 19, 2024
1 parent 8478655 commit 3769732
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bin/upload_sarif_to_github
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path to .sarif report>"
Expand Down Expand Up @@ -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

0 comments on commit 3769732

Please sign in to comment.