Commit 67eb448ed5992ddc6e5438ebc4e7971c92570558

script to check if specific Noosfero ActionItems version has in commit messages in git repository
  
1#!/usr/bin/perl
2use utf8;
3use strict;
4use warnings;
5use feature 'say';
6use WWW::Mechanize;
7use File::Basename;
8use Getopt::Std;
9
10use constant SCRIPTURL => 'http://www.colivre.coop.br';
11
12# Getopt::Std method for --version and --help
13sub VERSION_MESSAGE {
14 our $VERSION = '0.1';
15 say basename($0) . " [-q] [VERSION]\n";
16 say "check if all actionitems have at least one commit message on git repository";
17 say "if version not specified then will try read version from lib/<project_name>.rb file";
18 say "version: $VERSION";
19 exit 0;
20}
21
22sub get_project_version {
23 my $project_name = shift;
24 open my $VERSION_FILE, '<', "lib/$project_name.rb" or return undef;
25 local $/ = undef;
26 my $version_file_content = <$VERSION_FILE>;
27 my ($version) = $version_file_content =~ m/VERSION = '(\d+\.\d+\.\d+)'/;
28 return $version;
29}
30
31sub get_version_topic {
32 my $name = $_[0];
33 my $version = sprintf "%02dx%02dx%02d", split(/\./, $_[1]);
34 my $mech = WWW::Mechanize->new(agent => 'colivre-robot', autocheck => 1 ) or die $!;
35 my $topic = "$name.${name}Version$version";
36 print STDERR "accessing $topic... ";
37 $mech->get(SCRIPTURL . "/$topic");
38 say STDERR "ok";
39 return $mech->response->decoded_content;
40}
41
42sub git_commit_message {
43 my $action_item = shift;
44 print STDERR "looking for $action_item in git log... ";
45 open my $GIT_LOG, '-|', 'git', 'log', "--grep=$action_item", '--oneline';
46 my $git_log_result = <$GIT_LOG>;
47 close $GIT_LOG;
48 if($git_log_result) {
49 say STDERR "ok";
50 return chomp($git_log_result);
51 }
52 else {
53 say STDERR "nok";
54 return undef;
55 }
56}
57
58sub find_missing_action_items {
59 my $html_topic = shift;
60 my @missing_action_item = ();
61 while($html_topic =~ m{<a href="/[\d\w]+/(ActionItem\d+)" class="twikiLink">\#\d+</a>}sigo) {
62 my $action_item = $1;
63 my $commit_message = git_commit_message($action_item);
64 unless($commit_message) {
65 push @missing_action_item, $action_item;
66 }
67 }
68 return @missing_action_item;
69}
70
71#---- main
72
73our $opt_q;
74getopts('q');
75close STDERR if $opt_q;
76
77my $project_name = basename($ENV{PWD});
78my $version = $#ARGV < 0 ? get_project_version($project_name) : $ARGV[0];
79die "please, inform version!" unless $version;
80
81my $html_topic = get_version_topic(ucfirst $project_name, $version);
82my @missing_action_item = find_missing_action_items($html_topic);
83
84print ucfirst $project_name, " v$version: ";
85say @missing_action_item ? "ActionItems missing! (@missing_action_item)" : "ok!";