~rjarry/dlrepo

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH dlrepo] tag: add description

Details
Message ID
<20241001083035.560110-1-julien.floret@6wind.com>
DKIM signature
pass
Download raw message
Patch: +96 -1
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 <julien.floret@6wind.com>
Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
---
 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 dfea4b5865eb..266446edab2f 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 35878efcad20..1ad60535010f 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 3caef1c2d3ad..c6b2d8c42713 100644
--- a/dlrepo/templates/tag.html
+++ b/dlrepo/templates/tag.html
@@ -8,6 +8,17 @@
{% endblock %}

{% block page_content %}

{% if tag.description %}
<section>
  <div>
    <span>
      {{tag.description}}
    </span>
  </div>
</section>
{% endif %}

{% if tag.released or tag.locked or tag.publish_status or tag.stable %}
<section class="tag-status">
  {% if tag.released %}
diff --git a/dlrepo/views/branch.py b/dlrepo/views/branch.py
index 2b0d66abac75..b7e66352b328 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 92967a098146..1f484a2b2768 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 f76e710acd36..4aa6f960c142 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 7cf8bf7e0f4a..f67cdae74721 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 ba1ea7fe13ca..fb7f43a3a01c 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.39.2

[dlrepo/patches/.build.yml] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D4KBVEIVPNO8.30NGXJPGKKNAD@fra02>
In-Reply-To
<20241001083035.560110-1-julien.floret@6wind.com> (view parent)
DKIM signature
missing
Download raw message
dlrepo/patches/.build.yml: FAILED in 28s

[tag: add description][0] from [Julien Floret][1]

[0]: https://lists.sr.ht/~rjarry/dlrepo/patches/55263
[1]: julien.floret@6wind.com

✗ #1341280 FAILED dlrepo/patches/.build.yml https://builds.sr.ht/~rjarry/job/1341280

Applied: [PATCH dlrepo] tag: add description

Details
Message ID
<172808324243.1037873.4884781081581502792@ringo.home>
In-Reply-To
<20241001083035.560110-1-julien.floret@6wind.com> (view parent)
DKIM signature
pass
Download raw message
Julien Floret <julien.floret@6wind.com> wrote:
> 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 <julien.floret@6wind.com>
> Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
> ---

Acked-by: Robin Jarry <robin@jarry.cc>

Applied, thanks.

To git@git.sr.ht:~rjarry/dlrepo
   e3c2f693a68c..7c9669a881a2  main -> main
Reply to thread Export thread (mbox)