-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathchangelog.sh
More file actions
95 lines (92 loc) 路 3.04 KB
/
Copy pathchangelog.sh
File metadata and controls
95 lines (92 loc) 路 3.04 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function changelog {
if [ -d "tests" ]; then
cp "/usr/lib/node_modules/@treehouses/cli/CHANGELOG.md" .
else
cp "/usr/lib/node_modules/@treehouses/cli/CHANGELOG.md" ../.
fi
local LOGPATH displaymode version1 version2 CURRENT
CURRENT=$(treehouses version)
LOGPATH="$SCRIPTFOLDER/CHANGELOG.md"
checkargn $# 3
displaymode="$1"
version1="$2"
version2="$3"
if [ ! -f "$LOGPATH" ]; then
log_and_exit1 "Error: file does not exist!"
fi
case "$displaymode" in
view)
checkargn $# 1
view $LOGPATH
;;
"")
checkargn $# 0
cat $LOGPATH
;;
compare)
case "$version1" in
"")
log_and_exit1 "Error: only 'compare [previous version]' and 'compare [previous version] [later version] are supported."
;;
*)
case "$version2" in
"")
checkargn $# 2
dpkg --compare-versions "$CURRENT" "gt" "$version1"
gt="$?"
if [[ $gt -eq 0 ]]; then
sed "/^### $CURRENT/!d;s//&\n/;s/.*\n//;:a;/^### $version1/bb;\$!{n;ba};:b;s//\n&/;P;D" $LOGPATH #grabs text between version numbers, print bottom to top
else # Needs to specify previous version instead of current
echo "ERROR: Must specify a previous version (less than $CURRENT)"
fi
;;
*)
checkargn $# 3
dpkg --compare-versions "$version2" "gt" "$version1"
gt="$?"
dpkg --compare-versions "$version2" "eq" "$version1"
eq="$?"
if [[ $gt -eq 0 ]]; then
sed "/^### $version2/!d;s//&\n/;s/.*\n//;:a;/^### $version1/bb;\$!{n;ba};:b;s//\n&/;P;D" $LOGPATH
elif [[ $eq -eq 0 ]]; then
echo "ERROR: Must specify different versions for comparisons (cannot compare same version to itself)"
else
sed "/^### $version1/!d;s//&\n/;s/.*\n//;:a;/^### $version2/bb;\$!{n;ba};:b;s//\n&/;P;D" $LOGPATH
echo "Did you mean: $BASENAME changelog compare $version2 $version1"
fi
;;
esac
;;
esac
;;
*)
log_and_exit1 "Error: only 'view', 'compare' and blank options are supported."
;;
esac
}
function changelog_help {
CYAN='\033[1;36m'
NC='\033[0m' #no color
echo
echo "Usage: $BASENAME changelog"
echo " Views the treehouses changelog generated by auto-changelog."
echo
echo "Usage: $BASENAME changelog view"
echo " Opens the raw changelog in vim read only mode."
echo
echo "Usage: $BASENAME changelog compare [previous version]"
echo " Displays all changes since a previous version to the current version."
echo
echo "Usage: $BASENAME changelog compare [previous version] [later version]"
echo " Displays all changes since a previous version to the version specified."
echo
echo "Example: $BASENAME changelog"
echo
echo -e "${CYAN}- \`treehouses services privatebin icon refactor\` [\`#1254\`](https://github.com/treehouses/cli/pull/1254)"
echo
echo "> 12 May 2020"
echo
echo "#### [1.20.22](https://github.com/treehouses/cli/compare/1.20.21...1.20.22)"
echo
echo -e "### Changelog${NC}"
}