[wip] There should be a plugin approach for output
This commit is contained in:
parent
756cc3957a
commit
e77830a144
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.*.sw*
|
54
changelog
54
changelog
@ -8,22 +8,9 @@ CHANGELOG=/etc/changelog
|
||||
|
||||
msg(){ echo -e "$@"; }
|
||||
panic(){ msg "${@} Exiting."; exit 1;}
|
||||
template(){
|
||||
local 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
|
||||
@ -51,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(){
|
||||
@ -62,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
|
||||
|
||||
@ -74,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"
|
||||
@ -85,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"
|
||||
|
15
hooks-output/changelog-server.sh
Normal file
15
hooks-output/changelog-server.sh
Normal 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
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user