|
1 | 1 | #! /bin/bash |
2 | 2 |
|
| 3 | +# Declare a varaiable for caching |
| 4 | +declare cache; |
| 5 | + |
3 | 6 | function id_current_tag() { |
4 | 7 | local INPUT="${1}" |
5 | 8 | git describe --tags --abbrev=0 ${INPUT} |
6 | 9 | } |
7 | 10 |
|
8 | | -function enumerate_tag_history() { |
| 11 | +function run_enumerate_tag_history() { |
9 | 12 | local HEAD_TAG=$(id_current_tag HEAD) |
10 | 13 | { git rev-list --tags --ancestry-path "$(git tag --no-contains "${HEAD_TAG}" | sort -V | head -n1)^..HEAD" ; wait ;} | xargs -I{} git tag --points-at "{}" 2>/dev/null ; |
11 | 14 | wait ; |
12 | 15 | } |
13 | 16 |
|
| 17 | +function enumerate_tag_history() { |
| 18 | + if [[ -z "${cache}" ]] ; then |
| 19 | + cache=$(run_enumerate_tag_history | grep -vE "v?\d+.\d+.\d+-dev" ; wait;) |
| 20 | + fi ; |
| 21 | + printf "%s\n" "${cache}" ; |
| 22 | + wait ; |
| 23 | +} |
| 24 | + |
| 25 | +function id_parent_tag() { |
| 26 | + local INPUT="${1}" |
| 27 | + enumerate_tag_history | grep -A 1 -F -f <(id_current_tag ${INPUT} ) | tail -n1 |
| 28 | + wait ; |
| 29 | +} |
| 30 | + |
14 | 31 | # step 1: is designed to determine the current and previous Git tags and |
15 | 32 | # then construct a Git range based on these tags. If no argument is provided, it defaults to |
16 | 33 | # using the tags. |
17 | 34 | if [[ -z "${1}" ]] ; then |
18 | | -GIT_CURRENT_TAG=$(id_current_tag) |
19 | | -GIT_PREVIOUS_TAG=$(enumerate_tag_history | grep -A 1 -F -f <(git describe --tags --abbrev=0 "${GIT_CURRENT_TAG}") | tail -n1 ) |
20 | | -FALLBACK_GIT_RANGE="${GIT_CURRENT_TAG}...${GIT_PREVIOUS_TAG}" |
| 35 | +# GIT_CURRENT_TAG=$(id_current_tag) |
| 36 | + |
| 37 | +for EACH_TAG in $(enumerate_tag_history | sort -Vr) ; do |
| 38 | +GIT_PREVIOUS_TAG=$(id_parent_tag "${EACH_TAG}") |
| 39 | +FALLBACK_GIT_RANGE="${EACH_TAG}...${GIT_PREVIOUS_TAG}" |
| 40 | +"${0}" "${FALLBACK_GIT_RANGE}" || : ; wait ; |
| 41 | +done; |
| 42 | +exit 0 ; |
21 | 43 | fi ; |
22 | 44 | GIT_RANGE="${1:-${FALLBACK_GIT_RANGE}}" |
23 | 45 |
|
24 | 46 | # cache the git log |
25 | 47 | CHANGELOG_BUFFER=".chagelog_buffer.txt" |
26 | 48 | cat <(git log "${GIT_RANGE}" --reverse --pretty=format:"COMMIT_START%n%h%n%B%nCOMMIT_END") >"${CHANGELOG_BUFFER}" ; wait ; |
27 | 49 |
|
| 50 | +RAW_IMPACTED_ISSUES=$(cat <"${CHANGELOG_BUFFER}" | grep -oE "([#]\d+){1}\b" | sort -id | uniq | xargs -L1 -I{} printf "%s, " "{}" ; wait ;) |
| 51 | +RAW_FLAGS_USED=$(cat <"${CHANGELOG_BUFFER}" | grep -oE "^([\[][A-Z]+[]]){1}" | sort -id | uniq -c | sort -rid | grep -oE "([A-Z]+){1}" | xargs -L1 -I{} printf "%s, " "{}" ; wait ;) |
| 52 | + |
| 53 | + |
| 54 | +# header |
28 | 55 | printf "%s\n\n" "## What Changed between \`${GIT_RANGE}\`" ; |
| 56 | +# insights table |
| 57 | +printf "%s\n%s\n" "| Details | |" "|------------------|---------------------|" ; |
| 58 | +printf "%s" "| Kinds of changes | " ; |
| 59 | +printf "%s\n" "${RAW_FLAGS_USED:-'None'} |" | sed -e 's/, |/ |/g' ; |
| 60 | +printf "%s" "| Impacted Issues | " ; |
| 61 | +printf "%s\n" "${RAW_IMPACTED_ISSUES:-'None'} |" | sed -e 's/, |/ |/g' ; |
| 62 | +printf "\n\n" ; |
29 | 63 |
|
30 | 64 | # auto-collect gitlog |
31 | 65 | for FILE_INPUT in $(git log --pretty=format:"%n" --name-only "${GIT_RANGE}" | sort -id | uniq) ; do |
|
61 | 95 |
|
62 | 96 | done ; |
63 | 97 |
|
| 98 | +unset cache 2>/dev/null || : ; |
| 99 | + |
64 | 100 | # remove the buffer |
65 | 101 | rm -f "${CHANGELOG_BUFFER}" 2>/dev/null || : ; |
0 commit comments