Add changelog + log
This commit is contained in:
parent
43c6c25657
commit
615cd74316
|
|
@ -1,5 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Load params as local variables
|
||||||
for kv in $*; do
|
for kv in $*; do
|
||||||
[[ $kv =~ ^.*=.*$ ]] && eval $kv
|
[[ $kv =~ ^.*=.*$ ]] && eval $kv
|
||||||
done
|
done
|
||||||
|
|
@ -11,6 +12,21 @@ done
|
||||||
[[ ! -e $FLATNOTES_ROOT ]] && echo "flatnotes directory does not exist" && exit 1
|
[[ ! -e $FLATNOTES_ROOT ]] && echo "flatnotes directory does not exist" && exit 1
|
||||||
[[ ! -e $GIT_SSH_KEY_FILE ]] && echo "ssh key file not found" && exit 1
|
[[ ! -e $GIT_SSH_KEY_FILE ]] && echo "ssh key file not found" && exit 1
|
||||||
|
|
||||||
|
CHANGELOG="[flatnotes] Changelog.md"
|
||||||
|
|
||||||
|
git_bin=$(which git)
|
||||||
|
function git
|
||||||
|
{
|
||||||
|
echo "[$(basename $0)] exec cmd: git $*"
|
||||||
|
$git_bin -C $FLATNOTES_ROOT $*
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_changelog
|
||||||
|
{
|
||||||
|
echo "| Date | Commit | Message |"
|
||||||
|
echo "| --- | --- | --- |"
|
||||||
|
$git_bin -C $FLATNOTES_ROOT log --date=iso --pretty=format:'| %ad | %h | %s |' $GIT_BRANCH
|
||||||
|
}
|
||||||
|
|
||||||
function url_parser {
|
function url_parser {
|
||||||
url=$1
|
url=$1
|
||||||
|
|
@ -63,7 +79,8 @@ function git_init
|
||||||
|
|
||||||
cd $FLATNOTES_ROOT
|
cd $FLATNOTES_ROOT
|
||||||
if [[ ! -d ${FLATNOTES_ROOT}/.git ]]; then
|
if [[ ! -d ${FLATNOTES_ROOT}/.git ]]; then
|
||||||
echo ".flatnotes" > .gitignore
|
echo ".flatnotes" > ${FLATNOTES_ROOT}/.gitignore
|
||||||
|
echo $CHANGELOG | sed -e 's, ,*,g' -re 's,(\[|\]),\\\1,g' >> ${FLATNOTES_ROOT}/.gitignore
|
||||||
git init
|
git init
|
||||||
git branch -m $GIT_BRANCH
|
git branch -m $GIT_BRANCH
|
||||||
git remote add origin $GIT_SSH_URL
|
git remote add origin $GIT_SSH_URL
|
||||||
|
|
@ -80,9 +97,12 @@ function start_inotify
|
||||||
{
|
{
|
||||||
inotifywait -q -m $FLATNOTES_ROOT -e access -e modify -e create -e delete | \
|
inotifywait -q -m $FLATNOTES_ROOT -e access -e modify -e create -e delete | \
|
||||||
while read -r directory action file; do
|
while read -r directory action file; do
|
||||||
if [[ "$file" =~ .*md$ || "$directory" == "${FLATNOTES_ROOT}/attachments" ]]; then
|
if [[ "$file" == "$CHANGELOG" ]]; then
|
||||||
|
echo "$CHANGELOG modified, skip"
|
||||||
|
elif [[ "$file" =~ .*md$ || "$directory" == "${FLATNOTES_ROOT}/attachments" ]]; then
|
||||||
echo "[inotifywait] event catched action=$action on directory=$directory file=$file"
|
echo "[inotifywait] event catched action=$action on directory=$directory file=$file"
|
||||||
autocommit_on_event "$directory" "$action" "$file"
|
autocommit_on_event "$directory" "$action" "$file"
|
||||||
|
build_changelog > "${FLATNOTES_ROOT}/${CHANGELOG}"
|
||||||
sleep 1
|
sleep 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
@ -94,16 +114,18 @@ function autocommit_on_event
|
||||||
action="$2"
|
action="$2"
|
||||||
file="$3"
|
file="$3"
|
||||||
|
|
||||||
if [[ $action == ACCESS ]]; then
|
|
||||||
# update local repo in case some file has been updated by other method than flatnotes
|
|
||||||
local_change=$(git status --short | wc -l)
|
local_change=$(git status --short | wc -l)
|
||||||
|
|
||||||
|
# update local repo in case some file has been updated by other method than flatnotes
|
||||||
[[ $local_change > 0 ]] && git stash save -a local_changes
|
[[ $local_change > 0 ]] && git stash save -a local_changes
|
||||||
git -C $FLATNOTES_ROOT pull -X ours
|
git pull -X ours
|
||||||
[[ $local_change > 0 ]] && git stash pop && git stash clear
|
[[ $local_change > 0 ]] && git stash pop && git stash clear
|
||||||
else
|
|
||||||
git -C $FLATNOTES_ROOT add .
|
if [[ $action != ACCESS ]]; then
|
||||||
git -C $FLATNOTES_ROOT commit -am "Autocommit action=$action on file=$file detected"
|
[[ $local_change == 0 ]] && echo "autocommit_on_event: nothing to commit" && return
|
||||||
git -C $FLATNOTES_ROOT push
|
git add .
|
||||||
|
git commit -am "Autocommit action=$action on file=$file detected"
|
||||||
|
git push
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue