Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignore file option #27

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions lib/mix_audit/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule MixAudit.CLI do
switches: [
ignore_advisory_ids: :string,
ignore_package_names: :string,
ignore_file: :string,
version: :boolean,
help: :boolean,
format: :string,
Expand Down
17 changes: 17 additions & 0 deletions lib/mix_audit/cli/audit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ defmodule MixAudit.CLI.Audit do
format = Keyword.get(opts, :format)
ignored_advisory_ids = ignored_advisory_ids(opts)
ignored_package_names = ignored_package_names(opts)
ignored_ids_from_file = ignored_ids_from_file(opts)

# Synchronize and get security advisories
advisories =
MixAudit.Repo.advisories()
|> Enum.reject(&(&1.id in ignored_advisory_ids))
|> Enum.reject(&(&1.id in ignored_ids_from_file))
|> Enum.group_by(& &1.package)

# Get project dependencies
Expand Down Expand Up @@ -45,4 +47,19 @@ defmodule MixAudit.CLI.Audit do
|> String.split(",")
|> Enum.map(&String.trim/1)
end

defp ignored_ids_from_file(opts) do
opts
|> Keyword.get(:ignore_file, ".mix-audit-skips")
|> File.read()
|> case do
{:ok, content} ->
content
|> String.split("\n")
|> Enum.reject(fn line -> String.starts_with?(line, "#") or line == "" end)

_ ->
[]
end
baldarn marked this conversation as resolved.
Show resolved Hide resolved
end
end
1 change: 1 addition & 0 deletions lib/mix_audit/cli/help.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule MixAudit.CLI.Help do
IO.puts("--format The format of the report to generate (human, json)")
IO.puts("--ignore-advisory-ids A comma-separated list of advisory IDs to ignore")
IO.puts("--ignore-package-names A comma-separated list of package names to ignore")
IO.puts("--ignore-file Path of the ignore file (default .mix-audit-skips)")
IO.puts("")
System.halt(0)
end
Expand Down