-
Notifications
You must be signed in to change notification settings - Fork 730
feat(security-contacts): resolve GitHub handles to emails using cdp identities [CM-1323] #4342
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
mbani01
merged 10 commits into
main
from
feat/resovle_github_handles_using_cdp_identities
Jul 15, 2026
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a49b631
feat: add read-only CDP db connection to packages_worker
mbani01 e3cbd9f
feat: add findResolvableEmailsForMembers DAL query
mbani01 980c641
feat: add CDP handle to email resolution for security contacts
mbani01 37341d2
feat: wire CDP email resolution into security-contacts batch
mbani01 c97e046
feat: score cdp-unverified resolved emails into fallback band
mbani01 5bc246f
fix: keep verified CDP resolution when merged with an unverified one
mbani01 e285e62
fix: harden CDP email resolution against empty inputs
mbani01 b3b0731
fix: fix incorrect taks queue
mbani01 eb629f3
chore: remove 5-contact cap on security contacts
mbani01 178f6c0
Merge branch 'main' into feat/resovle_github_handles_using_cdp_identi…
mbani01 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
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
58 changes: 58 additions & 0 deletions
58
services/apps/packages_worker/src/security-contacts/resolveCdpEmails.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,58 @@ | ||
| import { | ||
| findMembersByGithubHandles, | ||
| findResolvableEmailsForMembers, | ||
| } from '@crowd/data-access-layer/src/members/identities' | ||
| import { QueryExecutor } from '@crowd/data-access-layer/src/queryExecutor' | ||
|
|
||
| import { ProvenanceEntry, RawContact } from './types' | ||
|
|
||
| function latestTimestamp(provenance: ProvenanceEntry[]): string { | ||
| return provenance | ||
| .map((p) => p.declaredAt ?? p.fetchedAt) | ||
| .reduce((a, b) => (new Date(b).getTime() > new Date(a).getTime() ? b : a)) | ||
| } | ||
|
mbani01 marked this conversation as resolved.
|
||
|
|
||
| export async function resolveCdpEmails( | ||
|
mbani01 marked this conversation as resolved.
|
||
| cdpQx: QueryExecutor, | ||
| handleContacts: RawContact[], | ||
| ): Promise<RawContact[]> { | ||
|
mbani01 marked this conversation as resolved.
|
||
| if (handleContacts.length === 0) return [] | ||
|
|
||
| const handles = [...new Set(handleContacts.map((c) => c.value.toLowerCase()))] | ||
| const members = await findMembersByGithubHandles(cdpQx, handles) | ||
| if (members.length === 0) return [] | ||
|
|
||
| const memberIdsByHandle = new Map<string, string[]>() | ||
| for (const m of members) { | ||
| const key = m.githubHandle.toLowerCase() | ||
| memberIdsByHandle.set(key, [...(memberIdsByHandle.get(key) ?? []), m.memberId]) | ||
| } | ||
|
|
||
| const emails = await findResolvableEmailsForMembers(cdpQx, [ | ||
| ...new Set(members.map((m) => m.memberId)), | ||
| ]) | ||
| const emailsByMember = new Map<string, { verified: string[]; unverified: string[] }>() | ||
| for (const e of emails) { | ||
| const bucket = emailsByMember.get(e.memberId) ?? { verified: [], unverified: [] } | ||
| ;(e.verified ? bucket.verified : bucket.unverified).push(e.email) | ||
| emailsByMember.set(e.memberId, bucket) | ||
| } | ||
|
|
||
| return handleContacts.flatMap((contact) => { | ||
| const fetchedAt = latestTimestamp(contact.provenance) | ||
| const memberIds = memberIdsByHandle.get(contact.value.toLowerCase()) ?? [] | ||
| return memberIds.flatMap((memberId) => { | ||
| const bucket = emailsByMember.get(memberId) | ||
| if (!bucket) return [] | ||
| const useVerified = bucket.verified.length > 0 | ||
| const source = useVerified ? 'cdp-verified' : 'cdp-unverified' | ||
| return (useVerified ? bucket.verified : bucket.unverified).map((email) => ({ | ||
| channel: 'email' as const, | ||
| value: email, | ||
| role: contact.role, | ||
| tier: contact.tier, | ||
|
mbani01 marked this conversation as resolved.
|
||
| provenance: [{ source, sourceTier: contact.tier, fetchedAt }], | ||
|
mbani01 marked this conversation as resolved.
|
||
| })) | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| }) | ||
| }) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.