Skip to content
Commits on Source (3)
......@@ -92,7 +92,7 @@ def get_last_commit_hash(
def format_fork_metadata(
fork: Dict, header: Dict[str, str], deadline: Optional[str] = None
fork: Dict, header: Dict[str, str], deadline: Optional[str] = None, custom_renku_url: Optional[str] = None
) -> Dict:
"""Format and add fields to a fork's metadata. The
resulting metadata will have the following fields:
......@@ -119,9 +119,12 @@ def format_fork_metadata(
meta["commit"] = get_last_commit_hash(meta["id"], base, header, deadline)
# Build a renku autostart url using the commit hash
if custom_renku_url is None:
renku_base = f"{re.sub(r'/gitlab.*$', '', base)}"
else:
renku_base = custom_renku_url
autostart_url = (
f"{re.sub(r'/gitlab.*$', '', base)}"
f"/projects/{namespace}/{repo.removesuffix('.git')}/sessions/"
f"{renku_base}/projects/{namespace}/{repo.removesuffix('.git')}/sessions/"
f"new?autostart=1&commit={meta['commit']}&branch=master"
)
meta["autostart_url"] = autostart_url
......@@ -144,9 +147,15 @@ def format_fork_metadata(
is_flag=True,
help="Only consider forks belonging to a group (and not an individual user).",
)
def collect_forks(repo_url, token_path, deadline=None, group_only=False):
@click.option(
"--custom-renku-url",
type=str,
help="If you are using a custom renku deployment, you can provide the base url here.",
)
def collect_forks(repo_url, token_path, deadline=None, group_only=False, custom_renku_url=None):
"""Gather metadata about all forks of input project into a JSON file.
REPO_URL must be the URL to the Gitlab repository."""
token = ingest_token(token_path)
# Check for valid deadline format
if deadline is not None:
......@@ -160,7 +169,7 @@ def collect_forks(repo_url, token_path, deadline=None, group_only=False):
forks = filter_group_forks(forks)
# Reformat metadata for convenience
meta = map(lambda f: format_fork_metadata(f, header, deadline), forks)
meta = map(lambda f: format_fork_metadata(f, header, deadline, custom_renku_url), forks)
print(json.dumps(list(meta)))
......