[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Gitorious and debian/watch file



On 10/15/2013 05:58 PM, Andrew Shadura wrote:
> Same link works for tags: https://gitorious.org/osm-c-tools/osmctools/0.1.tar.gz

That's nice to know, but it only works when you add 'archive/' before
the 0.1.tar.gz.

> So the only real problem is to find the right tag.

Those are listed in the refs JSON.

I've wipped up a Q&D Gitorious watch service, you can see it working for
osm-c-tools at:

http://linuxminded.nl/tmp/gitorious-watch/?project=osm-c-tools&repo=osmctools

The code in question comes down to the gitorious-watch.pl as attached,
that's a CLI tool and just a proof-of-concept. The online code just
formats the output as HTML.

I could make this into a CGI to run on Alioth where previous watch file
redirect services were also hosted IIRC.

Regards,

Bas

-- 
GnuPG: 0xE88D4AF1 (new) / 0x77A975AD (old)
#!/usr/bin/perl -w

use strict;
use File::Basename;
use Getopt::Long qw(:config bundling no_ignore_case);
use HTTP::Request::Common;
use LWP::UserAgent;
use URI::Escape;
use JSON;

my %cfg = (
	    project => '',
	    repo    => '',
	    verbose => 0,
	    help    => 0,
          );

my $result = GetOptions(
			 'p|project=s' => \$cfg{project},
			 'r|repo=s'    => \$cfg{repo},
			 'v|verbose'   => \$cfg{verbose},
			 'h|help'      => \$cfg{help},
		       );

if(!$result || $cfg{help}) {
	print STDERR "\n" if(!$result);

	print "Usage: ". basename($0) ." -p <PROJECT> -r <REPO> [OPTIONS]\n\n";
	print "Options:\n";
	print "-p, --project <NAME>   Project name on Gitorious\n";
	print "-r, --repo <NAME>      Repository name on Gitorious\n";
	print "-v, --verbose          Enable verbose output\n";
	print "-h, --help             Display this usage information\n";
	
	exit 1;
}

my $ua = LWP::UserAgent->new(agent => 'gitorious-redirect');

if($cfg{project} && $cfg{repo}) {
	my $base_url  = 'https://gitorious.org/';
	   $base_url .= URI::Escape::uri_escape($cfg{project}).'/';
	   $base_url .= URI::Escape::uri_escape($cfg{repo});

	my $url = $base_url.'/refs';

	print "Retrieving URL: $url ... " if($cfg{verbose});

        my $req = HTTP::Request->new(GET => $url);
        my $res = $ua->request($req);
        
	if($res->is_success) {
		print "Success\n" if($cfg{verbose});

                my $json = $res->content;
		my $data = JSON::decode_json($json);

		if($data->{tags} && @{$data->{tags}}) {
			print "Tag | URL\n";
			foreach my $tag (@{$data->{tags}}) {
				my ($name, $hash) = @{$tag};

				my $url  = $base_url.'/archive/';
				   $url .= URI::Escape::uri_escape($hash).'.tar.gz';

				print "$name | $url\n";
			}
		}
		else {
			print "Error: No tags found in Gitorious repo!\n";

			exit 1;
		}
        }
        else {
		print "Failed!\n" if($cfg{verbose});
                print "Error: Failed to retrieve URL! ($url)\n";
                print "HTTP Status: ".$res->code." ".$res->message."\n";

		exit 1;
        }
}
else {
	print "No project and/or repo specified, cannot query Gitorious without them.\n";

	exit 1;
}


Reply to: