Created
November 14, 2024 23:30
-
-
Save barryhughes/2658649e68f0de413bf9fc89454caddf to your computer and use it in GitHub Desktop.
Bash > List all PRs merged since a given commit was tagged (since a given version)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Attempts to list PRs merged since a given tag was created. | |
# | |
# Run from within the repo you are interested in (of course fetch/pull | |
# down all the latest changes from remote). | |
# | |
# Usage: prs-merged-since <tag_name> | |
# Example: prs-merged-since v1.0.0 | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 <tag_name>" | |
exit 1 | |
fi | |
TAG_NAME=$1 | |
# Get the date of the tag | |
TAG_DATE=$(git log -1 --format=%ai "$TAG_NAME" 2>/dev/null) | |
if [ $? -ne 0 ]; then | |
echo "Error: Tag '$TAG_NAME' not found" | |
exit 1 | |
fi | |
# Convert tag date to timestamp for comparison | |
TAG_TIMESTAMP=$(date -d "$TAG_DATE" +%s) | |
# Get all merged pull requests with their merge dates | |
git log --merges --format="%ai | %s" | while read line; do | |
MERGE_DATE=$(echo "$line" | cut -d'|' -f1) | |
MERGE_TIMESTAMP=$(date -d "$MERGE_DATE" +%s) | |
# Only show PRs merged after the tag date | |
if [ $MERGE_TIMESTAMP -gt $TAG_TIMESTAMP ]; then | |
# Extract PR number and title | |
PR_INFO=$(echo "$line" | cut -d'|' -f2) | |
if [[ $PR_INFO =~ "Merge pull request #"([0-9]+)" from" ]]; then | |
PR_NUMBER="${BASH_REMATCH[1]}" | |
echo "PR #$PR_NUMBER | $MERGE_DATE | $PR_INFO" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment