@@ -417,30 +417,44 @@ def create(package)
417417 "url" => advisory [ "references" ]
418418 }
419419
420+ if ENV [ "DEBUG" ]
421+ # Add json versions of files in json directory.
422+ json_dir = File . join ( "json" , package . name )
423+ FileUtils . mkdir_p ( json_dir )
424+
425+ json_path = File . join ( json_dir , "#{ primary_id } .json" )
426+ File . write ( json_path , JSON . pretty_generate ( {
427+ "advisory" => advisory ,
428+ "vulnerabilities" => vulnerabilities
429+ } ) )
430+ end
431+
420432 FileUtils . mkdir_p ( File . dirname ( filename_to_write ) )
421433 File . open ( filename_to_write , "w" ) do |file |
422434 # create an automatically generated advisory yaml file
423435 file . write new_data . to_yaml
424436
425- # The data we just wrote is incomplete,
426- # and therefore should not be committed as is
427- # We can not directly translate from GitHub to rubysec advisory format
428- #
429- # The patched_versions field is not exactly available.
430- # - GitHub has a first_patched_version field,
431- # but rubysec advisory needs a ruby version spec
432- #
433- # The unaffected_versions field is similarly not directly available
434- # This optional field must be inferred from the vulnerableVersionRange
435- #
436- # To help write those fields, we put all the github data below.
437- #
438- # The second block of yaml in a .yaml file is ignored (after the second "---" line)
439- # This effectively makes this data a large comment
440- # Still it should be removed before the data goes into rubysec
441- file . write "# GitHub advisory data below - **Remove this data before committing**\n "
442- file . write "# Use this data to write patched_versions (and potentially unaffected_versions) above\n "
443- file . write advisory . merge ( "vulnerabilities" => vulnerabilities ) . to_yaml
437+ if ENV [ "DEBUG" ]
438+ # The data we just wrote is incomplete,
439+ # and therefore should not be committed as is
440+ # We can not directly translate from GitHub to rubysec advisory format
441+ #
442+ # The patched_versions field is not exactly available.
443+ # - GitHub has a first_patched_version field,
444+ # but rubysec advisory needs a ruby version spec
445+ #
446+ # The unaffected_versions field is similarly not directly available
447+ # This optional field must be inferred from the vulnerableVersionRange
448+ #
449+ # To help write those fields, we put all the github data below.
450+ #
451+ # The second block of yaml in a .yaml file is ignored (after the second "---" line)
452+ # This effectively makes this data a large comment
453+ # Still it should be removed before the data goes into rubysec
454+ file . write "# GitHub advisory data below - **Remove this data before committing**\n "
455+ file . write "# Use this data to write patched_versions (and potentially unaffected_versions) above\n "
456+ file . write advisory . merge ( "vulnerabilities" => vulnerabilities ) . to_yaml
457+ end
444458 end
445459 puts "Wrote: #{ filename_to_write } "
446460 filename_to_write
0 commit comments