-
Notifications
You must be signed in to change notification settings - Fork 67.1k
Expand file tree
/
Copy pathshort-versions.ts
More file actions
33 lines (29 loc) · 972 Bytes
/
short-versions.ts
File metadata and controls
33 lines (29 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// This module creates shortcuts for version comparisons in Liquid conditional strings.
//
// Supported:
// {% if fpt %}
// {% if ghec %}
// {% if ghes %}
//
// For the custom operator handling in statements like {% if ghes > 3.0 %}, see `lib/liquid-tags/if-ver.js`.
import type { ExtendedRequest } from '@/types.js'
import type { Response, NextFunction } from 'express'
export default async function shortVersions(
req: ExtendedRequest,
res: Response | null,
next: NextFunction,
): Promise<void> {
if (!req.context) throw new Error('No context on request')
const { currentVersion, currentVersionObj } = req.context
if (!currentVersionObj) {
return next()
}
// Add the short name to context.
req.context[currentVersionObj.shortName] = true
// Add convenience props.
if (currentVersion) {
req.context.currentRelease = currentVersion.split('@')[1]
req.context.currentVersionShortName = currentVersionObj.shortName
}
return next()
}