Skip to content

Commit

Permalink
[infra] changelog will now show github usernames which makes contribu…
Browse files Browse the repository at this point in the history
…tors stand out more in releases (#20214)
  • Loading branch information
joshdholtz committed May 2, 2022
1 parent 90a0345 commit eb4584e
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,47 @@ private_lane :send_mac_app_ci_reminder do
end
end

desc "Generate changelog from GitHub compare and PR data for mentioning GitHub usernames in release notes"
private_lane :github_changelog do |options|
old_version = options[:old_version] || current_version
path = "/repos/fastlane/fastlane/compare/#{old_version}...HEAD"

# Get all commits from previous version (tag) to HEAD
resp = github_api(path: path)
body = JSON.parse(resp[:body])
commits = body["commits"].reverse

formatted = commits.map do |commit|
# Default to commit message info
message = commit["commit"]["message"].lines.first.strip
name = commit["commit"]["author"]["name"]
username = commit["author"]["login"]

# Get pull request associate with commit message
sha = commit["sha"]
pr_resp = github_api(path: "/search/issues?q=repo:fastlane/fastlane+is:pr+base:master+SHA:#{sha}")
body = JSON.parse(pr_resp[:body])
items = body["items"]

if items.size == 1
item = items.first
message = "#{item['title']} (##{item['number']})"
username = item["user"]["login"]
else
UI.user_error!("Cannot generate changelog. Multiple commits found for #{sha}")
end

"* #{message} via #{name} (@#{username})"
end.join("\n")

formatted
end

desc "Print out the changelog since the last tagged release and open the GitHub page with the changes"
lane :show_changelog do |options|
old_version = options[:old_version] || current_version

changes = sh("git log --pretty='* %s via %aN' #{old_version}...HEAD --no-merges ..", log: $verbose).gsub("\n\n", "\n")
changes.gsub!("[WIP]", "") # sometimes a [WIP] is merged
changes = github_changelog(old_version: old_version)

github_diff_url = "https://github.com/fastlane/fastlane/compare/#{old_version}...master"
sh("open #{github_diff_url}")
Expand Down

0 comments on commit eb4584e

Please sign in to comment.