Skip to content

Commit f8b08dc

Browse files
committed
feat(changelog): add ability to extract ranges by date
Signed-off-by: Kevin O'Donnell <kevin@blockchaintp.com>
1 parent 2bf759e commit f8b08dc

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

bash/changelog

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ source "$(dirname "${BASH_SOURCE[0]}")/includer.sh"
2222

2323
options::standard
2424
options::add -o l -d "add hyperlinks to commits" -x ADD_LINKS
25+
options::add -o f -d "from date" -a -e FROM_DATE
26+
options::add -o t -d "to date" -a -e TO_DATE
27+
options::add -o d -d "show commit date" -x SHOW_DATE
28+
2529
options::parse_available "$@"
2630

2731
export GIT_PAGER=cat
@@ -38,15 +42,39 @@ function ::fromto() {
3842
return
3943
fi
4044
if [ "$ADD_LINKS" = "true" ] && [ -n "$base_url" ]; then
41-
git::cmd log "$from"..."$to" --no-merges \
42-
--pretty=format:"* %s [view commit]($base_url/%H)"
45+
if [ "$SHOW_DATE" != "true" ]; then
46+
git::cmd log "$from"..."$to" --no-merges \
47+
--pretty=format:"* %s [view commit]($base_url/%H)"
48+
else
49+
git::cmd log "$from"..."$to" --no-merges \
50+
--pretty=format:"* %ci - %s [view commit]($base_url/%H)"
51+
fi
4352
else
44-
git::cmd log "$from"..."$to" --no-merges --pretty=format:"* %s"
53+
if [ "$SHOW_DATE" != "true" ]; then
54+
git::cmd log "$from"..."$to" --no-merges --pretty=format:"* %s"
55+
else
56+
git::cmd log "$from"..."$to" --no-merges --pretty=format:"* %ci - %s"
57+
fi
58+
4559
fi
4660
echo
4761
echo
4862
}
4963

64+
function ::current_branch() {
65+
git::cmd rev-parse --abbrev-ref HEAD
66+
}
67+
68+
function ::date_to_commit_before() {
69+
local theDate=${1:?}
70+
git::cmd rev-list -n 1 --first-parent --before="$theDate" "$(::current_branch)"
71+
}
72+
73+
function ::date_to_commit_after() {
74+
local theDate=${1:?}
75+
git::cmd rev-list -n 1 --first-parent --before="$theDate" "$(::current_branch)"
76+
}
77+
5078
function ::full() {
5179
local later_tag=
5280
echo "# CHANGELOG"
@@ -82,4 +110,21 @@ function ::full() {
82110
done
83111
}
84112

85-
::full
113+
if [ -n "$TO_DATE" ]; then
114+
to_commit=$(::date_to_commit_before "$TO_DATE")
115+
fi
116+
117+
if [ -n "$FROM_DATE" ]; then
118+
from_commit=$(::date_to_commit_after "$FROM_DATE")
119+
fi
120+
121+
if [ -n "$FROM_DATE" ] || [ -n "$TO_DATE" ]; then
122+
if [ -z "$to_commit" ]; then
123+
echo "No change history in the requested range"
124+
exit 0
125+
else
126+
::fromto "$from_commit" "$to_commit"
127+
fi
128+
else
129+
::full
130+
fi

0 commit comments

Comments
 (0)