Story & Task Linker Script

By Marcin Okraszewski - okrasz_news -at- o2 -dot- pl

This script links tasks with stories in batch mode. You just provide story ID and range of task IDs.

It runs on Linux or requires Cygwin with curl for Windows (unfortunately my case). Just run without params to get usage help.

One limatation is that it works only with Agilo with HTTP authentication, not form based authorization, because this is what I use. This is just when you install Agilo on plain Trac. It wouldn't be a big deal to update it though, probably just adding proper post data to login request would make it.

There is also no fancy input check but it wasn't supposed to be bullet proof tool.

I hope it will help someone. I have saved hours with that probably.

Please note that the urls for Agilo 0.7 and 0.8 are different so you will need to uncomment the respective line at the end of the script.

#!/bin/sh
# author: Marcin Okraszewski - okrasz_news -at- o2 -dot- pl

if [ $# -lt 6 ] ; then
  echo "This script creates links between story and tasks (and
hopefully other links as well)."
  echo
  echo "Syntax:"
  echo "   $0 AGILO_URL USER PASS STORY_ID TASK_ID_FROM TASK_ID_TO"
  echo "Where:"
  echo "   AGILO_URL - base URL to your Agilo project"
  echo "   USER - your user name"
  echo "   PASS - your password"
  echo "   STORY_ID - ID of the story that will have tasked linked"
  echo "   TASK_ID_FROM - ID of the first of tasks to link to story
(inclusive)"
  echo "   TASK_ID_TO - ID of the last task to link to the story
(inclusive)"
  echo
  echo "Example:"
  echo "    $0 http://localhost/demo admin adminPass 1 3 5"
  echo "This example will link tasks 3-5 to a story 1  "
  echo "in Agilo project http://localhost/demo"
  echo
  echo "NOTE: to link a single task, use the same number "
  echo "in TASK_ID_FROM and TASK_ID_TO"
  echo
  echo "(c) Marcin Okraszewski - okrasz_news -at- o2 -dot- pl"
  exit
fi

agilo=$1
user=$2
pass=$3
dst=$4
from=$5
to=$6

cookies=cookies.txt

# get form token
echo "Obtaining form token"
curl --digest -u "$user:$pass" -c "$cookies" $agilo > /dev/null
formtoken=$( cat cookies.txt | grep trac_form_token | cut -f 7 | tr -d "\r" )

# login; try to log in either form based or with HTTP authentication
# unfortunately couldn't use post data and HTTP authentication to
# make it in a single run; instead just doing both ways works - either
one will work
echo "Logging into $agilo"
# try logging login for form based login
loginData="__FORM_TOKEN=$formtoken&user=$user&password=$pass"
curl -b "$cookies" -c "$cookies" -d "$loginData" $agilo/login > /dev/null
# try logging with digest HTTP authentication
curl -b "$cookies" -c "$cookies" --digest -u "$user:$pass"  $agilo/login > /dev/null

# create links
for (( i=$from ; i <= $to ; i++ )) ; do
  echo -n -e "\nlink $i to $dst "
  data="__FORM_TOKEN=$formtoken&url_orig=%2Fav%2Fticket%2F438%3Fpane%3Dedit&src=$dst&dest=$i&autocomplete_parameter=&cmd=create+link"
  # for agilo 0.9.14 - 1.3.14PRO
  curl  -e "$agilo/ticket/$dst" -b "$cookies" -d "$data" $agilo/links 2>/dev/null
$agilo/agilo-links 2>/dev/null
done

rm "$cookies"
Last modified 3 years ago Last modified on 10/23/2015 06:08:58 PM

1.3.15 © 2008-2016 Agilo Software all rights reserved (this page was served in: 0.16991 sec.)