Skip to content

Commit

Permalink
Fix scripts/get-compare-link.sh (#1890)
Browse files Browse the repository at this point in the history
Co-authored-by: Raúl Barroso <ra.barroso@gmail.com>
  • Loading branch information
hariso and raulb authored Oct 9, 2024
1 parent 515adc6 commit 579a71b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions scripts/get-compare-link.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ git fetch --tags || { echo "Failed to fetch tags"; exit 1; }
latest_tag=$(git describe --tags "$(git rev-list --tags --max-count=1)") || { echo "Failed to get latest tag"; exit 1; }

# Get the owner and repository name from the remote URL
repo_url=$(git config --get remote.origin.url)
IFS='/' read -ra parts <<< "$repo_url"
owner="${parts[-2]}"
repo="${parts[-1]%.git}" # Remove the .git extension if it exists
# Get the remote URL
remote_url=$(git config --get remote.origin.url)

# Extract owner/repo from the URL
if [[ $remote_url =~ ^https://github.com/ ]]; then
# For HTTPS URLs
owner_repo=$(echo $remote_url | sed -E 's|https://github.com/||' | sed -E 's/\.git$//')
elif [[ $remote_url =~ ^git@ ]]; then
# For SSH URLs
owner_repo=$(echo $remote_url | sed -E 's/^git@github.com://' | sed -E 's/\.git$//')
else
echo "Unrecognized GitHub URL format"
exit 1
fi

# Create a link to compare the latest tag and the main branch
comparison_link="https://github.com/$owner/$repo/compare/$latest_tag...main"
comparison_link="https://github.com/$owner_repo/compare/$latest_tag...main"

echo "Comparison Link: $comparison_link"

0 comments on commit 579a71b

Please sign in to comment.