Commit 67eb448ed5992ddc6e5438ebc4e7971c92570558
- Diff rendering mode:
- inline
- side by side
actionitems-check
(85 / 0)
|   | |||
| 1 | #!/usr/bin/perl | ||
| 2 | use utf8; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use feature 'say'; | ||
| 6 | use WWW::Mechanize; | ||
| 7 | use File::Basename; | ||
| 8 | use Getopt::Std; | ||
| 9 | |||
| 10 | use constant SCRIPTURL => 'http://www.colivre.coop.br'; | ||
| 11 | |||
| 12 | # Getopt::Std method for --version and --help | ||
| 13 | sub 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 | |||
| 22 | sub 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 | |||
| 31 | sub 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 | |||
| 42 | sub 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 | |||
| 58 | sub 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 | |||
| 73 | our $opt_q; | ||
| 74 | getopts('q'); | ||
| 75 | close STDERR if $opt_q; | ||
| 76 | |||
| 77 | my $project_name = basename($ENV{PWD}); | ||
| 78 | my $version = $#ARGV < 0 ? get_project_version($project_name) : $ARGV[0]; | ||
| 79 | die "please, inform version!" unless $version; | ||
| 80 | |||
| 81 | my $html_topic = get_version_topic(ucfirst $project_name, $version); | ||
| 82 | my @missing_action_item = find_missing_action_items($html_topic); | ||
| 83 | |||
| 84 | print ucfirst $project_name, " v$version: "; | ||
| 85 | say @missing_action_item ? "ActionItems missing! (@missing_action_item)" : "ok!"; |

