~cosmicrose/hex_licenses

36b177e0ac9fd77ec9833ca2972911ae61477e00 — Rosa Richter a month ago bec75c7
Add --update flag to tasks
M lib/hex_licenses/spdx.ex => lib/hex_licenses/spdx.ex +1 -0
@@ 1,5 1,6 @@
defmodule HexLicenses.SPDX do
  def fetch_licenses do
    {:ok, _} = HTTPoison.start()
    HTTPoison.get!("https://spdx.org/licenses/licenses.json")
    |> Map.fetch!(:body)
  end

M lib/mix/tasks/licenses.ex => lib/mix/tasks/licenses.ex +8 -1
@@ 13,6 13,7 @@ defmodule Mix.Tasks.Licenses do
  ## Command line options

    * `--osi` - additionally check if all licenses are approved by the [Open Source Initiative](https://opensource.org/licenses)
    * `--update` - pull down a fresh copy of the SPDX license list instead of using the version checked in with this tool.

  """
  @shortdoc "Lists all dependencies along with a summary of their licenses."


@@ 23,7 24,13 @@ defmodule Mix.Tasks.Licenses do
  def run(args) do
    check_osi_approved = "--osi" in args

    license_list = HexLicenses.SPDX.licenses()
    license_list =
      if "--update" in args do
        HexLicenses.SPDX.fetch_licenses()
        |> HexLicenses.SPDX.parse_licenses()
      else
        HexLicenses.SPDX.licenses()
      end

    check =
      HexLicenses.license_check(license_list)

M lib/mix/tasks/licenses/explain.ex => lib/mix/tasks/licenses/explain.ex +10 -1
@@ 13,6 13,7 @@ defmodule Mix.Tasks.Licenses.Explain do
  ## Command line options

    * `--osi` - additionally check if all licenses are approved by the [Open Source Initiative](https://opensource.org/licenses)
    * `--update` - pull down a fresh copy of the SPDX license list instead of using the version checked in with this tool.
  """

  use Mix.Task


@@ 29,8 30,16 @@ defmodule Mix.Tasks.Licenses.Explain do
        [:osi_approved, :not_approved]
      end

    license_list =
      if "--update" in args do
        HexLicenses.SPDX.fetch_licenses()
        |> HexLicenses.SPDX.parse_licenses()
      else
        HexLicenses.SPDX.licenses()
      end

    unsafe_deps =
      HexLicenses.SPDX.licenses()
      license_list
      |> HexLicenses.license_check()
      |> Enum.reject(fn {_deps, licenses} -> licenses == :not_in_hex end)
      |> Enum.filter(fn {_dep, licenses} ->

M lib/mix/tasks/licenses/lint.ex => lib/mix/tasks/licenses/lint.ex +9 -1
@@ 20,6 20,7 @@ defmodule Mix.Tasks.Licenses.Lint do
    * `--reuse` - additionally check if the licenses declared in `mix.exs` match those in the `LICENSES` directory
      according to the [REUSE specification](https://reuse.software).
    * `--osi` - additionally check if all licenses are approved by the [Open Source Initiative](https://opensource.org/licenses)
    * `--update` - pull down a fresh copy of the SPDX license list instead of using the version checked in with this tool.
  """
  use Mix.Task



@@ 27,7 28,14 @@ defmodule Mix.Tasks.Licenses.Lint do

  def run(args) do
    package = Mix.Project.get!().project()[:package]
    license_list = HexLicenses.SPDX.licenses()
    license_list =
      if "--update" in args do
        HexLicenses.SPDX.fetch_licenses()
        |> HexLicenses.SPDX.parse_licenses()
      else
        HexLicenses.SPDX.licenses()
      end

    {:ok, result} = HexLicenses.lint(package, license_list)

    error? = false