Skip to content
Snippets Groups Projects
Commit ea78cc22 authored by André Gomes's avatar André Gomes
Browse files

Optimize logic for GitLab URL parsing

parent d6ab14e2
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ description = "A package to perform IP Analysis for GitHub and GitLab projects"
readme = "README.md"
license = { text = "EPL-2.0" }
requires-python = ">=3.9"
dependencies = ["chardet==5.2.0", "Jinja2==3.1.6", "python-gitlab==6.1.0", "PyGithub==2.6.1"]
dependencies = ["chardet==5.2.0", "Jinja2==3.1.6", "PyGithub==2.6.1", "python-gitlab==6.1.0", "requests==2.32.4"]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)",
......
......@@ -20,6 +20,7 @@ from datetime import datetime
from pathlib import Path
from subprocess import PIPE, Popen
from time import sleep
from urllib.parse import urlparse
import gitlab
......@@ -39,8 +40,9 @@ def get_dependency_locations(gl, config, repositories):
line_count = 0
for repo in repositories:
# From URL to ID (required by python-gitlab)
repo = repo.replace(config.get('General', 'GitlabURL', fallback='https://gitlab.eclipse.org') + '/', '')
repo = repo.replace('.git', '')
repo = urlparse(repo).path.lstrip('/').removesuffix('.git')
# Remove any trailing slashes
repo = repo.rstrip('/')
dependency_locations[repo] = {}
line_count = line_count + 1
......@@ -63,8 +65,9 @@ def get_dependency_locations(gl, config, repositories):
tokens = line.strip().split(';')
proj_id = tokens[0]
# Get rid of base URL, if included (required by python-gitlab)
proj_id = proj_id.replace(config.get('General', 'GitlabURL',
fallback='https://gitlab.eclipse.org') + '/', '')
proj_id = urlparse(proj_id).path.lstrip('/').removesuffix('.git')
# Remove any trailing slashes
proj_id = proj_id.rstrip('/')
try:
dependency_locations[proj_id][tokens[2]].append(tokens[1])
except KeyError:
......@@ -88,8 +91,9 @@ def get_dependency_locations(gl, config, repositories):
line_count = line_count + 1
proj_id = line.strip()
# Get rid of base URL, if included (required by python-gitlab)
proj_id = proj_id.replace(config.get('General', 'GitlabURL',
fallback='https://gitlab.eclipse.org') + '/', '')
proj_id = urlparse(proj_id).path.lstrip('/').removesuffix('.git')
# Remove any trailing slashes
proj_id = proj_id.rstrip('/')
dependency_locations[proj_id] = {}
print("Read " + str(line_count) + " project(s) from " + input_file)
logger.info("Read " + str(line_count) + " project(s) from " + input_file)
......@@ -101,8 +105,10 @@ def get_dependency_locations(gl, config, repositories):
elif config.has_option('Groups', 'BaseGroupID'):
# Get rid of base URL, if included in BaseGroupID (required by python-gitlab)
base_group_id = config.get('Groups', 'BaseGroupID')
base_group_id = base_group_id.replace(config.get('General', 'GitlabURL',
fallback='https://gitlab.eclipse.org') + '/', '')
base_group_id = urlparse(base_group_id).path.lstrip('/')
# Remove any trailing slashes
base_group_id = base_group_id.rstrip('/')
try:
# Set base group ID to work
base_group = gl.groups.get(base_group_id, lazy=True)
......@@ -132,7 +138,11 @@ def get_dependency_locations(gl, config, repositories):
dependency_locations[proj.path_with_namespace] = {}
# Work with a single project ID
elif config.has_option('Projects', 'SingleProjectID'):
dependency_locations[config.get('Projects', 'SingleProjectID')] = {}
# Get rid of base URL, if included (required by python-gitlab)
repo = urlparse(config.get('Projects', 'SingleProjectID')).path.lstrip('/').removesuffix('.git')
# Remove any trailing slashes
repo = repo.rstrip('/')
dependency_locations[repo] = {}
else:
# No valid option provided, exit
print("Insufficient parameters provided. Exiting...")
......
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