Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Feb 4, 2025
1 parent 0b70e1e commit 91dd66b
Showing 1 changed file with 4 additions and 44 deletions.
48 changes: 4 additions & 44 deletions scripts/github-changelog.cr
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,6 @@ record PullRequest,
md = title.match(/\[fixup #(.\d+)/) || return
md[1]?.try(&.to_i)
end

def clean_title
title.sub(/^\[?(?:#{type}|#{sub_topic})(?::|\]:?) /i, "").sub(/\s*\[Backport [^\]]+\]\s*/, "")
end

def backported?
labels.any?(&.starts_with?("backport"))
end

def backport?
title.includes?("[Backport ")
end
end

def query_milestone(api_token, repository, number)
Expand Down Expand Up @@ -324,9 +312,8 @@ end

milestone = query_milestone(api_token, repository, milestone)

class ChangelogEntry
struct ChangelogEntry
getter pull_requests : Array(PullRequest)
property backported_from : PullRequest?

def initialize(pr : PullRequest)
@pull_requests = [pr]
Expand Down Expand Up @@ -355,18 +342,13 @@ class ChangelogEntry
if pr.deprecated?
io << "**[deprecation]** "
end
io << pr.clean_title
io << pr.title.sub(/^\[?(?:#{pr.type}|#{pr.sub_topic})(?::|\]:?) /i, "")

io << " ("
pull_requests.join(io, ", ") do |pr|
pr.link_ref(io)
end

if backported_from = self.backported_from
io << ", backported from "
backported_from.link_ref(io)
end

authors = collect_authors
if authors.present?
io << ", thanks "
Expand All @@ -379,26 +361,15 @@ class ChangelogEntry

def collect_authors
authors = [] of String

if backported_from = self.backported_from
if author = backported_from.author
authors << author
end
end

pull_requests.each_with_index do |pr, i|
next if backported_from && i.zero?

pull_requests.each do |pr|
author = pr.author || next
authors << author unless authors.includes?(author)
end

authors
end

def print_ref_labels(io)
pull_requests.each { |pr| print_ref_label(io, pr) }
backported_from.try { |pr| print_ref_label(io, pr) }
end

def print_ref_label(io, pr)
Expand All @@ -409,7 +380,7 @@ class ChangelogEntry
end

entries = milestone.pull_requests.compact_map do |pr|
ChangelogEntry.new(pr) unless pr.fixup? || pr.backported?
ChangelogEntry.new(pr) unless pr.fixup?
end

milestone.pull_requests.each do |pr|
Expand All @@ -423,17 +394,6 @@ milestone.pull_requests.each do |pr|
end
end

milestone.pull_requests.each do |pr|
next unless pr.backported?

backport = entries.find { |entry| entry.pr.backport? && entry.pr.clean_title == pr.clean_title }
if backport
backport.backported_from = pr
else
STDERR.puts "Unresolved backport: #{pr.clean_title.inspect} (##{pr.number})"
end
end

sections = entries.group_by(&.pr.section)

SECTION_TITLES = {
Expand Down

0 comments on commit 91dd66b

Please sign in to comment.