Skip to content

Instantly share code, notes, and snippets.

@maxRN
Created March 22, 2022 21:13
Show Gist options
  • Save maxRN/671c9cfd977473ab5113d8f95544ae59 to your computer and use it in GitHub Desktop.
Save maxRN/671c9cfd977473ab5113d8f95544ae59 to your computer and use it in GitHub Desktop.
Get Jira issues for file from commit history
#!/bin/bash
JIRA_BASE_URL="https:\/\/your.jira.com\/browse\/"
# --follow lists all commits for the particular file, even through renames
# %B is short for commit subject line + body
COMMIT_MESSAGES=$(git log --pretty=format:%B --follow -- $1)
# matches Jira issue keys, e.g. JIRA-123
PATTERN='([[:upper:]]+-[[:digit:]]+)'
# -e is pattern to match against; -E means to interpret regex as extended pattern; -o only prints the matched words
grep -E -e ${PATTERN} -o <<< ${COMMIT_MESSAGES} | sed -e "s/^/${JIRA_BASE_URL}/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment