Skip to content

Instantly share code, notes, and snippets.

@richardneish
Created January 22, 2014 10:55
Show Gist options
  • Save richardneish/8556865 to your computer and use it in GitHub Desktop.
Save richardneish/8556865 to your computer and use it in GitHub Desktop.
Perl script to get JIRA details from a git commit in Atlassian Stash using the REST API documented at https://developer.atlassian.com/static/rest/stash/2.9.4/stash-jira-integration-rest.html and the Perl JSON::PP module.
#!/usr/bin/perl -w
use strict;
use lib "./lib"; # Required if you have JSON.PP installed locally. This makes the script self-contained.
use JSON::PP;
my $config = require "config.pl"; # Your private configuration - username / password / Stash URL.
use Data::Dumper;
use POSIX qw(strftime);
sub usageExit() {
die "Usage: commits_for_issue <issue key> ...";
}
usageExit unless $ARGV[0];
my $heading = 'Commits for issue(s)' . join(' ', @ARGV);
print "<html><body>\n<title>$heading</title>\n<h1>$heading</h1>\n<ul>\n";
do {
my $issueKey = shift @ARGV;
my $json = decode_json `curl --silent --basic --user $config->{USER}:$config->{PASSWORD} $config->{STASH_BASE_URL}rest/j
ira/1.0/issues/${issueKey}/commits`;
for (my $i=0; $i < $json->{size}; $i++) {
my $changelist = $json->{values}[$i];
print '<li><a href="http://stash.it.hk.hibm.hsbc/projects/PEW/repos/' .
$changelist->{repository}->{slug} .
'/commits/' . $changelist->{toCommit}->{id} . '">' .
strftime("%c", localtime($changelist->{toCommit}->{authorTimestamp}/1000)) . ' ' .
$changelist->{repository}->{slug} . ' ' . $changelist->{toCommit}->{displayId} .
' ' . $changelist->{toCommit}->{message} . "</a></li>\n";
}
} until not @ARGV;
print "</ul></body></html>\n";
{
USER => 'stash_username',
PASSWORD => 'stash_password',
STASH_BASE_URL => 'http://stash.server.address/',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment