@narumitw/pi-starship 0.55.1 → 0.55.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
- package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
- package/dist/chunks/commands-ATILSUVK.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +20 -55
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +588 -618
- package/src/config.ts +580 -660
- package/src/effective-config.ts +46 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +101 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +57 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +22 -24
- package/src/modules/render.ts +124 -140
- package/src/modules/thinking.ts +27 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +125 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -603
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- package/dist/chunks/package-LG5H7BBM.js.map +0 -7
package/src/runtime/github-pr.ts
CHANGED
|
@@ -7,338 +7,309 @@ const MAX_GH_OUTPUT_BYTES = 128 * 1024;
|
|
|
7
7
|
const MAX_URL_LENGTH = 4_096;
|
|
8
8
|
const MAX_CHECKS = 1_000;
|
|
9
9
|
const MAX_FIELD_LENGTH = 128;
|
|
10
|
-
const RFC3339_TIMESTAMP =
|
|
11
|
-
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(?:Z|[+-](\d{2}):(\d{2}))$/u;
|
|
10
|
+
const RFC3339_TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(?:Z|[+-](\d{2}):(\d{2}))$/u;
|
|
12
11
|
export const TERMINAL_PR_LIFETIME_MS = 24 * 60 * 60 * 1_000;
|
|
13
12
|
|
|
14
13
|
const GH_PR_FIELDS = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
"number",
|
|
15
|
+
"isDraft",
|
|
16
|
+
"url",
|
|
17
|
+
"state",
|
|
18
|
+
"closedAt",
|
|
19
|
+
"mergedAt",
|
|
20
|
+
"reviewDecision",
|
|
21
|
+
"statusCheckRollup",
|
|
23
22
|
] as const;
|
|
24
23
|
|
|
25
24
|
interface GithubPrQueryOptions {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
platform?: NodeJS.Platform;
|
|
26
|
+
environment?: Readonly<Record<string, string | undefined>>;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
interface CheckSummary {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
failed: number;
|
|
31
|
+
pending: number;
|
|
32
|
+
total: number;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
type PullRequestState = "OPEN" | "CLOSED" | "MERGED";
|
|
37
36
|
type ReviewDecision = "APPROVED" | "CHANGES_REQUESTED" | "REVIEW_REQUIRED" | "";
|
|
38
37
|
|
|
39
38
|
export function ghPrViewInvocation(platform: NodeJS.Platform = process.platform): {
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
command: string;
|
|
40
|
+
args: string[];
|
|
42
41
|
} {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
return {
|
|
43
|
+
command: platform === "win32" ? "gh.exe" : "gh",
|
|
44
|
+
args: ["pr", "view", "--json", GH_PR_FIELDS.join(",")],
|
|
45
|
+
};
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
export function githubPrEnvironment(
|
|
50
|
-
|
|
49
|
+
source: Readonly<Record<string, string | undefined>> = process.env,
|
|
51
50
|
): Record<string, string | undefined> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
const environment: Record<string, string | undefined> = Object.create(null);
|
|
52
|
+
for (const [name, value] of Object.entries(source)) {
|
|
53
|
+
const normalized = name.toUpperCase();
|
|
54
|
+
if (normalized === "GH_HOST" || normalized === "GH_REPO") continue;
|
|
55
|
+
Object.defineProperty(environment, name, {
|
|
56
|
+
value,
|
|
57
|
+
writable: true,
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return environment;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
export async function queryGithubPr(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
exec: WorkspaceExec,
|
|
67
|
+
cwd: string,
|
|
68
|
+
signal?: AbortSignal,
|
|
69
|
+
now = Date.now(),
|
|
70
|
+
options: GithubPrQueryOptions = {},
|
|
72
71
|
): Promise<GithubPrSnapshot | undefined> {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
72
|
+
const invocation = ghPrViewInvocation(options.platform);
|
|
73
|
+
try {
|
|
74
|
+
const result = await exec(invocation.command, invocation.args, {
|
|
75
|
+
cwd,
|
|
76
|
+
signal,
|
|
77
|
+
timeout: GH_TIMEOUT_MS,
|
|
78
|
+
maxOutputBytes: MAX_GH_OUTPUT_BYTES,
|
|
79
|
+
environment: githubPrEnvironment(options.environment),
|
|
80
|
+
});
|
|
81
|
+
if (result.killed || result.code !== 0) return undefined;
|
|
82
|
+
if (Buffer.byteLength(result.stdout) > MAX_GH_OUTPUT_BYTES) return undefined;
|
|
83
|
+
return buildGithubPrSnapshot(JSON.parse(result.stdout), now);
|
|
84
|
+
} catch {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
export function buildGithubPrSnapshot(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const checks = summarizeChecks(pr.statusCheckRollup);
|
|
104
|
-
const expiresAt = terminalExpiry(state, closedAt, mergedAt);
|
|
105
|
-
if (state !== "OPEN" && (expiresAt === undefined || now >= expiresAt)) return undefined;
|
|
89
|
+
export function buildGithubPrSnapshot(value: unknown, now = Date.now()): GithubPrSnapshot | undefined {
|
|
90
|
+
try {
|
|
91
|
+
const pr = record(value);
|
|
92
|
+
const number = positiveInteger(pr.number);
|
|
93
|
+
const isDraft = requiredBoolean(pr.isDraft);
|
|
94
|
+
const url = requiredBoundedString(pr.url, MAX_URL_LENGTH, true);
|
|
95
|
+
const state = pullRequestState(pr.state);
|
|
96
|
+
const closedAt = optionalTimestamp(pr.closedAt);
|
|
97
|
+
const mergedAt = optionalTimestamp(pr.mergedAt);
|
|
98
|
+
const reviewDecision = reviewDecisionValue(pr.reviewDecision);
|
|
99
|
+
const checks = summarizeChecks(pr.statusCheckRollup);
|
|
100
|
+
const expiresAt = terminalExpiry(state, closedAt, mergedAt);
|
|
101
|
+
if (state !== "OPEN" && (expiresAt === undefined || now >= expiresAt)) return undefined;
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
103
|
+
const presentationState: GithubPrState =
|
|
104
|
+
state === "MERGED" ? "merged" : state === "CLOSED" ? "closed" : isDraft ? "draft" : "open";
|
|
105
|
+
const checksText = formatChecks(checks);
|
|
106
|
+
const review = formatReview(reviewDecision);
|
|
107
|
+
const status = compactStatus(presentationState, checks, checksText, review);
|
|
108
|
+
const snapshot: GithubPrSnapshot = {
|
|
109
|
+
number: String(number),
|
|
110
|
+
link: osc8Link(url, `#${number}`),
|
|
111
|
+
state: presentationState,
|
|
112
|
+
checks: checksText,
|
|
113
|
+
review,
|
|
114
|
+
status,
|
|
115
|
+
...(expiresAt === undefined ? {} : { expiresAt }),
|
|
116
|
+
};
|
|
117
|
+
return Object.freeze(snapshot);
|
|
118
|
+
} catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
125
121
|
}
|
|
126
122
|
|
|
127
123
|
export function githubPrSnapshotEqual(
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
left: GithubPrSnapshot | undefined,
|
|
125
|
+
right: GithubPrSnapshot | undefined,
|
|
130
126
|
): boolean {
|
|
131
|
-
|
|
127
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
132
128
|
}
|
|
133
129
|
|
|
134
130
|
function terminalExpiry(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
state: PullRequestState,
|
|
132
|
+
closedAt: number | undefined,
|
|
133
|
+
mergedAt: number | undefined,
|
|
138
134
|
): number | undefined {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
if (state === "OPEN") return undefined;
|
|
136
|
+
const terminalAt = state === "MERGED" ? mergedAt : closedAt;
|
|
137
|
+
return terminalAt === undefined ? undefined : terminalAt + TERMINAL_PR_LIFETIME_MS;
|
|
142
138
|
}
|
|
143
139
|
|
|
144
140
|
function summarizeChecks(value: unknown): CheckSummary {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
141
|
+
if (!Array.isArray(value) || value.length > MAX_CHECKS) throw new Error("Invalid PR checks");
|
|
142
|
+
const summary: CheckSummary = { failed: 0, pending: 0, total: value.length };
|
|
143
|
+
for (const item of value) {
|
|
144
|
+
const check = record(item);
|
|
145
|
+
const state = optionalUppercase(check.state);
|
|
146
|
+
const status = optionalUppercase(check.status);
|
|
147
|
+
const conclusion = optionalUppercase(check.conclusion);
|
|
148
|
+
if (state === "SUCCESS") continue;
|
|
149
|
+
if (state === "FAILURE" || state === "ERROR") {
|
|
150
|
+
summary.failed += 1;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (state === "PENDING" || state === "EXPECTED") {
|
|
154
|
+
summary.pending += 1;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (status && status !== "COMPLETED") {
|
|
158
|
+
summary.pending += 1;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (conclusion === "SUCCESS" || conclusion === "SKIPPED" || conclusion === "NEUTRAL") {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (
|
|
165
|
+
conclusion === "FAILURE" ||
|
|
166
|
+
conclusion === "CANCELLED" ||
|
|
167
|
+
conclusion === "TIMED_OUT" ||
|
|
168
|
+
conclusion === "ACTION_REQUIRED" ||
|
|
169
|
+
conclusion === "STARTUP_FAILURE"
|
|
170
|
+
) {
|
|
171
|
+
summary.failed += 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
summary.pending += 1;
|
|
175
|
+
}
|
|
176
|
+
return summary;
|
|
181
177
|
}
|
|
182
178
|
|
|
183
179
|
function formatChecks(checks: CheckSummary): string {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
compactCount("…", checks.pending),
|
|
190
|
-
]
|
|
191
|
-
.filter(Boolean)
|
|
192
|
-
.join(" ");
|
|
180
|
+
if (checks.total === 0) return "-";
|
|
181
|
+
const passed = checks.total - checks.failed - checks.pending;
|
|
182
|
+
return [compactCount("✓", passed), compactCount("×", checks.failed), compactCount("…", checks.pending)]
|
|
183
|
+
.filter(Boolean)
|
|
184
|
+
.join(" ");
|
|
193
185
|
}
|
|
194
186
|
|
|
195
187
|
function compactCount(symbol: string, count: number): string {
|
|
196
|
-
|
|
188
|
+
return count > 0 ? `${symbol}${count}` : "";
|
|
197
189
|
}
|
|
198
190
|
|
|
199
191
|
function formatReview(review: ReviewDecision): string {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
192
|
+
if (review === "APPROVED") return "R✓";
|
|
193
|
+
if (review === "CHANGES_REQUESTED") return "R×";
|
|
194
|
+
if (review === "REVIEW_REQUIRED") return "R?";
|
|
195
|
+
return "";
|
|
204
196
|
}
|
|
205
197
|
|
|
206
|
-
function compactStatus(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (checks.failed > 0) return compactCount("×", checks.failed);
|
|
216
|
-
if (review === "R×") return review;
|
|
217
|
-
if (checks.pending > 0) return compactCount("…", checks.pending);
|
|
218
|
-
if (review === "R✓" || review === "R?") return review;
|
|
219
|
-
return checksText;
|
|
198
|
+
function compactStatus(state: GithubPrState, checks: CheckSummary, checksText: string, review: string): string {
|
|
199
|
+
if (state === "merged") return "M";
|
|
200
|
+
if (state === "closed") return "C";
|
|
201
|
+
if (state === "draft") return "D";
|
|
202
|
+
if (checks.failed > 0) return compactCount("×", checks.failed);
|
|
203
|
+
if (review === "R×") return review;
|
|
204
|
+
if (checks.pending > 0) return compactCount("…", checks.pending);
|
|
205
|
+
if (review === "R✓" || review === "R?") return review;
|
|
206
|
+
return checksText;
|
|
220
207
|
}
|
|
221
208
|
|
|
222
209
|
function osc8Link(value: string, label: string): string {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
210
|
+
if (!getCapabilities().hyperlinks || hasTerminalControls(value)) return label;
|
|
211
|
+
try {
|
|
212
|
+
const url = new URL(value);
|
|
213
|
+
if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password) {
|
|
214
|
+
return label;
|
|
215
|
+
}
|
|
216
|
+
const normalized = url.toString();
|
|
217
|
+
if (normalized.length > MAX_URL_LENGTH || hasTerminalControls(normalized)) return label;
|
|
218
|
+
return `\u001b]8;;${normalized}\u0007${label}\u001b]8;;\u0007`;
|
|
219
|
+
} catch {
|
|
220
|
+
return label;
|
|
221
|
+
}
|
|
235
222
|
}
|
|
236
223
|
|
|
237
224
|
function hasTerminalControls(value: string): boolean {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
);
|
|
245
|
-
});
|
|
225
|
+
return Array.from(value).some((character) => {
|
|
226
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
227
|
+
return (
|
|
228
|
+
codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) || (codePoint >= 0xd800 && codePoint <= 0xdfff)
|
|
229
|
+
);
|
|
230
|
+
});
|
|
246
231
|
}
|
|
247
232
|
|
|
248
233
|
function record(value: unknown): Record<string, unknown> {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
234
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
235
|
+
throw new Error("Expected PR object");
|
|
236
|
+
}
|
|
237
|
+
return value as Record<string, unknown>;
|
|
253
238
|
}
|
|
254
239
|
|
|
255
240
|
function positiveInteger(value: unknown): number {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
241
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
242
|
+
throw new Error("Invalid PR number");
|
|
243
|
+
}
|
|
244
|
+
return value;
|
|
260
245
|
}
|
|
261
246
|
|
|
262
247
|
function requiredBoolean(value: unknown): boolean {
|
|
263
|
-
|
|
264
|
-
|
|
248
|
+
if (typeof value !== "boolean") throw new Error("Invalid PR boolean");
|
|
249
|
+
return value;
|
|
265
250
|
}
|
|
266
251
|
|
|
267
252
|
function requiredBoundedString(value: unknown, maxLength: number, allowEmpty = false): string {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
) {
|
|
273
|
-
throw new Error("Invalid PR string");
|
|
274
|
-
}
|
|
275
|
-
return value;
|
|
253
|
+
if (typeof value !== "string" || value.length > maxLength || (!allowEmpty && value.length === 0)) {
|
|
254
|
+
throw new Error("Invalid PR string");
|
|
255
|
+
}
|
|
256
|
+
return value;
|
|
276
257
|
}
|
|
277
258
|
|
|
278
259
|
function optionalUppercase(value: unknown): string | undefined {
|
|
279
|
-
|
|
280
|
-
|
|
260
|
+
if (value === null || value === undefined || value === "") return undefined;
|
|
261
|
+
return requiredBoundedString(value, MAX_FIELD_LENGTH).toUpperCase();
|
|
281
262
|
}
|
|
282
263
|
|
|
283
264
|
function optionalTimestamp(value: unknown): number | undefined {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
minute > 59 ||
|
|
314
|
-
second > 59 ||
|
|
315
|
-
offsetHour > 23 ||
|
|
316
|
-
offsetMinute > 59
|
|
317
|
-
) {
|
|
318
|
-
throw new Error("Invalid PR timestamp");
|
|
319
|
-
}
|
|
320
|
-
const timestamp = Date.parse(text);
|
|
321
|
-
if (!Number.isFinite(timestamp)) throw new Error("Invalid PR timestamp");
|
|
322
|
-
return timestamp;
|
|
265
|
+
if (value === null || value === undefined || value === "") return undefined;
|
|
266
|
+
const text = requiredBoundedString(value, MAX_FIELD_LENGTH);
|
|
267
|
+
const match = RFC3339_TIMESTAMP.exec(text);
|
|
268
|
+
if (!match) throw new Error("Invalid PR timestamp");
|
|
269
|
+
const [, yearText, monthText, dayText, hourText, minuteText, secondText, offsetHourText, offsetMinuteText] = match;
|
|
270
|
+
const year = Number(yearText);
|
|
271
|
+
const month = Number(monthText);
|
|
272
|
+
const day = Number(dayText);
|
|
273
|
+
const hour = Number(hourText);
|
|
274
|
+
const minute = Number(minuteText);
|
|
275
|
+
const second = Number(secondText);
|
|
276
|
+
const offsetHour = Number(offsetHourText ?? 0);
|
|
277
|
+
const offsetMinute = Number(offsetMinuteText ?? 0);
|
|
278
|
+
if (
|
|
279
|
+
month < 1 ||
|
|
280
|
+
month > 12 ||
|
|
281
|
+
day < 1 ||
|
|
282
|
+
day > daysInMonth(year, month) ||
|
|
283
|
+
hour > 23 ||
|
|
284
|
+
minute > 59 ||
|
|
285
|
+
second > 59 ||
|
|
286
|
+
offsetHour > 23 ||
|
|
287
|
+
offsetMinute > 59
|
|
288
|
+
) {
|
|
289
|
+
throw new Error("Invalid PR timestamp");
|
|
290
|
+
}
|
|
291
|
+
const timestamp = Date.parse(text);
|
|
292
|
+
if (!Number.isFinite(timestamp)) throw new Error("Invalid PR timestamp");
|
|
293
|
+
return timestamp;
|
|
323
294
|
}
|
|
324
295
|
|
|
325
296
|
function daysInMonth(year: number, month: number): number {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
297
|
+
if (month === 2) {
|
|
298
|
+
const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
299
|
+
return leapYear ? 29 : 28;
|
|
300
|
+
}
|
|
301
|
+
return month === 4 || month === 6 || month === 9 || month === 11 ? 30 : 31;
|
|
331
302
|
}
|
|
332
303
|
|
|
333
304
|
function pullRequestState(value: unknown): PullRequestState {
|
|
334
|
-
|
|
335
|
-
|
|
305
|
+
if (value === "OPEN" || value === "CLOSED" || value === "MERGED") return value;
|
|
306
|
+
throw new Error("Invalid PR state");
|
|
336
307
|
}
|
|
337
308
|
|
|
338
309
|
function reviewDecisionValue(value: unknown): ReviewDecision {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
310
|
+
if (value === null || value === undefined || value === "" || value === "UNKNOWN") return "";
|
|
311
|
+
if (value === "APPROVED" || value === "CHANGES_REQUESTED" || value === "REVIEW_REQUIRED") {
|
|
312
|
+
return value;
|
|
313
|
+
}
|
|
314
|
+
throw new Error("Invalid PR review decision");
|
|
344
315
|
}
|