-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: centralize semver-aware cooldown calculation #14600
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
markhallen
wants to merge
8
commits into
main
Choose a base branch
from
feat/extract-cooldown-calculation-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b75885e
refactor: extract shared cooldown calculations
markhallen 46fedcf
feat: apply semver-aware cooldown across checkers
markhallen 2eaf27b
Fix Sorbet type errors for DAY_IN_SECONDS and unnecessary T.must calls
markhallen 92dd35d
fix: change Sorbet type from strict to strong in cooldown calculation…
markhallen 7768354
Address review feedback: guard against edge cases in within_cooldown_…
markhallen db7ae68
Merge branch 'main' into feat/extract-cooldown-calculation-pr
markhallen 6a275a8
Fix within_cooldown_window?: keep future releases in cooldown
markhallen d872afc
refactor: remove duplicated DAY_IN_SECONDS, delegate to CooldownCalcu…
markhallen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
53 changes: 53 additions & 0 deletions
53
common/lib/dependabot/update_checkers/cooldown_calculation.rb
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # typed: strong | ||
| # frozen_string_literal: true | ||
|
|
||
| require "sorbet-runtime" | ||
| require "dependabot/package/release_cooldown_options" | ||
| require "dependabot/version" | ||
|
|
||
| module Dependabot | ||
| module UpdateCheckers | ||
| # Shared utility module for cooldown period calculations. | ||
| # | ||
| # Provides stateless module methods used by ecosystem update checkers | ||
| # to determine whether a release is within its cooldown window and | ||
| # how many cooldown days apply for a given version bump. | ||
| module CooldownCalculation | ||
| extend T::Sig | ||
|
|
||
| DAY_IN_SECONDS = T.let(24 * 60 * 60, Integer) | ||
|
|
||
| sig { params(release_date: Time, cooldown_days: Integer).returns(T::Boolean) } | ||
| def self.within_cooldown_window?(release_date, cooldown_days) | ||
| (Time.now.to_i - release_date.to_i) < (cooldown_days * DAY_IN_SECONDS) | ||
| end | ||
|
|
||
| sig do | ||
| params( | ||
| cooldown: Dependabot::Package::ReleaseCooldownOptions, | ||
| current_version: T.nilable(Dependabot::Version), | ||
| new_version: Dependabot::Version | ||
| ).returns(Integer) | ||
| end | ||
| def self.cooldown_days_for(cooldown, current_version, new_version) | ||
| return cooldown.default_days unless current_version | ||
|
|
||
| cooldown.cooldown_days_for( | ||
| current_version.semver_parts, | ||
| new_version.semver_parts | ||
| ) | ||
| end | ||
|
|
||
| sig do | ||
| params( | ||
| cooldown: T.nilable(Dependabot::Package::ReleaseCooldownOptions), | ||
| dependency_name: String, | ||
| cooldown_enabled: T::Boolean | ||
| ).returns(T::Boolean) | ||
| end | ||
| def self.skip_cooldown?(cooldown, dependency_name, cooldown_enabled: true) | ||
| cooldown.nil? || !cooldown_enabled || !cooldown.included?(dependency_name) | ||
| end | ||
| end | ||
| end | ||
| end | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.