Compare commits

..

2 Commits

Author SHA1 Message Date
alban
e77830a144 [wip] There should be a plugin approach for output 2020-05-16 02:38:09 +02:00
alban
756cc3957a [fix] cosmetic 2020-05-16 01:34:53 +02:00
3 changed files with 52 additions and 17 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.*.sw*

View File

@ -8,21 +8,9 @@ CHANGELOG=/etc/changelog
msg(){ echo -e "$@"; }
panic(){ msg "${@} Exiting."; exit 1;}
template(){
t=$(mktemp)
cat << HEREDOC >$t
$(date "+%Y-%m-%d %H:%M") $CHANGELOG_USERNAME
$( echo -e "$@"|sed 's/^/ /' )
HEREDOC
[[ -f $CHANGELOG ]] && cat /etc/changelog >> $t
cat "$t" > $CHANGELOG
rm -f "$t"
}
ENTRY_FILE=$(mktemp)
change(){
local TMP=$(mktemp)
TMP="$1"
while true ; do
echo -e "\nType the nature of the change.\nExample: > mysql: do not start on boot\n"
read -e -p "> " SUB
@ -50,8 +38,7 @@ change(){
echo -e "\nHere is the content you are about to add.\n\n$(cat $TMP)\n"
read -e -p "OK? [Yn]: " -i y RETURN
[[ "N" == ${RETURN^^} ]] && return
template "$(cat $TMP)"
rm $TMP
echo $TMP
}
hookContentComment(){
@ -61,6 +48,22 @@ hookContentComment(){
echo "$CONTENT" >> $TMP
}
hookOutputFile(){
[[ -z "$1" ]] && echo "Writing a local changelog entry to $CHANGELOG" && return
local t=$(mktemp)
TMP="$1"
cat << HEREDOC >$t
$(date "+%Y-%m-%d %H:%M") $CHANGELOG_USERNAME
$( echo -e "$@"|sed 's/^/ /' )
HEREDOC
[[ -f $CHANGELOG ]] && cat /etc/changelog >> $t
cat "$t" > $CHANGELOG
rm -f "$t"
}
# Exec
@ -73,6 +76,16 @@ for (( i = 0; i < ${#HOOKS_CONTENT[@]} ; i++ )); do
HOOKS_CONTENT_MENU+=("$( ${HOOKS_CONTENT[$i]} )")
done
# Build the hook content menu
HOOKS_OUTPUT+=("hookOutputFile")
declare -a HOOKS_OUTPUT_MENU
[[ -n "hooks-output/*" ]] && source hooks-output/*
for (( i = 0; i < ${#HOOKS_OUTPUT[@]} ; i++ )); do
TXT=$( ${HOOKS_OUTPUT[$i]} )
HOOKS_OUTPUT_MENU+=("$( ${HOOKS_OUTPUT[$i]} )")
done
echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
@ -84,5 +97,11 @@ echo -e "\nWelcome to Serious Changelogs Inc. Do you have something for me?\n"
[[ ! -f $CHANGELOG ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n"
# parse command
change
change "$ENTRY_FILE"
for (( i=0; i<${#HOOKS_OUTPUT_MENU[@]}; i++)) ; do
echo "${HOOKS_OUTPUT_MENU[$i]}"
${HOOKS_OUTPUT[$i]} $ENTRY_FILE
done
rm "$ENTRY_FILE"

View File

@ -0,0 +1,15 @@
#!/bin/bash
HOOKS_OUTPUT+=( hookOutputChangelogServer )
CHANGELOG_SERVER=http://localhost:3000
hookOutputChangelogServer(){
[[ -z "$1" ]] && echo "Sending changelog to remote server" && return
CONTENT=$(jq -aRs . $1|tr '"' '\"')
PAYLOAD="{\"author\":\"$CHANGELOG_USERNAME\",\"server\":\"$(hostname -f)\",\"content\":${CONTENT}}"
URL=$( curl -X POST -H "Content-Type: application/json" -s -d "${PAYLOAD}" "$CHANGELOG_SERVER/changelog/_doc"; )
echo "$FILE: $URL" >> $TMP
}