~rjarry/dlrepo

dlrepo: display summarized branch information v1 APPLIED

This small series is for having a summarized information of the branch
metadata, such as the cleanup policy and the actual number of tags, on
the web UI and from the command line through dlrepo-cli.

Julien Floret (3):
  branch: export number of locked and stable tags
  templates: display summarized branch information
  cli: add verbose mode to branches command

 dlrepo-cli                   | 44 ++++++++++++++++++++++++++++++++++--
 dlrepo/templates/branch.html | 17 ++++++++++----
 dlrepo/views/branch.py       |  6 +++++
 3 files changed, 61 insertions(+), 6 deletions(-)

-- 
2.30.2
#963460 .build.yml success
dlrepo/patches/.build.yml: SUCCESS in 1m38s

[display summarized branch information][0] from [Julien Floret][1]

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

✓ #963460 SUCCESS dlrepo/patches/.build.yml https://builds.sr.ht/~rjarry/job/963460
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rjarry/dlrepo/patches/40021/mbox | git am -3
Learn more about email & git

[PATCH dlrepo 1/3] branch: export number of locked and stable tags Export this patch

A GET request on "/branches" already returned the number of daily and
released tags. It can be interesting to have the number of locked and
stable tags, too.

Signed-off-by: Julien Floret <julien.floret@6wind.com>
Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
---
 dlrepo/views/branch.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/dlrepo/views/branch.py b/dlrepo/views/branch.py
index 2b306ebfceb4..720ba24437f4 100644
--- a/dlrepo/views/branch.py
+++ b/dlrepo/views/branch.py
@@ -33,12 +33,18 @@ class BranchesView(BaseView):
                "name": b.name,
                "daily_tags": 0,
                "released_tags": 0,
                "locked_tags": 0,
                "stable_tags": 0,
            }
            for t in b.get_tags():
                if t.is_released():
                    br["released_tags"] += 1
                else:
                    br["daily_tags"] += 1
                if t.is_locked():
                    br["locked_tags"] += 1
                if t.is_stable():
                    br["stable_tags"] += 1
            br.update(b.get_cleanup_policy())
            data["branches"].append(br)
        if "html" in self.request.headers.get("Accept", "json"):
-- 
2.30.2

[PATCH dlrepo 2/3] templates: display summarized branch information Export this patch

In the branch page on the web UI, have a tight top one-liner showing
the tag cleanup policy (ie the maximum released & daily tags for this
branch that are not cleaned up), along with the current tag count, eg:

0/12 tags released, 2/10 daily.

When no cleanup policy is defined (0 by default, meaning an infinite
number of tags), we just display the current tag count, eg:

0 tag released, 2 daily.

When some daily tags are locked, preventing them to be cleaned up, we
display the number of locked tags:

0/12 tags released, 13/10 daily (3 locked).

Signed-off-by: Julien Floret <julien.floret@6wind.com>
Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
---
 dlrepo/templates/branch.html | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/dlrepo/templates/branch.html b/dlrepo/templates/branch.html
index c2e953328ecd..ad0cd375fc39 100644
--- a/dlrepo/templates/branch.html
+++ b/dlrepo/templates/branch.html
@@ -9,6 +9,19 @@

{% block page_content %}
{% set tags = branch.tags|sort(attribute='name')|list %}
{% set released = tags|selectattr('released')|list|length %}
{% set max_released = branch.cleanup_policy.max_released_tags %}
{% set daily = tags|length - released %}
{% set max_daily = branch.cleanup_policy.max_daily_tags %}
{% set locked = tags|selectattr('locked')|list|length %}
<section>
  <div>
    <span>
      {{released}}{{'/%d' % max_released if max_released}} tag{{'s' if released > 1 or max_released}} released,
      {{daily}}{{'/%d' % max_daily if max_daily}} daily{{' (%d locked)' % locked if locked}}.
    </span>
  </div>
</section>
{% set width = tags|map(attribute='name')|map('length')|max|default(80) %}
{% set width = [width, 10]|max %}
<section class="tags" style="column-width: {{width * 0.8}}em;">
@@ -35,10 +48,6 @@
      {{tag.name}}
    </a>
  </div>
  {% else %}
  <div>
   No tags for branch {{branch.name}}.
  </div>
  {% endfor %}
</section>
{% endblock %}
-- 
2.30.2

[PATCH dlrepo 3/3] cli: add verbose mode to branches command Export this patch

Add a -v/--verbose global option to get more detailed output and use
it in the "branches" command to show the current count of released,
daily and locked tags along with the tag cleanup policy.

Signed-off-by: Julien Floret <julien.floret@6wind.com>
Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
---
 dlrepo-cli | 44 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/dlrepo-cli b/dlrepo-cli
index 13fa16f5157b..545269df93d9 100755
--- a/dlrepo-cli
+++ b/dlrepo-cli
@@ -72,6 +72,14 @@ def main():
        Only applies to non-binary data.
        """,
    )
    parser.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        help="""
        More verbose output.
        """,
    )
    sub = parser.add_subparsers(title="sub-command help", metavar="SUB_COMMAND")
    sub.required = True

@@ -293,8 +301,40 @@ def branches(args):
        print(json.dumps(data, indent=2))
    else:
        print("URL: %s" % client.make_url(url))
        for branch in data["branches"]:
            print(branch["name"])
        if args.verbose:
            out = []
            branch_len = 0
            released_len = 0
            daily_len = 0
            for branch in data["branches"]:
                line = {
                    "name": f"{branch['name']}:",
                    "released": f"{branch['released_tags']}",
                    "daily": f"{branch['daily_tags']}",
                    "locked": f"{branch['locked_tags']}",
                }
                if branch["max_released_tags"]:
                    line["released"] += f"/{branch['max_released_tags']}"
                if branch["max_daily_tags"]:
                    line["daily"] += f"/{branch['max_daily_tags']}"
                out.append(line)
                branch_len = max(branch_len, len(line["name"]))
                released_len = max(released_len, len(line["released"]))
                daily_len = max(daily_len, len(line["daily"]))

            for line in out:
                print(
                    line["name"].ljust(branch_len),
                    "released",
                    line["released"].rjust(released_len),
                    "daily",
                    line["daily"].rjust(daily_len),
                    "locked",
                    line["locked"],
                )
        else:
            for branch in data["branches"]:
                print(branch["name"])


# --------------------------------------------------------------------------------------
-- 
2.30.2
dlrepo/patches/.build.yml: SUCCESS in 1m38s

[display summarized branch information][0] from [Julien Floret][1]

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

✓ #963460 SUCCESS dlrepo/patches/.build.yml https://builds.sr.ht/~rjarry/job/963460