Skip to content

Instantly share code, notes, and snippets.

@MrCarb0n
Last active July 2, 2022 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrCarb0n/f01011f1873f9e48aca351d8e1ff748e to your computer and use it in GitHub Desktop.
Save MrCarb0n/f01011f1873f9e48aca351d8e1ff748e to your computer and use it in GitHub Desktop.
commit title to changelog generator for magisk module repository.
#!/usr/bin/bash
# debug
# set -xv
BANNER() {
echo -e $B
echo "╭─────────────────────────────────────╮"
echo "│ Commit' title to CHANGELOG.md │"
echo "│ generator for magisk module repo. │"
echo "│ │"
echo "│ Author: MrCarb0n @ Git(Hub|Lab) XDA │"
echo "╰─────────────────────────────────────╯"
echo -e $N
}
COLOR() {
B="\033[1;34m" G="\033[1;30m"
N="\033[0m" R="\033[0;31m"
}
COLOR && BANNER
# clean up variable and older *.md files
cleanup() {
[ -n ctmp ] && unset ctmp
find . -type f -name "*.md" ! -name "$outFile" -delete
case $1 in
0)
exit 0
;;
1)
exit 1
;;
esac
}
trap "$(cleanup 1)" SIGQUIT
# read git repo path
readGitPath() {
local Q="| Enter your git repository path:" NL="\n - $G"
read -p "$(echo -e $N$B$Q$G$NL)" gitDir
[ -d "$gitDir/.git" ] ||
{
echo -e "$R ! invalid input.\n ! $gitDir not a git repo.$N"
cleanup 1
}
}
# create output file if doesn't exist
createOutFile() {
local Q="| Enter output markdown filename:" NL="\n - $G"
read -p "$(echo -e $N$B$Q$G$NL)" outFile
[ ! -f "$outFile" ] && touch "$outFile" ||
{
echo -e "$R ! $outFile already exists.\n ! remove or rename existed file before next run.$N"
cleanup 1
}
}
# verify selected branch
verifyBranch() {
local Q="| Enter git branch name:" NL="\n - $G"
read -p "$(echo -e $N$B$Q$G$NL)" branch
gitBranch="$(git -C "$gitDir" branch | cut -d '*' -f2 | xargs)"
for b in "$gitBranch"; do
[ "$branch" = "$b" ] ||
{
echo -e "$R ! $branch branch not found.\n - available: $gitBranch"
cleanup 1
}
done
}
# run primary tasks
readGitPath && createOutFile && verifyBranch || cleanup 1
# get total commit
# totalGitCommit=$(git -C $gitDir rev-list --count HEAD)
commitHash="$(git -C $gitDir log --oneline --pretty=%h | xargs)"
# get update version
getVersion() {
grep 'version=' $gitDir/module.prop | cut -d '=' -f2
}
# get commit title
getCommit() {
git -C "$gitDir" log --oneline -1 --pretty="%s"
}
# checkout every commit and match the difference then print
makeCL() {
echo -e "$N$B| Building $outFile file:$N"
# switch to input branch
git -C "$gitDir" checkout -q $branch
# run changelog loop
for c in $commitHash; do
git -C "$gitDir" checkout -q $c
if [ -n ctmp ] && [ "$(getVersion)" = "$ctmp" ]; then
echo "* $(getCommit)" >> $outFile
else
echo "#### $(getVersion)" >> $outFile
echo "* $(getCommit)" >> $outFile
ctmp="$(getVersion)"
fi
git -C "$gitDir" checkout -q $branch
done && {
echo -e "$G - done"
}
}
# build changelog file and clean up
makeCL && cleanup 0 || cleanup 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment