Skip to content

Commit

Permalink
Merge pull request #171 from github-community-projects/enforce-name-l…
Browse files Browse the repository at this point in the history
…imit

fix: Enforce repository name length limit in dialogs
  • Loading branch information
zkoppert authored Jun 13, 2024
2 parents 9dda625 + b37f33c commit 55bf136
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/app/components/dialog/CreateMirrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const CreateMirrorDialog = ({
onChange={(e) => setRepoName(e.target.value)}
block
placeholder="e.g. repository-name"
maxLength={100}
/>
<FormControl.Caption>
This is a private mirror of{' '}
Expand Down
1 change: 1 addition & 0 deletions src/app/components/dialog/EditMirrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const EditMirrorDialog = ({
onChange={(e) => setNewMirrorName(e.target.value)}
block
placeholder="e.g. repository-name"
maxLength={100}
/>
<FormControl.Caption>
This is a private mirror of{' '}
Expand Down
4 changes: 2 additions & 2 deletions src/server/repos/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const CreateMirrorSchema = z.object({
forkRepoOwner: z.string(),
forkRepoName: z.string(),
forkId: z.string(),
newRepoName: z.string(),
newRepoName: z.string().max(100),
newBranchName: z.string(),
})

Expand All @@ -17,7 +17,7 @@ export const ListMirrorsSchema = z.object({
export const EditMirrorSchema = z.object({
orgId: z.string(),
mirrorName: z.string(),
newMirrorName: z.string(),
newMirrorName: z.string().max(100),
})

export const DeleteMirrorSchema = z.object({
Expand Down
19 changes: 19 additions & 0 deletions test/server/repos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,23 @@ describe('Repos router', () => {
})
expect(stubbedGit.clone).toHaveBeenCalledTimes(1)
})

it('reject repository names over the character limit', async () => {
const caller = reposRouter.createCaller(createTestContext())

await caller
.createMirror({
forkId: 'test',
orgId: 'test',
forkRepoName: 'fork-test',
forkRepoOwner: 'github',
newBranchName: 'test',
newRepoName: 'a'.repeat(101),
})
.catch((error) => {
expect(error.message).toMatch(
/String must contain at most 100 character\(s\)/,
)
})
})
})

0 comments on commit 55bf136

Please sign in to comment.