Repository navigation
Expand file tree
/
Copy pathdeprecated-env.ts
More file actions
91 lines (82 loc) · 3.47 KB
/
Copy pathdeprecated-env.ts
File metadata and controls
91 lines (82 loc) · 3.47 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function shownEnvValue(rawValue: string): string {
const singleLine = rawValue.replace(/[\r\n]/g, " ");
if (singleLine.length <= 80) {
return singleLine;
}
return `${singleLine.slice(0, 77)}...`;
}
// USE_PIPELINE exposes these two tools, but they live in the `ci` toolset, not `pipelines`.
// Suggesting `ci` would also turn on catalog tools the flag does not expose.
const LEGACY_TOOLS_OUTSIDE_NAMED_TOOLSET: Readonly<Record<string, string>> = {
pipelines: "validate_ci_lint,validate_project_ci_lint",
};
function legacyToolsetReplacement(toolset: string): string {
const toolsets = `GITLAB_TOOLSETS=core,${toolset}`;
const extraTools = LEGACY_TOOLS_OUTSIDE_NAMED_TOOLSET[toolset];
if (extraTools === undefined) {
return toolsets;
}
return `${toolsets} and GITLAB_TOOLS=${extraTools}`;
}
function legacyToolsetWarning(envName: string, rawValue: string, toolset: string): string {
// An explicit GITLAB_TOOLSETS list replaces the default toolsets; it does not merge.
// Legacy USE_* flags add tools on top of defaults, so the hint must keep `core`.
const replacement = legacyToolsetReplacement(toolset);
if (rawValue === "true") {
return (
`${envName} is deprecated and will be removed in the next major version. ` +
`Use ${replacement} instead.`
);
}
const shown = shownEnvValue(rawValue);
return (
`${envName} is set to "${shown}" and is deprecated. ` +
`This value does not enable the ${toolset} toolset. Remove it. ` +
`Set ${replacement} only if you want those tools in addition to core.`
);
}
export interface DeprecatedEnvInput {
readOnlyMode: boolean;
/** Value the user set for GITLAB_PERMISSION_MODE / --permission-mode, before GITLAB_READ_ONLY_MODE overrides it. */
permissionModeRaw: string | undefined;
allowedGroupsRaw: string | undefined;
oauthAllowedGroupsRaw: string | undefined;
useWikiRaw: string | undefined;
useMilestoneRaw: string | undefined;
usePipelineRaw: string | undefined;
}
/**
* Builds startup warnings for deprecated env vars / CLI flags.
* Pure function so the messages and conflict detection are unit-testable.
*/
export function getDeprecatedEnvWarnings(input: DeprecatedEnvInput): string[] {
const warnings: string[] = [];
if (input.readOnlyMode) {
const conflict =
input.permissionModeRaw !== undefined && input.permissionModeRaw !== "readonly"
? ` It OVERRIDES the configured permission mode "${input.permissionModeRaw}"; the server runs as "readonly".`
: "";
warnings.push(
"GITLAB_READ_ONLY_MODE is deprecated and will be removed in the next major version. " +
`Use GITLAB_PERMISSION_MODE=readonly or --permission-mode=readonly instead.${conflict}`
);
}
if (input.allowedGroupsRaw) {
warnings.push(
input.oauthAllowedGroupsRaw
? "GITLAB_ALLOWED_GROUPS is deprecated and ignored because GITLAB_OAUTH_ALLOWED_GROUPS is set. Remove it."
: "GITLAB_ALLOWED_GROUPS is deprecated and will be removed in the next major version. Use GITLAB_OAUTH_ALLOWED_GROUPS instead."
);
}
const legacyToolsetFlags: Array<[string | undefined, string, string]> = [
[input.useWikiRaw, "USE_GITLAB_WIKI", "wiki"],
[input.useMilestoneRaw, "USE_MILESTONE", "milestones"],
[input.usePipelineRaw, "USE_PIPELINE", "pipelines"],
];
for (const [rawValue, envName, toolset] of legacyToolsetFlags) {
if (rawValue !== undefined) {
warnings.push(legacyToolsetWarning(envName, rawValue, toolset));
}
}
return warnings;
}