Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/github_advisory_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.sync(min_year: 2000, gem_name: nil)
# Filter out advisories with a CVE year that is before the min_year
gh_advisories.select! { |v| v.cve_after_year?(min_year) }

files_written = gh_advisories.filter_map(&:sync).flatten.compact!
files_written = gh_advisories.filter_map(&:sync).flatten.compact

puts "\nSync completed"
if files_written.empty?
Expand Down
39 changes: 39 additions & 0 deletions spec/github_advisory_sync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,42 @@ def generated(field, gem_name, lines)
end
end
end

RSpec.describe GitHub::GitHubAdvisorySync do
describe ".sync" do
def sync_with(results)
advisories = results.map do |files|
instance_double(GitHub::GitHubAdvisory, cve_after_year?: true, sync: files)
end
client = instance_double(GitHub::GraphQLAPIClient, all_rubygem_advisories: advisories)
allow(GitHub::GraphQLAPIClient).to receive(:new).and_return(client)

silence_output { described_class.sync }
end

def silence_output
original = $stdout
$stdout = StringIO.new
yield
ensure
$stdout = original
end

it "returns the files written when every advisory changed a file" do
expect(sync_with([["gems/a/CVE-1.yml"], ["gems/b/CVE-2.yml"]]))
.to eq(["gems/a/CVE-1.yml", "gems/b/CVE-2.yml"])
end

it "ignores advisories that left their files unchanged" do
expect(sync_with([[nil], ["gems/b/CVE-2.yml"]])).to eq(["gems/b/CVE-2.yml"])
end

it "returns an empty list when nothing changed" do
expect(sync_with([[nil], [nil]])).to eq([])
end

it "returns an empty list when GitHub has no advisories" do
expect(sync_with([])).to eq([])
end
end
end