forked from metcalfc/changelog-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchangelog.sh
executable file
·69 lines (57 loc) · 1.45 KB
/
changelog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -eou pipefail
head_ref=$1
shift
base_ref=$1
shift
repo_url=$1
shift
fetch=false;
compare_operator="..."
extra_flags=""
while [[ $# -gt 0 ]]; do
case $1 in
--reverse)
extra_flags="${extra_flags} --reverse"
shift
;;
--fetch)
fetch=true;
shift;
;;
--head_ref_only)
compare_operator=".."
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
esac
done
# By default a GitHub action checkout is shallow. Get all the tags, branches,
# and history. Redirect output to standard error which we can collect in the
# action.
if [ "$fetch" == "true" ]; then
git fetch --depth=1 origin +refs/tags/*:refs/tags/* 1>&2
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* 1>&2
git fetch --prune --unshallow 1>&2
fi
# if folks don't have a base ref to compare against just use the initial
# commit. This will show all the changes since the beginning but I can't
# think of a better default.
if [ -z "$base_ref" ]
then
base_ref=$(git rev-list --max-parents=0 HEAD)
fi
# Bash quoting will get you. Do not quote the extra_flags. If its null
# we want it to disappear. If you quote it, it will go to git as an ""
# and thats not a valid arg.
log=$(git log "${base_ref}""${compare_operator}""${head_ref}" \
--pretty=format:"- [%h](http://github.com/${repo_url}/commit/%H) - %s" \
${extra_flags})
if [ -z "$log" ];
then
log="No Changes."
fi
echo "$log"