An open-source, faster Devin alternative
TypeScript
Add repository access action to Git deploy settings (#843)
Mohamed Habib5f1bd4e1dc1e
diff --git a/web/src/managed-agents/GitHub.test.tsx b/web/src/managed-agents/GitHub.test.tsxindex a663b1d3..e0a00fbd 100644--- a/web/src/managed-agents/GitHub.test.tsx+++ b/web/src/managed-agents/GitHub.test.tsx@@ -19,7 +19,8 @@ vi.mock('./api', () => api)vi.mock('./authorization-window', () => authorization)const { ManagedProjectGitHub } = await import('./GitHub')-const { githubConnectionLabel } = await import('./github-connection')+const { githubConnectionLabel, githubInstallationSettingsUrl } =+ await import('./github-connection')async function settle(until: () => boolean, label: string) {for (let attempt = 0; attempt < 50; attempt += 1) {@@ -118,4 +119,23 @@ describe('ManagedProjectGitHub', () => {}),).toBe('diggerhq · installation 164620985 · selected repositories')})++ it('links to the settings page that can grant more repositories', () => {+ expect(+ githubInstallationSettingsUrl({+ accountLogin: 'diggerhq',+ accountType: 'Organization',+ githubInstallationId: 164620985,+ }),+ ).toBe(+ 'https://github.com/organizations/diggerhq/settings/installations/164620985',+ )+ expect(+ githubInstallationSettingsUrl({+ accountLogin: 'octocat',+ accountType: 'User',+ githubInstallationId: 42,+ }),+ ).toBe('https://github.com/settings/installations/42')+ })})diff --git a/web/src/managed-agents/Settings.tsx b/web/src/managed-agents/Settings.tsxindex edc2e50f..34ac6b12 100644--- a/web/src/managed-agents/Settings.tsx+++ b/web/src/managed-agents/Settings.tsx@@ -39,6 +39,7 @@ import {type ManagedGitBuild,} from './api'import { launchAuthorizationWindow } from './authorization-window'+import { githubInstallationSettingsUrl } from './github-connection'const selectClassName ='border-input bg-background h-9 min-w-48 rounded-md border px-3 text-sm disabled:opacity-50'@@ -113,6 +114,9 @@ export function ManagedProjectSettings({ projectId }: { projectId: string }) {: undefinedconst connectionId =pickedConnectionId || savedConnectionId || activeConnections[0]?.id || ''+ const activeConnection = activeConnections.find(+ (connection) => connection.id === connectionId,+ )const repositories = useQuery({queryKey: ['managed-deployment-source-repos', projectId, connectionId],@@ -252,9 +256,8 @@ export function ManagedProjectSettings({ projectId }: { projectId: string }) {<PanelTitle>Deploy from GitHub</PanelTitle><PanelDescription className="mt-1 max-w-2xl">Connect a repository and pick a branch. Every push to that branch- builds the project and publishes it to the development- environment; pull requests against it get their own preview- environment.+ builds and publishes the project; pull requests against it get+ their own preview deployment.</PanelDescription></div>{source ? (@@ -403,7 +406,29 @@ export function ManagedProjectSettings({ projectId }: { projectId: string }) {</select></div><div className="grid gap-1.5">- <Label htmlFor="deployment-source-repository">Repository</Label>+ <div className="flex items-center justify-between gap-3">+ <Label htmlFor="deployment-source-repository">+ Repository+ </Label>+ {activeConnection?.repositorySelection === 'selected' ? (+ <Button+ type="button"+ variant="link"+ size="sm"+ className="h-auto px-0 text-xs"+ asChild+ >+ <a+ href={githubInstallationSettingsUrl(activeConnection)}+ target="_blank"+ rel="noreferrer"+ >+ Add more repositories+ <ExternalLink className="size-3" />+ </a>+ </Button>+ ) : null}+ </div><selectid="deployment-source-repository"className={selectClassName}@@ -453,7 +478,8 @@ export function ManagedProjectSettings({ projectId }: { projectId: string }) {</div><div className="grid gap-1.5"><Label htmlFor="deployment-source-path">- Directory <span className="text-muted-foreground">(optional)</span>+ Directory{' '}+ <span className="text-muted-foreground">(optional)</span></Label><Inputid="deployment-source-path"@@ -469,7 +495,7 @@ export function ManagedProjectSettings({ projectId }: { projectId: string }) {onCheckedChange={setPreviewsEnabled}/><Label htmlFor="deployment-source-previews">- Preview environment for every pull request+ Preview deployment for every pull request</Label></div><div className="flex items-center gap-2 sm:col-span-2">diff --git a/web/src/managed-agents/github-connection.ts b/web/src/managed-agents/github-connection.tsindex e07283fe..e1215351 100644--- a/web/src/managed-agents/github-connection.ts+++ b/web/src/managed-agents/github-connection.ts@@ -9,3 +9,17 @@ export function githubConnectionLabel(connection: {: 'selected repositories'return `${connection.accountLogin} · installation ${connection.githubInstallationId} · ${repositories}`}++export function githubInstallationSettingsUrl(connection: {+ accountLogin: string+ accountType: string+ githubInstallationId: number+}) {+ const installation = encodeURIComponent(+ String(connection.githubInstallationId),+ )+ if (connection.accountType.toLowerCase() === 'organization') {+ return `https://github.com/organizations/${encodeURIComponent(connection.accountLogin)}/settings/installations/${installation}`+ }+ return `https://github.com/settings/installations/${installation}`+}