Skip to content

formula_creator: detect GitHub version from latest release #20025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

abitrolly
Copy link
Contributor

@abitrolly abitrolly commented May 30, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

If --set-version is absent, and version is not detected from URL, and the URL is GitHub URL, then fetch GitHub version from the latest release, and change URL to be tarball URL from the latest release.

Also makes GitHub parsing more compact, and moves version check from write! to parse_url where the detection logic is.

So the data is collected from the two API calls:

$ curl -s https://api.github.com/repos/Homebrew/brew/releases/latest | jq
{
  "url": "https://api.github.com/repos/Homebrew/brew/releases/220927354",
  "assets_url": "https://api.github.com/repos/Homebrew/brew/releases/220927354/assets",
  "upload_url": "https://uploads.github.com/repos/Homebrew/brew/releases/220927354/assets{?name,label}",
  "html_url": "https://github.com/Homebrew/brew/releases/tag/4.5.3",
  "id": 220927354,
  "author": {
    "login": "MikeMcQuaid",
    "id": 125011,
    "node_id": "MDQ6VXNlcjEyNTAxMQ==",
    "avatar_url": "https://avatars.githubusercontent.com/u/125011?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/MikeMcQuaid",
    "html_url": "https://github.com/MikeMcQuaid",
    "followers_url": "https://api.github.com/users/MikeMcQuaid/followers",
    "following_url": "https://api.github.com/users/MikeMcQuaid/following{/other_user}",
    "gists_url": "https://api.github.com/users/MikeMcQuaid/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/MikeMcQuaid/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/MikeMcQuaid/subscriptions",
    "organizations_url": "https://api.github.com/users/MikeMcQuaid/orgs",
    "repos_url": "https://api.github.com/users/MikeMcQuaid/repos",
    "events_url": "https://api.github.com/users/MikeMcQuaid/events{/privacy}",
    "received_events_url": "https://api.github.com/users/MikeMcQuaid/received_events",
    "type": "User",
    "user_view_type": "public",
    "site_admin": false
  },
  "node_id": "RE_kwDOAyxcHc4NKxV6",
  "tag_name": "4.5.3",
  "target_commitish": "master",
  "name": "4.5.3",
  "draft": false,
  "prerelease": false,
  "created_at": "2025-05-25T04:55:46Z",
  "published_at": "2025-05-26T07:41:42Z",
  "assets": [
    {
      "url": "https://api.github.com/repos/Homebrew/brew/releases/assets/258620307",
      "id": 258620307,
      "node_id": "RA_kwDOAyxcHc4PajuT",
      "name": "Homebrew-4.5.3.pkg",
      "label": null,
      "uploader": {
        "login": "Bo98",
        "id": 1190754,
        "node_id": "MDQ6VXNlcjExOTA3NTQ=",
        "avatar_url": "https://avatars.githubusercontent.com/u/1190754?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Bo98",
        "html_url": "https://github.com/Bo98",
        "followers_url": "https://api.github.com/users/Bo98/followers",
        "following_url": "https://api.github.com/users/Bo98/following{/other_user}",
        "gists_url": "https://api.github.com/users/Bo98/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/Bo98/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/Bo98/subscriptions",
        "organizations_url": "https://api.github.com/users/Bo98/orgs",
        "repos_url": "https://api.github.com/users/Bo98/repos",
        "events_url": "https://api.github.com/users/Bo98/events{/privacy}",
        "received_events_url": "https://api.github.com/users/Bo98/received_events",
        "type": "User",
        "user_view_type": "public",
        "site_admin": false
      },
      "content_type": "application/octet-stream",
      "state": "uploaded",
      "size": 117207576,
      "digest": null,
      "download_count": 8317,
      "created_at": "2025-05-27T19:23:09Z",
      "updated_at": "2025-05-27T19:24:22Z",
      "browser_download_url": "https://github.com/Homebrew/brew/releases/download/4.5.3/Homebrew-4.5.3.pkg"
    }
  ],
  "tarball_url": "https://api.github.com/repos/Homebrew/brew/tarball/4.5.3",
  "zipball_url": "https://api.github.com/repos/Homebrew/brew/zipball/4.5.3",
  "body": "<!-- Release notes generated using configuration in .github/release.yml at master -->\r\n\r\n## What's Changed\r\n* tap: get autobump list from `autobump.txt` file by @botantony in https://github.com/Homebrew/brew/pull/19923\r\n* Improve readability of disabled command message by @dduugg in https://github.com/Homebrew/brew/pull/19930\r\n* cask: document shell completion stanzas by @EricFromCanada in https://github.com/Homebrew/brew/pull/19929\r\n* Phase out using `cgi` library by @Bo98 in https://github.com/Homebrew/brew/pull/19938\r\n* docs/Homebrew-on-Linux: update instructions for Fedora-based distros by @xty in https://github.com/Homebrew/brew/pull/19944\r\n* Revert \"cask/artifact/abstract_uninstall: fix `trash_paths`\" by @carlocab in https://github.com/Homebrew/brew/pull/19941\r\n* Portable Ruby 3.4.4 by @p-linnane in https://github.com/Homebrew/brew/pull/19949\r\n* patches audit: bitbucket patches should use api by @Moisan in https://github.com/Homebrew/brew/pull/19880\r\n* dev-cmd/generate-*-api: simulate latest macOS by @EricFromCanada in https://github.com/Homebrew/brew/pull/19950\r\n* cmd/list: skip invalid Caskroom files by @EricFromCanada in https://github.com/Homebrew/brew/pull/19943\r\n* docs/Deprecating-Disabling-* review by @EricFromCanada in https://github.com/Homebrew/brew/pull/19958\r\n* Bitbucket: update generated urls by @samford in https://github.com/Homebrew/brew/pull/19973\r\n* cask/dsl: set `no_autobump!` automatically in some cases by @botantony in https://github.com/Homebrew/brew/pull/19910\r\n* bump-formula-pr: fix case when only `url` is provided by @bevanjkay in https://github.com/Homebrew/brew/pull/19971\r\n* utils/spdx: do case insensitive comparison. by @MikeMcQuaid in https://github.com/Homebrew/brew/pull/19976\r\n* Anonymous OCI registry mirror support  by @byjrack in https://github.com/Homebrew/brew/pull/19885\r\n* docs/Cask-Cookbook review by @EricFromCanada in https://github.com/Homebrew/brew/pull/19968\r\n* docs/FAQ: fix broken link by @p-linnane in https://github.com/Homebrew/brew/pull/19982\r\n* Include annotations in tapioca updates by @dduugg in https://github.com/Homebrew/brew/pull/19985\r\n* Prohibit non-ASCII characters in URLs, nudge toward punycode by @colindean in https://github.com/Homebrew/brew/pull/19977\r\n* dev-cmd/tap-new: fix root_url warning. by @MikeMcQuaid in https://github.com/Homebrew/brew/pull/19987\r\n* dev-cmd/update-maintainers: various fixes. by @MikeMcQuaid in https://github.com/Homebrew/brew/pull/19986\r\n* cask/audit: skip audit_rosetta on Intel-only casks & OSes by @EricFromCanada in https://github.com/Homebrew/brew/pull/19983\r\n* Truncate long release notes in formula PR descriptions by @issyl0 in https://github.com/Homebrew/brew/pull/19989\r\n* dependabot: use more groups. by @MikeMcQuaid in https://github.com/Homebrew/brew/pull/19991\r\n* bundle/commands/exec: fix exit code handling. by @MikeMcQuaid in https://github.com/Homebrew/brew/pull/19993\r\n* dev-cmd/bump-formula-pr: use `Formatter.truncate`. by @MikeMcQuaid in https://github.com/Homebrew/brew/pull/19995\r\n* cask/dsl: set `no_autobump!` if livecheck uses `:extract_plist` by @botantony in https://github.com/Homebrew/brew/pull/19998\r\n* uninstall: exclude configurational filess that belong to other formulae by @botantony in https://github.com/Homebrew/brew/pull/19959\r\n* docs: localize internal URLs by @EricFromCanada in https://github.com/Homebrew/brew/pull/20000\r\n* docs/Typechecking review by @EricFromCanada in https://github.com/Homebrew/brew/pull/20001\r\n* bundle: add support for selective cleanup by @Bo98 in https://github.com/Homebrew/brew/pull/20002\r\n* feat: add clarification of macOS patches in Support-Tiers by @SMillerDev in https://github.com/Homebrew/brew/pull/20007\r\n* feat: add _ to powershell completion filename by @daeho-ro in https://github.com/Homebrew/brew/pull/20008\r\n\r\n## New Contributors\r\n* @xty made their first contribution in https://github.com/Homebrew/brew/pull/19944\r\n* @byjrack made their first contribution in https://github.com/Homebrew/brew/pull/19885\r\n\r\n**Full Changelog**: https://github.com/Homebrew/brew/compare/4.5.2...4.5.3",
  "reactions": {
    "url": "https://api.github.com/repos/Homebrew/brew/releases/220927354/reactions",
    "total_count": 22,
    "+1": 13,
    "-1": 0,
    "laugh": 0,
    "hooray": 2,
    "confused": 0,
    "heart": 4,
    "rocket": 2,
    "eyes": 1
  },
  "mentions_count": 16
}

@abitrolly abitrolly force-pushed the new-detect-latest-release branch 2 times, most recently from b363843 to 0dff1e9 Compare May 30, 2025 07:41
@abitrolly abitrolly changed the title formula_creator: deduplicate GitHub check formula_creator: refactor GitHub and version checks May 30, 2025
@abitrolly abitrolly marked this pull request as draft May 30, 2025 07:44
@abitrolly abitrolly force-pushed the new-detect-latest-release branch from 0dff1e9 to ad976c4 Compare May 30, 2025 08:15
@abitrolly abitrolly marked this pull request as ready for review May 30, 2025 08:16
@abitrolly abitrolly changed the title formula_creator: refactor GitHub and version checks formula_creator: detect GitHub version from latest release May 30, 2025
@abitrolly abitrolly force-pushed the new-detect-latest-release branch from 9d4be72 to 25f480e Compare May 30, 2025 10:37
abitrolly added 3 commits May 31, 2025 05:37
Fail in `parse_url`, where the missing @Version is parsed.

`Version.detect()` returns `Version` object, and `@version` can
only be `NULL` after it.
@abitrolly abitrolly force-pushed the new-detect-latest-release branch from 25f480e to 825afde Compare May 31, 2025 02:37
user = Regexp.last_match(1)
repo = Regexp.last_match(2)
@github = GitHub.repository(user, repo) if @fetch
when %r{github\.com/(\S+)/(\S+)/(archive|releases)/}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(archive|releases) is still no longer handled

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abitrolly Can you do this or close out the PR please? Please prioritise completing existing PRs before opening new ones.

abitrolly and others added 3 commits June 3, 2025 17:38
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants