kanboard-api-client-shell/add_todo.sh

52 lines
1.7 KiB
Bash
Raw Permalink Normal View History

2020-11-07 20:54:07 +00:00
#!/bin/sh
if [ -f ./.env ] ; then
. ./.env
else
echo "add_todo.sh: Warning: no '.env' file found."
fi
if [ -z "$_api_auth" ] ; then
echo "add_todo.sh: Error: No API authorisation credentials supplied."
exit 3
fi
_title="$1"
2020-11-07 23:06:26 +00:00
# remove newlines (https://stackoverflow.com/a/38672741/1885932)
_description="$(echo "$2" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')"
2020-11-07 20:54:07 +00:00
_api_url='http://kanboard.docker.home/jsonrpc.php'
_project_id=4
_position=1
_column_id=13
_swimlane_id=15
_result="$(curl --user $_api_auth \
--silent \
--data '{"jsonrpc": "2.0", "method": "createTask", "id": 1, "params":{"project_id": '"$_project_id"', "title": "'"$_title"'","description": "'"$_description"'"}}' \
$_api_url)"
_task_id="$(echo "$_result" | jq '.result')"
if [ "$_task_id" != null ] ; then
echo "Task created: $_task_id"
else
echo "Error: $_result"
2020-11-08 00:08:50 +00:00
printf "Subject: Fail: Todo: '%s'\n\n%s\n----------------------\n%s" "$_title" "$_result" "$_description" | sendmail -f server@gabbaell.co.uk kanboard.docker@gabbaell.co.uk
2020-11-07 20:54:07 +00:00
exit 6
fi
_result="$(curl --user $_api_auth \
--silent \
--data '{"jsonrpc": "2.0", "method": "moveTaskPosition", "id": 1, "params":{"project_id": '"$_project_id"', "task_id": '"$_task_id"',"column_id": '"$_column_id"',"position": '"$_position"',"swimlane_id": '"$_swimlane_id"'}}' \
$_api_url)"
_status="$(echo "$_result" | jq '.result')"
if [ "$_status" = true ] ; then
echo "Task moved: $_status"
2020-11-08 00:08:50 +00:00
printf "Subject: OK: Todo: '%s'\n\n%s" "$_title" "$_description" | sendmail -f server@gabbaell.co.uk kanboard.docker@gabbaell.co.uk
2020-11-07 20:54:07 +00:00
else
echo "Error: $_result"
2020-11-08 00:08:50 +00:00
printf "Subject: Fail: Todo: '%s'\n\n%s\n----------------------\n%s" "$_title" "$_result" "$_description" | sendmail -f server@gabbaell.co.uk kanboard.docker@gabbaell.co.uk
2020-11-07 20:54:07 +00:00
exit 9
fi