This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #127494] TODO test for $AUTOLOAD being set for DESTROY
[perl5.git] / Porting / cherrymaint
CommitLineData
813fcdee
DG
1#!/usr/bin/env perl
2use 5.010;
3use strict;
4use warnings;
5use File::Basename;
6use Getopt::Long;
f61ba6bb 7require LWP::UserAgent;
813fcdee
DG
8
9my %votemap = (
10 'unexamined' => 0,
b63bc9b3
FR
11 'rejected' => 1,
12 'vote' => 4,
13 'picked' => 5,
813fcdee
DG
14);
15
b63bc9b3
FR
16
17chomp(my $git_addr = `git config --get cherrymaint.address`);
18my $addr = length $git_addr ? $git_addr : 'localhost:3000';
19
813fcdee
DG
20# Usage
21my $program = basename $0;
22my $usage = << "HERE";
b63bc9b3 23Usage: $program [--address address] [ACTION] [COMMIT]
813fcdee
DG
24
25 ACTIONS: (default is 'vote' if omitted)
26
27HERE
28$usage .= join( "\n", map { " --$_" } (sort keys %votemap), 'help' );
29$usage .= "\n" . << "HERE";
30
31 COMMIT: a git revision ID (SHA1 or symbolic reference like HEAD)
32
cbba5ad3
KW
33 You must first tunnel $addr to perl5.git.perl.org:3000? E.g.
34 \$ ssh -C -L${\ join q{:} => reverse split /:/, $addr}:3000 perl5.git.perl.org
35
813fcdee
DG
36HERE
37
38die $usage if grep { /^(--help|-h)$/ } @ARGV;
39
40# Determine action
b63bc9b3
FR
41my %opt = (address => \$addr);
42GetOptions( \%opt, 'address=s', keys %votemap ) or die $usage;
813fcdee 43
e2880212 44if ( keys(%opt) > 2 ) {
b63bc9b3 45 die "Error: cherrymaint takes only one action argument\n\n$usage"
813fcdee
DG
46}
47
b63bc9b3 48my ($action) = grep { exists $votemap{$_} } keys %opt;
813fcdee
DG
49$action ||= 'vote';
50
51# Determine commit SHA1
52my $commit = shift @ARGV;
53
54unless ( defined $commit ) {
55 die "Error: cherrymaint requires an explicit commit ID\n\n$usage"
56}
57
58my $short_id = qx/git rev-parse --short $commit/;
59if ( $? ) {
60 die "Error: couldn't get git commit SHA1 from '$commit'\n";
61}
62chomp $short_id;
63
64# Confirm actions
65unless ( $action eq 'vote' ) {
66 say "Are you sure you want to mark $short_id as $action? (y/n)";
67 my $ans = <STDIN>;
68 exit 0 unless $ans =~ /^y/i;
69}
70
71# Send the action to cherrymaint
72my $n = $votemap{$action};
b63bc9b3 73my $url = "http://$addr/mark?commit=${short_id}&value=${n}";
813fcdee
DG
74
75my $ua = LWP::UserAgent->new(
76 agent => 'Porting/cherrymaint ',
77 timeout => 30,
78 env_proxy => 1,
79);
80
81my $response = $ua->get($url);
82
83if ($response->is_success) {
84 say "Done.";
85}
86else {
b63bc9b3
FR
87 die $response->status_line . << "HERE";
88
89Have you remembered to tunnel $addr to perl5.git.perl.org:3000? E.g.
90 \$ ssh -C -L${\ join q{:} => reverse split /:/, $addr}:3000 perl5.git.perl.org
91
92Or maybe you created a different tunnel? You can specify the address to use
93either on the command line with --address, or by doing
94 \$ git config cherrymaint.address host:port
813fcdee 95
813fcdee 96HERE
5c2555b7 97
730ad6b9 98# Note that you can vote through your browser by pointing it at the local
5c2555b7
KW
99# end of the tunnel. For example, L<http://localhost:3000/> if you went with
100# the suggested default values
813fcdee
DG
101}
102
103exit 0;