summaryrefslogtreecommitdiff
path: root/Porting/cherrymaint
blob: f4092a9df5b6c4a2ac32b2fe25c561cd687e3a85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use File::Basename;
use Getopt::Long;
require LWP::UserAgent;

my %votemap = (
  'unexamined' => 0,
  'rejected'   => 1,
  'vote'       => 4,
  'picked'     => 5,
);


chomp(my $git_addr = `git config --get cherrymaint.address`);
my $addr = length $git_addr ? $git_addr : 'localhost:3000';

# Usage
my $program = basename $0;
my $usage = << "HERE";
Usage: $program [--address address] [ACTION] [COMMIT]

  ACTIONS: (default is 'vote' if omitted)

HERE
$usage .= join( "\n", map { "    --$_" } (sort keys %votemap), 'help' );
$usage .= "\n" . << "HERE";

  COMMIT: a git revision ID (SHA1 or symbolic reference like HEAD)

  You must first tunnel $addr to perl5.git.perl.org:3000? E.g.
  \$ ssh -C -L${\ join q{:} => reverse split /:/, $addr}:3000 perl5.git.perl.org

HERE

die $usage if grep { /^(--help|-h)$/ } @ARGV;

# Determine action
my %opt = (address => \$addr);
GetOptions( \%opt, 'address=s', keys %votemap ) or die $usage;

if ( keys(%opt) > 2 ) {
  die "Error: cherrymaint takes only one action argument\n\n$usage"
}

my ($action) = grep { exists $votemap{$_} } keys %opt;
$action ||= 'vote';

# Determine commit SHA1
my $commit = shift @ARGV;

unless ( defined $commit ) {
  die "Error: cherrymaint requires an explicit commit ID\n\n$usage"
}

my $short_id = qx/git rev-parse --short $commit/;
if ( $? ) {
  die "Error: couldn't get git commit SHA1 from '$commit'\n";
}
chomp $short_id;

# Confirm actions
unless ( $action eq 'vote' ) {
  say "Are you sure you want to mark $short_id as $action? (y/n)";
  my $ans = <STDIN>;
  exit 0 unless $ans =~ /^y/i;
}

# Send the action to cherrymaint
my $n = $votemap{$action};
my $url = "http://$addr/mark?commit=${short_id}&value=${n}";

my $ua = LWP::UserAgent->new(
  agent => 'Porting/cherrymaint ',
  timeout => 30,
  env_proxy => 1,
);

my $response = $ua->get($url);

if ($response->is_success) {
    say "Done.";
}
else {
    die $response->status_line . << "HERE";

Have you remembered to tunnel $addr to perl5.git.perl.org:3000? E.g.
  \$ ssh -C -L${\ join q{:} => reverse split /:/, $addr}:3000 perl5.git.perl.org

Or maybe you created a different tunnel? You can specify the address to use
either on the command line with --address, or by doing
  \$ git config cherrymaint.address host:port

HERE

# Note that you can vote through your browser by pointing it at the the local
# end of the tunnel.  For example, L<http://localhost:3000/> if you went with
# the suggested default values
}

exit 0;