-
Notifications
You must be signed in to change notification settings - Fork 31
fix(integrations): Fix "Update in GitHub" flow #2215
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
Twixes
wants to merge
5
commits into
main
Choose a base branch
from
fix/github-integration-finish-setup
base: main
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
5 commits
Select commit
Hold shift + click to select a range
3a64bbd
feat(integrations): wire github finish setup and installation setting…
Twixes f28cb70
Address AI comments
Twixes 2dfa8e7
Update githubInstallationSettingsUrl.test.ts
Twixes 1b62287
fix(integrations): address github review comments
cursoragent 457d483
chore(integrations): remove unused github test import
cursoragent 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
54 changes: 54 additions & 0 deletions
54
apps/code/src/renderer/features/integrations/utils/githubInstallationSettingsUrl.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,54 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| githubInstallationSettingsUrl, | ||
| resolveGithubInstallationId, | ||
| } from "./githubInstallationSettingsUrl"; | ||
|
|
||
| describe("githubInstallationSettingsUrl", () => { | ||
| it("uses org settings for organization accounts", () => { | ||
| expect( | ||
| githubInstallationSettingsUrl("99", { | ||
| type: "Organization", | ||
| name: "posthog", | ||
| }), | ||
| ).toBe( | ||
| "https://github.com/organizations/posthog/settings/installations/99", | ||
| ); | ||
| }); | ||
|
|
||
| it("uses user settings for personal accounts", () => { | ||
| expect( | ||
| githubInstallationSettingsUrl("42", { type: "User", name: "octocat" }), | ||
| ).toBe("https://github.com/settings/installations/42"); | ||
| }); | ||
| }); | ||
| describe("resolveGithubInstallationId", () => { | ||
| it.each([ | ||
| [ | ||
| "prefers top-level installation_id over integration_id and config", | ||
| { | ||
| id: 99, | ||
| kind: "github", | ||
| installation_id: "a", | ||
| config: { installation_id: "c" }, | ||
| }, | ||
| "a", | ||
| ], | ||
| [ | ||
| "falls back to integration_id when installation_id is absent", | ||
| { id: 1, kind: "github", integration_id: 12345 }, | ||
| "12345", | ||
| ], | ||
| [ | ||
| "falls back to config.installation_id as last resort", | ||
| { id: 1, kind: "github", config: { installation_id: "c" } }, | ||
| "c", | ||
| ], | ||
| ])("%s", (_label, input, expected) => { | ||
| expect( | ||
| resolveGithubInstallationId( | ||
| input as Parameters<typeof resolveGithubInstallationId>[0], | ||
| ), | ||
| ).toBe(expected); | ||
| }); | ||
| }); | ||
44 changes: 44 additions & 0 deletions
44
apps/code/src/renderer/features/integrations/utils/githubInstallationSettingsUrl.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,44 @@ | ||
| import type { Integration } from "../stores/integrationStore"; | ||
|
|
||
| interface GithubInstallationAccount { | ||
| type?: string | null; | ||
| name?: string | null; | ||
| } | ||
|
|
||
| export function githubInstallationSettingsUrl( | ||
| installationId: string, | ||
| account?: GithubInstallationAccount | null, | ||
| ): string { | ||
| const accountType = account?.type; | ||
| const accountName = account?.name; | ||
| if ( | ||
| typeof accountType === "string" && | ||
| accountType.toLowerCase() === "organization" && | ||
| typeof accountName === "string" && | ||
| accountName | ||
| ) { | ||
| return `https://github.com/organizations/${accountName}/settings/installations/${installationId}`; | ||
| } | ||
| return `https://github.com/settings/installations/${installationId}`; | ||
| } | ||
|
|
||
| /** Resolves a GitHub App installation id from team or user integration payloads. */ | ||
| export function resolveGithubInstallationId( | ||
| integration: Integration, | ||
| ): string | null { | ||
| const legacy = integration as { | ||
| installation_id?: string | null; | ||
| integration_id?: string | number | null; | ||
| }; | ||
| const candidates = [ | ||
| legacy.installation_id, | ||
| legacy.integration_id, | ||
| integration.config?.installation_id, | ||
| ]; | ||
| for (const value of candidates) { | ||
| if (value === null || value === undefined) continue; | ||
| const id = String(value).trim(); | ||
| if (id) return id; | ||
| } | ||
| return null; | ||
| } |
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.