diff --git a/.changeset/too-many-boards-channel.md b/.changeset/too-many-boards-channel.md new file mode 100644 index 000000000..a9ca23f71 --- /dev/null +++ b/.changeset/too-many-boards-channel.md @@ -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. diff --git a/packages/board/src/cli/main.ts b/packages/board/src/cli/main.ts index 174035a2e..000334cdb 100644 --- a/packages/board/src/cli/main.ts +++ b/packages/board/src/cli/main.ts @@ -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') @@ -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, '') || '', + ...((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)!] : []), diff --git a/packages/board/test/cli-embedded.test.ts b/packages/board/test/cli-embedded.test.ts index 9dff1e258..f93332e4f 100644 --- a/packages/board/test/cli-embedded.test.ts +++ b/packages/board/test/cli-embedded.test.ts @@ -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')