Skip to content

Commit

Permalink
Adjust dump functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
gudmdharalds committed Oct 30, 2023
1 parent 5c9bc0d commit 4ba6e4a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3080,7 +3080,7 @@ function vipgoci_run_scan(
'repo-owner' => $options['repo-owner'],
'repo-name' => $options['repo-name'],
'commit' => $options['commit'],
'prs_implicated' => array_keys( $prs_implicated ),
'prs_implicated' => $prs_implicated,
)
);
}
Expand Down
64 changes: 55 additions & 9 deletions results.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,14 @@ function vipgoci_results_filter_duplicate(
function vipgoci_results_output_dump(
string $output_file,
array $data
) :void {
): void {
vipgoci_log(
'Preparing to dump results to file',
array(
'output' => $output_file,
)
);

if (
( is_file( $output_file ) ) &&
( ! is_writeable( $output_file ) )
Expand All @@ -1089,15 +1096,54 @@ function vipgoci_results_output_dump(
'output_file' => $output_file,
)
);

return;
}

if ( isset( $data['prs_implicated'] ) ) {
$tmp_prs_implicated = $data['prs_implicated'];

$data['prs_implicated'] = array();

foreach ( $tmp_prs_implicated as $pr_number => $pr_data ) {
if ( isset( $pr_data->title ) ) {
$data['prs_implicated'][ $pr_number ]['title'] = $pr_data->title;
}

if ( isset( $pr_data->base->ref ) ) {
$data['prs_implicated'][ $pr_number ]['base_branch'] = $pr_data->base->ref;
}

if ( isset( $pr_data->head->ref ) ) {
$data['prs_implicated'][ $pr_number ]['head_branch'] = $pr_data->head->ref;
}

if ( isset( $pr_data->user->login ) ) {
$data['prs_implicated'][ $pr_number ]['creator'] = $pr_data->user->login;
}
}

unset( $tmp_prs_implicated );
unset( $pr_number );
unset( $pr_data );
}

$res = file_put_contents(
$output_file,
json_encode(
$data,
JSON_PRETTY_PRINT
),
FILE_APPEND
);

if ( false === $res ) {
vipgoci_log(
'Unable to write results to output file due to error',
);
} else {
file_put_contents(
$output_file,
json_encode(
$data,
JSON_PRETTY_PRINT
),
FILE_APPEND
vipgoci_log(
'Successfully wrote results to file'
);
}
}

0 comments on commit 4ba6e4a

Please sign in to comment.