231 Commits

Author SHA1 Message Date
Mike McQuaid
a1f112f3fe
Move o* output methods to Utils::Output
This reduces the surface area of our `Kernel` monkeypatch and removes
the need to `include Kernel` in a bunch of modules.

While we're here, also move `Kernel#require?` to `Homebrew` and fully
scope the calls to it.
2025-08-20 19:20:19 +01:00
Eric Knibbe
827480f06b
messages/comments: wording fixes 2025-08-16 00:57:59 -04:00
Patrick Linnane
9821a7e896
fix new offenses
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2025-03-27 03:38:09 +00:00
Nanda H Krishna
1d35406905
livecheck: fix parent reference handling 2025-03-10 13:21:00 -04:00
Douglas Eichelberger
9515714b44
Add interface for livecheck strategies 2025-02-26 16:45:39 -08:00
Douglas Eichelberger
9aa8ab1789
Simplify livecheck_find_versions_parameters 2025-02-25 10:56:32 -05:00
Sam Ford
b6eb945320
livecheck: Add Options class
This adds a `Livecheck::Options` class, which is intended to house
various configuration options that are set in `livecheck` blocks,
conditionally set by livecheck at runtime, etc. The general idea is
that when we add features involving configurations options (e.g., for
livecheck, strategies, curl, etc.), we can make changes to `Options`
without needing to modify parameters for strategy `find_versions`
methods, `Strategy` methods like `page_headers` and `page_content`,
etc. This is something that I've been trying to improve over the years
and `Options` should help to reduce maintenance overhead in this area
while also strengthening type signatures.

`Options` replaces the existing `homebrew_curl` option (which related
strategies pass to `Strategy` methods and on to `curl_args`) and the
new `url_options` (which contains `post_form` or `post_json` values
that are used to make `POST` requests). I recently added `url_options`
as a temporary way of enabling `POST` support without `Options` but
this restores the original `Options`-based implementation.

Along the way, I added a `homebrew_curl` parameter to the `url` DSL
method, allowing us to set an explicit value in `livecheck` blocks.
This is something that we've needed in some cases but I also intend
to replace implicit/inferred `homebrew_curl` usage with explicit
values in `livecheck` blocks once this is available for use. My
intention is to eventually remove the implicit behavior and only rely
on explicit values. That will align with how `homebrew_curl` options
work for other URLs and makes the behavior clear just from looking at
the `livecheck` block.

Lastly, this removes the `unused` rest parameter from `find_versions`
methods. I originally added `unused` as a way of handling parameters
that some `find_versions` methods have but others don't (e.g., `cask`
in `ExtractPlist`), as this allowed us to pass various arguments to
`find_versions` methods without worrying about whether a particular
parameter is available. This isn't an ideal solution and I originally
wanted to handle this situation by only passing expected arguments to
`find_versions` methods but there was a technical issue standing in
the way. I recently found an answer to the issue, so this also
replaces the existing `ExtractPlist` special case with generic logic
that checks the parameters for a strategy's `find_versions` method
and only passes expected arguments.

Replacing the aforementioned `find_versions` parameters with `Options`
ensures that the remaining parameters are fairly consistent across
strategies and any differences are handled by the aforementioned
logic. Outside of `ExtractPlist`, the only other difference is that
some `find_versions` methods have a `provided_content` parameter but
that's currently only used by tests (though it's intended for caching
support in the future). I will be renaming that parameter to `content`
in an upcoming PR and expanding it to the other strategies, which
should make them all consistent outside of `ExtractPlist`.
2025-02-25 10:56:31 -05:00
Douglas Eichelberger
936b9b5369
Move nil check inside demodulize 2025-02-24 11:57:20 -08:00
Sam Ford
efeff905eb
livecheck: refactor livecheck_strategy_names
This refactors the `livecheck_strategy_names` method to align with
Doug's `livecheck_find_versions_parameters` implementation.
2025-02-21 20:24:28 -05:00
Sam Ford
6cfe151292
livecheck: create constant for no versions message 2025-02-20 22:39:19 -05:00
Sam Ford
a7cacfff1c
livecheck: refactor HEAD-only formula handling
The existing code for handling a `HEAD`-only formula involves two
return values that can be `nil` but this isn't apparent because the
related methods aren't typed. This adds type signatures to the
methods and updates the livecheck code to account for `nil` return
values (making it clear which methods can return `nil`).

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2025-02-20 22:39:18 -05:00
Sam Ford
b4757af656
livecheck: Add support for POST requests
livecheck currently doesn't support `POST` requests but it wasn't
entirely clear how best to handle that. I initially approached it as
a `Post` strategy but unfortunately that would have required us to
handle response body parsing (e.g., JSON, XML, etc.) in some fashion.
We could borrow some of the logic from related strategies but we would
still be stuck having to update `Post` whenever we add a strategy for
a new format.

Instead, this implements `POST` support by borrowing ideas from the
`using: :post` and `data` `url` options found in formulae. This uses
a `post_form` option to handle form data and `post_json` to handle
JSON data, encoding the hash argument for each into the appropriate
format. The presence of either option means that curl will use a
`POST` request.

With this approach, we can make a `POST` request using any strategy
that calls `Strategy::page_headers` or `::page_content` (directly or
indirectly) and everything else works the same as usual. The only
change needed in related strategies was to pass the options through
to the `Strategy` methods.

For example, if we need to parse a JSON response from a `POST`
request, we add a `post_data` or `post_json` hash to the `livecheck`
block `url` and use `strategy :json` with a `strategy` block. This
leans on existing patterns that we're already familiar with and
shouldn't require any notable maintenance burden when adding new
strategies, so it seems like a better approach than a `Post` strategy.
2025-02-07 08:53:47 -05:00
Nanda H Krishna
b737b16569
livecheck: remove URL and Strategy info in some cases 2025-01-07 10:27:58 +05:30
Nanda H Krishna
053a33415e
livecheck: modify resource_version_info data
Co-authored-by: Sam Ford <1584702+samford@users.noreply.github.com>
2025-01-07 02:17:33 +05:30
Nanda H Krishna
cb2346dd58
livecheck: improve formula :parent handling 2025-01-07 02:08:21 +05:30
Nanda H Krishna
e2df3fee81
livecheck: allow parent formula reference in resources 2025-01-07 02:08:21 +05:30
Sam Ford
79e20b3512
Standardize livecheck block language formatting 2024-12-02 10:13:04 -05:00
Sam Ford
01cb74e525
livecheck: clarify livecheckable language
Formulae, casks, and resources have a `#livecheckable?` method that
indicates whether they contain a `livecheck` block. This is intended
to be read as "has a livecheckable?", not "is livecheckable?" (as
livecheck can find versions for some packages/resources without a
`livecheck` block). Unfortunately, correct understanding of this
method's behavior [outside of documentation] relies on historical
knowledge that few people possess, so this is often confusing to
anyone who hasn't been working on livecheck since 2020.

In the olden days, a "livecheckable" was a Ruby file containing a
`livecheck` block (originally a hash) with a filename that
corresponded to a related formula. The `livecheck` blocks in
livecheckable files were integrated into their respective formulae in
August 2020, so [first-party] livecheckables ceased to exist at that
time. From that point forward, we simply referred to these as
`livecheck` blocks.

With that in mind, this clarifies the situation by replacing
"livecheckable" language. This includes renaming `#livecheckable?` to
`#livecheck_defined?`, replacing usage of "livecheckable" as a noun
with "`livecheck` block", replacing "livecheckable" as a boolean with
"livecheck_defined", and replacing incorrect usage of "livecheckable"
as an adjective with "checkable".
2024-12-02 10:13:03 -05:00
Douglas Eichelberger
521c463e36
Manually resolve Style/SafeNavigationChainLength violations 2024-11-05 16:44:12 +00:00
Sam Ford
d7b515bf73
livecheck: error on invalid url symbol
Up to now, we haven't been accounting for `#url` symbol arguments in
`livecheck` blocks that don't reference a checkable URL. This can
either be an invalid symbol (e.g., using the `:stable` formula symbol
in a cask) or a valid symbol where the referenced URL doesn't exist
(e.g., using `:head` when there's no `head` URL). [Almost all of the
valid symbols are required URLs but `head` is optional.]

Over the years, we've had a handful of slips where we've used `:url`
in formulae (when it's only valid in casks) and `:stable` in casks
(when it's only valid in formulae). In this scenario,
`livecheck_url_string` is `nil`, so livecheck falls back to
`#checkable_urls`. In this scenario, `stable` and `url` are the first
checkable URLs for formulae and casks (respectively), so the checks
ended up working as expected merely by chance. This isn't obvious in
the output and even the debug output looks normal. It only becomes
apparent that livecheck isn't working as expected if it iterates
through more than one checkable URL before reaching one that works
(not the case in those instances).

With that in mind, this adds an error when a `#url` symbol is used
but it doesn't correspond to a checkable URL. This will account for
both of the mentioned scenarios (invalid symbols and valid ones
referencing a non-existent URL) and prevent livecheck from quietly
proceeding in an unexpected manner.
2024-10-25 09:54:28 -04:00
Sam Ford
9e47fc9f31
livecheck: move #preprocess_url into strategies
`Livecheck#preprocess_url` only contains logic for rewriting Git URLs,
so it makes more sense for this code to be part of the `Git` strategy
instead. Outside of better code organization, this saves us from
having to maintain the list of strategies to skip processing (which
is sometimes forgotten when a new strategy is added) and makes it
easier to do something similar in other strategies as needed.

One thing to note is that `Livecheck#preprocess_url` was previously
called on the URL before each strategy's `#match?` method was called.
To maintain the existing behavior, this calls `Git#preprocess_url` in
`Git#match?`. However, we need the processed URL when we use the `Git`
strategy, so we have to call `Git#preprocess_url` again. To avoid
duplicating effort, I've added a `@processed_urls` hash to the `Git`
strategy and have set up `Git#preprocess_url` to cache processed
URLs, so we only do the work once. There may be a better way of
handling it but this seems to work as expected.
2024-09-28 11:29:07 -04:00
Bo Anderson
0ae1dbeacf
Add typing for Cask#url and fix detected issues 2024-08-23 16:39:23 +01:00
Bo Anderson
f877fc5058
livecheck: remove module_function 2024-08-23 04:57:28 +01:00
Sam Ford
0a2e9661b6
Strategy#from_url: remove unused param
The `url_provided` parameter of the `Strategy#from_url` method was
originally introduced in #9529 but I removed it in a later commit in
that PR in favor of a different approach. Unfortunately, I forgot to
remove the `url_provided` parameter, as it was no longer needed after
that change. This removes the parameter and updates `#from_url` calls
accordingly.
2024-07-25 13:41:40 -04:00
Sam Ford
34fbf09841
Merge pull request #17842 from sazriel26/livecheck-for-head-only
[livecheck] Help to check head only formulae
2024-07-25 13:40:08 -04:00
Sam Ford
fcaeacd0da
livecheck: remove unused URI require
`URI#parse` was originally added in #9074 and replaced with
`Addressable::URI#parse` in #13306 but `require "uri"` wasn't removed
at the time. livecheck doesn't use `URI` now, so this removes the
unused `require`.
2024-07-25 12:41:34 -04:00
Sam Ford
f23d0ce373
livecheck: convert head-only strings to Versions
`brew livecheck` currently gives a Sorbet type error when run on a
HEAD-only formula: `Parameter 'version': Expected type Version, got
type String with value "c06c10d"`. This happens because the `current`
and `latest` values are strings but `LivecheckVersion#create` expects
a `Version` object.

This addresses the issue by creating a `Version` object from the
related commit strings. This ensures that the type of these variables
is more uniform, which makes them easier to reason about.
2024-07-25 10:23:39 -04:00
Sharon Azriel
31f4570cc2
[livecheck] Help to check head only formulae 2024-07-25 10:22:05 -04:00
Sam Ford
11d6785bea
Add utils/backtrace requires
This is primarily intended to resolve the `uninitialized constant
Utils::Backtrace` error in `formula_versions.rb:60` but I expanded it
to try to cover all existing usage of `Utils::Backtrace`.

I've followed the existing pattern, where `utils/backtrace` is
required in the context of where it's used. Many of these cases use
`Backtrace` in a conditional manner, so I've tried to ensure that the
`require` follows suit.
2024-07-15 17:48:47 -04:00
Bevan Kay
6c90e65f6f
livecheck/livecheck: fix passing an alternative url 2024-05-08 15:02:43 +10:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Sam Ford
111ac5810c
livecheck: Clean up whitespace, ordering 2024-03-31 21:01:40 -04:00
Sam Ford
a4134125f2
livecheck: Clarify --extract-plist behavior
From the description of the `--extract-plist` option, it would seem
that the `ExtractPlist` strategy is only enabled when the option is
used. Instead, livecheck automatically enables the strategy if the
command is run on only one cask. This rewords descriptions of the
option to clarify the behavior.
2024-03-31 21:01:40 -04:00
Sam Ford
a8d506fdda
livecheck: Add ExtractPlist skip to SkipConditions
When the `--extract-plist` option was added to livecheck, conditions
were added in `#run_checks` to skip casks using `ExtractPlist` if the
`--extract-plist` isn't used and the run involves multiple
formulae/casks. This integrates the skip into the `SkipConditions`
class.
2024-03-31 21:01:39 -04:00
Sam Ford
25d07c3838
livecheck: Add throttle info to debug, JSON output 2024-03-21 10:11:50 -04:00
Michael Cho
bfec6eecac
livecheck: support throttle DSL
Signed-off-by: Michael Cho <michael@michaelcho.dev>
2024-03-21 10:11:49 -04:00
Razvan Azamfirei
4129200b96
livecheck: add --extract-plist switch 2024-03-21 11:50:27 +00:00
Mike McQuaid
ea2892f8ee
brew.rb: handle missing args. 2024-03-07 16:20:20 +00:00
Issy Long
c86a402110
Fix RuboCop Lint/RedundantDirGlobSort offenses 2024-02-24 23:59:31 +00:00
Bo Anderson
89531e9ff3
Update all dependencies 2023-12-15 16:24:46 +00:00
Bo Anderson
5692c8ecbf
Fix style violations under newer RuboCop 2023-12-14 05:47:12 +00:00
Mike McQuaid
79a6091d08
Cask#full_name: properly output Homebrew org names
This was not returning the full name correctly for e.g. anything in
Homebrew/homebrew-fonts.

While we're here, fix up a few other places where `tap.core_cask_tap?`
can be used more appropriately.
2023-12-13 13:17:12 +00:00
Douglas Eichelberger
4a062b117c Rename block var 2023-12-12 10:19:58 -08:00
Douglas Eichelberger
e8d87fe256 Strict type livecheck/livecheck 2023-12-12 10:10:18 -08:00
Douglas Eichelberger
c75fc63d61 refactor out except! calls 2023-12-12 10:09:49 -08:00
Bo Anderson
b42256d286
Deprecate, disable & delete code for Homebrew 4.2.0 2023-12-07 23:42:13 +00:00
Bo Anderson
582049454f
vendor/bundle/ruby: cleanup unneeded files 2023-09-26 18:39:57 +01:00
apainintheneck
85bd4c7e1f utils/backtrace: scrub sorbet-runtime from backtrace
Ever since we started using this at runtime it's been polluting
the backtrace output. This makes it harder to debug errors and
increases the amount of info users have to paste into the box
when filing an issue.

This is a very direct approach. Essentially, we strip out
everything related to the `sorbet-runtime` gem whenever the top
line in the backtrace is unrelated to sorbet-runtime.

The hope is that this will allow errors related to sorbet to
be diagnosed easily while also reducing the backtrace size
for all other types of errors.

Sometimes it is useful to see the full backtrace though.
For those cases, we include the full backtrace when
`--verbose` is passed in and print a warning that the
Sorbet lines have been removed from the backtrace the
first time they are removed.

Note: This requires gems to be set up so that the call to
`Gem.paths.home` works correctly. For that reason, it must
be included after `utils/gems` which is included in
`standalone/load_path` already.
2023-09-21 21:07:22 -07:00
Sam Ford
88109b16c3
Livecheck#preprocess_url: compare with URI host
We now have a `gitea` formula in homebrew/core and its `stable` URL
uses a dl.gitea.com tarball. Since the URL's domain is gitea.com,
livecheck tries to preprocess the URL into a `.git` URL but the
resulting URL doesn't work because it's not a Git repository.

Gitea repositories use gitea.com (with no subdomain), so
`#preprocess_url` should be comparing the URI host (`dl.gitea.com`)
instead of the domain (`gitea.com`). This change allows gitea.com
repository URLs to continue to be preprocessed into a `.git` URL
while dl.gitea.com URLs are left untouched.

This makes the same change for the other domains, as they don't use
a subdomain either.
2023-09-04 00:49:23 -04:00
Patrick Linnane
1c4073df38
Livecheck: allow quiet output with --newer-only 2023-08-15 17:43:36 -07:00