github_changelog_generator 1.18.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b4b0ae75606e17c5e16de177c480681cd39a56e4898d1dc411187aa65115694
4
- data.tar.gz: 844d1023dcb2fd10c3ed6045fd190882092a2ff2525153bbd6017b0c72c43458
3
+ metadata.gz: 02c70cf1019c3603b290a41cc84ec82077593e8d469c962ab5fa4fe734fba333
4
+ data.tar.gz: 9ffd88608d0ab0fe21dd2a8f2d0da2d5129acd8a7c34f306d518a1e06a6d42d7
5
5
  SHA512:
6
- metadata.gz: 8e68b447064d152fa0142e4883d67fd7636887204612b57e9130aa3564b4f591d97cfa98a503f3c7f5eff3f8de592216e1ef53a5b3e8f9dffcaa4b477bfbeaad
7
- data.tar.gz: 9d0e534125f4fb418034aa63c3404e37aadb6a2c9c59f27b26bc384e60365793379ebbd0418d2cc6afb2cfbc63541f6863e56737ca5eb9a4d642ec6cc2cacacb
6
+ metadata.gz: 3f6980de2561fb771959cb5105bb496086ad06cc99a154e4b5aa433000919870c9c61e76803394c19a5fdd7c508007f945a09ed44d5e6a50d476c5daa434e328
7
+ data.tar.gz: 7fe4fd627c90f0be974e78491c2f99079ee5998365dc8d3249f340e7e5194b35db550ca399acdd2c26d238ef4d0d795a6c9ad079796f203a80882d73f12d1310
@@ -81,17 +81,22 @@ module GitHubChangelogGenerator
81
81
  else
82
82
  # Either there were no events or no merged event. GitHub's api can be
83
83
  # weird like that apparently. Check for a rebased comment before erroring.
84
- no_events_pr = associate_rebase_comment_prs(tags, [pr], total)
85
- raise StandardError, "No merge sha found for PR #{pr['number']} via the GitHub API" unless no_events_pr.empty?
86
-
87
- found = true
88
- i += 1
89
- print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose]
84
+ found = associate_pr_without_merge_event(tags, pr, total)
85
+ i += 1 if found
90
86
  end
91
87
  found
92
88
  end
93
89
  end
94
90
 
91
+ def associate_pr_without_merge_event(tags, pull_request, total)
92
+ unassociated = associate_rebase_comment_prs(tags, [pull_request], total)
93
+ return false if pull_request["comments_incomplete"]
94
+
95
+ raise StandardError, "No merge sha found for PR #{pull_request['number']} via the GitHub API" unless unassociated.empty?
96
+
97
+ true
98
+ end
99
+
95
100
  # Associate merged PRs by the HEAD of the release branch. If no
96
101
  # --release-branch was specified, then the github default branch is used.
97
102
  #
@@ -127,29 +132,37 @@ module GitHubChangelogGenerator
127
132
  # Any remaining PRs were not found in the list of tags by their merge
128
133
  # commit and not found in any specified release branch. Fallback to
129
134
  # rebased commit comment.
130
- @fetcher.fetch_comments_async(prs_left)
135
+ pending = prs_left.reject { |pr| pr["comments_incomplete"] }
136
+ @fetcher.fetch_comments_async(pending) unless pending.empty?
131
137
  prs_left.reject do |pr|
132
- found = false
133
- if pr["comments"] && (rebased_comment = pr["comments"].reverse.find { |c| c["body"].match(%r{rebased commit: ([0-9a-f]{40})}i) })
134
- rebased_sha = rebased_comment["body"].match(%r{rebased commit: ([0-9a-f]{40})}i)[1]
135
- if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(rebased_sha) })
136
- pr["first_occurring_tag"] = oldest_tag["name"]
137
- found = true
138
- i += 1
139
- elsif sha_in_release_branch?(rebased_sha)
140
- found = true
141
- i += 1
142
- else
143
- raise StandardError, "PR #{pr['number']} has a rebased SHA comment but that SHA was not found in the release branch or any tags"
144
- end
145
- print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose]
146
- else
147
- puts "Warning: PR #{pr['number']} merge commit was not found in the release branch or tagged git history and no rebased SHA comment was found"
148
- end
149
- found
138
+ next false if pr["comments_incomplete"]
139
+
140
+ next false unless associate_rebased_pr(tags, pr)
141
+
142
+ i += 1
143
+ print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose]
144
+ true
150
145
  end
151
146
  end
152
147
 
148
+ def associate_rebased_pr(tags, pull_request)
149
+ rebased_sha = (pull_request["comments"] || []).reverse_each.lazy.filter_map do |comment|
150
+ comment["body"][/rebased commit: ([0-9a-f]{40})/i, 1]
151
+ end.first
152
+ unless rebased_sha
153
+ puts "Warning: PR #{pull_request['number']} merge commit was not found in the release branch or tagged git history and no rebased SHA comment was found"
154
+ return false
155
+ end
156
+
157
+ if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(rebased_sha) })
158
+ pull_request["first_occurring_tag"] = oldest_tag["name"]
159
+ return true
160
+ end
161
+ return true if sha_in_release_branch?(rebased_sha)
162
+
163
+ raise StandardError, "PR #{pull_request['number']} has a rebased SHA comment but that SHA was not found in the release branch or any tags"
164
+ end
165
+
153
166
  # Fill :actual_date parameter of specified issue by closed date of the commit, if it was closed by commit.
154
167
  # @param [Hash] issue
155
168
  def find_closed_date_by_commit(issue)
@@ -23,7 +23,7 @@ module GitHubChangelogGenerator
23
23
  # @param [Array] filtered_tags is the list of filtered tags ordered from newest -> oldest
24
24
  # @return [Hash] key is the tag to output, value is an array of [Left Tag, Right Tag]
25
25
  # PRs to include in this section will be >= [Left Tag Date] and <= [Right Tag Date]
26
- # rubocop:disable Style/For - for allows us to be more concise
26
+ # rubocop:disable Style/For -- for allows us to be more concise
27
27
  def build_tag_section_mapping(section_tags, filtered_tags)
28
28
  tag_mapping = {}
29
29
  for i in 0..(section_tags.length - 1)
@@ -253,11 +253,22 @@ Make sure, that you push tags to remote repo via 'git push --tags'"
253
253
 
254
254
  prs.each do |pr|
255
255
  semaphore.async do
256
- pr["comments"] = []
257
- iterate_pages(client, "issue_comments", pr["number"]) do |new_comment|
258
- pr["comments"].concat(new_comment)
256
+ comments = []
257
+ missing_page = false
258
+ iterate_pages(client, "issue_comments", pr["number"]) do |page|
259
+ if page.nil?
260
+ missing_page = true
261
+ else
262
+ comments.concat(page)
263
+ end
259
264
  end
260
- pr["comments"] = pr["comments"].map { |comment| stringify_keys_deep(comment.to_hash) }
265
+
266
+ if missing_page
267
+ Helper.log.warn "Omitting PR ##{pr['number']} from the changelog because GitHub returned incomplete comments needed to identify its release"
268
+ comments.clear
269
+ end
270
+ pr["comments_incomplete"] = missing_page
271
+ pr["comments"] = comments.map { |comment| stringify_keys_deep(comment.to_hash) }
261
272
  end
262
273
  end
263
274