-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config/package-rules):
matchCurrentAge
(#23264)
Co-authored-by: Rhys Arkins <rhys@arkins.net> Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
- Loading branch information
1 parent
399b96e
commit 8970661
Showing
14 changed files
with
343 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,78 @@ | ||
import { DateTime } from 'luxon'; | ||
import { CurrentAgeMatcher } from './current-age'; | ||
|
||
describe('util/package-rules/current-age', () => { | ||
const matcher = new CurrentAgeMatcher(); | ||
|
||
describe('match', () => { | ||
const t0 = DateTime.fromISO('2023-07-07', { zone: 'utc' }); | ||
|
||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.setSystemTime(t0.toMillis()); | ||
}); | ||
|
||
it('returns false if release is older', () => { | ||
const result = matcher.matches( | ||
{ | ||
currentVersionTimestamp: '2020-01-01', | ||
}, | ||
{ | ||
matchCurrentAge: '< 1 year', // younger than 1 year | ||
}, | ||
); | ||
expect(result).toBeFalse(); | ||
}); | ||
|
||
it('returns false if release is younger', () => { | ||
const result = matcher.matches( | ||
{ | ||
currentVersionTimestamp: '2020-01-01', | ||
}, | ||
{ | ||
matchCurrentAge: '> 10 years', // older than 10 yrs | ||
}, | ||
); | ||
expect(result).toBeFalse(); | ||
}); | ||
|
||
it('returns null if release invalid', () => { | ||
const result = matcher.matches( | ||
{ | ||
currentVersionTimestamp: 'abc', | ||
}, | ||
{ | ||
matchCurrentAge: '> 2 days', // older than 2 days | ||
}, | ||
); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('returns false if release undefined', () => { | ||
const result = matcher.matches( | ||
{ | ||
currentVersionTimestamp: undefined, | ||
}, | ||
{ | ||
matchCurrentAge: '> 2 days', // older than 2 days | ||
}, | ||
); | ||
expect(result).toBeFalse(); | ||
}); | ||
|
||
it('returns true if age matches', () => { | ||
const result = matcher.matches( | ||
{ | ||
currentVersionTimestamp: '2020-01-01', | ||
}, | ||
{ | ||
matchCurrentAge: '> 3 years', // older than 3 years | ||
}, | ||
); | ||
expect(result).toBeTrue(); | ||
}); | ||
}); | ||
}); |
This file contains 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,21 @@ | ||
import is from '@sindresorhus/is'; | ||
import type { PackageRule, PackageRuleInputConfig } from '../../config/types'; | ||
import { satisfiesDateRange } from '../pretty-time'; | ||
import { Matcher } from './base'; | ||
|
||
export class CurrentAgeMatcher extends Matcher { | ||
override matches( | ||
{ currentVersionTimestamp }: PackageRuleInputConfig, | ||
{ matchCurrentAge }: PackageRule, | ||
): boolean | null { | ||
if (!is.string(matchCurrentAge)) { | ||
return null; | ||
} | ||
|
||
if (!is.string(currentVersionTimestamp)) { | ||
return false; | ||
} | ||
|
||
return satisfiesDateRange(currentVersionTimestamp, matchCurrentAge); | ||
} | ||
} |
This file contains 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 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 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 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.