Created
September 5, 2022 03:36
-
-
Save rugyoga/fb160c34f406052eb0eaf38b73ad7701 to your computer and use it in GitHub Desktop.
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
def to_string(r) do | |
r | |
|> changelist() | |
|> Enum.map_join("\n=====\n", &stringify_change/1) | |
end | |
@spec changelist(term) :: [change_t()] | |
defp changelist(r = %_{__audit_trail__: audit_trail}) do | |
if audit_trail, do: [{r, audit_trail} | changelist(record(audit_trail))], else: [] | |
end | |
defp changelist(_), do: [] | |
@spec stringify_change(change_t()) :: binary() | |
defp stringify_change({post, {pre, filename, line}}) do | |
diff = Audit.Delta.delta(unaudit_fun(pre), unaudit_fun(post)) | |
code = Audit.FileCache.get(filename) |> Enum.at(line - 1) | |
filename = String.replace_prefix(filename, "#{Audit.Github.git_root()}/", "") | |
url = Audit.Github.git_url(filename, line) | |
[ | |
"github url: #{url}", | |
"local path: #{filename}:#{line}", | |
"code: #{String.trim(code)}", | |
"diff: #{inspect(diff)}" | |
] | |
|> Enum.join("\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment