Skip to content

Instantly share code, notes, and snippets.

@GuyPaddock
Last active January 17, 2023 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuyPaddock/d242f2592cd844a7d95d614489440644 to your computer and use it in GitHub Desktop.
Save GuyPaddock/d242f2592cd844a7d95d614489440644 to your computer and use it in GitHub Desktop.
Extract Issue Tags from Commit History in a Branch Based Off develop
#!/usr/bin/env bash
##
# @file
# Extracts all of the issue tags in commit messages of a branch_ref and lists them.
#
# Usage:
# list-issues.sh [branch_ref ref] [base branch_ref ref]
#
# - If [branch_ref ref] is not specified, it defaults to "HEAD" (whatever is
# currently checked out.
# - If [base branch_ref ref] is not specified, it defaults to "main"
# (the develop branch_ref).
#
# If the Git history looked like this:
# [ABC-123] Some change
# [ABC-456] Another change
# [ABC-123] [ABC-786] Still other changes
#
# Then the output would be a sorted list of tickets, like this:
# ABC-123
# ABC-456
# ABC-786
#
set -eu
################################################################################
# Constants
################################################################################
project="ABC"
default_branch_ref="HEAD"
default_base_branch_ref="main"
################################################################################
# Command-line Arguments with Defaults
################################################################################
branch_ref="${1:-${default_branch_ref}}"
base_branch_ref="${2:-${default_base_branch_ref}}"
################################################################################
# Main Script
################################################################################
git log --format=oneline "${base_branch_ref}...${branch_ref}" | \
sed -E 's/\[|\]/\n/g' | grep -E "^${project}-" | sort --numeric-sort | uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment