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

Enhance changelog script to pull milestone info from GitHub #14230

Merged
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
47 changes: 37 additions & 10 deletions scripts/github-changelog.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def query_prs(api_token, repository, milestone)
repository(owner: $owner, name: $repository) {
milestones(query: $milestone, first: 1) {
nodes {
closedAt
description
dueOn
title
pullRequests(first: 300) {
nodes {
number
Expand Down Expand Up @@ -81,6 +85,28 @@ module LabelNameConverter
end
end

record Milestone,
closed_at : Time?,
description : String,
due_on : Time?,
title : String,
pull_requests : Array(PullRequest) do
include JSON::Serializable

@[JSON::Field(key: "dueOn")]
@due_on : Time?

@[JSON::Field(key: "closedAt")]
@closed_at : Time?

@[JSON::Field(key: "pullRequests", root: "nodes")]
@pull_requests : Array(PullRequest)

def release_date
closed_at || due_on
end
end

record PullRequest,
number : Int32,
title : String,
Expand Down Expand Up @@ -245,24 +271,20 @@ end

response = query_prs(api_token, repository, milestone)
parser = JSON::PullParser.new(response.body)
array = parser.on_key! "data" do
milestone = parser.on_key! "data" do
parser.on_key! "repository" do
parser.on_key! "milestones" do
parser.on_key! "nodes" do
parser.read_begin_array
a = parser.on_key! "pullRequests" do
parser.on_key! "nodes" do
Array(PullRequest).new(parser)
end
end
milestone = Milestone.new(parser)
parser.read_end_array
a
milestone
end
end
end
end

sections = array.group_by(&.section)
sections = milestone.pull_requests.group_by(&.section)

SECTION_TITLES = {
"breaking" => "Breaking changes",
Expand All @@ -279,9 +301,14 @@ SECTION_TITLES = {

TOPIC_ORDER = %w[lang stdlib compiler tools other]

puts "## [#{milestone}] (#{Time.local.to_s("%F")})"
puts "## [#{milestone.title}] (#{milestone.release_date.try(&.to_s("%F")) || "unreleased"})"
if description = milestone.description.presence
puts
print "_", description
puts "_"
end
puts
puts "[#{milestone}]: https://github.com/crystal-lang/crystal/releases/#{milestone}"
puts "[#{milestone.title}]: https://github.com/crystal-lang/crystal/releases/#{milestone.title}"
puts

SECTION_TITLES.each do |id, title|
Expand Down
Loading