Skip to content

Commit 94e82bd

Browse files
[FEATURE] Improved initial implementation a bunch (- WIP #155 -)
Changes in file generate_changelog.sh: * added some caching while re-generationg * now generates new changelog from scratch if given no options * now extracts impacted issues and kinds of changes as well as per-file changes * improved initial formatting a bit
1 parent 1e90003 commit 94e82bd

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

generate_changelog.sh

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,65 @@
11
#! /bin/bash
22

3+
# Declare a varaiable for caching
4+
declare cache;
5+
36
function id_current_tag() {
47
local INPUT="${1}"
58
git describe --tags --abbrev=0 ${INPUT}
69
}
710

8-
function enumerate_tag_history() {
11+
function run_enumerate_tag_history() {
912
local HEAD_TAG=$(id_current_tag HEAD)
1013
{ 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 ;
1114
wait ;
1215
}
1316

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+
1431
# step 1: is designed to determine the current and previous Git tags and
1532
# then construct a Git range based on these tags. If no argument is provided, it defaults to
1633
# using the tags.
1734
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 ;
2143
fi ;
2244
GIT_RANGE="${1:-${FALLBACK_GIT_RANGE}}"
2345

2446
# cache the git log
2547
CHANGELOG_BUFFER=".chagelog_buffer.txt"
2648
cat <(git log "${GIT_RANGE}" --reverse --pretty=format:"COMMIT_START%n%h%n%B%nCOMMIT_END") >"${CHANGELOG_BUFFER}" ; wait ;
2749

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
2855
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" ;
2963

3064
# auto-collect gitlog
3165
for FILE_INPUT in $(git log --pretty=format:"%n" --name-only "${GIT_RANGE}" | sort -id | uniq) ; do
@@ -61,5 +95,7 @@ fi ;
6195

6296
done ;
6397

98+
unset cache 2>/dev/null || : ;
99+
64100
# remove the buffer
65101
rm -f "${CHANGELOG_BUFFER}" 2>/dev/null || : ;

0 commit comments

Comments
 (0)