Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/onboarding/githubConnectPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ describe("isAnyIntegrationStale", () => {
});

describe("buildInstallationSettingsUrl", () => {
it("builds an org settings url", () => {
it("links an org install to the app page (org settings are owner-only)", () => {
expect(
buildInstallationSettingsUrl(
{ type: "Organization", name: "acme" },
"42",
),
).toBe("https://github.com/organizations/acme/settings/installations/42");
).toBe("https://github.com/apps/posthog");
});

it("builds a personal settings url otherwise", () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/onboarding/githubConnectPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,17 @@ export function isAnyIntegrationStale(
);
}

// GitHub's per-installation settings page for an org install is owner-only and
// 404s for members, so org installs point at the app page, which loads for
// anyone (owners get Configure, members get request access).
const POSTHOG_GITHUB_APP_URL = "https://github.com/apps/posthog";
Comment thread
charlesvien marked this conversation as resolved.
Outdated

export function buildInstallationSettingsUrl(
account: GithubInstallationAccount | null | undefined,
installationId: string,
): string {
if (account?.type === "Organization" && account.name) {
return `https://github.com/organizations/${account.name}/settings/installations/${installationId}`;
if (account?.type === "Organization") {
Comment thread
charlesvien marked this conversation as resolved.
Outdated
return POSTHOG_GITHUB_APP_URL;
}
return `https://github.com/settings/installations/${installationId}`;
}
Expand Down
15 changes: 12 additions & 3 deletions packages/core/src/settings/githubRepoSummary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@ describe("summarizeReposByOwner", () => {
});

describe("githubInstallationSettingsUrl", () => {
it("builds an org URL for organization accounts", () => {
it("links organization installs to the app page (org settings are owner-only)", () => {
expect(
githubInstallationSettingsUrl({
installation_id: 42,
account: { type: "Organization", name: "acme" },
}),
).toBe("https://github.com/organizations/acme/settings/installations/42");
).toBe("https://github.com/apps/posthog");
});

it("builds a user URL otherwise", () => {
it("matches the organization account type case-insensitively", () => {
expect(
githubInstallationSettingsUrl({
installation_id: 42,
account: { type: "organization", name: "acme" },
}),
).toBe("https://github.com/apps/posthog");
});

it("builds a user installation URL otherwise", () => {
expect(
githubInstallationSettingsUrl({
installation_id: 7,
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/settings/githubRepoSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ export interface GithubInstallationLike {
account?: GithubInstallationAccount | null;
}

// GitHub's per-installation settings page for an org install is owner-only and
// 404s for members, so org installs point at the app page, which loads for
// anyone (owners get Configure, members get request access).
const POSTHOG_GITHUB_APP_URL = "https://github.com/apps/posthog";

export function githubInstallationSettingsUrl(
integration: GithubInstallationLike,
): string {
const accountType = integration.account?.type;
const accountName = integration.account?.name;
if (
typeof accountType === "string" &&
accountType.toLowerCase() === "organization" &&
typeof accountName === "string" &&
accountName
accountType.toLowerCase() === "organization"
) {
return `https://github.com/organizations/${accountName}/settings/installations/${integration.installation_id}`;
return POSTHOG_GITHUB_APP_URL;
}
return `https://github.com/settings/installations/${integration.installation_id}`;
}
Loading