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 | 1 | #!/usr/bin/perl |
| 2 | 2 | use strict; |
| 3 | 3 | use warnings; |
| 4 | -use LWP::Simple; | |
| 5 | 4 | use JSON; |
| 6 | 5 | use Text::Template; |
| 6 | +use LWP::UserAgent; | |
| 7 | 7 | use Plack::Builder; |
| 8 | 8 | |
| 9 | +$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0; | |
| 10 | + | |
| 9 | 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 | 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 | 26 | foreach(@{$dec_result_v4->{'packages'}}) { |
| 21 | 27 | my $package = $_->{'pkg_name'}; |
| 22 | 28 | my $status = $_->{'results'}{'epel-7-x86_64'}{'status'}; |
| 23 | 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 | 33 | foreach(@{$dec_result_v5->{'packages'}}) { |
| 28 | 34 | my $package = $_->{'pkg_name'}; |
| 29 | 35 | my $status = $_->{'results'}{'epel-7-x86_64'}{'status'}; |
| 30 | 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 | 57 | sub info2html { |
| 38 | - my $inforef = copr_info(); | |
| 58 | + my $info = copr_info(); | |
| 39 | 59 | my $table_entries=""; |
| 40 | - foreach my $key (%{$inforef}) { | |
| 60 | + foreach my $key (%{$info}) { | |
| 41 | 61 | next if(ref($key) eq 'HASH'); |
| 42 | 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 | 64 | $fill_row = "success"; |
| 45 | 65 | } |
| 46 | 66 | else { |
| ... | ... | @@ -49,8 +69,9 @@ sub info2html { |
| 49 | 69 | |
| 50 | 70 | $table_entries .= "<tr class=\"$fill_row\"> |
| 51 | 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 | 75 | </tr>"; |
| 55 | 76 | } |
| 56 | 77 | ... | ... |