aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
Diffstat (limited to 'gn3')
-rw-r--r--gn3/api/metadata.py23
-rw-r--r--gn3/db/datasets.py31
2 files changed, 53 insertions, 1 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index fe7e903..a6a88fc 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -7,7 +7,8 @@ from flask import request
from flask import current_app
from gn3.db.datasets import (retrieve_metadata,
- save_dataset_metadata)
+ save_metadata,
+ get_history)
from gn3.db.rdf import RDF_PREFIXES
from gn3.db.rdf import (query_frame_and_compact,
query_and_compact,
@@ -263,6 +264,26 @@ CONSTRUCT {
)
+@metadata.route("/datasets/<id_>/history")
+def view_history(id_):
+ history = get_history(
+ git_dir=Path(current_app.config.get("DATA_DIR"),
+ "gn-docs"),
+ name=id_,
+ ).either(
+ lambda error: {
+ "error": "Unable to fetch history",
+ "error_description": error,
+ },
+ lambda history: {
+ "id": id_,
+ "history": history,
+ })
+ if history.get("error"):
+ raise Exception(history.get("error_description"))
+ return history
+
+
@metadata.route("/datasets/search/<term>", methods=["GET"])
def search_datasets(term):
"""Search datasets"""
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}",
+ ])