-
-
Save KyMidd/2d659bc59931bb2e1b4c530fc2d163fc to your computer and use it in GitHub Desktop.
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
# Checkout the PR branch | |
echo "Checking out PR branch" | |
git checkout -q "${{ github.event.pull_request.head.ref }}" | |
echo "Github head ref is ${{ github.event.pull_request.head.ref }}" | |
# Find current branch name | |
echo "Finding current branch name" | |
CURRENT_BRANCH=$(git branch | grep ^\* | cut -d "*" -f 2 | cut -d " " -f 2) | |
echo "Current branch is $CURRENT_BRANCH" | |
# Find hash of commit most common ancestor, e.g. where branch began | |
echo "Finding hash of commit most common ancestor, e.g. where branch began" | |
BRANCH_MERGE_BASE=$(git merge-base ${BASE_BRANCH} ${CURRENT_BRANCH}) | |
echo "Branch merge base is $BRANCH_MERGE_BASE" | |
# Find all commits since common ancestor | |
echo "Finding all commits since common ancestor" | |
BRANCH_COMMITS=$(git rev-list ${BRANCH_MERGE_BASE}..HEAD) | |
echo "Branch commits are $BRANCH_COMMITS" | |
# Find first commit, extract commit message and then Jira ticket number | |
FIRST_COMMIT=$(echo $BRANCH_COMMITS | head -n 1) | |
echo "First commit is $FIRST_COMMIT" | |
FIRST_COMMIT_MESSAGE=$(git log --max-count=1 --format=%B "$FIRST_COMMIT" | awk 'NF') | |
echo "First commit message is $FIRST_COMMIT_MESSAGE" | |
NORMALIZED_FIRST_COMMIT_MESSAGE=$(echo $FIRST_COMMIT_MESSAGE | tr '[:lower:]' '[:upper:]') | |
echo "Normalized first commit message is $NORMALIZED_FIRST_COMMIT_MESSAGE" | |
JIRA_TICKET=$(echo $NORMALIZED_FIRST_COMMIT_MESSAGE | grep -o -E '^[A-Z]{2,}-[0-9]+' || true) | |
echo "Jira ticket is $JIRA_TICKET" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment