Last active
October 31, 2025 17:10
-
-
Save carlocab/66002bdc98a2da82ec406c5d741ff032 to your computer and use it in GitHub Desktop.
Helper Script for Homebrew Mass Bottling Tracking Issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env brew ruby | |
| # Marks a comment in the tracking issue as resolved if it is about a formula that is already bottled. | |
| ISSUE = 184132 | |
| bottle_tag = Utils::Bottles::Tag.new(arch: :arm64, system: :sequoia) | |
| MINIMIZE_COMMENT_MUTATION = <<~GRAPHQL | |
| mutation ($input: MinimizeCommentInput!) { | |
| minimizeComment(input: $input) { | |
| clientMutationId | |
| } | |
| } | |
| GRAPHQL | |
| UPDATE_COMMENT_MUTATION = <<~GRAPHQL | |
| mutation ($input: UpdateIssueCommentInput!) { | |
| updateIssueComment(input: $input) { | |
| clientMutationId | |
| } | |
| } | |
| GRAPHQL | |
| AUTOMATIC_COMMENT_HEADER = "<!-- PLEASE DO NOT EDIT BELOW THIS LINE -- CONTENTS ARE AUTOGENERATED -->" | |
| url = GitHub.url_to("repos", "Homebrew", "homebrew-core", "issues", ISSUE.to_s, "comments") | |
| def process(body) | |
| lines = body.lines(chomp: true) | |
| links_start = lines.find_index(AUTOMATIC_COMMENT_HEADER) | |
| lines = lines[0..(links_start - 1)] if links_start.present? && links_start > 0 | |
| lines << AUTOMATIC_COMMENT_HEADER | |
| lines | |
| end | |
| seen_formulae = {} | |
| GitHub::API.paginate_rest(url) do |result, _| | |
| result.each do |comment| | |
| body = comment.fetch("body") | |
| formula_name = body[/ bottle request for ([^\s]+) /, 1] | |
| next if formula_name.blank? | |
| classifier = if seen_formulae.keys.include?(formula_name) | |
| ohai "#{formula_name} has an earlier bottle attempt, resolving duplicate issue comment" | |
| seen_formulae[formula_name][:duplicate_urls] << comment.fetch("html_url") | |
| "DUPLICATE" | |
| else | |
| seen_formulae[formula_name] ||= {} | |
| seen_formulae[formula_name][:html_url] = comment.fetch("html_url") | |
| seen_formulae[formula_name][:node_id] = comment.fetch("node_id") | |
| seen_formulae[formula_name][:body] = comment.fetch("body") | |
| seen_formulae[formula_name][:duplicate_urls] ||= [] | |
| formula = Formulary.factory(formula_name) | |
| next unless formula.bottle_specification.tag?(bottle_tag, no_older_versions: true) | |
| ohai "#{formula_name} is bottled now, resolving issue comment" | |
| "RESOLVED" | |
| end | |
| node_id = comment.fetch("node_id") | |
| input = { classifier: , subjectId: node_id } | |
| variables = { input: } | |
| GitHub::API.open_graphql(MINIMIZE_COMMENT_MUTATION, variables:) | |
| next if classifier == "RESOLVED" | |
| next if (original_url = seen_formulae[formula_name][:html_url]).blank? | |
| lines = process(body) | |
| lines << "Duplicate of #{original_url}" | |
| body = lines.join("\n") | |
| id = comment.fetch("node_id") | |
| variables = { input: { body:, id: } } | |
| ohai "Updating comment to point to original" | |
| GitHub::API.open_graphql(UPDATE_COMMENT_MUTATION, variables:) | |
| end | |
| end | |
| seen_formulae.each do |name, hash| | |
| next if (dupes = hash[:duplicate_urls]).blank? | |
| next if (body = hash[:body]).blank? | |
| next if (id = hash[:node_id]).blank? | |
| lines = process(body) | |
| lines << "### Duplicates" | |
| lines += dupes | |
| body = lines.join("\n") | |
| variables = { input: { body:, id: } } | |
| ohai "Updating original comment to include references to duplicates" | |
| GitHub::API.open_graphql(UPDATE_COMMENT_MUTATION, variables:) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment