Skip to content

Commit 6e9ad14

Browse files
hsbtclaude
andcommitted
Make NEWS.md release-link footer idempotent
Seed available_footnotes from the existing release-tag link defs in the file before overlaying freshly fetched URLs, so gems whose Octokit fetches are skipped this run keep their URLs instead of being stranded at their old positions. With every used ref backed by a footnote, the reject step can drop all release-tag defs unconditionally and re-emit them in body-ref order, eliminating the back-and-forth reordering between consecutive scheduled bot runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7ecca26 commit 6e9ad14

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

tool/update-NEWS-github-release.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,16 @@ def update_news_md(results)
339339
i += 1
340340
end
341341

342-
# All footnote definitions we can emit from this run, indexed by ref name
342+
# All footnote definitions we can emit, indexed by ref name. Seed from existing
343+
# release-tag defs in the file so gems skipped this run (e.g. transient API
344+
# failures) keep their URLs, then overlay freshly fetched URLs.
345+
release_ref_pattern = %r{^\[([^\]]+)\]:\s+(https://github\.com/[^/]+/[^/]+/releases/tag/.*)}
343346
available_footnotes = {}
347+
new_lines.each do |line|
348+
if (m = line.match(release_ref_pattern))
349+
available_footnotes[m[1]] = "[#{m[1]}]: #{m[2]}"
350+
end
351+
end
344352
results.each do |r|
345353
r[:footnote_links].each do |fl|
346354
available_footnotes[fl[:ref]] = "[#{fl[:ref]}]: #{fl[:url]}"
@@ -349,18 +357,10 @@ def update_news_md(results)
349357

350358
# Refs the regenerated body actually uses (e.g. `][gem-vX.Y.Z]`)
351359
used_refs = new_lines.join.scan(/\]\[([^\]]+)\]/).flatten.uniq
352-
used_set = used_refs.to_set
353360

354-
# Drop existing GitHub release-tag link defs that are either orphaned (no
355-
# body reference) or about to be re-emitted from this run's results. Defs
356-
# still referenced by gems we couldn't refresh are preserved in place.
357-
release_ref_pattern = %r{^\[([^\]]+)\]:\s+https://github\.com/[^/]+/[^/]+/releases/tag/}
358-
new_lines.reject! do |line|
359-
if (m = line.match(release_ref_pattern))
360-
ref = m[1]
361-
!used_set.include?(ref) || available_footnotes.key?(ref)
362-
end
363-
end
361+
# Drop all existing GitHub release-tag link defs; the used subset is
362+
# re-emitted below in body-ref order so the footer is deterministic.
363+
new_lines.reject! { |line| line.match?(release_ref_pattern) }
364364

365365
# Trim trailing blank lines so the appended footer block is clean
366366
new_lines.pop while new_lines.last == "\n"

0 commit comments

Comments
 (0)