Skip to content

Commit d78df16

Browse files
committed
fix: repository url validation
1 parent d032ed2 commit d78df16

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/pages/code-repositories/create-edit/create-edit.validator.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,10 @@ import { boolean, object, string } from 'yup'
22

33
// Custom validation for repositoryUrl
44
const urlValidation = string().test('is-valid-url', 'Invalid URL for the selected git service', function (value) {
5-
const { gitService, private: isPrivate } = this.parent
5+
const { gitService } = this.parent
66
if (gitService === 'gitea') return value.startsWith('https://gitea')
7-
if (gitService === 'github') {
8-
const isValid = /^(https:\/\/github\.com\/.+|git@github\.com:.+\.git)$/.test(value)
9-
if (value.startsWith('git@github') && !isPrivate)
10-
return this.createError({ message: 'Private must be selected for SSH URLs' })
11-
return isValid
12-
}
13-
if (gitService === 'gitlab') {
14-
const isValid = /^(https:\/\/gitlab\.com\/.+|git@gitlab\.com:.+\.git)$/.test(value)
15-
if (value.startsWith('git@gitlab') && !isPrivate)
16-
return this.createError({ message: 'Private must be selected for SSH URLs' })
17-
return isValid
18-
}
7+
if (gitService === 'github') return /^(https:\/\/github\.com\/.+|git@github\.com:.+\.git)$/.test(value)
8+
if (gitService === 'gitlab') return /^(https:\/\/gitlab\.com\/.+|git@gitlab\.com:.+\.git)$/.test(value)
199
return true
2010
})
2111

src/pages/code-repositories/create-edit/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export default function ({
161161
if (watch('private')) {
162162
validSecret = await trigger('secret')
163163
setSecretName(watch('secret'))
164-
}
164+
} else setSecretName(undefined)
165165
const validRepositoryUrl = await trigger('repositoryUrl')
166166
if (validRepositoryUrl && validSecret) setTestConnectUrl(watch('repositoryUrl'))
167167
}

0 commit comments

Comments
 (0)