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

RFC healthcheck #30

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
69 changes: 57 additions & 12 deletions src/AnalyzeRegistry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using Tokei_jll # count lines of code

export general_registry, find_package, find_packages
export analyze, analyze_from_registry, analyze_from_registry!
export healthcheck

include("count_loc.jl")
const LicenseTableEltype=@NamedTuple{license_filename::String, licenses_found::Vector{String}, license_file_percent_covered::Float64}
Expand Down Expand Up @@ -106,19 +107,10 @@ function Base.show(io::IO, p::Package)
* has documentation: $(p.docs)
* has tests: $(p.runtests)
"""
ci_services = (p.github_actions => "GitHub Actions",
p.travis => "Travis",
p.appveyor => "AppVeyor",
p.cirrus => "Cirrus",
p.circle => "Circle",
p.drone => "Drone CI",
p.buildkite => "Buildkite",
p.azure_pipelines => "Azure Pipelines",
p.gitlab_pipeline => "GitLab Pipeline",
)
if any(first.(ci_services))
ci = ci_services(p)
if any(first.(ci))
body *= " * has continuous integration: true\n"
for (k, v) in ci_services
for (k, v) in ci
if k
body *= " * $(v)\n"
end
Expand All @@ -130,6 +122,59 @@ function Base.show(io::IO, p::Package)
print(io, strip(body))
end

function ci_services(p)
return (p.github_actions => "GitHub Actions",
p.travis => "Travis",
p.appveyor => "AppVeyor",
p.cirrus => "Cirrus",
p.circle => "Circle",
p.drone => "Drone CI",
p.buildkite => "Buildkite",
p.azure_pipelines => "Azure Pipelines",
p.gitlab_pipeline => "GitLab Pipeline")
end

emojify(b::Bool) = b ? "☑" : "◻"

function print_check(io, check, name, parens)
print(io, emojify(check), " ", name)
if check && !isempty(parens)
println(io, " (", parens, ")")
else
println(io)
end
end

healthcheck(p::Package) = healthcheck(stdout, p)

function healthcheck(io::IO, p::Package)
Copy link
Member

@giordano giordano Feb 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the idea is to have something similar also for RegistryCI, perhaps we want to have multiple methods for different MIMEs (plain text vs markdown)? Or this can be show(::IO, ::MIME"markdown", ::Package)?

jl_test = count_loc(p.lines_of_code, "test", :Julia)
jl_src = count_loc(p.lines_of_code, "src", :Julia)
jl_doc = count_docs(p.lines_of_code)
println(io, p.name, ".jl")
print_check(io, jl_src > 5, "Has code", "$(jl_src) lines")
print_check(io, p.docs, "Has docs", "$(jl_doc) lines")
print_check(io, p.runtests && jl_test > 5, "Has tests", "$(jl_test) lines")
licenses = String[]
append!(licenses, p.licenses_in_project)
for lic in p.license_files
append!(licenses, lic.licenses_found)
end
print_check(io, !isempty(licenses) && any(is_osi_approved, licenses), "Has license(s)", "")
for lic in licenses
check = is_osi_approved(lic)
print(io, " $lic (")
if check
print(io, "✔ OSI-approved)")
else
print(io, "⨉ not OSI-approved)")
end
println(io)
end
services = [v for (k,v) in ci_services(p) if k]
print_check(io, !isempty(services), "Has CI", join(services, ", "))
end

"""
general_registry() -> String

Expand Down
7 changes: 5 additions & 2 deletions src/count_loc.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function count_loc(dir)
function count_loc(dir::AbstractString)
# we `cd` so that we get relative paths in the `tokei` output.
# This makes it easy to process later, since we have uniform filepaths
json = cd(dir) do
Expand Down Expand Up @@ -54,4 +54,7 @@ function loc_update!(d, key, new)
d[key] = (; files = prev.files + 1, code = prev.code + new.code, comments = prev.comments + new.comments, blanks = prev.blanks + new.blanks )
end

count_julia_loc(table, dir) = sum(row.code for row in table if row.directory == dir && row.language == :Julia; init=0)
count_julia_loc(table, dir) = count_loc(table, dir, :Julia)
count_loc(table, dir::AbstractString, language::Symbol) = sum(row.code for row in table if row.directory == dir && row.language == language; init=0)
count_loc(table, dir::AbstractString) = sum(row.code for row in table if row.directory == dir; init=0)
count_docs(table) = sum(row.code + row.comments for row in table if row.directory in ("docs", "doc"); init=0)