diff --git a/apps/api/src/documentation/github/setup.test.ts b/apps/api/src/documentation/github/setup.test.ts index 746ebe1..d5df8d3 100644 --- a/apps/api/src/documentation/github/setup.test.ts +++ b/apps/api/src/documentation/github/setup.test.ts @@ -248,6 +248,8 @@ describe("account-bound GitHub setup proof", () => { mock as unknown as DocsGitHubApp, ); expect(result.repositories).toHaveLength(1); + // Offered even with an installation, so another organization can be added. + expect(result.installUrl).toMatch(/\/installations\/new$/); expect(result.installations).toEqual([ { installationId: 7, accountLogin: "org", accountType: "Organization" }, ]); diff --git a/apps/api/src/documentation/github/setup.ts b/apps/api/src/documentation/github/setup.ts index 9c32310..b01f1d9 100644 --- a/apps/api/src/documentation/github/setup.ts +++ b/apps/api/src/documentation/github/setup.ts @@ -205,14 +205,11 @@ export async function listSetupRepositories( (input.page ?? 1) > 100 ) throw new GitHubDocsError("GITHUB_INVALID_REQUEST", 400); + // Always offered: a user with one installation may still need to add an organization. + const installUrl = `https://github.com/apps/${encodeURIComponent(config.appSlug)}/installations/new`; const installationId = input.installationId ?? installations[0]?.id; if (installationId === undefined) - return { - installations: [], - repositories: [], - nextPage: null, - installUrl: `https://github.com/apps/${encodeURIComponent(config.appSlug)}/installations/new`, - }; + return { installations: [], repositories: [], nextPage: null, installUrl }; if (!installations.some((i) => i.id === installationId)) throw new GitHubDocsError("GITHUB_REPOSITORY_NOT_AUTHORIZED", 403); const page = input.page ?? 1; @@ -238,7 +235,7 @@ export async function listSetupRepositories( defaultBranch: r.default_branch, })), nextPage: batch.repositories.length === 100 ? page + 1 : null, - installUrl: null, + installUrl, }; } diff --git a/apps/web/components/content/documentation-source.tsx b/apps/web/components/content/documentation-source.tsx index 8faf2b4..baa62a3 100644 --- a/apps/web/components/content/documentation-source.tsx +++ b/apps/web/components/content/documentation-source.tsx @@ -279,7 +279,7 @@ export function DocumentationSource({ sessionStorage.removeItem(installRedirectKey); return; } - if (!repositories.installUrl || sessionStorage.getItem(installRedirectKey)) return; + if (sessionStorage.getItem(installRedirectKey)) return; sessionStorage.setItem(installRedirectKey, "1"); window.location.assign(repositories.installUrl); }, [repositories, installRedirectKey]); @@ -770,7 +770,7 @@ export function DocumentationSource({ lead="Pick the GitHub account and repository that will hold your docs or pages." /> {!repositories &&
Loading…
} - {repositories?.installUrl && ( + {repositories && repositories.installations.length === 0 && (+ Organization missing? Use “Add an organization or account” below. On + GitHub, an organization owner installs the app or approves your request. +