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/read-id-as-channel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/board': patch
---

`vb read <name>` on a long name with a digit that's no channel's and close to none, like a message ID that doesn't go bare, now says that `#<name>` reads it as a message's thread, and offers that command.
5 changes: 5 additions & 0 deletions packages/board/src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1548,15 +1548,20 @@ async function run(command: string | undefined, args: string[]): Promise<number>
const channels = (await everyChannel(board)).map((c) => c.path)
if (!channels.some((path) => path === target || path.startsWith(target.replace(/\/?$/, '/')))) {
const guess = closest(target, channels)
// A long name with a digit, like no channel's and under none, may be a message's ID that doesn't go bare:
// `#` reads its thread. A short one is a typo.
const id = !guess && /^[\w-]{16,}$/.test(target) && /\d/.test(target)
throw new Failed({
class: 'not_found',
reason: 'channel_not_found',
message: `Couldn't find channel ${target}.${guess ? ` Did you mean ${guess}?` : ''}`,
details: [
'A channel appears with its first post: one nobody has posted in yet is not there to read.',
...(id ? [`If ${target} is a message's ID, #${target} reads its thread.`] : []),
...(teamDefault ? [`This is ${teamDefault.team ?? 'the team'}'s default board: --name reads another of its boards.`] : []),
],
next: [
...(id ? [{ instruction: 'Read it as a message', argv: [...cli(), 'read', `#${target}`] }] : []),
{ instruction: 'See its channels', argv: [...cli(), 'channels', ...(teamDefault?.team !== undefined ? ['--scope', teamDefault.team] : [])] },
...(teamDefault ? [{ instruction: "Read it on another of the team's boards", argv: rerun('--name', '<BOARD>') }] : []),
],
Expand Down
6 changes: 6 additions & 0 deletions packages/board/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,12 @@ describe('cli', () => {

// A typo'd channel is an error, not an empty read; an empty read in a real channel isn't.
expect(await vb(['read', 'open-wrok'])).toMatchObject({ code: 1, stdout: '', stderr: expect.stringMatching(/^error: Couldn't find channel open-wrok\. Did you mean open-work\?\n/) })
// A name like no channel's may be a message's ID that doesn't go bare: the error says how to read it as one.
const opaque = await vb(['read', '5d08b9af-5b45-465b-bb43-3b24e540ed95'])
expect(opaque).toMatchObject({ code: 1, stdout: '' })
expect(opaque.stderr).toContain("If 5d08b9af-5b45-465b-bb43-3b24e540ed95 is a message's ID, #5d08b9af-5b45-465b-bb43-3b24e540ed95 reads its thread.")
expect(opaque.stderr).toContain("vb read '#5d08b9af-5b45-465b-bb43-3b24e540ed95'")
expect((await vb(['read', 'open-wrok'])).stderr).not.toContain("is a message's ID")
expect(await vb(['read', 'open-work', '--text', 'nothing like this'])).toMatchObject({ code: 0, stdout: expect.stringMatching(/^open-work · 0 threads · cursor \d+\n\nnew since then: vb read open-work --text 'nothing like this' --after \d+\n$/) })
expect(await vb(['read', 'open-work', '--messages'])).toMatchObject({ code: 2 })
})
Expand Down