Compare commits
2 Commits
031aad7aa3
...
e77830a144
Author | SHA1 | Date | |
---|---|---|---|
|
e77830a144 | ||
|
756cc3957a |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.*.sw*
|
53
changelog
53
changelog
@ -8,21 +8,9 @@ CHANGELOG=/etc/changelog
|
|||||||
|
|
||||||
msg(){ echo -e "$@"; }
|
msg(){ echo -e "$@"; }
|
||||||
panic(){ msg "${@} Exiting."; exit 1;}
|
panic(){ msg "${@} Exiting."; exit 1;}
|
||||||
template(){
|
ENTRY_FILE=$(mktemp)
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
change(){
|
change(){
|
||||||
local TMP=$(mktemp)
|
TMP="$1"
|
||||||
while true ; do
|
while true ; do
|
||||||
echo -e "\nType the nature of the change.\nExample: > mysql: do not start on boot\n"
|
echo -e "\nType the nature of the change.\nExample: > mysql: do not start on boot\n"
|
||||||
read -e -p "> " SUB
|
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"
|
echo -e "\nHere is the content you are about to add.\n\n$(cat $TMP)\n"
|
||||||
read -e -p "OK? [Yn]: " -i y RETURN
|
read -e -p "OK? [Yn]: " -i y RETURN
|
||||||
[[ "N" == ${RETURN^^} ]] && return
|
[[ "N" == ${RETURN^^} ]] && return
|
||||||
template "$(cat $TMP)"
|
echo $TMP
|
||||||
rm $TMP
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hookContentComment(){
|
hookContentComment(){
|
||||||
@ -61,6 +48,22 @@ hookContentComment(){
|
|||||||
echo "$CONTENT" >> $TMP
|
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
|
# Exec
|
||||||
|
|
||||||
@ -73,6 +76,16 @@ for (( i = 0; i < ${#HOOKS_CONTENT[@]} ; i++ )); do
|
|||||||
HOOKS_CONTENT_MENU+=("$( ${HOOKS_CONTENT[$i]} )")
|
HOOKS_CONTENT_MENU+=("$( ${HOOKS_CONTENT[$i]} )")
|
||||||
done
|
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"
|
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"
|
[[ ! -f $CHANGELOG ]] && template "* Changelog: Added $CHANGELOG file\nIt was not serious. Fixed!\n\n"
|
||||||
|
|
||||||
# parse command
|
# 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