Skip to content
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

livecheck: move #preprocess_url into strategies #18455

Conversation

samford
Copy link
Member

@samford samford commented Sep 28, 2024

  • 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?

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.

@samford samford force-pushed the livecheck/move-preprocess-url-into-strategies branch from beb5431 to b54b2bf Compare September 28, 2024 15:26
`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.
@samford samford force-pushed the livecheck/move-preprocess-url-into-strategies branch from b54b2bf to 9e47fc9 Compare September 28, 2024 15:29
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Seems fine, thanks @samford!

@MikeMcQuaid MikeMcQuaid merged commit 490a553 into Homebrew:master Sep 30, 2024
27 checks passed
@samford samford deleted the livecheck/move-preprocess-url-into-strategies branch September 30, 2024 12:30
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