@sequenceholdings/studio-cli 0.9.24 → 0.9.27
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/README.md +14 -2
- package/dist/app-preview/commands.d.ts +7 -0
- package/dist/app-preview/commands.js +264 -0
- package/dist/app-preview/fingerprint.d.ts +20 -0
- package/dist/app-preview/fingerprint.js +32 -0
- package/dist/app-preview/install.d.ts +31 -0
- package/dist/app-preview/install.js +53 -0
- package/dist/app-preview/namespace-probe.d.ts +13 -0
- package/dist/app-preview/namespace-probe.js +50 -0
- package/dist/app-preview/plan.d.ts +28 -0
- package/dist/app-preview/plan.js +41 -0
- package/dist/app-preview/run.d.ts +32 -0
- package/dist/app-preview/run.js +48 -0
- package/dist/app-preview/runners.d.ts +73 -0
- package/dist/app-preview/runners.js +226 -0
- package/dist/app-preview/secrets.d.ts +48 -0
- package/dist/app-preview/secrets.js +104 -0
- package/dist/app-preview/target.d.ts +28 -0
- package/dist/app-preview/target.js +62 -0
- package/dist/artifact/delegate.d.ts +0 -11
- package/dist/artifact/delegate.js +6 -127
- package/dist/artifact/sandbox.js +1 -1
- package/dist/auth.js +1 -3
- package/dist/command-help.d.ts +3 -3
- package/dist/command-help.js +7 -3
- package/dist/config.d.ts +0 -7
- package/dist/config.js +0 -12
- package/dist/edge-auth-headers.js +1 -18
- package/dist/functions/commands.d.ts +15 -0
- package/dist/functions/commands.js +67 -11
- package/dist/main.js +1 -1
- package/dist/registry/lifecycle-commands.js +7 -0
- package/dist/repos/commands.d.ts +1 -4
- package/dist/repos/commands.js +2 -19
- package/dist/templates/catalog.d.ts +1 -1
- package/dist/templates/catalog.js +1 -1
- package/package.json +8 -8
- package/release-summary.json +4 -1
- package/dist/preview.d.ts +0 -90
- package/dist/preview.js +0 -292
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequenceholdings/studio-cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.27",
|
|
4
4
|
"description": "Unified Sequence Studio CLI — `seq-studio init` / `add` / `deploy` (app monorepos), `seq-studio agents`, `seq-studio process` (Lattice), `seq-studio artifact`, `seq-studio functions` / `secrets`, `seq-studio repos`, and `seq-studio auth whoami`. Includes Auth0 browser login shared with seqapi.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
"tsx": "^4.20.3",
|
|
46
46
|
"yaml": "^2.8.4",
|
|
47
47
|
"zod": "4.6.6",
|
|
48
|
-
"@sequenceholdings/lattice": "0.1.9",
|
|
49
|
-
"@sequenceholdings/managed-functions": "0.5.14",
|
|
50
48
|
"@sequenceholdings/agent-spec": "0.1.6",
|
|
51
|
-
"@sequenceholdings/
|
|
49
|
+
"@sequenceholdings/lattice": "0.1.9",
|
|
50
|
+
"@sequenceholdings/artifact-studio": "0.11.23",
|
|
52
51
|
"@sequenceholdings/storage": "0.1.8",
|
|
52
|
+
"@sequenceholdings/managed-functions": "0.5.16",
|
|
53
53
|
"@sequenceholdings/platform": "0.1.5"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@sequenceholdings/orm": "2.
|
|
57
|
-
"@sequenceholdings/pipeline-spec": "0.3.
|
|
56
|
+
"@sequenceholdings/orm": "2.12.1",
|
|
57
|
+
"@sequenceholdings/pipeline-spec": "0.3.15"
|
|
58
58
|
},
|
|
59
59
|
"peerDependenciesMeta": {
|
|
60
60
|
"@sequenceholdings/orm": {
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"@types/semver": "^7.8.0",
|
|
71
71
|
"typescript": "^5.6.0",
|
|
72
72
|
"vitest": "^4.1.12",
|
|
73
|
-
"@sequenceholdings/orm": "2.
|
|
74
|
-
"@sequenceholdings/pipeline-spec": "0.3.
|
|
73
|
+
"@sequenceholdings/orm": "2.12.1",
|
|
74
|
+
"@sequenceholdings/pipeline-spec": "0.3.15"
|
|
75
75
|
},
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=20"
|
package/release-summary.json
CHANGED
|
@@ -7,5 +7,8 @@
|
|
|
7
7
|
"0.9.21": "New seq-studio docs search|read|list; repos clone adds agent docs guidance. Clones roll back on failure; new repos attach-login. Devbox sign-in no longer uses a shared identity. Browser login fails fast without a terminal. envs add accepts local:<name>. init and deploy flag lockfiles CI can't use.",
|
|
8
8
|
"0.9.22": "New init --github <owner>/<name> --org <org> starts an app in its own new private GitHub repository. repos pulls create and edit take --type (bug, performance, enhancement, feature, chore); a Pull needs one to merge. repo init adds a required pr-type check.",
|
|
9
9
|
"0.9.23": "ORM plans now accept retained table and column rename hints when previewing a fresh schema. Includes ORM 2.11.1 and updated dependent packages; incremental migrations retain rename-source validation.",
|
|
10
|
-
"0.9.24": "Artifact builds now use Atlas UI 4.0.0 and its DatePicker and DateRangePicker controls. Legacy public date field exports are removed."
|
|
10
|
+
"0.9.24": "Artifact builds now use Atlas UI 4.0.0 and its DatePicker and DateRangePicker controls. Legacy public date field exports are removed.",
|
|
11
|
+
"0.9.25": "function deploy --adopt, on a local Atlas running on a personal development database branch, takes over a function that a database copy brought from another runtime, so it deploys and runs there under its own slug.",
|
|
12
|
+
"0.9.26": "Includes ORM 2.12.0: resolved tables can set rows: { keys: 'indexed' } so a policy or link filter that probes them by key reaches every source's index instead of rebuilding the view per probed row. Atlas checks that only the generated view reads its key relations.",
|
|
13
|
+
"0.9.27": "Includes ORM 2.12.1: orm generate --migration-export writes compact JSON, so namespaces with many operations stay under the export size limit, and committed migration chain links carry their reviewed destructive flag, which repository CI reads as consent to apply that data loss."
|
|
11
14
|
}
|
package/dist/preview.d.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-PR preview-environment resolution for `seq-studio artifact`.
|
|
3
|
-
*
|
|
4
|
-
* Lets an engineer target a specific PR's Vercel preview deployment
|
|
5
|
-
* (`https://studio-atlas-git-<slug>.preview.seqholdings.com`) WITHOUT
|
|
6
|
-
* hand-editing `~/.config/seq-studio/config.toml`. See
|
|
7
|
-
* `docs/preview-environments.md` for the full lifecycle.
|
|
8
|
-
*
|
|
9
|
-
* SLUG ALGORITHM — must stay byte-for-byte in sync with the other
|
|
10
|
-
* places that compute the same slug from a branch name:
|
|
11
|
-
* - `.github/workflows/preview-deploy.yml` (replace non-alnum, lowercase, trim hyphens)
|
|
12
|
-
* - `.github/workflows/trigger-preview.yml` (same bash pipeline)
|
|
13
|
-
* - `atlas/src/server/db.ts:sanitize` (`.replace(/[^a-zA-Z0-9-]/g, '-').toLowerCase().replace(/^-+|-+$/g, '')`)
|
|
14
|
-
* - `databricks/lakebase/atlas-db/pr-lifecycle.ts:sanitize`
|
|
15
|
-
* Changing it here without changing those produces a host that does NOT
|
|
16
|
-
* match what `preview-deploy.yml` actually deployed.
|
|
17
|
-
*/
|
|
18
|
-
/** Cloudflare zone the preview aliases live on. */
|
|
19
|
-
export declare const PREVIEW_DOMAIN = "preview.seqholdings.com";
|
|
20
|
-
/** Vercel project name → the `<project>-git-<slug>` alias label prefix. */
|
|
21
|
-
export declare const PREVIEW_PROJECT = "studio-atlas";
|
|
22
|
-
/**
|
|
23
|
-
* Mirror of `preview-deploy.yml`'s `PROTECTED` list. A branch whose slug
|
|
24
|
-
* matches one of these (or starts with `dev-`) never gets a preview — the
|
|
25
|
-
* workflow's guard refuses to deploy it — so the CLI refuses to target it.
|
|
26
|
-
*/
|
|
27
|
-
export declare const PREVIEW_PROTECTED_SLUGS: readonly ["banksouth", "staging", "dev", "production", "main", "development", "master"];
|
|
28
|
-
/**
|
|
29
|
-
* Vercel deploys the preview under the DNS label `studio-atlas-git-<slug>`.
|
|
30
|
-
* A single DNS label can be at most 63 chars; Vercel hash-truncates labels
|
|
31
|
-
* past that, so the resulting host can NOT be computed from the slug and must
|
|
32
|
-
* be read back from the deployment. This is the SAME cutoff the workflow uses
|
|
33
|
-
* (`[ "${#LABEL}" -le 63 ]`).
|
|
34
|
-
*/
|
|
35
|
-
export declare const MAX_LABEL_LENGTH = 63;
|
|
36
|
-
/** Apply the canonical branch → slug transform. */
|
|
37
|
-
export declare function previewSlug(branchOrSlug: string): string;
|
|
38
|
-
/** The `studio-atlas-git-<slug>` DNS label Vercel assigns the preview. */
|
|
39
|
-
export declare function previewLabel(slug: string): string;
|
|
40
|
-
/** True for protected slugs that never get a preview (mirror of the workflow). */
|
|
41
|
-
export declare function isProtectedPreviewSlug(slug: string): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* True when the slug is short enough that its preview host can be computed
|
|
44
|
-
* without reading the real alias back from Vercel (label ≤ 63 chars).
|
|
45
|
-
*/
|
|
46
|
-
export declare function isComputablePreviewSlug(slug: string): boolean;
|
|
47
|
-
/** The computed preview host for a (short) slug. */
|
|
48
|
-
export declare function previewHost(slug: string): string;
|
|
49
|
-
export interface ResolvedPreview {
|
|
50
|
-
/** The canonical branch slug. */
|
|
51
|
-
slug: string;
|
|
52
|
-
/** Fully-qualified `https://…preview.seqholdings.com` URL. */
|
|
53
|
-
url: string;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Resolve a `preview:<branch-or-slug>` target to its computed preview URL.
|
|
57
|
-
* Throws for protected slugs and for long slugs whose alias can't be computed
|
|
58
|
-
* (the caller should fall back to `--pr <number>` or `--env-url <url>`).
|
|
59
|
-
*/
|
|
60
|
-
export declare function resolvePreviewFromSlug(branchOrSlug: string): ResolvedPreview;
|
|
61
|
-
/** Injectable `gh` runner so PR resolution is unit-testable. */
|
|
62
|
-
export type GhRunner = (args: string[]) => Promise<string>;
|
|
63
|
-
interface GhPrComment {
|
|
64
|
-
body?: string;
|
|
65
|
-
author?: {
|
|
66
|
-
login?: string;
|
|
67
|
-
} | null;
|
|
68
|
-
createdAt?: string;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Find the real `*.preview.seqholdings.com` alias the Vercel bot posts on the
|
|
72
|
-
* PR. This is the ONLY reliable way to get the host for a long (hash-truncated)
|
|
73
|
-
* slug — we can't compute it. Returns the newest trusted match or null.
|
|
74
|
-
*/
|
|
75
|
-
export declare function findPreviewUrlInComments(comments: ReadonlyArray<GhPrComment> | undefined, { expectedHost, requireTrustedAuthor, }?: {
|
|
76
|
-
expectedHost?: string;
|
|
77
|
-
requireTrustedAuthor?: boolean;
|
|
78
|
-
}): string | null;
|
|
79
|
-
/**
|
|
80
|
-
* Resolve a preview env from a PR number. Reads the PR's head branch (and the
|
|
81
|
-
* Vercel bot's preview-URL comment) via `gh`. Prefers the real alias from the
|
|
82
|
-
* comment — which works even for long, hash-truncated slugs — and falls back to
|
|
83
|
-
* computing the host from the branch slug for short slugs. Throws for protected
|
|
84
|
-
* slugs and for long slugs with no resolvable alias.
|
|
85
|
-
*/
|
|
86
|
-
export declare function resolvePreviewByPr({ pr, runGh, }: {
|
|
87
|
-
pr: number;
|
|
88
|
-
runGh?: GhRunner;
|
|
89
|
-
}): Promise<ResolvedPreview>;
|
|
90
|
-
export {};
|
package/dist/preview.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process';
|
|
2
|
-
import { promisify } from 'node:util';
|
|
3
|
-
/**
|
|
4
|
-
* Per-PR preview-environment resolution for `seq-studio artifact`.
|
|
5
|
-
*
|
|
6
|
-
* Lets an engineer target a specific PR's Vercel preview deployment
|
|
7
|
-
* (`https://studio-atlas-git-<slug>.preview.seqholdings.com`) WITHOUT
|
|
8
|
-
* hand-editing `~/.config/seq-studio/config.toml`. See
|
|
9
|
-
* `docs/preview-environments.md` for the full lifecycle.
|
|
10
|
-
*
|
|
11
|
-
* SLUG ALGORITHM — must stay byte-for-byte in sync with the other
|
|
12
|
-
* places that compute the same slug from a branch name:
|
|
13
|
-
* - `.github/workflows/preview-deploy.yml` (replace non-alnum, lowercase, trim hyphens)
|
|
14
|
-
* - `.github/workflows/trigger-preview.yml` (same bash pipeline)
|
|
15
|
-
* - `atlas/src/server/db.ts:sanitize` (`.replace(/[^a-zA-Z0-9-]/g, '-').toLowerCase().replace(/^-+|-+$/g, '')`)
|
|
16
|
-
* - `databricks/lakebase/atlas-db/pr-lifecycle.ts:sanitize`
|
|
17
|
-
* Changing it here without changing those produces a host that does NOT
|
|
18
|
-
* match what `preview-deploy.yml` actually deployed.
|
|
19
|
-
*/
|
|
20
|
-
/** Cloudflare zone the preview aliases live on. */
|
|
21
|
-
export const PREVIEW_DOMAIN = 'preview.seqholdings.com';
|
|
22
|
-
/** Vercel project name → the `<project>-git-<slug>` alias label prefix. */
|
|
23
|
-
export const PREVIEW_PROJECT = 'studio-atlas';
|
|
24
|
-
const LABEL_PREFIX = `${PREVIEW_PROJECT}-git-`;
|
|
25
|
-
/**
|
|
26
|
-
* Mirror of `preview-deploy.yml`'s `PROTECTED` list. A branch whose slug
|
|
27
|
-
* matches one of these (or starts with `dev-`) never gets a preview — the
|
|
28
|
-
* workflow's guard refuses to deploy it — so the CLI refuses to target it.
|
|
29
|
-
*/
|
|
30
|
-
export const PREVIEW_PROTECTED_SLUGS = [
|
|
31
|
-
'banksouth',
|
|
32
|
-
'staging',
|
|
33
|
-
'dev',
|
|
34
|
-
'production',
|
|
35
|
-
'main',
|
|
36
|
-
'development',
|
|
37
|
-
'master',
|
|
38
|
-
];
|
|
39
|
-
/**
|
|
40
|
-
* Vercel deploys the preview under the DNS label `studio-atlas-git-<slug>`.
|
|
41
|
-
* A single DNS label can be at most 63 chars; Vercel hash-truncates labels
|
|
42
|
-
* past that, so the resulting host can NOT be computed from the slug and must
|
|
43
|
-
* be read back from the deployment. This is the SAME cutoff the workflow uses
|
|
44
|
-
* (`[ "${#LABEL}" -le 63 ]`).
|
|
45
|
-
*/
|
|
46
|
-
export const MAX_LABEL_LENGTH = 63;
|
|
47
|
-
/** Apply the canonical branch → slug transform. */
|
|
48
|
-
export function previewSlug(branchOrSlug) {
|
|
49
|
-
return branchOrSlug.replace(/[^a-zA-Z0-9-]/g, '-').toLowerCase().replace(/^-+|-+$/g, '');
|
|
50
|
-
}
|
|
51
|
-
/** The `studio-atlas-git-<slug>` DNS label Vercel assigns the preview. */
|
|
52
|
-
export function previewLabel(slug) {
|
|
53
|
-
return `${LABEL_PREFIX}${slug}`;
|
|
54
|
-
}
|
|
55
|
-
/** True for protected slugs that never get a preview (mirror of the workflow). */
|
|
56
|
-
export function isProtectedPreviewSlug(slug) {
|
|
57
|
-
return (PREVIEW_PROTECTED_SLUGS.includes(slug) ||
|
|
58
|
-
slug.startsWith('dev-'));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* True when the slug is short enough that its preview host can be computed
|
|
62
|
-
* without reading the real alias back from Vercel (label ≤ 63 chars).
|
|
63
|
-
*/
|
|
64
|
-
export function isComputablePreviewSlug(slug) {
|
|
65
|
-
return previewLabel(slug).length <= MAX_LABEL_LENGTH;
|
|
66
|
-
}
|
|
67
|
-
/** The computed preview host for a (short) slug. */
|
|
68
|
-
export function previewHost(slug) {
|
|
69
|
-
return `${previewLabel(slug)}.${PREVIEW_DOMAIN}`;
|
|
70
|
-
}
|
|
71
|
-
const PROTECTED_HINT = PREVIEW_PROTECTED_SLUGS.join(', ');
|
|
72
|
-
/**
|
|
73
|
-
* Resolve a `preview:<branch-or-slug>` target to its computed preview URL.
|
|
74
|
-
* Throws for protected slugs and for long slugs whose alias can't be computed
|
|
75
|
-
* (the caller should fall back to `--pr <number>` or `--env-url <url>`).
|
|
76
|
-
*/
|
|
77
|
-
export function resolvePreviewFromSlug(branchOrSlug) {
|
|
78
|
-
const slug = previewSlug(branchOrSlug);
|
|
79
|
-
if (!slug) {
|
|
80
|
-
throw new Error('Preview env requires a branch or slug, e.g. --env preview:my-branch');
|
|
81
|
-
}
|
|
82
|
-
if (isProtectedPreviewSlug(slug)) {
|
|
83
|
-
throw new Error(`Refusing to target a protected branch slug "${slug}". ` +
|
|
84
|
-
`Protected slugs never get a preview (${PROTECTED_HINT}, or anything starting with "dev-").`);
|
|
85
|
-
}
|
|
86
|
-
if (!isComputablePreviewSlug(slug)) {
|
|
87
|
-
throw new Error(`Branch slug "${slug}" is too long (label "${previewLabel(slug)}" is ` +
|
|
88
|
-
`${previewLabel(slug).length} > ${MAX_LABEL_LENGTH} chars): Vercel ` +
|
|
89
|
-
`hash-truncates the alias, so the preview host can't be computed. ` +
|
|
90
|
-
`Resolve it with --pr <number> (reads the real alias from the PR) or ` +
|
|
91
|
-
`pass --env-url <https://…preview.seqholdings.com>.`);
|
|
92
|
-
}
|
|
93
|
-
return { slug, url: `https://${previewHost(slug)}` };
|
|
94
|
-
}
|
|
95
|
-
const execFileAsync = promisify(execFile);
|
|
96
|
-
const defaultGhRunner = async (args) => {
|
|
97
|
-
try {
|
|
98
|
-
const { stdout } = await execFileAsync('gh', args, { encoding: 'utf8' });
|
|
99
|
-
return stdout;
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
103
|
-
throw new Error(`Failed to run \`gh ${args.join(' ')}\`. Install the GitHub CLI and run ` +
|
|
104
|
-
`\`gh auth login\`, or pass --env-url <url> directly. (${message})`);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const TRUSTED_PREVIEW_COMMENT_AUTHORS = new Set([
|
|
108
|
-
'vercel',
|
|
109
|
-
'vercel[bot]',
|
|
110
|
-
'github-actions',
|
|
111
|
-
'github-actions[bot]',
|
|
112
|
-
]);
|
|
113
|
-
function compareIsoDesc(a, b) {
|
|
114
|
-
if (a === b)
|
|
115
|
-
return 0;
|
|
116
|
-
return a > b ? -1 : 1;
|
|
117
|
-
}
|
|
118
|
-
function commentsNewestFirst(comments) {
|
|
119
|
-
const withDates = comments
|
|
120
|
-
.map((c) => ({ c, d: typeof c.createdAt === 'string' ? c.createdAt : null }))
|
|
121
|
-
.filter((x) => x.d !== null);
|
|
122
|
-
if (withDates.length === 0)
|
|
123
|
-
return comments;
|
|
124
|
-
return [...comments].sort((a, b) => {
|
|
125
|
-
const da = typeof a.createdAt === 'string' ? a.createdAt : '';
|
|
126
|
-
const db = typeof b.createdAt === 'string' ? b.createdAt : '';
|
|
127
|
-
return compareIsoDesc(da, db);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Find the real `*.preview.seqholdings.com` alias the Vercel bot posts on the
|
|
132
|
-
* PR. This is the ONLY reliable way to get the host for a long (hash-truncated)
|
|
133
|
-
* slug — we can't compute it. Returns the newest trusted match or null.
|
|
134
|
-
*/
|
|
135
|
-
export function findPreviewUrlInComments(comments, { expectedHost, requireTrustedAuthor = true, } = {}) {
|
|
136
|
-
if (!comments)
|
|
137
|
-
return null;
|
|
138
|
-
const ordered = commentsNewestFirst(comments);
|
|
139
|
-
const expected = expectedHost?.toLowerCase();
|
|
140
|
-
const re = /https:\/\/[a-z0-9-]+\.preview\.seqholdings\.com/gi;
|
|
141
|
-
const labelPrefix = LABEL_PREFIX.toLowerCase();
|
|
142
|
-
const isTrusted = (comment) => TRUSTED_PREVIEW_COMMENT_AUTHORS.has(comment.author?.login ?? '');
|
|
143
|
-
const search = (predicate) => {
|
|
144
|
-
for (const comment of ordered) {
|
|
145
|
-
if (!comment?.body)
|
|
146
|
-
continue;
|
|
147
|
-
if (!predicate(comment))
|
|
148
|
-
continue;
|
|
149
|
-
for (const match of comment.body.matchAll(re)) {
|
|
150
|
-
const url = match[0];
|
|
151
|
-
if (!url)
|
|
152
|
-
continue;
|
|
153
|
-
let host;
|
|
154
|
-
try {
|
|
155
|
-
host = new URL(url).host.toLowerCase();
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (!host.endsWith(`.${PREVIEW_DOMAIN}`))
|
|
161
|
-
continue;
|
|
162
|
-
if (!host.startsWith(labelPrefix))
|
|
163
|
-
continue;
|
|
164
|
-
if (expected && host !== expected)
|
|
165
|
-
continue;
|
|
166
|
-
return url;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return null;
|
|
170
|
-
};
|
|
171
|
-
if (requireTrustedAuthor) {
|
|
172
|
-
return search(isTrusted);
|
|
173
|
-
}
|
|
174
|
-
return search(() => true);
|
|
175
|
-
}
|
|
176
|
-
async function tryResolvePreviewUrlFromDeployments({ runGh, headSha, }) {
|
|
177
|
-
if (!headSha)
|
|
178
|
-
return null;
|
|
179
|
-
const repoStdout = await runGh(['repo', 'view', '--json', 'nameWithOwner']);
|
|
180
|
-
let repo;
|
|
181
|
-
try {
|
|
182
|
-
repo = JSON.parse(repoStdout);
|
|
183
|
-
}
|
|
184
|
-
catch {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
const nameWithOwner = repo.nameWithOwner;
|
|
188
|
-
if (!nameWithOwner)
|
|
189
|
-
return null;
|
|
190
|
-
const deploymentsStdout = await runGh([
|
|
191
|
-
'api',
|
|
192
|
-
`repos/${nameWithOwner}/deployments?sha=${encodeURIComponent(headSha)}&per_page=100`,
|
|
193
|
-
]);
|
|
194
|
-
let deployments;
|
|
195
|
-
try {
|
|
196
|
-
deployments = JSON.parse(deploymentsStdout);
|
|
197
|
-
}
|
|
198
|
-
catch {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
const previewDeployments = deployments
|
|
202
|
-
.filter((d) => typeof d.id === 'number' && /preview/i.test(d.environment ?? ''))
|
|
203
|
-
.sort((a, b) => compareIsoDesc(a.created_at ?? '', b.created_at ?? ''));
|
|
204
|
-
const chosen = previewDeployments[0];
|
|
205
|
-
if (!chosen?.id)
|
|
206
|
-
return null;
|
|
207
|
-
const statusesStdout = await runGh([
|
|
208
|
-
'api',
|
|
209
|
-
`repos/${nameWithOwner}/deployments/${chosen.id}/statuses?per_page=100`,
|
|
210
|
-
]);
|
|
211
|
-
let statuses;
|
|
212
|
-
try {
|
|
213
|
-
statuses = JSON.parse(statusesStdout);
|
|
214
|
-
}
|
|
215
|
-
catch {
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
const candidates = statuses
|
|
219
|
-
.filter((s) => typeof s.environment_url === 'string' && s.environment_url.length > 0)
|
|
220
|
-
.sort((a, b) => compareIsoDesc(a.created_at ?? '', b.created_at ?? ''));
|
|
221
|
-
const isPreviewHost = (url) => {
|
|
222
|
-
try {
|
|
223
|
-
const host = new URL(url).hostname.toLowerCase();
|
|
224
|
-
return host.endsWith(`.${PREVIEW_DOMAIN}`) && host.startsWith(LABEL_PREFIX.toLowerCase());
|
|
225
|
-
}
|
|
226
|
-
catch {
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
const success = candidates.find((s) => s.state === 'success' && isPreviewHost(s.environment_url));
|
|
231
|
-
if (success?.environment_url)
|
|
232
|
-
return success.environment_url;
|
|
233
|
-
const any = candidates.find((s) => isPreviewHost(s.environment_url));
|
|
234
|
-
return any?.environment_url ?? null;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Resolve a preview env from a PR number. Reads the PR's head branch (and the
|
|
238
|
-
* Vercel bot's preview-URL comment) via `gh`. Prefers the real alias from the
|
|
239
|
-
* comment — which works even for long, hash-truncated slugs — and falls back to
|
|
240
|
-
* computing the host from the branch slug for short slugs. Throws for protected
|
|
241
|
-
* slugs and for long slugs with no resolvable alias.
|
|
242
|
-
*/
|
|
243
|
-
export async function resolvePreviewByPr({ pr, runGh = defaultGhRunner, }) {
|
|
244
|
-
if (!Number.isInteger(pr) || pr <= 0) {
|
|
245
|
-
throw new Error(`--pr must be a positive integer (got "${pr}").`);
|
|
246
|
-
}
|
|
247
|
-
const stdout = await runGh([
|
|
248
|
-
'pr',
|
|
249
|
-
'view',
|
|
250
|
-
String(pr),
|
|
251
|
-
'--json',
|
|
252
|
-
'headRefName,headRefOid,comments',
|
|
253
|
-
]);
|
|
254
|
-
let parsed;
|
|
255
|
-
try {
|
|
256
|
-
parsed = JSON.parse(stdout);
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
throw new Error(`Could not parse \`gh pr view ${pr}\` output as JSON.`);
|
|
260
|
-
}
|
|
261
|
-
const branch = parsed.headRefName;
|
|
262
|
-
if (!branch) {
|
|
263
|
-
throw new Error(`Could not read the head branch for PR #${pr} from gh.`);
|
|
264
|
-
}
|
|
265
|
-
const slug = previewSlug(branch);
|
|
266
|
-
if (isProtectedPreviewSlug(slug)) {
|
|
267
|
-
throw new Error(`PR #${pr} targets a protected branch slug "${slug}", which never gets a preview.`);
|
|
268
|
-
}
|
|
269
|
-
// If the slug is short, the alias is deterministic; prefer the computed host.
|
|
270
|
-
// This avoids accidentally targeting a stale or user-pasted preview URL.
|
|
271
|
-
if (isComputablePreviewSlug(slug)) {
|
|
272
|
-
return { slug, url: `https://${previewHost(slug)}` };
|
|
273
|
-
}
|
|
274
|
-
// Long, hash-truncated slugs require reading the real alias back from Vercel.
|
|
275
|
-
// Prefer deployment metadata over comment text (comments can be stale or
|
|
276
|
-
// user-authored).
|
|
277
|
-
const fromDeployment = await tryResolvePreviewUrlFromDeployments({
|
|
278
|
-
runGh,
|
|
279
|
-
headSha: parsed.headRefOid ?? '',
|
|
280
|
-
}).catch(() => null);
|
|
281
|
-
if (fromDeployment)
|
|
282
|
-
return { slug, url: fromDeployment };
|
|
283
|
-
// Fall back to the Vercel comment if deployments aren't available.
|
|
284
|
-
const fromComment = findPreviewUrlInComments(parsed.comments);
|
|
285
|
-
if (fromComment)
|
|
286
|
-
return { slug, url: fromComment };
|
|
287
|
-
// No trusted Vercel comment yet — error loudly and ask for an explicit URL.
|
|
288
|
-
throw new Error(`PR #${pr} (branch "${branch}", slug "${slug}") has a long, ` +
|
|
289
|
-
`hash-truncated alias and no preview URL was found in the PR comments ` +
|
|
290
|
-
`yet. Wait for the Vercel "Visit Preview" comment, or pass ` +
|
|
291
|
-
`--env-url <https://…preview.seqholdings.com> directly.`);
|
|
292
|
-
}
|