-
Notifications
You must be signed in to change notification settings - Fork 0
Add jiraProjectKey and discordChannelId to the Project schema #158 #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kigiri
merged 2 commits into
master
from
158-add-jiraprojectkey-and-discordchannelid-to-the-project-schema
Aug 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
api/team-directory.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { get } from './lmdb-store.ts' | ||
|
|
||
| // Matches the `Person` shape from tickets.ts (issue 1, a separate branch as | ||
| // of this issue) — duplicated rather than imported since this issue has no | ||
| // dependency on it. | ||
| export type Person = { | ||
| id: string | ||
| name: string | ||
| emails: string[] | ||
| githubLogin?: string | ||
| discordId?: string | ||
| jiraAccountId?: string | ||
| } | ||
|
|
||
| type GoogleUser = { | ||
| id: string | ||
| primaryEmail: string | ||
| emails: string[] | ||
| name: string | ||
| } | ||
|
|
||
| type JiraUser = { | ||
| accountId: string | ||
| email: string | null | ||
| } | ||
|
|
||
| // `name`/`global_name` come back as `[]`, not `null`, when unset on some | ||
| // store records (an upstream sync quirk) — typed loosely and guarded with | ||
| // `typeof` rather than trusted. | ||
| type GithubUser = { | ||
| login: string | ||
| name: unknown | ||
| } | ||
|
|
||
| type DiscordUser = { | ||
| id: string | ||
| global_name: unknown | ||
| } | ||
|
|
||
| const GOOGLE_USER_QUERY = | ||
| '{id: .id, primaryEmail: .primaryEmail, emails: [.emails[]?.address], name: .name.fullName}' | ||
| const JIRA_USER_QUERY = '{accountId: .accountId, email: .emailAddress}' | ||
| const GITHUB_USER_QUERY = '{login: .login, name: .name}' | ||
| const DISCORD_USER_QUERY = '{id: .id, global_name: .global_name}' | ||
|
|
||
| // github/user and discord/user carry no email to join against google/user | ||
| // by, so this falls back to an exact, case-insensitive full-name match — | ||
| // the only signal shared with google/user's `name.fullName`. A name shared | ||
| // by more than one account is dropped rather than guessed at (e.g. two | ||
| // real github accounts both just named "Henri"). | ||
| const uniqueByName = <T>( | ||
| items: T[], | ||
| getName: (item: T) => unknown, | ||
| ): Map<string, T> => { | ||
| const byName = new Map<string, T>() | ||
| const ambiguous = new Set<string>() | ||
| for (const item of items) { | ||
| const name = getName(item) | ||
| if (typeof name !== 'string' || !name) continue | ||
| const key = name.toLowerCase() | ||
| if (byName.has(key)) ambiguous.add(key) | ||
| else byName.set(key, item) | ||
| } | ||
| for (const key of ambiguous) byName.delete(key) | ||
| return byName | ||
| } | ||
|
|
||
| export const mergeTeamDirectory = ( | ||
| googleUsers: GoogleUser[], | ||
| jiraUsers: JiraUser[], | ||
| githubUsers: GithubUser[], | ||
| discordUsers: DiscordUser[], | ||
| ): Person[] => { | ||
| const githubByName = uniqueByName(githubUsers, (u) => u.name) | ||
| const discordByName = uniqueByName(discordUsers, (u) => u.global_name) | ||
|
|
||
| return googleUsers.map((user) => { | ||
| const emails = [...new Set([user.primaryEmail, ...user.emails])] | ||
| const jiraUser = jiraUsers.find((j) => j.email && emails.includes(j.email)) | ||
| const nameKey = user.name.toLowerCase() | ||
| return { | ||
| id: user.id, | ||
| name: user.name, | ||
| emails, | ||
| jiraAccountId: jiraUser?.accountId, | ||
| githubLogin: githubByName.get(nameKey)?.login, | ||
| discordId: discordByName.get(nameKey)?.id, | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| export const buildTeamDirectory = async (): Promise<Person[]> => { | ||
| const [googleUsers, jiraUsers, githubUsers, discordUsers] = await Promise | ||
| .all([ | ||
| get<GoogleUser[]>('google/user', { q: GOOGLE_USER_QUERY }), | ||
| get<JiraUser[]>('jira/user', { q: JIRA_USER_QUERY }), | ||
| get<GithubUser[]>('github/user', { q: GITHUB_USER_QUERY }), | ||
| get<DiscordUser[]>('discord/user', { q: DISCORD_USER_QUERY }), | ||
| ]) | ||
| return mergeTeamDirectory(googleUsers, jiraUsers, githubUsers, discordUsers) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.