Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/commands/agents/agents-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const agentsCreate = async (promptArg: string, options: AgentCreateOption
log(` CLI: ${chalk.cyan(`netlify agents:show ${agentRunner.id}`)}`)
log(
` View in browser: ${chalk.blue(
`https://app.netlify.com/sites/${site.id ?? siteInfo.id}/agents/${agentRunner.id}`,
`https://app.netlify.com/projects/${siteInfo.name}/agent-runs/${agentRunner.id}`,
)}`,
)
log(``)
Expand Down
6 changes: 5 additions & 1 deletion src/commands/agents/agents-show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ export const agentsShow = async (id: string, options: AgentShowOptions, command:
log(` Stop: ${chalk.cyan(`netlify agents:stop ${agentRunner.id}`)}`)
}

log(` View in browser: ${chalk.blue(`https://app.netlify.com/sites/${site.id ?? ''}/agents/${agentRunner.id}`)}`)
log(
` View in browser: ${chalk.blue(
`https://app.netlify.com/projects/${siteInfo.name}/agent-runs/${agentRunner.id}`,
)}`,
)

return agentRunner
} catch (error_) {
Expand Down
65 changes: 32 additions & 33 deletions src/utils/hooks/requires-site-info-with-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,44 @@ const requiresSiteInfoWithProject = async (command: Command) => {

let siteId = site.id

// If --project flag is provided, resolve it to a site ID
if (options.project && !siteId) {
// If --project flag is provided, resolve it to a site ID (overrides linked site)
if (options.project) {
try {
// Try to get site by ID first (if project looks like an ID)
if (options.project.length === 24 && /^[a-f0-9]+$/i.test(options.project)) {
const siteData = await api.getSite({ siteId: options.project })
if (siteData.id) {
siteId = siteData.id
// Update the site info in the command
baseCommand.netlify.site.id = siteId
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
baseCommand.netlify.siteInfo = siteData as any // Type assertion needed due to API type mismatch
}
} else {
const sites = await api.listSites({
filter: 'all',
name: options.project,
})
const matchedSite = sites.find((site) => site.name === options.project)

if (matchedSite?.id) {
siteId = matchedSite.id
// Update the site info in the command
baseCommand.netlify.site.id = siteId
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
baseCommand.netlify.siteInfo = matchedSite as any // Type assertion needed due to API type mismatch
} else {
return logAndThrowError(`Project "${options.project}" not found. Make sure you have access to this project.`)
}
const siteData = await api.getSite({ siteId: options.project })
if (siteData.id) {
siteId = siteData.id
baseCommand.netlify.site.id = siteId
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
baseCommand.netlify.siteInfo = siteData as any
}
} catch (error_) {
const error = error_ as APIError
if (error.status === 401) {
return logAndThrowError(`Not authorized to access project "${options.project}"`)
}
if (error.status === 404) {
return logAndThrowError(`Project "${options.project}" not found`)
try {
const sites = await api.listSites({
filter: 'all',
name: options.project,
})
const matchedSite = sites.find((site) => site.name === options.project)

if (matchedSite?.id) {
siteId = matchedSite.id
baseCommand.netlify.site.id = siteId
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
baseCommand.netlify.siteInfo = matchedSite as any
} else {
return logAndThrowError(
`Project "${options.project}" not found. Make sure you have access to this project.`,
)
}
} catch (listError) {
return logAndThrowError(`Failed to resolve project "${options.project}": ${(listError as Error).message}`)
}
} else if (error.status === 401) {
return logAndThrowError(`Not authorized to access project "${options.project}"`)
} else {
return logAndThrowError(`Failed to resolve project "${options.project}": ${error.message}`)
}
return logAndThrowError(`Failed to resolve project "${options.project}": ${error.message}`)
}
}

Expand Down
Loading