kanboard-api-client-shell/add_todo.sh

52 lines
1.7 KiB
Bash
Executable File

#!/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"
# remove newlines (https://stackoverflow.com/a/38672741/1885932)
_description="$(echo "$2" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')"
_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"
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
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"
printf "Subject: OK: Todo: '%s'\n\n%s" "$_title" "$_description" | sendmail -f server@gabbaell.co.uk kanboard.docker@gabbaell.co.uk
else
echo "Error: $_result"
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
exit 9
fi