Skip to content

Commit

Permalink
Merge pull request #362 from bento-platform/features/katsu-version
Browse files Browse the repository at this point in the history
add git info to katsu service-info
  • Loading branch information
davidlougheed committed Jan 10, 2023
2 parents 6bf2861 + 2cab68d commit 6cd31b6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
42 changes: 41 additions & 1 deletion chord_metadata_service/metadata/service_info.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
from .. import __version__
from .settings import CHORD_SERVICE_TYPE, CHORD_SERVICE_ID
from .settings import CHORD_SERVICE_TYPE, CHORD_SERVICE_ID, DEBUG
import subprocess
import os

path_for_git = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))


def before_first_request_func():
try:
subprocess.run(["git", "config", "--global", "--add", "safe.directory", str(path_for_git)])
except Exception as e:
except_name = type(e).__name__
print("Error in dev-mode retrieving git folder configuration", except_name)


before_first_request_func()

# Service info according to spec https://github.com/ga4gh-discovery/ga4gh-service-info

SERVICE_INFO = {
"id": CHORD_SERVICE_ID,
"name": "Metadata Service", # TODO: Globally unique?
"type": CHORD_SERVICE_TYPE,
"environment": "prod",
"description": "Metadata service implementation based on Phenopackets schema",
"organization": {
"name": "C3G",
Expand All @@ -15,3 +31,27 @@
"contactUrl": "mailto:ksenia.zaytseva@mcgill.ca",
"version": __version__
}


def service_info_git():
info = {
**SERVICE_INFO,
"environment": "dev",
}
try:
res_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"])
if res_tag:
info["git_tag"] = res_tag.decode().rstrip()
res_branch = subprocess.check_output(["git", "branch", "--show-current"])
if res_branch:
info["git_branch"] = res_branch.decode().rstrip()

except Exception as e:
except_name = type(e).__name__
print("Error in dev-mode retrieving git information", except_name)

return info # updated service info with the git info


if DEBUG:
SERVICE_INFO = service_info_git()
8 changes: 3 additions & 5 deletions scripts/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,9 @@ def ingest_phenopackets(katsu_server_url, table_id, phenopackets_json_location):
sys.exit()
else:
print(
"Something else went wrong when ingesting phenopackets, possibly due to duplications."
)
print(
"Double check phenopackets_json_location config, or remove "
"duplicated individuals from the database and try again."
"""Something went wrong ingesting phenopackets, possibly due to duplications.
Check phenopackets_json_location config,
or remove duplicated individuals from the database and try again."""
)
sys.exit()

Expand Down

0 comments on commit 6cd31b6

Please sign in to comment.