Skip to content

Commit

Permalink
Add modified and git metadata to register.json
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Jan 29, 2024
1 parent e58076a commit 963aa85
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions ogc/bblocks/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import datetime
import os
import shutil
import subprocess
Expand Down Expand Up @@ -181,6 +182,8 @@
if sparql_conf and sparql_conf.get('query'):
register_additional_metadata['sparqlEndpoint'] = sparql_conf['query']

register_additional_metadata['modified'] = datetime.datetime.now().isoformat()

if os.environ.get('BBP_GIT_INFO_FILE'):
with open(os.environ['BBP_GIT_INFO_FILE']) as f:
git_info = f.readline().strip()
Expand All @@ -196,22 +199,26 @@
base_url = args.base_url
github_base_url = args.github_base_url
git_repo_path = None
if not base_url or not github_base_url:
try:
import git
repo = git.Repo()
git_repo_path = Path(repo.working_dir)
remote_branch = repo.active_branch.tracking_branch()
remote = repo.remote(remote_branch.remote_name)
remote_url = next(remote.urls)
gh_repo = get_github_repo(remote_url)
if gh_repo:
try:
import git
repo = git.Repo()
git_repo_path = Path(repo.working_dir)
remote_branch = repo.active_branch.tracking_branch()
remote = repo.remote(remote_branch.remote_name)
remote_url = next(remote.urls)
gh_repo = get_github_repo(remote_url)
if gh_repo:
if not base_url:
base_url = f"https://{gh_repo[0]}.github.io/{gh_repo[1]}/"
if not github_base_url:
github_base_url = f"https://github.com/{gh_repo[0]}/{gh_repo[1]}/"
print(f"Autodetected GitHub repo {gh_repo[0]}/{gh_repo[1]}")
except:
print('[WARN] Could not autodetect base_url / github_base_url', file=sys.stderr)
pass
print(f"Autodetected GitHub repo {gh_repo[0]}/{gh_repo[1]}")
register_additional_metadata['gitHubRepository'] = github_base_url
if remote_url:
register_additional_metadata['gitRepository'] = remote_url
except:
print('[WARN] Could not autodetect base_url / github_base_url', file=sys.stderr)
pass

steps = args.steps.split(',') if args.steps else None

Expand Down

0 comments on commit 963aa85

Please sign in to comment.