Skip to content

Commit 5478ea8

Browse files
committed
Refactor swift
Signed-off-by: Tushar Goel <[email protected]>
1 parent b9b3391 commit 5478ea8

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

minecode_pipelines/pipes/swift.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ def mine_swift_packageurls(packages_urls, start_index, logger):
4242
for package_repo_url in package_batch:
4343
if not package_repo_url:
4444
continue
45-
logger(f"Processing package repo URL: {package_repo_url}")
46-
git_ls_remote = fetch_git_tags_raw(package_repo_url, 60, logger)
47-
if not git_ls_remote:
48-
continue
45+
logger(f"Processing package repo URL: {package_repo_url}")
46+
git_ls_remote = fetch_git_tags_raw(package_repo_url, 60, logger)
47+
if not git_ls_remote:
48+
continue
4949

50-
tags_and_commits = get_tags_and_commits_from_git_output(git_ls_remote)
51-
if not tags_and_commits:
52-
continue
50+
tags_and_commits = get_tags_and_commits_from_git_output(git_ls_remote)
51+
if not tags_and_commits:
52+
continue
5353

54-
yield generate_package_urls(
55-
package_repo_url=package_repo_url, tags_and_commits=tags_and_commits
56-
)
54+
yield generate_package_urls(
55+
package_repo_url=package_repo_url, tags_and_commits=tags_and_commits, logger=logger
56+
)
5757

5858

5959
def load_swift_package_urls(swift_index_repo):
@@ -63,8 +63,10 @@ def load_swift_package_urls(swift_index_repo):
6363
return packages_urls
6464

6565

66-
def generate_package_urls(package_repo_url, tags_and_commits):
67-
org, name = split_org_repo(package_repo_url)
66+
def generate_package_urls(package_repo_url, tags_and_commits, logger):
67+
org, name = split_org_repo(package_repo_url, logger)
68+
if not org or not name:
69+
return None, []
6870
org = "github.com/" + org
6971
base_purl = PackageURL(type="swift", namespace=org, name=name)
7072
updated_purls = []
@@ -99,9 +101,14 @@ def fetch_git_tags_raw(repo_url: str, timeout: int = 60, logger=None) -> str | N
99101
if git_executable is None:
100102
logger("Git executable not found in PATH")
101103
return None
104+
105+
if not repo_url:
106+
logger("No repository URL provided")
107+
return None
102108

103109
if not is_safe_repo_url(repo_url):
104-
raise ValueError(f"Unsafe repo URL: {repo_url}")
110+
logger(f"Unsafe repository URL: {repo_url}")
111+
return None
105112

106113
try:
107114
result = subprocess.run( # NOQA
@@ -120,7 +127,7 @@ def fetch_git_tags_raw(repo_url: str, timeout: int = 60, logger=None) -> str | N
120127

121128

122129
# FIXME duplicated with miners github
123-
def split_org_repo(url_like):
130+
def split_org_repo(url_like, logger):
124131
"""
125132
Given a URL-like string to a GitHub repo or a repo name as in org/name,
126133
split and return the org and name.
@@ -137,7 +144,8 @@ def split_org_repo(url_like):
137144
"""
138145
segments = [s.strip() for s in url_like.split("/") if s.strip()]
139146
if not len(segments) >= 2:
140-
raise ValueError(f"Not a GitHub-like URL: {url_like}")
147+
logger(f"Could not parse org and name from URL-like: {url_like}")
148+
return None, None
141149
org = segments[-2]
142150
name = segments[-1]
143151
if name.endswith(".git"):

pyproject-minecode_pipelines.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "flot.buildapi"
44

55
[project]
66
name = "minecode_pipelines"
7-
version = "0.0.1b45"
7+
version = "0.0.1b46"
88
description = "A library for mining packageURLs and package metadata from ecosystem repositories."
99
readme = "minecode_pipelines/README.rst"
1010
license = { text = "Apache-2.0" }

0 commit comments

Comments
 (0)