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
5 changes: 5 additions & 0 deletions .changeset/too-many-boards-channel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/board': patch
---

When a team's plan has no room for a named board (`too_many_boards`), the CLI now also suggests making a channel for it on the team's board, with the `channels create` command.
26 changes: 24 additions & 2 deletions packages/board/src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,9 +1015,15 @@ function failureOf(error: unknown): Failure {
{ instruction: "Or the team's own board, which it posts to and changes the grants of", argv: [...rerunWithout(['--name']).filter((arg) => arg !== '--ensure'), '--name', 'General'] },
]
: flags.name !== undefined
? [{ instruction: "Use the team's board instead", argv: rerunWithout(['--name']).filter((arg) => arg !== '--ensure') }]
? [
{ instruction: "Use the team's board instead", argv: rerunWithout(['--name']).filter((arg) => arg !== '--ensure') },
{ instruction: "Or give it a channel of its own on the team's board", argv: channelFor(flags.name) },
]
: process.env.BOARD_NAME
? [{ instruction: "Use the team's board instead: unset BOARD_NAME, then run", argv: rerunWithout([]).filter((arg) => arg !== '--ensure') }]
? [
{ instruction: "Use the team's board instead: unset BOARD_NAME, then run", argv: rerunWithout([]).filter((arg) => arg !== '--ensure') },
{ instruction: "Or give it a channel of its own on the team's board: unset BOARD_NAME, then run", argv: channelFor(process.env.BOARD_NAME) },
]
: [],
)
if (code === 'private_boards_unavailable')
Expand Down Expand Up @@ -1083,6 +1089,22 @@ function failureOf(error: unknown): Failure {
}

/** The options that say which board this run is on, and as whom, as typed: what a way out to another command keeps. */
/** A channel on the team's own board, in place of the board a plan has no room for. */
const channelFor = (name: string): string[] => [
...cli(),
'channels',
'create',
// A board's name can be `My Board`; a channel's path is lowercase segments, such as `my-board`.
name
.normalize('NFKD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.replace(/[^a-z0-9_-]+/g, '-')
.replace(/^[^a-z0-9]+|-+$/g, '') || '<channel>',
...((flags.scope ?? flags.team) !== undefined ? ['--scope', (flags.scope ?? flags.team)!] : []),
...(flags.as ? ['--as', flags.as] : []),
]

const onThisBoard = (): string[] => [
...(flags.url !== undefined ? ['--url', flags.url] : []),
...((flags.scope ?? flags.team) !== undefined ? ['--scope', (flags.scope ?? flags.team)!] : []),
Expand Down
24 changes: 24 additions & 0 deletions packages/board/test/cli-embedded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,30 @@ describe('the embedded CLI', () => {
}
})

it("offers a channel on the team's board when the plan has no room for a named one", async () => {
const home = await isolated()
vi.stubEnv('VERCEL_AUTH_TOKEN', 'user:u_jb')
vi.stubEnv('VERCEL_ORG_ID', 'team_test')
const api = fakeMessageboard({ oneBoard: true })
const fetching = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => api.fetch(input, init))
const run = (...args: string[]) => capture(() => main(args, { name: 'board', commands: local }))
const cwd = process.cwd()
process.chdir(home)
try {
const said = await run('post', 'general', 'hi', '--scope', 'test', '--name', 'scratch', '--ensure')
expect(said).toMatchObject({ code: 1, stdout: '' })
expect(said.stderr).toContain('The team has all the boards it can.')
expect(said.stderr).toContain(' vb post general hi --scope test\n')
expect(said.stderr).toContain(' vb channels create scratch --scope test\n')
// A board's name can hold what a channel's path can't.
expect((await run('post', 'general', 'hi', '--scope', 'test', '--name', 'My Board', '--ensure')).stderr).toContain(' vb channels create my-board --scope test\n')
} finally {
fetching.mockRestore()
process.chdir(cwd)
await rm(home, { recursive: true, force: true })
}
})

it('tells a project it has no access to a board, and who fixes that', async () => {
const home = await isolated()
vi.stubEnv('VERCEL_AUTH_TOKEN', 'project:prj_pong:preview')
Expand Down