SVN

After Integrating Visual SVN & Jira with Slack, I decided to replace the existing bat file calling a python script with something a bit more extensible.

I also wanted to change Slack's SVN integration to a custom one that would point to the revision on our Fisheye server, which would show the changes made and link to Jira when we added the  ticket <ProjectName-Ticket#> in the Commit Notes, which Fisheye does out of the box

.Net REST Console App

I decided to build a console app that call the slack incoming webhooks API. It needed to:

  • Accept a channel name, title & API Token
  • Accept a SVN Projectname & revision number to call SVNlook & get author & log details. (When fired by SVN Server)
  • Accept a Jenkins name to hit up the Jenkins JSON API for build details
  • Parse success/fail messages and convert them to the Slack notification color names (good, warning & danger)
  • Create a JSON Object
  • Post the JSON object to the slack API
  • A verbose option for debugging
  • Manually enter message text, and author to integrate with other apps down the line.

.Net Apache Common CLI

As there is quite a large set of parameters, I made use of the .Net port of the Apache Commons CLI libraries by Akutz. This handles all aspects of console arguments, while adhering to best practices and existing expectation when passing argument to a cone application.

An example of the init & usage syntax is below.

options.AddOption("a", "apiToken", true, "API token.");
...
get
{
  if (_apiToken == null && Globals.CMD.HasOption('a'))
  {
     _apiToken = CMD.GetOptionValue('a');
  }
  return _apiToken;
}

This is a huge help in argument management, and also handled the help messages.

There was very little documention on .Net CLI, though using the Apache usage documentation was fine, just remeber to capitalise the method name i nthe .ent vesrion, for example option.AddOption instead  of option.addOption, option.HasOption instead of option.hasOption and so on.

And one last catch, the Apache DefaultParser was called the BasicParser in the .Net port.

BasicParser parser = new BasicParser();
CommandLine commandLine = parser.Parse(options, args);

RestSharp

Restsharp likely needs no instruction has a library for simple Rest messaging.

I found it very easy to use, apart from one hitch that had me stumped for much longer than I would like to admit.

The following code (I thought) added the query string with the API token for slacker to the url.

 var request = new RestRequest(resource, Method.POST);
request.AddParameter("token", "CfkRAp1041vYQVb");

However, doing so, and then trying to add any details to body via request.AddBody resulted in it not being added, nor raising an error attempting to do so.

request.RequestFormat = DataFormat.Json;
request.AddBody(json); //Ignored if AddParameter was previously called

Opening up Wireshark showed that the query string was being added to the body.

After a bit of head scratching I found that AddParameter took a third argument,

request.AddParameter("token", "CfkRAp1041vYQVb", ParameterType.QueryString);

SVN versioning

As I planned to use this exe on various production servers, automated SVN versioning was the next logical step.

I utilised Avi Turner's SVN versioning script on stackoverflow to update the $WCREV$ tag I inserted into the AssemblyFileVersion in AssemblyInfo.cs and rev.subwcrev-template used to track the currently checked out & built version.

 Costura.Fody

Finally, I though I would try my hand at weaving assemblies into the .exe for a single file deployment.

I settled on Costura.Fody as many had said that it Just Works™

After adding both Fody and Costura.Fody via the VS2013 package manager, I assumed the various build xml files automatically would need to be tweaked. Though, when I hit build, I realised that I didn't need to touch them at all, and ended up with a exe file where every assembly set to copy local, in this case RestSharp, was embedded into the exe.

Finding a Suitable Collaborative Chat Tool

After trying Campfire, Bitrix24 and HipChat, I finally settled on Slack as my preference for a collaboration tool for our team.

Campfire was very bare bones, and the various window client options just didn't do it for me.

Hipchat had huge potential, though when i get into it, most of the features I wanted where not in the software, but on their suggestions page. Some with hundreds of votes but no reply.

Bitrix was close, but is a whole intranet in the cloud so was a bit of overkill. I only needed the chat. and it does that ok, though didn't have the IRC like room set up I was after.

Slack

Slack was everything I was after. I was a bit critical when the instructions for the windows client consisted of how to turn the webpage into a chrome application shortcut. I originally wanted something that would give the taskbar a notify glow (not a blink as some clients did) so the dev's new that there was a conversation going on, but not annoying enough ot break them out of the zone if there were not participating.

A quick search confirmed that neither a script, or extension that would glow the task bar, though the use of notifications would likely do the job, if not a bit more distracting than I would like.

The chat, room and search features were everything I wanted, but the real power cam via the integration tools.

In a few clicks a Jira channel was showing new & closed tickets from my on premises install. Though I was sure to vote for confluence integration in their integration feedback survey, as that was not out of the box,. though likely not difficult to craft my own.

SVN Integration

Next was SVN, this was a bit trickier as the instructions for integration was a perl script on github.

The next challenge was that I was not suing SVN on a linux box,. but SVN server in windows. This meant that Visual SVN called a batch file, passed in the repository name and revision as arguments, which needed that to fire the Perlscript.

First of all, I needed Perl. and grabbed a download of Active State Perl

Next, triggering the script via Visual SVN.

Right clicking on the repository in Visual SVN, then Properties then the Hooks tab brought up a window, where i could Edit the Post-commit hook.

Here I entered the DOS command to fire my batch file.

c:
cd\Program Files (x86)\VisualSVN Server\bin\
hook %1 %2

Next I created hook.bat and placed it in the folder above. This woulds take the 2 args and pass it to the PERL script.

"C:\Perl\bin\perl.exe" "C:\Program Files (x86)\VisualSVN Server\bin\svn.pl" %1 %2

With the plumbing ot the Perl script out of the way, I modified the PERL script to run on windows, which involved changing the linux friendly...

my $log = `/usr/bin/svnlook log -r $ARGV[1] $ARGV[0]`;
my $who = `/usr/bin/svnlook author -r $ARGV[1] $ARGV[0]`;

To the more windows command line friendly...

my $log = `svnlook log -r $ARGV[1] $ARGV[0]`;
my $who = `svnlook author -r $ARGV[1] $ARGV[0]`;

 

After testing by firing my bat file manually, and a few SVN commits, I had all my SVN updates posted to their own channel in Slack.

Confluence is next, so that updates and new pages can go into their own channel too.