-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Changelog.jl for changelog infrastructure.
- Loading branch information
1 parent
2fabe9c
commit bee303d
Showing
5 changed files
with
20 additions
and
144 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[deps] | ||
Changelog = "5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e" | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8" | ||
MarkdownAST = "d0879d2d-cac2-40c8-9cee-1863dc0c7391" |
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 |
---|---|---|
@@ -1,138 +1,13 @@ | ||
# ================================================================================= | ||
# Utilities for managing CHANGELOG.md and generating a Documenter-friendly version | ||
# ================================================================================= | ||
|
||
const CHANGELOG_LINK_SEPARATOR = "<!-- Links to pull requests/issues/etc. generated by docs/changelog.jl -->" | ||
|
||
function collect_links(; | ||
changelog_inputfile::String, | ||
repo::String, | ||
) | ||
# Output mapping tokens to the full URL | ||
# (e.g. "[#123]" => "https://github.com/JuliaDocs/Documenter.jl/issues/123") | ||
linkmap = Dict{String, String}() | ||
|
||
# Read the source file and split the content to ignore the list of links | ||
content = read(changelog_inputfile, String) | ||
content = first(split(content, CHANGELOG_LINK_SEPARATOR)) | ||
|
||
# Rule: [abc#XXXX] -> https://github.com/abc/issues/XXXX | ||
# Description: Replace issue/PR numbers with a link to the default repo | ||
# Example: [JuliaLang/julia#123] -> https://github.com/JuliaLang/julia/issues/123 | ||
# There is no need to distinguish between PRs and Issues because GitHub redirects. | ||
for m in eachmatch(r"\[(?<repo>[a-zA-Z0-9/]+?)\#(?<id>[0-9]+)\]", content) | ||
linkmap[m.match] = "https://github.com/$(m["repo"])/issues/$(m["id"])" | ||
end | ||
|
||
# Rule: [#XXXX] -> https://github.com/url/issue/XXXX | ||
# Description: Replace issue/PR numbers with a link to the default repo | ||
# Example: [#123] -> https://github.com/JuliaDocs/Documenter.jl/issues/123 | ||
# There is no need to distinguish between PRs and Issues because GitHub redirects. | ||
for m in eachmatch(r"\[\#(?<id>[0-9]+)\]", content) | ||
linkmap[m.match] = "https://github.com/$(repo)/issues/$(m["id"])" | ||
end | ||
|
||
# Rule: [@XXXX] -> https://github.com/XXXX | ||
# Description: Replace users with a link to their GitHub | ||
# Example: [@odow] -> https://github.com/odow | ||
for m in eachmatch(r"\[@(?<id>.+?)\]", content) | ||
linkmap[m.match] = "https://github.com/$(m["id"])" | ||
end | ||
|
||
# Rule: ## Version [vX.Y.Z] -> url/releases/tag/vX.Y.Z | ||
# Description: Replace version headers with a link to the GitHub release | ||
# Example: ## Version [v0.27.0] -> https://github.com/JuliaDocs/Documenter.jl/releases/tag/v0.27.0 | ||
for m in eachmatch(r"^\#\# Version (?<token>\[(?<tag>v[0-9]+.[0-9]+.[0-9]+)\])"m, content) | ||
linkmap[m["token"]] = "https://github.com/$(repo)/releases/tag/$(m["tag"])" | ||
end | ||
|
||
return linkmap | ||
end | ||
|
||
# Rewrite CHANGELOG.md to a Documenter-friendly markdown file | ||
function rewrite_changelog(; | ||
changelog_inputfile::String, | ||
changelog_outputfile::String, | ||
# current_module::String, | ||
repo::String, | ||
branch::String = "master", | ||
) | ||
# Get the map of token to full URL | ||
linkmap = collect_links(; changelog_inputfile, repo) | ||
|
||
# Read the source file and split the content to ignore the list of links | ||
content = read(changelog_inputfile, String) | ||
content = first(split(content, CHANGELOG_LINK_SEPARATOR)) | ||
|
||
# Replace all link tokens with full URLs | ||
for (k, v) in linkmap | ||
content = replace(content, k => "$k($v)") | ||
end | ||
|
||
# Header to set EditURL | ||
header = """ | ||
```@meta | ||
EditURL = "https://github.com/$repo/blob/$branch/CHANGELOG.md" | ||
``` | ||
""" | ||
|
||
# Write it all out | ||
open(changelog_outputfile, "w") do io | ||
write(io, header) | ||
write(io, content) | ||
end | ||
|
||
return | ||
end | ||
|
||
# Collect and add all links to the CHANGELOG.md footer. | ||
function write_link_footer(; | ||
changelog_inputfile::String, | ||
changelog_outputfile::String = changelog_inputfile, | ||
repo::String, | ||
using Changelog | ||
|
||
# Changelog.generate( | ||
# Changelog.Documenter(), | ||
# joinpath(@__DIR__, "..", "CHANGELOG.md"), | ||
# joinpath(@__DIR__, "src", "release-notes.md"); | ||
# repo = "JuliaDocs/Documenter.jl", | ||
# ) | ||
Changelog.generate( | ||
Changelog.CommonMark(), | ||
joinpath(@__DIR__, "..", "CHANGELOG.md"); | ||
repo = "JuliaDocs/Documenter.jl", | ||
) | ||
# Get the map of token to full URL | ||
linkmap = collect(collect_links(; changelog_inputfile, repo)) | ||
|
||
# Sort releases first, then own issues, then external issues, then other things | ||
sort!(linkmap; by = function(x) | ||
k, v = x | ||
if occursin("/releases/tag/", v) | ||
# Sort releases by version number | ||
return (1, VersionNumber(match(r"\[(?<version>.*)\]", k)["version"])) | ||
elseif occursin("github.com/$(repo)/issues/", v) | ||
# Sort issues by number | ||
n = parse(Int, match(r"\[\#(?<id>\d+)\]", k)["id"]) | ||
return (2, n) | ||
elseif occursin(r"github\.com/.*/issues/", v) | ||
# Sort by repo name, then issues by number | ||
m = match(r"\[(?<repo>.*)\#(?<id>\d+)\]", k) | ||
n = parse(Int, m["id"]) | ||
return (3, m["repo"], n) | ||
else | ||
return (4,) | ||
end | ||
end) | ||
|
||
# Read the source file and split the content to ignore the list of links | ||
content = read(changelog_inputfile, String) | ||
content = strip(first(split(content, CHANGELOG_LINK_SEPARATOR))) | ||
|
||
# Write it all out | ||
open(changelog_outputfile, "w") do io | ||
write(io, content) | ||
write(io, "\n\n\n") | ||
write(io, CHANGELOG_LINK_SEPARATOR) | ||
write(io, "\n\n") | ||
for (k, v) in linkmap | ||
println(io, k, ": ", v) | ||
end | ||
end | ||
|
||
return | ||
end | ||
|
||
# Run write_link_footer if this script is invoked by `julia docs/changelog.jl` | ||
if abspath(PROGRAM_FILE) == @__FILE__ | ||
write_link_footer(; changelog_inputfile = "CHANGELOG.md", repo = "JuliaDocs/Documenter.jl") | ||
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