Commit 70015f6571253ea32df789b079919e1929fe1056

  • Tree SHA1: 165235a
  • Parent SHA1: 67eb448 (script to check if specific Noosfero ActionItems version has in commit messages in git repository)
  • raw diff | raw patch
print colored messages and remove print and say calls from methods
  
55use feature 'say';
66use WWW::Mechanize;
77use File::Basename;
8use Term::ANSIColor;
89use Getopt::Std;
910
1011use constant SCRIPTURL => 'http://www.colivre.coop.br';
3434 my $version = sprintf "%02dx%02dx%02d", split(/\./, $_[1]);
3535 my $mech = WWW::Mechanize->new(agent => 'colivre-robot', autocheck => 1 ) or die $!;
3636 my $topic = "$name.${name}Version$version";
37 print STDERR "accessing $topic... ";
3837 $mech->get(SCRIPTURL . "/$topic");
39 say STDERR "ok";
4038 return $mech->response->decoded_content;
4139}
4240
43sub git_commit_message {
44 my $action_item = shift;
45 print STDERR "looking for $action_item in git log... ";
46 open my $GIT_LOG, '-|', 'git', 'log', "--grep=$action_item", '--oneline';
47 my $git_log_result = <$GIT_LOG>;
48 close $GIT_LOG;
49 if($git_log_result) {
50 say STDERR "ok";
51 return chomp($git_log_result);
52 }
53 else {
54 say STDERR "nok";
55 return undef;
56 }
57}
58
5941sub find_missing_action_items {
6042 my $html_topic = shift;
43 my $pre_block_for_each_commit = shift;
44 my $pos_block_for_each_commit = shift;
6145 my @missing_action_item = ();
6246 while($html_topic =~ m{<a href="/[\d\w]+/(ActionItem\d+)" class="twikiLink">\#\d+</a>}sigo) {
6347 my $action_item = $1;
64 my $commit_message = git_commit_message($action_item);
65 unless($commit_message) {
48 &$pre_block_for_each_commit($action_item);
49 open my $GIT_LOG, '-|', 'git', 'log', "--grep=$action_item", '--oneline';
50 my $git_log_result = <$GIT_LOG>;
51 close $GIT_LOG;
52 $git_log_result = $git_log_result ? chomp $git_log_result : undef;
53 &$pos_block_for_each_commit($git_log_result);
54 unless($git_log_result) {
6655 push @missing_action_item, $action_item;
6756 }
6857 }
6958 return @missing_action_item;
7059}
7160
61sub get_current_branch {
62 open my $GIT_STATUS, '-|', 'git', 'status';
63 my $git_status = <$GIT_STATUS>;
64 close $GIT_STATUS;
65 return $git_status =~ m/# On branch (.+)\n/s ? $1 : undef;
66}
67
7268#---- main
7369
7470our $opt_q;
7575my $version = $#ARGV < 0 ? get_project_version($project_name) : $ARGV[0];
7676die "please, inform version!" unless $version;
7777
78print STDERR "accessing topic for $project_name v$version... ";
7879my $html_topic = get_version_topic(ucfirst $project_name, $version);
79my @missing_action_item = find_missing_action_items($html_topic);
80say STDERR "ok";
8081
81print ucfirst $project_name, " v$version: ";
82say @missing_action_item ? "ActionItems missing! (@missing_action_item)" : "ok!";
82my $current_git_branch = get_current_branch;
83say STDERR "checking '$current_git_branch' branch... ";
84
85my @missing_action_item = find_missing_action_items(
86 $html_topic,
87 sub { print STDERR $_[0], "\t" },
88 sub { say STDERR $_[0] ? colored('ok', 'green') : colored('nok', 'red') }
89);
90
91print ucfirst $project_name, " v$version ";
92say @missing_action_item ? ('has ', colored('missing', 'red'), ' ActionItems!') : ('was ', colored('ok!', 'green'));