Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ try {
}

async function main() {
const deploymentId = VERCEL_DEPLOYMENT.startsWith("dpl_")
? VERCEL_DEPLOYMENT
// Extract domain from URL if needed
const domain = extractDomain(VERCEL_DEPLOYMENT);

const deploymentId = domain.startsWith("dpl_")
? domain
: await oraPromise(
getDeploymentId(VERCEL_DEPLOYMENT),
getDeploymentId(domain),
"Getting deployment id"
);
const srcFiles = await oraPromise(
Expand Down Expand Up @@ -71,7 +74,9 @@ async function getDeploymentSource(id) {
}

async function getDeploymentId(domain) {
const deployment = await getJSONFromAPI(`/v13/deployments/${domain}`);
let path = `/v13/deployments/${domain}`;
if (VERCEL_TEAM) path += `?teamId=${VERCEL_TEAM}`;
const deployment = await getJSONFromAPI(path);
return deployment.id;
}

Expand Down Expand Up @@ -116,3 +121,24 @@ function flattenTree({ name, children = [] }) {
childrenNamed.map(flattenTree)
);
}

function extractDomain(input) {
// If it's already a deployment ID, return as is
if (input.startsWith("dpl_")) {
return input;
}

// If it's a full URL, extract the domain
if (input.startsWith("http://") || input.startsWith("https://")) {
try {
const url = new URL(input);
return url.hostname;
} catch (error) {
console.log(error("Invalid URL format"));
return input;
}
}

// If it's already a domain, return as is
return input;
}
Loading