Skip to content

Commit e2d9963

Browse files
authored
Merge pull request #569 from middlewarehq/fix/gitlab-token-validaity
Refactor GitLab validity check to include custom domain support
2 parents 9f5f552 + 6c83ce5 commit e2d9963

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

web-server/src/content/Dashboards/ConfigureGitlabModalBody.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ export const ConfigureGitlabModalBody: FC<{
4848

4949
const checkDomainWithRegex = (domain: string) => {
5050
const regex =
51-
/^(https:\/\/)?[a-zA-Z0-9]+([-.][a-zA-Z0-9]+)*\.[a-zA-Z]{2,}(:[0-9]{1,5})?(\/.*)?$/;
51+
/^(https?:\/\/)[a-zA-Z0-9]+([-.][a-zA-Z0-9]+)*\.[a-zA-Z]{2,}(:[0-9]{1,5})?(\/.*)?$/;
5252
return regex.test(domain);
5353
};
54-
5554
const handleTokenChange = (e: string) => {
5655
token.set(e);
5756
showScopeError.set('');
@@ -79,7 +78,7 @@ export const ConfigureGitlabModalBody: FC<{
7978
}
8079

8180
depFn(isLoading.true);
82-
await checkGitLabValidity(token.value)
81+
await checkGitLabValidity(token.value, customDomain.value)
8382
.then(async (res) => {
8483
return res;
8584
})

web-server/src/utils/auth.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ export const getMissingPATScopes = async (pat: string) => {
6363

6464
// Gitlab functions
6565

66-
export const checkGitLabValidity = async (accessToken: string) => {
67-
const url = 'https://gitlab.com/api/v4/personal_access_tokens/self';
66+
export const checkGitLabValidity = async (
67+
accessToken: string,
68+
customDomain?: string
69+
) => {
70+
const baseUrl = customDomain || 'https://gitlab.com';
71+
const url = `${baseUrl}/api/v4/personal_access_tokens/self`;
6872
try {
6973
const response = await axios.get(url, {
7074
headers: {

0 commit comments

Comments
 (0)