Commit 70015f6571253ea32df789b079919e1929fe1056
- Diff rendering mode:
- inline
- side by side
actionitems-check
(30 / 23)
|   | |||
| 5 | 5 | use feature 'say'; | |
| 6 | 6 | use WWW::Mechanize; | |
| 7 | 7 | use File::Basename; | |
| 8 | use Term::ANSIColor; | ||
| 8 | 9 | use Getopt::Std; | |
| 9 | 10 | ||
| 10 | 11 | use constant SCRIPTURL => 'http://www.colivre.coop.br'; | |
| … | … | ||
| 34 | 34 | my $version = sprintf "%02dx%02dx%02d", split(/\./, $_[1]); | |
| 35 | 35 | my $mech = WWW::Mechanize->new(agent => 'colivre-robot', autocheck => 1 ) or die $!; | |
| 36 | 36 | my $topic = "$name.${name}Version$version"; | |
| 37 | print STDERR "accessing $topic... "; | ||
| 38 | 37 | $mech->get(SCRIPTURL . "/$topic"); | |
| 39 | say STDERR "ok"; | ||
| 40 | 38 | return $mech->response->decoded_content; | |
| 41 | 39 | } | |
| 42 | 40 | ||
| 43 | sub 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 | |||
| 59 | 41 | sub find_missing_action_items { | |
| 60 | 42 | my $html_topic = shift; | |
| 43 | my $pre_block_for_each_commit = shift; | ||
| 44 | my $pos_block_for_each_commit = shift; | ||
| 61 | 45 | my @missing_action_item = (); | |
| 62 | 46 | while($html_topic =~ m{<a href="/[\d\w]+/(ActionItem\d+)" class="twikiLink">\#\d+</a>}sigo) { | |
| 63 | 47 | 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) { | ||
| 66 | 55 | push @missing_action_item, $action_item; | |
| 67 | 56 | } | |
| 68 | 57 | } | |
| 69 | 58 | return @missing_action_item; | |
| 70 | 59 | } | |
| 71 | 60 | ||
| 61 | sub 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 | |||
| 72 | 68 | #---- main | |
| 73 | 69 | ||
| 74 | 70 | our $opt_q; | |
| … | … | ||
| 75 | 75 | my $version = $#ARGV < 0 ? get_project_version($project_name) : $ARGV[0]; | |
| 76 | 76 | die "please, inform version!" unless $version; | |
| 77 | 77 | ||
| 78 | print STDERR "accessing topic for $project_name v$version... "; | ||
| 78 | 79 | my $html_topic = get_version_topic(ucfirst $project_name, $version); | |
| 79 | my @missing_action_item = find_missing_action_items($html_topic); | ||
| 80 | say STDERR "ok"; | ||
| 80 | 81 | ||
| 81 | print ucfirst $project_name, " v$version: "; | ||
| 82 | say @missing_action_item ? "ActionItems missing! (@missing_action_item)" : "ok!"; | ||
| 82 | my $current_git_branch = get_current_branch; | ||
| 83 | say STDERR "checking '$current_git_branch' branch... "; | ||
| 84 | |||
| 85 | my @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 | |||
| 91 | print ucfirst $project_name, " v$version "; | ||
| 92 | say @missing_action_item ? ('has ', colored('missing', 'red'), ' ActionItems!') : ('was ', colored('ok!', 'green')); |

