-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Détection automatique des liens morts dans le JSON et corrections ass…
…ociées (#52) * Create .tool-versions * Install Elixir * Revert versions * Make sure those links do not regress * Run the tests during CI * Fix broken links (#50)
- Loading branch information
Showing
5 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# See useful links for maintenance here: | ||
# https://github.com/etalab/transport-site/blob/master/.tool-versions | ||
|
||
elixir 1.15.5-otp-24 | ||
erlang 24.3.4.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Mix.install([ | ||
{:jason, "~> 1.4"}, | ||
{:req, "~> 0.4.8"} | ||
]) | ||
|
||
defmodule Deadlinks do | ||
# scan an Elixir structure to find links | ||
def scan(x) when is_list(x) or is_map(x) do | ||
x | ||
|> Enum.map(&scan(&1)) | ||
|> List.flatten() | ||
|> Enum.reject(&is_nil(&1)) | ||
end | ||
|
||
def scan(x) when is_tuple(x), do: scan(x |> Tuple.to_list()) | ||
def scan(value = "http" <> _), do: value | ||
def scan(_), do: nil | ||
end | ||
|
||
broken_json_links = | ||
"**/*.json" | ||
|> Path.wildcard() | ||
|> Enum.map(fn x -> | ||
x | ||
|> File.read!() | ||
|> Jason.decode!() | ||
end) | ||
|> Deadlinks.scan() | ||
|> Enum.uniq() | ||
|> Enum.map(fn x -> | ||
Req.head!(x) | ||
|> Map.take([:status]) | ||
|> Map.put(:url, x) | ||
end) | ||
|> Enum.reject(fn %{status: x} -> x == 200 end) | ||
|
||
unless broken_json_links == [] do | ||
IO.puts("Some links are broken, please fix them:\n") | ||
IO.puts(broken_json_links |> Enum.map(&inspect(&1)) |> Enum.join("\n")) | ||
System.halt(1) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters