1- # Copyright (C) 2021 SUSE Linux GmbH
2- #
3- # This program is free software; you can redistribute it and/or modify
4- # it under the terms of the GNU General Public License as published by
5- # the Free Software Foundation; either version 2 of the License, or
6- # (at your option) any later version.
7- #
8- # This program is distributed in the hope that it will be useful,
9- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11- # GNU General Public License for more details.
12- #
13- # You should have received a copy of the GNU General Public License along
14- # with this program; if not, see <http://www.gnu.org/licenses/>.
15-
1+ # Copyright SUSE LLC
2+ # SPDX-License-Identifier: GPL-2.0-or-later
163package Cavil::Controller::Report ;
174use Mojo::Base ' Mojolicious::Controller' , -signatures;
185
196use Mojo::Asset::File;
20- use Mojo::JSON ' from_json' ;
217use Cavil::Util ' lines_context' ;
228
239sub report ($self ) {
@@ -30,14 +16,13 @@ sub report ($self) {
3016
3117 return $self -> render(text => ' not indexed' , status => 408) unless $pkg -> {indexed };
3218
33- return $self -> render(text => ' no report' , status => 408) unless my $report = $self -> reports-> cached_dig_report($id );
34-
35- $report = from_json($report );
36- $self -> _sanitize_report($report );
19+ return $self -> render(text => ' no report' , status => 408)
20+ unless my $report = $self -> reports-> sanitized_dig_report($id );
3721
3822 $self -> respond_to(
3923 json => sub { $self -> render(json => {report => $report , package => $pkg }) },
4024 txt => sub { $self -> render(' reviewer/report' , report => $report , package => $pkg ) },
25+ mcp => sub { $self -> render(text => $self -> helpers-> mcp_report($id )) },
4126 html => sub {
4227 my $min = $self -> app-> config(' min_files_short_report' );
4328 $self -> render(' reviewer/report' , report => $report , package => $pkg , max_number_of_files => $min );
@@ -92,81 +77,4 @@ sub spdx ($self) {
9277 $self -> render(template => ' report/waiting' , status => 408);
9378}
9479
95- sub _sanitize_report ($self , $report ) {
96-
97- # Flags
98- $report -> {flags } = $report -> {flags } || [];
99-
100- # Files
101- my $files = $report -> {files };
102- my $expanded = $report -> {expanded };
103- my $lines = $report -> {lines };
104- my $snippets = $report -> {missed_snippets };
105-
106- my @missed ;
107- for my $file (keys %$snippets ) {
108- $expanded -> {$file } = 1;
109- my ($max_risk , $match , $license , $spdx ) = @{$report -> {missed_files }{$file }};
110- $license = ' Keyword' unless $license ;
111- push (
112- @missed ,
113- {
114- id => $file ,
115- name => $files -> {$file },
116- max_risk => $max_risk ,
117- license => $license ,
118- spdx => $spdx ,
119- match => int ($match * 1000 + 0.5) / 10.
120- }
121- );
122- }
123- delete $report -> {missed_files };
124- delete $report -> {missed_snippets };
125- $report -> {missed_files } = [sort { $b -> {max_risk } cmp $a -> {max_risk } || $a -> {name } cmp $b -> {name } } @missed ];
126-
127- $report -> {files } = [];
128- for my $file (sort { $files -> {$a } cmp $files -> {$b } } keys %$files ) {
129- my $path = $files -> {$file };
130- push @{$report -> {files }}, my $current = {id => $file , path => $path , expand => $expanded -> {$file }};
131-
132- if ($lines -> {$file }) {
133- $current -> {lines } = lines_context($lines -> {$file });
134- }
135- }
136-
137- # Risks
138- my $chart = $report -> {chart } = {};
139- my $risks = $report -> {risks };
140- $report -> {risks } = {};
141- my $licenses = $report -> {licenses };
142- for my $risk (reverse sort keys %$risks ) {
143- my $current = $report -> {risks }{$risk } = {};
144- $risk = $risks -> {$risk };
145-
146- for my $lic (sort keys %$risk ) {
147- my $current = $current -> {$lic } = {};
148- my $license = $licenses -> {$lic };
149- my $name = $current -> {name } = $license -> {name };
150- $current -> {spdx } = $license -> {spdx };
151-
152- my $matches = $risk -> {$lic };
153- my %files = map { $_ => 1 } map {@$_ } values %$matches ;
154- $chart -> {$name } = keys %files ;
155-
156- $current -> {flags } = $license -> {flags };
157-
158- my $list = $current -> {files } = [];
159- for my $file (sort keys %files ) {
160- push @$list , [$file , $files -> {$file }];
161- }
162- }
163- }
164-
165- # Emails and URLs
166- my $emails = $report -> {emails };
167- $report -> {emails } = [map { [$_ , $emails -> {$_ }] } sort { $emails -> {$b } <=> $emails -> {$a } } keys %$emails ];
168- my $urls = $report -> {urls };
169- $report -> {urls } = [map { [$_ , $urls -> {$_ }] } sort { $urls -> {$b } <=> $urls -> {$a } } keys %$urls ];
170- }
171-
172801;
0 commit comments