From 4d0326e998136bc330171bf760bc1e8a0a6cccf4 Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Wed, 17 Apr 2024 15:47:23 +0300 Subject: Add an endpoint to query a dataset's git history from it's id. * gn3/api/metadata.py: Import get_history. (view_history): New endpoint. * gn3/db/datasets.py (get_history): New function. Signed-off-by: Munyoki Kilyungi --- gn3/db/datasets.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'gn3/db') diff --git a/gn3/db/datasets.py b/gn3/db/datasets.py index fef01a5..f3b4f9f 100644 --- a/gn3/db/datasets.py +++ b/gn3/db/datasets.py @@ -408,3 +408,34 @@ def save_metadata( ])) .then(lambda _: monadic_run_cmd(f"git -C {git_dir} \ push origin master --dry-run".split(" ")))) + + +def get_history(git_dir: str, name: str) -> Either: + """Get the git history for a given dataset. This history is + returned as a HTML formatted text. Example of the formatted + output: + + ``` + + 3 Weeks Ago + + + some-id + + + commit header + Author Name + + ``` + + """ + pretty_format_str = "%cr\ +\ +%h\ +%s%an" + return monadic_run_cmd([ + "git", "-C", + str(Path(git_dir) / "general/datasets/" / name), + "log", f"--pretty=format:{pretty_format_str}", + ]) -- cgit v1.2.3