Skip to content

Commit 98763f7

Browse files
benhancockdylanspyerDanielSLew
authored
fix: logs: deploy command instructs user to link to a site if one is … (#6867)
* fix: logs: deploy command instructs user to link to a site if one is not linked Co-authored-by: Dylan Spyer <[email protected]> * fix: logs: deploy command instructs user to link to a site if one is not linked * fix: logs:deploy command instructs user to link to a site if one is not linked Co-authored-by: Dylan Spyer <[email protected]> * fix: logs: deploy command instructs user to link to a site if one is not linked Co-authored-by: Dylan Spyer <[email protected]> * fix: logs: deploy command instructs user to link to a site if one is not linked Co-authored-by: Dylan Spyer <[email protected]> --------- Co-authored-by: Dylan Spyer <[email protected]> Co-authored-by: Daniel Lew <[email protected]>
1 parent 552e8e1 commit 98763f7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/commands/logs/build.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export const logsBuild = async (options: OptionValues, command: BaseCommand) =>
3939
const { id: siteId } = site
4040
const userId = command.netlify.globalConfig.get('userId')
4141

42+
if (!siteId) {
43+
log('You must link a site before attempting to view deploy logs')
44+
return
45+
}
46+
4247
const deploys = await client.listSiteDeploys({ siteId, state: 'building' })
4348

4449
if (deploys.length === 0) {

tests/integration/commands/logs/build.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { createLogsBuildCommand } from '../../../../src/commands/logs/index.js'
55
import { getWebSocket } from '../../../../src/utils/websockets/index.js'
66
import { startMockApi } from '../../utils/mock-api-vitest.js'
77
import { getEnvironmentVariables } from '../../utils/mock-api.js'
8+
import { callCli } from '../../utils/call-cli.js'
9+
import { getCLIOptions, withMockApi } from '../../utils/mock-api.js'
10+
import { withSiteBuilder } from '../../utils/site-builder.ts'
11+
import { join } from 'path'
812

913
vi.mock('../../../../src/utils/websockets/index.js', () => ({
1014
getWebSocket: vi.fn(),
@@ -47,12 +51,14 @@ const routes = [
4751

4852
describe('logs:deploy command', () => {
4953
let program: BaseCommand
54+
const originalEnv = { ...process.env }
5055

5156
afterEach(() => {
5257
vi.clearAllMocks()
5358
})
5459

5560
beforeEach(() => {
61+
process.env = { ...originalEnv }
5662
program = new BaseCommand('netlify')
5763

5864
createLogsBuildCommand(program)
@@ -107,4 +113,21 @@ describe('logs:deploy command', () => {
107113
expect(body.site_id).toEqual('site_id')
108114
expect(body.access_token).toEqual(env.NETLIFY_AUTH_TOKEN)
109115
})
116+
117+
test('should instruct user to link a site if one is not linked', async (t) => {
118+
await withSiteBuilder(t, async (builder) => {
119+
const projectPath = join('projects', 'project1')
120+
await builder.withNetlifyToml({ config: {}, pathPrefix: projectPath }).build()
121+
122+
await withMockApi(
123+
routes,
124+
async ({ apiUrl }) => {
125+
const options = getCLIOptions({ builder, apiUrl, env: { NETLIFY_SITE_ID: '' } })
126+
const stdout = await callCli(['logs:deploy'], { ...options, cwd: join(builder.directory, projectPath) })
127+
expect(stdout).toContain('You must link a site before attempting to view deploy logs')
128+
},
129+
true,
130+
)
131+
})
132+
})
110133
})

0 commit comments

Comments
 (0)