Skip to content

Commit

Permalink
Use the same format as GitHub's default for the release notes
Browse files Browse the repository at this point in the history
We're changing the format for the auto-generated release notes from:

- This is the PR title #1 (@author)

to:

* This is the PR title by @author in solidusio#1

By mimicking the default GitHub format, we make it easier to generate
them manually through GitHub's "Generate release notes" [1] button or
through the API [2].

At the same time, we're fixing the missing links to the PR when we copy
the draft content to the Changelog file, as GitHub doesn't autolink
references in files. From their documentation [3]:

> Note: Autolinked references are not created in wikis or files in a repository.

We'll still miss the link to the contributor, but it's a tradeoff we pay
to make our lives easier if the automation fails. Anyway, it can be
accessed once landed on the pull request URL.

[1] - https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes
[2] - https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#generate-release-notes-content-for-a-release
[3] - https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-url

Closes solidusio#4904 & 4908
  • Loading branch information
waiting-for-dev committed Feb 9, 2023
1 parent 065a19e commit b70cd0b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 71 deletions.
12 changes: 11 additions & 1 deletion dev_tools/lib/solidus/release_drafter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ def call(pr_number:, current_diff_source_tag:, candidate_tag:, branch:)
return if pr_labels.include?(SKIP_LABEL) || matching_labels.empty?

draft = @client.fetch_draft(tag: candidate_tag)
Builder.new(draft: draft, categories: LABELS.values, prepend: NO_EDIT_WARNING, append: full_changelog(current_diff_source_tag, candidate_tag))
Builder.new(
draft: draft,
categories: LABELS.values,
prepend: NO_EDIT_WARNING,
append: full_changelog(current_diff_source_tag, candidate_tag),
number_link_builder: number_link_builder
)
.then { |builder| add_pr(builder, pr, matching_labels) }
.then { |draft| save_release(draft, candidate_tag, branch) }
end
Expand Down Expand Up @@ -68,5 +74,9 @@ def full_changelog(current_diff_source_tag, candidate_tag)
**Full Changelog**: https://github.com/#{@repository}/compare/#{current_diff_source_tag}...#{candidate_tag}
TXT
end

def number_link_builder
->(number) { "https://github.com/#{@repository}/pull/#{number}" }
end
end
end
9 changes: 5 additions & 4 deletions dev_tools/lib/solidus/release_drafter/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ class Builder

TITLE_SEPARATOR = SEPARATOR

ENTRY_TEMPLATE = lambda do |title, number, user|
"- #{title} ##{number} (@#{user})"
ENTRY_TEMPLATE = lambda do |title, link, user|
"* #{title} by @#{user} in #{link}"
end.freeze

ENTRY_SEPARATOR = SEPARATOR

SECTION_SEPARATOR = SEPARATOR + SEPARATOR

def initialize(draft:, categories:, prepend: '', append: '')
def initialize(draft:, categories:, number_link_builder:, prepend: '', append: '')
@number_link_builder = number_link_builder
@categories = Set[*categories]
@prepend = prepend
@prepend_pattern = /^#{Regexp.quote(@prepend)}/m
Expand All @@ -39,7 +40,7 @@ def initialize(draft:, categories:, prepend: '', append: '')
end

def add(title:, number:, user:, categories:)
ENTRY_TEMPLATE.(title, number, user)
ENTRY_TEMPLATE.(title, @number_link_builder.(number), user)
.then { |entry| add_to_ast(entry, categories) }
.then { |ast| @draft.with(content: unparse(ast)) }
end
Expand Down
Loading

0 comments on commit b70cd0b

Please sign in to comment.