Skip to content

Commit a021e9f

Browse files
authored
feat: currentVersionAgeInDays, newVersionAgeInDays (#31818)
1 parent b7e5adb commit a021e9f

File tree

10 files changed

+173
-30
lines changed

10 files changed

+173
-30
lines changed

docs/usage/configuration-options.md

+1
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,7 @@ Here are some example `matchJsonata` strings for inspiration:
28692869
$exists(deprecationMessage)
28702870
$exists(vulnerabilityFixVersion)
28712871
manager = 'dockerfile' and depType = 'final'
2872+
updateType = 'major' and newVersionAgeInDays < 7
28722873
```
28732874

28742875
`matchJsonata` accepts an array of strings, and will return `true` if any of those JSONata expressions evaluate to `true`.

lib/config/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ export interface PackageRuleInputConfig extends Record<string, unknown> {
548548
packageRules?: (PackageRule & PackageRuleInputConfig)[];
549549
releaseTimestamp?: string | null;
550550
repository?: string;
551+
currentVersionAgeInDays?: number;
551552
currentVersionTimestamp?: string;
552553
enabled?: boolean;
553554
skipReason?: SkipReason;

lib/modules/manager/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export interface LookupUpdate {
9999
checksumUrl?: string;
100100
downloadUrl?: string;
101101
releaseTimestamp?: any;
102+
newVersionAgeInDays?: number;
102103
registryUrl?: string;
103104
}
104105

lib/util/date.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ describe('util/date', () => {
2222
const t = t0.minus({ days: 42 });
2323
expect(getElapsedDays(t.toISO()!)).toBe(42);
2424
});
25+
26+
it('rounds down', () => {
27+
const t = t0.minus({ days: 42, hours: 12 });
28+
expect(getElapsedDays(t.toISO()!)).toBe(42);
29+
});
2530
});
2631

2732
describe('getElapsedMinutes', () => {

lib/util/date.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { DateTime } from 'luxon';
22

33
const ONE_MINUTE_MS = 60 * 1000;
4-
const ONE_DAY_MS = 24 * 60 * ONE_MINUTE_MS;
54

65
export function getElapsedDays(timestamp: string): number {
7-
return Math.floor(
8-
(new Date().getTime() - new Date(timestamp).getTime()) / ONE_DAY_MS,
9-
);
6+
const currentVersionTimestampDate = DateTime.fromISO(timestamp);
7+
const now = DateTime.now();
8+
const diffInDays = now.diff(currentVersionTimestampDate, 'days').as('days');
9+
const ageInDays = Math.floor(diffInDays);
10+
return ageInDays;
1011
}
1112

1213
export function getElapsedMinutes(date: Date): number {

lib/util/template/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export const allowedFields = {
156156
currentValue: 'The extracted current value of the dependency being updated',
157157
currentVersion:
158158
'The version that would be currently installed. For example, if currentValue is ^3.0.0 then currentVersion might be 3.1.0.',
159+
currentVersionAgeInDays: 'The age of the current version in days',
159160
currentVersionTimestamp: 'The timestamp of the current version',
160161
currentDigest: 'The extracted current digest of the dependency being updated',
161162
currentDigestShort:
@@ -203,6 +204,7 @@ export const allowedFields = {
203204
newValue:
204205
'The new value in the upgrade. Can be a range or version e.g. "^3.0.0" or "3.1.0"',
205206
newVersion: 'The new version in the upgrade, e.g. "3.1.0"',
207+
newVersionAgeInDays: 'The age of the new version in days',
206208
packageFile: 'The filename that the dependency was found in',
207209
packageFileDir:
208210
'The directory with full path where the packageFile was found',

lib/workers/repository/process/lookup/generate.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Release } from '../../../../modules/datasource';
44
import type { LookupUpdate } from '../../../../modules/manager/types';
55
import type { VersioningApi } from '../../../../modules/versioning';
66
import type { RangeStrategy } from '../../../../types';
7+
import { getElapsedDays } from '../../../../util/date';
78
import { getMergeConfidenceLevel } from '../../../../util/merge-confidence';
89
import type { LookupUpdateConfig } from './types';
910
import { getUpdateType } from './update-type';
@@ -37,8 +38,9 @@ export async function generateUpdate(
3738
update.newDigest = release.newDigest;
3839
}
3940
// istanbul ignore if
40-
if (release.releaseTimestamp !== undefined) {
41+
if (release.releaseTimestamp) {
4142
update.releaseTimestamp = release.releaseTimestamp;
43+
update.newVersionAgeInDays = getElapsedDays(release.releaseTimestamp);
4244
}
4345
// istanbul ignore if
4446
if (release.registryUrl !== undefined) {

0 commit comments

Comments
 (0)