Commit 6e0a966e28a0b24f6b2d45798c4c607be4883c3a

Authored by Athos
1 parent 2fbbd6dd

Add status to api

Signed-off-by: Athos Ribeiro <athoscribeiro@gmail.com>
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Showing 1 changed file with 29 additions and 1 deletions   Show diff stats
spb_copr_status.psgi
... ... @@ -55,6 +55,22 @@ sub copr_info {
55 55 return $info;
56 56 }
57 57  
  58 +sub compare_versions {
  59 + my $info = copr_info();
  60 + my $match = {};
  61 + foreach my $key (%{$info}) {
  62 + next if(ref($key) eq 'HASH');
  63 + if($info->{$key}->{'v5_version'} eq $info->{$key}->{git_version}) {
  64 + $match->{$key} = 1;
  65 + }
  66 + else {
  67 + $match->{$key} = 0;
  68 + }
  69 + }
  70 +
  71 + return $match;
  72 +}
  73 +
58 74 sub info2html {
59 75 my $info = copr_info();
60 76 my $table_entries="";
... ... @@ -103,7 +119,8 @@ sub build_html {
103 119  
104 120 my %ROUTING = (
105 121 '/' => \&serve_html,
106   - '/api' => \&serve_json
  122 + '/api' => \&serve_json,
  123 + '/api/status' => \&serve_json_status
107 124 );
108 125  
109 126 my $app = sub {
... ... @@ -140,6 +157,17 @@ sub serve_json {
140 157 ];
141 158 };
142 159  
  160 +sub serve_json_status {
  161 + my $info = compare_versions();
  162 + my $json = JSON->new->allow_nonref;
  163 + my $json_info = $json->encode($info);
  164 + return [
  165 + '200',
  166 + [ 'Content-Type' => 'application/json'],
  167 + [ $json_info ],
  168 + ];
  169 +};
  170 +
143 171 builder {
144 172 enable "Static", path => qr!^(/css|/js)!, pass_through => 1;
145 173 $app;
... ...