forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(endoflife): Mock time (renovatebot#22575)
- Loading branch information
Showing
5 changed files
with
58 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,35 @@ | ||
import { DateTime } from 'luxon'; | ||
import { z } from 'zod'; | ||
import { UtcDate } from '../../../util/schema-utils'; | ||
import type { Release } from '../types'; | ||
|
||
const EndoflifeDateVersionScheme = z | ||
const ExpireableField = z.union([ | ||
UtcDate.transform((x) => { | ||
const now = DateTime.now().toUTC(); | ||
return x <= now; | ||
}), | ||
z.boolean(), | ||
]); | ||
|
||
export const EndoflifeDateVersions = z | ||
.object({ | ||
cycle: z.string(), | ||
latest: z.optional(z.string()), | ||
releaseDate: z.optional(z.string()), | ||
eol: z.optional(z.union([z.string(), z.boolean()])), | ||
discontinued: z.optional(z.union([z.string(), z.boolean()])), | ||
eol: z.optional(ExpireableField), | ||
discontinued: z.optional(ExpireableField), | ||
}) | ||
.transform(({ cycle, latest, releaseDate, eol, discontinued }): Release => { | ||
let isDeprecated = false; | ||
|
||
// If "eol" date or "discontinued" date has passed or any of the values is explicitly true, set to deprecated | ||
// "support" is not checked because support periods sometimes end before the EOL. | ||
if ( | ||
eol === true || | ||
discontinued === true || | ||
(typeof eol === 'string' && | ||
DateTime.fromISO(eol, { zone: 'utc' }) <= DateTime.now().toUTC()) || | ||
(typeof discontinued === 'string' && | ||
DateTime.fromISO(discontinued, { zone: 'utc' }) <= | ||
DateTime.now().toUTC()) | ||
) { | ||
isDeprecated = true; | ||
} | ||
|
||
let version = cycle; | ||
if (latest !== undefined) { | ||
version = latest; | ||
.transform( | ||
({ | ||
cycle, | ||
latest, | ||
releaseDate: releaseTimestamp, | ||
eol, | ||
discontinued, | ||
}): Release => { | ||
const version = latest ?? cycle; | ||
const isDeprecated = eol === true || discontinued === true; | ||
return { version, releaseTimestamp, isDeprecated }; | ||
} | ||
|
||
return { | ||
version, | ||
releaseTimestamp: releaseDate, | ||
isDeprecated, | ||
}; | ||
}); | ||
|
||
export const EndoflifeHttpResponseScheme = z.array(EndoflifeDateVersionScheme); | ||
) | ||
.array(); |
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