Commit cd6b0c6044c78d1ff914e1a0ed3f4aa6ab19135d
1 parent
04737788
Exists in
master
and in
2 other branches
add git versions
Showing
3 changed files
with
38 additions
and
15 deletions
Show diff stats
spb_copr_status.psgi
| 1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
| 2 | use strict; | 2 | use strict; |
| 3 | use warnings; | 3 | use warnings; |
| 4 | -use LWP::Simple; | ||
| 5 | use JSON; | 4 | use JSON; |
| 6 | use Text::Template; | 5 | use Text::Template; |
| 6 | +use LWP::UserAgent; | ||
| 7 | use Plack::Builder; | 7 | use Plack::Builder; |
| 8 | 8 | ||
| 9 | +$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0; | ||
| 10 | + | ||
| 9 | sub copr_info { | 11 | sub copr_info { |
| 10 | - my $result_v4 = get("http://copr.fedoraproject.org/api/coprs/softwarepublico/v4/monitor/"); | ||
| 11 | - my $result_v5 = get("http://copr.fedoraproject.org/api/coprs/softwarepublico/v5/monitor/"); | 12 | + my $ua = LWP::UserAgent->new; |
| 13 | + $ua->timeout(10); | ||
| 14 | + $ua->env_proxy; | ||
| 15 | + $ua->ssl_opts(SSL_verify_mode => 0x00); | ||
| 16 | + | ||
| 17 | + my $result_v4 = $ua->get("http://copr.fedoraproject.org/api/coprs/softwarepublico/v4/monitor/"); | ||
| 18 | + my $result_v5 = $ua->get("http://copr.fedoraproject.org/api/coprs/softwarepublico/v5/monitor/"); | ||
| 12 | 19 | ||
| 13 | my $json = JSON->new->allow_nonref; | 20 | my $json = JSON->new->allow_nonref; |
| 14 | 21 | ||
| 15 | - my $dec_result_v4 = $json->decode($result_v4); | ||
| 16 | - my $dec_result_v5 = $json->decode($result_v5); | ||
| 17 | - my %info; | ||
| 18 | - my $inforef = \%info; | 22 | + my $dec_result_v4 = $json->decode($result_v4->decoded_content); |
| 23 | + my $dec_result_v5 = $json->decode($result_v5->decoded_content); | ||
| 24 | + my $info = {}; | ||
| 19 | 25 | ||
| 20 | foreach(@{$dec_result_v4->{'packages'}}) { | 26 | foreach(@{$dec_result_v4->{'packages'}}) { |
| 21 | my $package = $_->{'pkg_name'}; | 27 | my $package = $_->{'pkg_name'}; |
| 22 | my $status = $_->{'results'}{'epel-7-x86_64'}{'status'}; | 28 | my $status = $_->{'results'}{'epel-7-x86_64'}{'status'}; |
| 23 | my $version = $_->{'results'}{'epel-7-x86_64'}{'pkg_version'}; | 29 | my $version = $_->{'results'}{'epel-7-x86_64'}{'pkg_version'}; |
| 24 | - $inforef->{$package}->{'v4_version'} = $version if $status eq "succeeded"; | 30 | + $info->{$package}->{'v4_version'} = $version if $status eq "succeeded"; |
| 25 | } | 31 | } |
| 26 | 32 | ||
| 27 | foreach(@{$dec_result_v5->{'packages'}}) { | 33 | foreach(@{$dec_result_v5->{'packages'}}) { |
| 28 | my $package = $_->{'pkg_name'}; | 34 | my $package = $_->{'pkg_name'}; |
| 29 | my $status = $_->{'results'}{'epel-7-x86_64'}{'status'}; | 35 | my $status = $_->{'results'}{'epel-7-x86_64'}{'status'}; |
| 30 | my $version = $_->{'results'}{'epel-7-x86_64'}{'pkg_version'}; | 36 | my $version = $_->{'results'}{'epel-7-x86_64'}{'pkg_version'}; |
| 31 | - $inforef->{$package}->{'v5_version'} = $version if $status eq "succeeded"; | 37 | + $info->{$package}->{'v5_version'} = $version if $status eq "succeeded"; |
| 38 | + } | ||
| 39 | + | ||
| 40 | + foreach my $key (%{$info}) { | ||
| 41 | + next if(ref($key) eq 'HASH'); | ||
| 42 | + | ||
| 43 | + my $spec = $ua->get("https://softwarepublico.gov.br/gitlab/softwarepublico/softwarepublico/raw/master/src/pkg-rpm/$key/$key.spec"); | ||
| 44 | + my $version = $1 if $spec->decoded_content =~ /^Version:\s*([^\s]+)\s*$/m; | ||
| 45 | + if($version =~ /%\{version\}/) { | ||
| 46 | + $version = $1 if $spec->decoded_content =~ /define version\s*([^\s]+)\s*$/m; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + my $release = $1 if $spec->decoded_content =~ /^Release:\s*([^\s]+)\s*$/m; | ||
| 50 | + $version = "$version-$release"; | ||
| 51 | + $info->{$key}->{'git_version'} = $version; | ||
| 32 | } | 52 | } |
| 33 | 53 | ||
| 34 | - return $inforef; | 54 | + return $info; |
| 35 | } | 55 | } |
| 36 | 56 | ||
| 37 | sub info2html { | 57 | sub info2html { |
| 38 | - my $inforef = copr_info(); | 58 | + my $info = copr_info(); |
| 39 | my $table_entries=""; | 59 | my $table_entries=""; |
| 40 | - foreach my $key (%{$inforef}) { | 60 | + foreach my $key (%{$info}) { |
| 41 | next if(ref($key) eq 'HASH'); | 61 | next if(ref($key) eq 'HASH'); |
| 42 | my $fill_row; | 62 | my $fill_row; |
| 43 | - if($inforef->{$key}->{'v4_version'} eq $inforef->{$key}->{'v5_version'}) { | 63 | + if($info->{$key}->{'v4_version'} eq $info->{$key}->{'v5_version'} && $info->{$key}->{'v4_version'} eq $info->{$key}->{git_version}) { |
| 44 | $fill_row = "success"; | 64 | $fill_row = "success"; |
| 45 | } | 65 | } |
| 46 | else { | 66 | else { |
| @@ -49,8 +69,9 @@ sub info2html { | @@ -49,8 +69,9 @@ sub info2html { | ||
| 49 | 69 | ||
| 50 | $table_entries .= "<tr class=\"$fill_row\"> | 70 | $table_entries .= "<tr class=\"$fill_row\"> |
| 51 | <td>$key</td> | 71 | <td>$key</td> |
| 52 | - <td>$inforef->{$key}->{'v4_version'}</td> | ||
| 53 | - <td>$inforef->{$key}->{'v5_version'}</td> | 72 | + <td>$info->{$key}->{'v4_version'}</td> |
| 73 | + <td>$info->{$key}->{'v5_version'}</td> | ||
| 74 | + <td>$info->{$key}->{'git_version'}</td> | ||
| 54 | </tr>"; | 75 | </tr>"; |
| 55 | } | 76 | } |
| 56 | 77 |
template.html.tt