From 7c9669a881a2cf589836d220ba21a80fd2f871ff Mon Sep 17 00:00:00 2001 From: Julien Floret Date: Tue, 1 Oct 2024 10:30:35 +0200 Subject: [PATCH] tag: add description Add the possibility to set a custom description on a tag with the "dlrepo-cli set-description BRANCH TAG DESCRIPTION" command. The message is stored in an internal ".description" file inside the tag directory. The description is displayed on top of the tag page on the web interface. It can also be read on the CLI using the "dlrepo-cli get-description BRANCH TAG" command. Signed-off-by: Julien Floret Acked-by: Thomas Faivre Acked-by: Robin Jarry --- dlrepo-cli | 36 ++++++++++++++++++++++++++++++++++++ dlrepo/fs/tag.py | 16 ++++++++++++++++ dlrepo/templates/tag.html | 11 +++++++++++ dlrepo/views/branch.py | 1 + dlrepo/views/tag.py | 8 +++++++- docs/dlrepo-api.7.scdoc | 3 +++ docs/dlrepo-cli.1.scdoc | 20 ++++++++++++++++++++ docs/dlrepo-layout.7.scdoc | 2 ++ 8 files changed, 96 insertions(+), 1 deletion(-) diff --git a/dlrepo-cli b/dlrepo-cli index dfea4b5..266446e 100755 --- a/dlrepo-cli +++ b/dlrepo-cli @@ -292,6 +292,42 @@ def lock(args): client.post(url, data) +# -------------------------------------------------------------------------------------- +@sub_command( + Arg("branch", metavar="BRANCH", help="the branch name"), + Arg("tag", metavar="TAG", help="the tag name"), +) +def get_description(args): + """ + Get a tag description. + """ + client = HttpClient(args.url) + url = os.path.join("branches", args.branch, args.tag, "") + data = client.get(url) + if args.raw_json: + print(json.dumps(data, indent=2)) + else: + print("URL: %s" % client.make_url(url)) + description = data.get("tag", {}).get("description") + if description is not None: + print(description) + + +# -------------------------------------------------------------------------------------- +@sub_command( + Arg("branch", metavar="BRANCH", help="the branch name"), + Arg("tag", metavar="TAG", help="the tag name"), + Arg("description", metavar="DESCRIPTION", help="the description"), +) +def set_description(args): + """ + Add a description on a tag. + """ + client = HttpClient(args.url) + url = os.path.join("branches", args.branch, args.tag, "") + client.post(url, {"tag": {"description": args.description}}) + + # -------------------------------------------------------------------------------------- @sub_command() def branches(args): diff --git a/dlrepo/fs/tag.py b/dlrepo/fs/tag.py index 35878ef..1ad6053 100644 --- a/dlrepo/fs/tag.py +++ b/dlrepo/fs/tag.py @@ -93,6 +93,22 @@ class Tag(SubDir): elif path.is_file(): path.unlink() + def _description_path(self) -> Path: + return self._path / ".description" + + def description(self) -> Optional[str]: + try: + return self._description_path().read_text().strip() + except FileNotFoundError: + return None + + def set_description(self, description: str): + description = description.strip() + if description: + self._description_path().write_text(f"{description}\n") + elif self._description_path().is_file(): + self._description_path().unlink() + def done_cb(self, task): if task.cancelled(): return diff --git a/dlrepo/templates/tag.html b/dlrepo/templates/tag.html index 3caef1c..c6b2d8c 100644 --- a/dlrepo/templates/tag.html +++ b/dlrepo/templates/tag.html @@ -8,6 +8,17 @@ {% endblock %} {% block page_content %} + +{% if tag.description %} +
+
+ + {{tag.description}} + +
+
+{% endif %} + {% if tag.released or tag.locked or tag.publish_status or tag.stable %}
{% if tag.released %} diff --git a/dlrepo/views/branch.py b/dlrepo/views/branch.py index 2b0d66a..b7e6635 100644 --- a/dlrepo/views/branch.py +++ b/dlrepo/views/branch.py @@ -95,6 +95,7 @@ class BranchView(BaseView): "locked": t.is_locked(), "stable": t.is_stable(), "publish_status": t.publish_status(), + "description": t.description(), } ) if "html" in self.request.headers.get("Accept", "json"): diff --git a/dlrepo/views/tag.py b/dlrepo/views/tag.py index 92967a0..1f484a2 100644 --- a/dlrepo/views/tag.py +++ b/dlrepo/views/tag.py @@ -55,6 +55,7 @@ class TagView(BaseView): "locked": tag.is_locked(), "stable": tag.is_stable(), "publish_status": tag.publish_status(), + "description": tag.description(), "jobs": [], }, } @@ -76,7 +77,7 @@ class TagView(BaseView): async def post(self): """ - Change the released, stable and/or locked statuses of a tag. + Change the released, stable and/or locked statuses, or description of a tag. """ tag = self._get_tag() try: @@ -90,6 +91,9 @@ class TagView(BaseView): stable = data.get("stable") if stable is not None and not isinstance(stable, bool): raise TypeError() + description = data.get("description") + if description is not None and not isinstance(description, str): + raise TypeError() except (TypeError, KeyError) as e: raise web.HTTPBadRequest(reason="invalid parameters") from e @@ -101,6 +105,8 @@ class TagView(BaseView): tag.set_locked(locked) if stable is not None: tag.set_stable(stable) + if description is not None: + tag.set_description(description) except FileNotFoundError as e: raise web.HTTPNotFound() from e except ValueError as e: diff --git a/docs/dlrepo-api.7.scdoc b/docs/dlrepo-api.7.scdoc index f76e710..4aa6f96 100644 --- a/docs/dlrepo-api.7.scdoc +++ b/docs/dlrepo-api.7.scdoc @@ -152,6 +152,7 @@ specified in the query parameters, only released tags are returned. "released": false, "locked": false, "publish_status": null, + "description": "foo bar", "timestamp": 1637001613.5863628 }, { @@ -159,6 +160,7 @@ specified in the query parameters, only released tags are returned. "released": true, "locked": false, "publish_status": "published to https://repo2.foo.org", + "description": "bla bla", "timestamp": 1637088073.7324917 }, ] @@ -229,6 +231,7 @@ user has access. "released": true, "locked": false, "publish_status": "published to https://repo2.foo.org", + "description": "bla bla", "jobs": [ { "name": "moo-x86_64-sqlite", diff --git a/docs/dlrepo-cli.1.scdoc b/docs/dlrepo-cli.1.scdoc index 7cf8bf7..f67cdae 100644 --- a/docs/dlrepo-cli.1.scdoc +++ b/docs/dlrepo-cli.1.scdoc @@ -225,6 +225,26 @@ Get or set a branch cleanup policy. _BRANCH_ The branch name. +## dlrepo-cli set-description BRANCH TAG DESCRIPTION + +Add a description to a tag. + +_BRANCH_ + The branch name. +_TAG_ + The tag name. +_DESCRIPTION_ + A string describing the purpose of the tag. + +## dlrepo-cli get-description BRANCH TAG + +Read the tag description. + +_BRANCH_ + The branch name. +_TAG_ + The tag name. + # SEE ALSO *dlrepo*(7), diff --git a/docs/dlrepo-layout.7.scdoc b/docs/dlrepo-layout.7.scdoc index ba1ea7f..fb7f43a 100644 --- a/docs/dlrepo-layout.7.scdoc +++ b/docs/dlrepo-layout.7.scdoc @@ -89,6 +89,8 @@ _.locked_ (optional) _.publish_status_ (optional) Text file containing details about the tag publication status to another dlrepo server. +_.description_ (optional) + Text file containing a short description of the tag. ## branches/{branch}/{tag}/{job}/ -- 2.45.2