Skip to content
Snippets Groups Projects
Unverified Commit 0eb86e2c authored by t2's avatar t2 Committed by GitHub
Browse files

for projects in gitlab subgroup (#3075) (#3247)


* for projects in gitlab subgroup (#3075)

* fix: false condition

* refactor pattern matching logic

---------

Co-authored-by: t2 <>
Co-authored-by: default avatarshatfield4 <seanhatfield5@gmail.com>
Co-authored-by: default avatarTimothy Carambat <rambat1010@gmail.com>
parent e978c90e
No related branches found
No related tags found
No related merge requests found
...@@ -45,30 +45,20 @@ class GitLabRepoLoader { ...@@ -45,30 +45,20 @@ class GitLabRepoLoader {
} }
#validGitlabUrl() { #validGitlabUrl() {
const UrlPattern = require("url-pattern");
const validPatterns = [ const validPatterns = [
new UrlPattern("https\\://gitlab.com/(:author*)/(:project(*))", { /https:\/\/gitlab\.com\/(?<author>[^\/]+)\/(?<project>.*)/,
segmentValueCharset: "a-zA-Z0-9-._~%+",
}),
// This should even match the regular hosted URL, but we may want to know // This should even match the regular hosted URL, but we may want to know
// if this was a hosted GitLab (above) or a self-hosted (below) instance // if this was a hosted GitLab (above) or a self-hosted (below) instance
// since the API interface could be different. // since the API interface could be different.
new UrlPattern( /(http|https):\/\/[^\/]+\/(?<author>[^\/]+)\/(?<project>.*)/,
"(:protocol(http|https))\\://(:hostname*)/(:author*)/(:project(*))",
{
segmentValueCharset: "a-zA-Z0-9-._~%+",
}
),
]; ];
let match = null; const match = validPatterns
for (const pattern of validPatterns) { .find((pattern) => this.repo.match(pattern)?.groups)
if (match !== null) continue; ?.exec(this.repo);
match = pattern.match(this.repo); if (!match?.groups) return false;
}
if (!match) return false;
const { author, project } = match;
const { author, project } = match.groups;
this.projectId = encodeURIComponent(`${author}/${project}`); this.projectId = encodeURIComponent(`${author}/${project}`);
this.apiBase = new URL(this.repo).origin; this.apiBase = new URL(this.repo).origin;
this.author = author; this.author = author;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment