feat: browse GitHub repository access across organizations (#12998)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - GitHub connections give agents access to approved repositories.
> - One GitHub identity can use installations across several
organizations.
> - The permissions page linked to one installation and showed an
unfiltered list.
> - Users could not easily find another organization or inspect a large
selection.
> - This change adds account filtering, search, and access configuration
links.
> - Users can inspect repository access in one compact view.

## Linked Issues or Issue Description

Refs #12993. Related repository-catalog work in #11228 and #11234 was
checked. This change only improves the existing GitHub connection
permissions page.

**What existing behavior does this improve?**

The GitHub connection permissions page and its repository display
metadata.

**Current behavior**

The page links directly to an existing installation. The repository list
has no account filter, search, height limit, or private-repository
marker. Refresh access occupies a separate section.

**Proposed behavior**

Show all authorized repositories by default. Filter by account or
organization and search by name. Open GitHub's account chooser to
configure access across organizations. Show GitHub icons and
private-repository locks. Keep refresh beside configuration and limit
the visible list to about ten rows.

**Reason and benefit**

Users can find repositories across organizations and configure missing
access without creating another GitHub identity. Large repository lists
no longer fill the page.

**Breaking changes**

None. Repository display metadata gains an optional private flag. Older
snapshots remain valid and gain the flag after access refresh. No SQL
migration is required.

## What Changed

- Add an All accounts view, account filter, search, and empty states.
- Link both configuration controls to GitHub's app account chooser.
- Place an accessible refresh icon beside the configuration button.
- Keep the repository heading and list in one section.
- Add GitHub icons and private-repository locks.
- Cap the scrollable list at ten rows using a design token.
- Persist GitHub's private flag only when the provider returns a
boolean.
- Recover missing legacy app configuration from GitHub installation
metadata.
- Update tests and the GitHub connection runbook.

## Verification

- Focused tests passed: 54 permissions-page tests and four GitHub
metadata tests.
- UI and server typechecks passed before submission. Token gates passed.
- Browser checks verified account filtering, search, empty results, and
the configuration destination.
- The live list contained 40 repositories. Its final height was 272
pixels, which fits ten single-line rows with gaps. Scrolling retained
all rows.
- A live access refresh populated 30 private-repository lock icons from
GitHub metadata.
- Full workspace typecheck and build passed. The broad local suite
stopped in the general-server group with 18 failed files. Failures
include macOS temporary-path handling and embedded PostgreSQL startup.
That run also overlapped the legacy fix and retained a stale GitHub
module; the final focused run passed all 58 tests. Clean-runner CI is
tracked separately.
- Latest-head review is 5/5 with the legacy chooser finding resolved.
All CI checks passed on commit
`0ff2b63f348f5c87d8b7df6e43388f60f5d872d9`, including build, typecheck,
all test shards, browser tests, and canary dry run.

## Risks

- Older repository snapshots lack visibility metadata until refreshed.
Unknown visibility does not display a lock.
- The account filter lists authorized installation owners. Users add
other organizations through GitHub's chooser.
- Filtering changes only the displayed list. GitHub remains
authoritative for repository access.

## Model Used

OpenAI GPT-6 (`gpt-6-astra`) via Codex. Reasoning, code execution, and
browser tools were used. The exact context window size was not exposed.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-09-07 10:01:58 -05:00
1 parent bac60d9d31
commit 932ddb7b37
8 files changed
+225 -62

No files matched your search

@@ -24,8 +24,8 @@ describe("GitHub grant metadata", () => {
}
if (url.pathname === "/user/installations/101/repositories") {
return json({ total_count: 2, repositories: secondPage
? [{ id: 2, full_name: "paperclipai/b", description: "must-not-persist", clone_url: "must-not-persist" }]
: [{ id: 1, full_name: "paperclipai/a" }],
? [{ id: 2, full_name: "paperclipai/b", private: true, description: "must-not-persist", clone_url: "must-not-persist" }]
: [{ id: 1, full_name: "paperclipai/a", private: false }],
}, !secondPage);
}
if (url.pathname === "/user/installations/102/repositories") {
@@ -45,14 +45,15 @@ describe("GitHub grant metadata", () => {
installationOwnerLogins: ["paperclipai", "octocat"],
repositories: [
{ id: "3", fullName: "octocat/c", installationId: "102" },
{ id: "1", fullName: "paperclipai/a", installationId: "101" },
{ id: "2", fullName: "paperclipai/b", installationId: "101" },
{ id: "1", fullName: "paperclipai/a", installationId: "101", private: false },
{ id: "2", fullName: "paperclipai/b", installationId: "101", private: true },
],
installationUrl: "https://github.com/apps/paperclip-development/installations/new",
managementUrl: "https://github.com/settings/installations/101",
appSlug: "paperclip-development",
webhookHealth: "pending",
});
expect(metadata.repositories[0]).not.toHaveProperty("private");
expect(JSON.stringify(metadata)).not.toContain("must-not-persist");
expect(request).toHaveBeenCalledTimes(6);
for (const [input, init] of request.mock.calls) {
@@ -61,6 +62,17 @@ describe("GitHub grant metadata", () => {
}
});
it("recovers a legacy grant's app chooser from GitHub installation metadata", async () => {
const request = vi.fn<typeof fetch>()
.mockResolvedValueOnce(json({ id: 42, login: "octocat" }))
.mockResolvedValueOnce(json({ installations: [{ id: 101, app_slug: "paperclip-staging", repository_selection: "selected" }] }))
.mockResolvedValueOnce(json({ repositories: [{ id: 1, full_name: "octocat/a" }] }));
await expect(loadGitHubGrantMetadata("ghu_secret", request)).resolves.toMatchObject({
appSlug: "paperclip-staging",
installationUrl: "https://github.com/apps/paperclip-staging/installations/new",
});
});
it("requires at least one installation with an accessible repository", async () => {
const request = vi.fn<typeof fetch>(async (input) => String(input).endsWith("/user")
? json({ id: 42, login: "octocat" })
+18 -8
View File
@@ -1942,7 +1942,7 @@ export async function loadGitHubGrantMetadata(
repositorySelection: "all" | "selected" | "mixed" | "none";
installationIds: string[];
installationOwnerLogins: string[];
repositories: Array<{ id: string; fullName: string; installationId: string }>;
repositories: Array<{ id: string; fullName: string; installationId: string; private?: boolean }>;
installationUrl: string;
managementUrl: string;
appSlug?: string;
@@ -1950,6 +1950,7 @@ export async function loadGitHubGrantMetadata(
lastAccessRefreshAt: string;
webhookHealth: "pending";
}> {
let resolvedAppSlug = appSlug;
const accessRefreshStartedAt = new Date().toISOString();
const github = async (path: string): Promise<{ data: Record<string, unknown>; hasNext: boolean }> => {
const response = await request(`https://api.github.com${path}`, {
@@ -1991,11 +1992,17 @@ export async function loadGitHubGrantMetadata(
const owners = new Set<string>();
const selections = new Set<"all" | "selected">();
const managementUrls = new Set<string>();
const repositories = new Map<string, { id: string; fullName: string; installationId: string }>();
const repositories = new Map<string, { id: string; fullName: string; installationId: string; private?: boolean }>();
for (const installation of installations) {
const installationId = githubId(installation.id);
if (!installationId) continue;
installationIds.push(installationId);
// Older grants predate the broker's appSlug field. GitHub's installation
// response identifies this token's app without choosing an environment.
if (!resolvedAppSlug && typeof installation.app_slug === "string"
&& /^[a-z0-9-]{1,100}$/.test(installation.app_slug)) {
resolvedAppSlug = installation.app_slug;
}
if (installation.repository_selection === "all" || installation.repository_selection === "selected") {
selections.add(installation.repository_selection);
}
@@ -2009,13 +2016,16 @@ export async function loadGitHubGrantMetadata(
if (!id || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(fullName)) {
throw unprocessable("GitHub returned invalid repository metadata", { code: "github_bad_response" });
}
repositories.set(id, { id, fullName, installationId });
repositories.set(id, {
id, fullName, installationId,
...(typeof repository.private === "boolean" ? { private: repository.private } : {}),
});
}
}
const repositoryCount = repositories.size;
if (installationIds.length === 0 || repositoryCount === 0) {
const installationUrl = appSlug
? `https://github.com/apps/${appSlug}/installations/new`
const installationUrl = resolvedAppSlug
? `https://github.com/apps/${resolvedAppSlug}/installations/new`
: "https://github.com/settings/installations";
throw unprocessable("GitHub access is required. Install Paperclip and grant at least one repository before refreshing access.", {
code: "github_installation_required",
@@ -2023,8 +2033,8 @@ export async function loadGitHubGrantMetadata(
managementUrl: "https://github.com/settings/installations",
});
}
const installationUrl = appSlug
? `https://github.com/apps/${appSlug}/installations/new`
const installationUrl = resolvedAppSlug
? `https://github.com/apps/${resolvedAppSlug}/installations/new`
: "https://github.com/settings/installations";
return {
userId,
@@ -2040,7 +2050,7 @@ export async function loadGitHubGrantMetadata(
managementUrl: managementUrls.size === 1
? managementUrls.values().next().value!
: "https://github.com/settings/installations",
...(appSlug ? { appSlug } : {}),
...(resolvedAppSlug ? { appSlug: resolvedAppSlug } : {}),
accessRevision: randomUUID(),
lastAccessRefreshAt: accessRefreshStartedAt,
webhookHealth: "pending",