Skip to content

An open-source, faster Devin alternative

TypeScript

web: repository problem in words, from problemMessage or the code

Igor Zalutski via Computer3827d5df33de
diff --git a/web/src/api/mock-work.ts b/web/src/api/mock-work.ts
index fb2bbb47..5c9dd128 100644
--- a/web/src/api/mock-work.ts
+++ b/web/src/api/mock-work.ts
@@ -32,6 +32,7 @@ const repo = {
name: 'knowledge',
branch: 'main',
problem: null as string | null,
+ problemMessage: null as string | null,
}
let repository: typeof repo | null = repo
@@ -374,13 +375,18 @@ export function workMock(
s === 'none'
? null
: s === 'problem' && repository
- ? { ...repository, problem: 'the GitHub app no longer has access' }
+ ? {
+ ...repository,
+ problem: 'access_denied',
+ problemMessage:
+ "The installation cannot read the repository's contents.",
+ }
: repository
if (rest === '/repository') {
if (method === 'PUT') {
const body = JSON.parse(typeof input === 'string' ? input : '{}') as Json
- repository = { ...repo, ...body, problem: null }
+ repository = { ...repo, ...body, problem: null, problemMessage: null }
return { repository }
}
return { repository: current }
diff --git a/web/src/managed-agents/work/Board.tsx b/web/src/managed-agents/work/Board.tsx
index 058823a3..55660653 100644
--- a/web/src/managed-agents/work/Board.tsx
+++ b/web/src/managed-agents/work/Board.tsx
@@ -37,6 +37,7 @@ import {
plural,
readyToClose,
repositoryName,
+ repositoryProblem,
staleDays,
type Filters,
type Tab,
@@ -188,7 +189,7 @@ export function Board() {
status={
<IndexStatus
repository={repositoryName(page.repository)}
- problem={page.repository.problem ?? null}
+ problem={repositoryProblem(page.repository)}
building={page.building}
asOf={page.asOf}
/>
@@ -394,7 +395,7 @@ function IndexStatus({
{problem ? (
<>
<span className="text-status-error">
- Cannot read {repository}: {problem}.
+ Cannot read {repository}. {problem}
</span>
<Link
to="/computer#work-repository"
diff --git a/web/src/managed-agents/work/RepositorySetting.tsx b/web/src/managed-agents/work/RepositorySetting.tsx
index c258e130..1562020f 100644
--- a/web/src/managed-agents/work/RepositorySetting.tsx
+++ b/web/src/managed-agents/work/RepositorySetting.tsx
@@ -13,7 +13,7 @@ import {
workKeys,
type Repository,
} from './api'
-import { repositoryName } from './board'
+import { repositoryName, repositoryProblem } from './board'
// Which repository holds the organization's working docs (tech design 3.1):
// one per organization, chosen from what its GitHub connection can reach.
@@ -59,7 +59,9 @@ export function WorkRepositorySetting({ id }: { id?: string }) {
</span>
</p>
{current.problem ? (
- <p className="text-status-error">{current.problem}</p>
+ <p className="text-status-error">
+ {repositoryProblem(current)}
+ </p>
) : (
<p className="text-muted-foreground">
Tracked items live here and show on the{' '}
diff --git a/web/src/managed-agents/work/api.ts b/web/src/managed-agents/work/api.ts
index 6e05dc54..42d3b1cb 100644
--- a/web/src/managed-agents/work/api.ts
+++ b/web/src/managed-agents/work/api.ts
@@ -26,8 +26,11 @@ export const RepositorySchema = z.looseObject({
name: z.string(),
branch: z.string(),
// Set when the repository can no longer be read (installation removed,
- // repository deleted, renamed or no longer granted; tech design 3.6).
+ // repository deleted, renamed or no longer granted; tech design 3.6): a
+ // stable code such as `access_denied` or `repository_not_found`, and the
+ // server's sentence for a person. See `repositoryProblem` in board.ts.
problem: z.string().nullable().optional(),
+ problemMessage: z.string().nullable().optional(),
})
export type Repository = z.infer<typeof RepositorySchema>
diff --git a/web/src/managed-agents/work/board.test.ts b/web/src/managed-agents/work/board.test.ts
index 32172b06..767ebd33 100644
--- a/web/src/managed-agents/work/board.test.ts
+++ b/web/src/managed-agents/work/board.test.ts
@@ -8,6 +8,7 @@ import {
presentBody,
pullLabel,
readyToClose,
+ repositoryProblem,
resolveAgainst,
staleDays,
} from './board'
@@ -131,6 +132,31 @@ describe('card wording', () => {
})
})
+describe('repository problem', () => {
+ const r = {
+ installationId: '1',
+ owner: 'acme',
+ name: 'knowledge',
+ branch: 'main',
+ }
+ it('prefers the server sentence, then words for a known code', () => {
+ expect(repositoryProblem({ ...r, problem: null })).toBeNull()
+ expect(
+ repositoryProblem({
+ ...r,
+ problem: 'access_denied',
+ problemMessage: 'GitHub said no.',
+ }),
+ ).toBe('GitHub said no.')
+ expect(repositoryProblem({ ...r, problem: 'repository_not_found' })).toBe(
+ 'The repository does not exist, or the GitHub installation no longer grants it.',
+ )
+ const unknown = repositoryProblem({ ...r, problem: 'something_new' })
+ expect(unknown).toBeTruthy()
+ expect(unknown).not.toContain('something_new')
+ })
+})
+
describe('the doc as shown', () => {
it('drops the frontmatter and the leading title', () => {
expect(
diff --git a/web/src/managed-agents/work/board.ts b/web/src/managed-agents/work/board.ts
index 66cd5c08..354d9eac 100644
--- a/web/src/managed-agents/work/board.ts
+++ b/web/src/managed-agents/work/board.ts
@@ -109,6 +109,32 @@ export function repositoryName(r: Repository) {
return `${r.owner}/${r.name}`
}
+// The server's problem codes (its RepositoryProblem), in words, for when it
+// sends no `problemMessage`.
+const PROBLEM_TEXT: Record<string, string> = {
+ installation_removed:
+ 'The GitHub installation is not connected to this organization.',
+ installation_suspended: 'The GitHub installation is suspended.',
+ repository_not_found:
+ 'The repository does not exist, or the GitHub installation no longer grants it.',
+ branch_not_found: 'The repository has no such branch.',
+ access_denied: "The GitHub installation cannot read the repository's files.",
+ github_app_not_configured: 'The GitHub App is not configured.',
+}
+
+/**
+ * Why the repository cannot be read, as a sentence; null when it can. The
+ * server's own message wins; a code is never shown as it is.
+ */
+export function repositoryProblem(r: Repository): string | null {
+ if (!r.problem) return null
+ return (
+ r.problemMessage?.trim() ||
+ PROBLEM_TEXT[r.problem] ||
+ 'GitHub refused the last read; check the repository setting.'
+ )
+}
+
// The index is this far behind before the board says how old it is.
const STALE_INDEX_MS = 5 * 60_000
diff --git a/web/src/managed-agents/work/screens.test.tsx b/web/src/managed-agents/work/screens.test.tsx
index 72621ca7..3f5392cc 100644
--- a/web/src/managed-agents/work/screens.test.tsx
+++ b/web/src/managed-agents/work/screens.test.tsx
@@ -250,13 +250,18 @@ describe('board', () => {
it('sends a repository problem to settings', async () => {
workApi.getOpenItems.mockResolvedValue(
openPage(items, {
- repository: { ...repository, problem: 'access was removed' },
+ repository: {
+ ...repository,
+ problem: 'access_denied',
+ problemMessage: 'GitHub refused access to the repository.',
+ },
}),
)
await render('/computer/work')
expect(container.textContent).toContain(
- 'Cannot read acme/knowledge: access was removed.',
+ 'Cannot read acme/knowledge. GitHub refused access to the repository.',
)
+ expect(container.textContent).not.toContain('access_denied')
expect(
container.querySelector('a[href="/computer#work-repository"]'),
).not.toBeNull()