Saturday, May 25, 2013

Extract Issue Tracker data from Github, with minimal fuss

How to easily extract your Github Issue Trackers

Did you know about Github's Issue Tracker feature?  You can easily add trackers for your project's to-do list.  You can associate them with MileStones (with or without dates) and can add multiple labels.  Pretty sweet, huh?
Github also gives you a nice UI to look over your items.

But sometimes the Github UI isn't ideal.  Business sometimes runs on other reporting mechanisms-- like spreadsheets.  So how can you get your Issue trackers out of Github and into a different reporting mechanism?

There are plenty of packaged solutions available.  Some are geared towards 3rd party products like other tracking systems.  Some are more generic.  I recently had a look over these and decided for simplicity I'd rather just write a shell script.

The script is below.  Roughly, here's what it does:

1)  Writes some HTML boilerplate to a file called 'hdr.txt'
2)  Uses Git's REST API to bring down my trackers.  You'll want to use your repo's credentials, of course.
3)  Strips away the HTTP header from the Issue tracker information.  The meat of the Issues are kept in a file called 'body.txt'
4)  Writes a file called 'footer.txt' that has some JavaScript that will extract the parts of the Issues I want. You can adjust this.
5)  Combines the header, body and footer into a file you can open with a browser.  Deletes temp files.


That's it!  If you run the script, you should end up with a file you can open with a browser-- it should offer you the Issue tracker fields you asked for.

Happy Issue Tracking!     




 #!/bin/bash  
 echo "<!-- There are 2 pieces of boilerplate that must be added. Both are surrounded by flowerbox comments. -->" > hdr.txt  
 echo "<!-- ***** Start Boilerplate 1 *********** --> " >> hdr.txt  
 echo " <script type='text/javascript'> " >> hdr.txt  
 echo " var results={"d": " >> hdr.txt  
 echo "<!-- **** End Boilerplate 1 ************** --> " >> hdr.txt  
 # Change the credentials here to point to your Git Repo. Note the  
 argument that specifies we want 'issues'  
 curl -i  
 "https://api.github.com/repos/RickJWagner/SOA_Samples/issues?page=1&per_page=10000"  
 > body.tmp0  
 # strip away the HTTP goop at the top of the file  
 sed '1,20d' body.tmp > body.tmp1  
 echo "<!-- ***** Start Boilerplate 2 *** -->" > footer.txt  
 echo "}" >> footer.txt  
 echo "  document.write('Your Records:');" >> footer.txt  
 echo "  document.write('<P>');" >> footer.txt  
 # All this quote nonsense is to make a CSV file, easily imported into a spreadsheet  
 # Note the syntax for selecting parts of the JSON we want  
 SQ="'"  
 DQ='"'  
 QS=$SQ$DQ$SQ  
 echo "for (var i = 0; i < results.d.length; i++) {" >> footer.txt  
 echo "  document.write($QS + results.d[i].title + $QS + ', ' + $QS + results.d[i].state + $QS);" >> footer.txt  
 echo "  document.write('<P>');" >> footer.txt  
 echo "}" >> footer.txt  
 echo "</script>" >> footer.txt  
 echo "<!-- ********* End Boilerplate 2 ******************* --> " >> footer.txt  
 cat hdr.txt body.tmp1 footer.txt > OpenWithBrowser.html  
 rm hdr.txt body.tmp0 body.tmp1 footer.txt  


No comments: