-
Notifications
You must be signed in to change notification settings - Fork 37
feat(web): upsert cli_session_pull_requests from PR webhooks #2875
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
Open
kilo-code-bot
wants to merge
4
commits into
convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head
Choose a base branch
from
convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/gt/toast/a6a495dc
base: convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
25bf277
feat(db): add cli_session_pull_requests side table + migration (#2872)
kilo-code-bot[bot] 3bd23ef
feat(web): upsert cli_session_pull_requests from PR webhooks
d4bc6ba
WIP: container eviction save
5020a99
fix(github-webhook): handle SSH session URLs + run upsert before clos…
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
50 changes: 50 additions & 0 deletions
50
apps/web/src/lib/integrations/platforms/github/webhook-handlers/normalize-git-url.test.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,50 @@ | ||
| import { normalizeGitUrl } from './normalize-git-url'; | ||
|
|
||
| describe('normalizeGitUrl', () => { | ||
| it('trims trailing .git from https URLs', () => { | ||
| expect(normalizeGitUrl('https://github.com/acme/widgets.git')).toBe( | ||
| 'https://github.com/acme/widgets' | ||
| ); | ||
| }); | ||
|
|
||
| it('returns the canonical https form when already canonical', () => { | ||
| expect(normalizeGitUrl('https://github.com/acme/widgets')).toBe( | ||
| 'https://github.com/acme/widgets' | ||
| ); | ||
| }); | ||
|
|
||
| it('converts git@github.com: ssh form into https', () => { | ||
| expect(normalizeGitUrl('git@github.com:acme/widgets.git')).toBe( | ||
| 'https://github.com/acme/widgets' | ||
| ); | ||
| }); | ||
|
|
||
| it('converts ssh form without .git suffix', () => { | ||
| expect(normalizeGitUrl('git@github.com:acme/widgets')).toBe('https://github.com/acme/widgets'); | ||
| }); | ||
|
|
||
| it('lower-cases host and owner/repo path', () => { | ||
| expect(normalizeGitUrl('https://GitHub.com/ACME/Widgets.git')).toBe( | ||
| 'https://github.com/acme/widgets' | ||
| ); | ||
| }); | ||
|
|
||
| it('treats https and ssh variants of the same repo as equal', () => { | ||
| const a = normalizeGitUrl('https://github.com/acme/widgets.git'); | ||
| const b = normalizeGitUrl('git@github.com:acme/widgets.git'); | ||
| const c = normalizeGitUrl('https://github.com/acme/widgets'); | ||
| expect(a).toBe(b); | ||
| expect(a).toBe(c); | ||
| }); | ||
|
|
||
| it('strips a trailing slash', () => { | ||
| expect(normalizeGitUrl('https://github.com/acme/widgets/')).toBe( | ||
| 'https://github.com/acme/widgets' | ||
| ); | ||
| }); | ||
|
|
||
| it('returns empty string for empty input', () => { | ||
| expect(normalizeGitUrl('')).toBe(''); | ||
| expect(normalizeGitUrl(' ')).toBe(''); | ||
| }); | ||
| }); |
34 changes: 34 additions & 0 deletions
34
apps/web/src/lib/integrations/platforms/github/webhook-handlers/normalize-git-url.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,34 @@ | ||
| /** | ||
| * Normalize a git remote URL to a canonical lower-cased https form so that | ||
| * equivalent https/ssh/`.git`-suffixed variants of the same repo compare equal. | ||
| * | ||
| * - Strips a trailing `.git` | ||
| * - Lower-cases host + owner/repo path | ||
| * - Converts `git@host:owner/repo` ssh form into `https://host/owner/repo` | ||
| * - Leaves non-http(s) URLs that it cannot parse as-is (lower-cased, `.git` stripped) | ||
| * | ||
| * Pure helper; no IO. | ||
| */ | ||
| export function normalizeGitUrl(url: string): string { | ||
| const trimmed = url.trim(); | ||
| if (trimmed === '') return ''; | ||
|
|
||
| const sshMatch = trimmed.match(/^git@([^:]+):(.+)$/); | ||
| const httpsForm = sshMatch ? `https://${sshMatch[1]}/${sshMatch[2]}` : trimmed; | ||
|
|
||
| try { | ||
| const parsed = new URL(httpsForm); | ||
| const host = parsed.host.toLowerCase(); | ||
| let pathname = parsed.pathname.toLowerCase(); | ||
| if (pathname.endsWith('.git')) { | ||
| pathname = pathname.slice(0, -'.git'.length); | ||
| } | ||
| while (pathname.endsWith('/')) { | ||
| pathname = pathname.slice(0, -1); | ||
| } | ||
| return `${parsed.protocol.toLowerCase()}//${host}${pathname}`; | ||
| } catch { | ||
| const lower = httpsForm.toLowerCase(); | ||
| return lower.endsWith('.git') ? lower.slice(0, -'.git'.length) : lower; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Duplicate webhooks can still repeat this side effect
This upsert now runs before
logWebhook, so the existing duplicate-delivery guard is bypassed for pull_request events. Replayed or retried webhooks will execute the database lookup/upsert again and refreshpr_last_synced_at/updated_ateven whenlogWebhookwould have returnedisDuplicate. If duplicate suppression should continue to apply to all webhook side effects, log/check the delivery before callingupsertSessionPullRequestsFromWebhook, while still placing the closed-event early return after the upsert for non-duplicates.