Skip to content

Commit eebfc0c

Browse files
authored
Sort subscription list alphabetically and normalize repo casing (#6)
* lowercase owner and repo name before insert * sort subscribed repo list
1 parent 005d72b commit eebfc0c

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/slack/commands/list.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { eq } from 'drizzle-orm'
1+
import { eq, sql } from 'drizzle-orm'
22
import { buildListBlocks } from '@bot/blocks/list'
33
import { db } from '@db/client'
44
import { repositories, subscriptions } from '@db/schema'
@@ -21,6 +21,10 @@ export async function handleList(
2121
.from(subscriptions)
2222
.innerJoin(repositories, eq(subscriptions.repositoryId, repositories.id))
2323
.where(eq(subscriptions.channelId, ctx.channelId))
24+
.orderBy(
25+
sql`lower(${repositories.owner})`,
26+
sql`lower(${repositories.repo})`,
27+
)
2428

2529
if (rows.length === 0) {
2630
await ctx.respond(

src/slack/commands/parse.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,11 @@ describe('parseRepo', () => {
4949
test('returns null for empty string', () => {
5050
expect(parseRepo('')).toBeNull()
5151
})
52+
53+
test('lowercases owner and repo', () => {
54+
expect(parseRepo('Torvalds/Linux')).toEqual({
55+
owner: 'torvalds',
56+
name: 'linux',
57+
})
58+
})
5259
})

src/slack/commands/parse.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ export function parseRepo(arg: string): { owner: string; name: string } | null {
1515
}
1616

1717
const idx = arg.indexOf('/')
18-
return { owner: arg.slice(0, idx), name: arg.slice(idx + 1) }
18+
return {
19+
owner: arg.slice(0, idx).toLowerCase(),
20+
name: arg.slice(idx + 1).toLowerCase(),
21+
}
1922
}

0 commit comments

Comments
 (0)