aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-04-17 15:47:23 +0300
committerBonfaceKilz2024-04-30 12:18:58 +0300
commit4d0326e998136bc330171bf760bc1e8a0a6cccf4 (patch)
tree67c67c84d91818ea687eacfc04ef1ddaf1dfc8c6 /gn3/db
parente4cc7ffce07f8c33f42e2ec0257277897217c98b (diff)
downloadgenenetwork3-4d0326e998136bc330171bf760bc1e8a0a6cccf4.tar.gz
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 <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/datasets.py31
1 files changed, 31 insertions, 0 deletions
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:
+
+ ```
+ <tr>
+ <td><i>3 Weeks Ago</i></td>
+ <td>
+ <a style='color:green;' href='..id=some-id' target='_blank'>
+ some-id
+ </a>
+ </td>
+ <td>commit header</td>
+ <td>Author Name</td>
+ </tr>
+ ```
+
+ """
+ pretty_format_str = "<tr><td><i>%cr</i></td>\
+<td>\
+<a style='color:green;' href='https://git.genenetwork.org/gn-docs/commit/general?id=%H' \
+target='_blank'>%h</a></td>\
+<td>%s</td><td>%an</td></tr>"
+ return monadic_run_cmd([
+ "git", "-C",
+ str(Path(git_dir) / "general/datasets/" / name),
+ "log", f"--pretty=format:{pretty_format_str}",
+ ])