From 0eb86e2c1238f3849a93f5c70f40eae2170deaf3 Mon Sep 17 00:00:00 2001 From: t2 <46615000+t2tx@users.noreply.github.com> Date: Tue, 18 Feb 2025 05:25:11 +0900 Subject: [PATCH] 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: shatfield4 <seanhatfield5@gmail.com> Co-authored-by: Timothy Carambat <rambat1010@gmail.com> --- .../RepoLoader/GitlabRepo/RepoLoader/index.js | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/collector/utils/extensions/RepoLoader/GitlabRepo/RepoLoader/index.js b/collector/utils/extensions/RepoLoader/GitlabRepo/RepoLoader/index.js index 79afd5a96..e22dd690a 100644 --- a/collector/utils/extensions/RepoLoader/GitlabRepo/RepoLoader/index.js +++ b/collector/utils/extensions/RepoLoader/GitlabRepo/RepoLoader/index.js @@ -45,30 +45,20 @@ class GitLabRepoLoader { } #validGitlabUrl() { - const UrlPattern = require("url-pattern"); const validPatterns = [ - new UrlPattern("https\\://gitlab.com/(:author*)/(:project(*))", { - segmentValueCharset: "a-zA-Z0-9-._~%+", - }), + /https:\/\/gitlab\.com\/(?<author>[^\/]+)\/(?<project>.*)/, // 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 // since the API interface could be different. - new UrlPattern( - "(:protocol(http|https))\\://(:hostname*)/(:author*)/(:project(*))", - { - segmentValueCharset: "a-zA-Z0-9-._~%+", - } - ), + /(http|https):\/\/[^\/]+\/(?<author>[^\/]+)\/(?<project>.*)/, ]; - let match = null; - for (const pattern of validPatterns) { - if (match !== null) continue; - match = pattern.match(this.repo); - } - if (!match) return false; - const { author, project } = match; + const match = validPatterns + .find((pattern) => this.repo.match(pattern)?.groups) + ?.exec(this.repo); + if (!match?.groups) return false; + const { author, project } = match.groups; this.projectId = encodeURIComponent(`${author}/${project}`); this.apiBase = new URL(this.repo).origin; this.author = author; -- GitLab