This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git


The following commit(s) were added to refs/heads/main by this push:
     new f3cfa3e  Show the form if the distribution package is not found
f3cfa3e is described below

commit f3cfa3e1d190e3900380b1474ffe6b196488a74c
Author: Sean B. Palmer <[email protected]>
AuthorDate: Wed Aug 6 20:46:30 2025 +0100

    Show the form if the distribution package is not found
---
 atr/htm.py               | 17 +++++++++++++-
 atr/routes/distribute.py | 59 +++++++++++++++++++++++++++++++++++-------------
 2 files changed, 59 insertions(+), 17 deletions(-)

diff --git a/atr/htm.py b/atr/htm.py
index 13df5f3..c33f41a 100644
--- a/atr/htm.py
+++ b/atr/htm.py
@@ -59,7 +59,7 @@ class BlockElementCallable:
 class Block:
     def __init__(self, element: htpy.Element | None = None, *elements: 
htpy.Element):
         self.element = element
-        self.elements = list(elements)
+        self.elements: list[htpy.Element | str] = list(elements)
 
     def __str__(self) -> str:
         return f"{self.element}{self.elements}"
@@ -75,6 +75,18 @@ class Block:
             return htpy.div[*self.elements]
         return self.element[*self.elements]
 
+    @property
+    def a(self) -> BlockElementCallable:
+        return BlockElementCallable(self, htpy.a)
+
+    @property
+    def code(self) -> BlockElementCallable:
+        return BlockElementCallable(self, htpy.code)
+
+    @property
+    def div(self) -> BlockElementCallable:
+        return BlockElementCallable(self, htpy.div)
+
     @property
     def h1(self) -> BlockElementCallable:
         return BlockElementCallable(self, htpy.h1)
@@ -98,3 +110,6 @@ class Block:
     @property
     def table(self) -> BlockElementCallable:
         return BlockElementCallable(self, htpy.table)
+
+    def text(self, text: str) -> None:
+        self.elements.append(text)
diff --git a/atr/routes/distribute.py b/atr/routes/distribute.py
index 9fb2d1b..78d081e 100644
--- a/atr/routes/distribute.py
+++ b/atr/routes/distribute.py
@@ -143,7 +143,7 @@ async def distribute(session: routes.CommitterSession, 
project: str, version: st
 async def distribute_post(session: routes.CommitterSession, project: str, 
version: str) -> str:
     form = await DistributeForm.create_form(data=await quart.request.form)
     if await form.validate():
-        return await _distribute_post_validated(form)
+        return await _distribute_post_validated(form, project, version)
     match len(form.errors):
         case 0:
             # Should not happen
@@ -155,8 +155,11 @@ async def distribute_post(session: 
routes.CommitterSession, project: str, versio
     return await _distribute_page(project=project, version=version, form=form)
 
 
-async def _distribute_page(*, project: str, version: str, form: 
DistributeForm) -> str:
-    # Used in the GET and POST routes
+# This function is used in both GET and POST routes
+async def _distribute_page(
+    *, project: str, version: str, form: DistributeForm, extra_content: 
htpy.Element | None = None
+) -> str:
+    # Validate the Release
     async with db.session() as data:
         release = await data.release(project_name=project, 
version=version).demand(
             RuntimeError(f"Release {project} {version} not found")
@@ -165,16 +168,24 @@ async def _distribute_page(*, project: str, version: str, 
form: DistributeForm)
             raise RuntimeError(f"Release {project} {version} is not a release 
preview")
         # if release.project.status != sql.ProjectStatus.ACTIVE:
         #     raise RuntimeError(f"Project {project} is not active")
-    form_content = forms.render_columns(form, action=quart.request.path, 
descriptions=True)
+
+    # Render the explanation and form
     block = htm.Block()
+
+    # Record a manual distribution
+    block.h1["Record a manual distribution"]
+    if extra_content:
+        block.append(extra_content)
     block.p[
         "Record a manual distribution during the ",
         htpy.span(".atr-phase-three.atr-phase-label")["FINISH"],
         " phase using the form below.",
     ]
     block.p["Please note that this form is a work in progress and not fully 
functional."]
-    content = _page("Record a manual distribution", *block.elements, 
form_content)
-    return await template.blank("Distribute", content=content)
+    block.append(forms.render_columns(form, action=quart.request.path, 
descriptions=True))
+
+    # Render the page
+    return await template.blank("Distribute", content=block.collect())
 
 
 async def _distribute_post_api(api_url: str) -> outcome.Outcome[basic.JSON]:
@@ -189,16 +200,37 @@ async def _distribute_post_api(api_url: str) -> 
outcome.Outcome[basic.JSON]:
         return outcome.Error(e)
 
 
-async def _distribute_post_validated(form: DistributeForm) -> str:
+async def _distribute_post_validated(form: DistributeForm, project: str, 
version: str) -> str:
     dd = DistributeData.model_validate(form.data)
     api_url = form.platform.data.value.template_url.format(
         owner_namespace=dd.owner_namespace,
         package=dd.package,
         version=dd.version,
     )
+    api_oc = await _distribute_post_api(api_url)
 
     block = htm.Block()
 
+    # Distribution submitted
+    block.h1["Distribution submitted"]
+    match api_oc:
+        case outcome.Result():
+            block.p["The distribution was submitted successfully."]
+        case outcome.Error(error):
+            div = htm.Block(htpy.div(".alert.alert-danger"))
+            div.p[
+                "This package and version was not found in ",
+                htpy.a(href=api_url)["the distribution platform API"],
+                ". Please check the package name and version.",
+            ]
+            div.pre(".atr-pre-wrap")[str(error)]
+            return await _distribute_page(
+                project=project,
+                version=version,
+                form=form,
+                extra_content=div.collect(),
+            )
+
     if dd.details:
         ## Details
         block.h2["Details"]
@@ -217,14 +249,13 @@ async def _distribute_post_validated(form: 
DistributeForm) -> str:
 
     ## API response
     block.h2["API response"]
-    match await _distribute_post_api(api_url):
+    match api_oc:
         case outcome.Result(result):
             block.pre[json.dumps(result, indent=2)]
-        case outcome.Error(exception):
-            block.pre[f"Error: {exception}"]
+        # case outcome.Error(exception):
+        #     block.pre[f"Error: {exception}"]
 
-    content = _page("Distribution submitted", block.collect())
-    return await template.blank("Distribution submitted", content=content)
+    return await template.blank("Distribution submitted", 
content=block.collect())
 
 
 def _distribute_post_table(block: htm.Block, dd: DistributeData) -> None:
@@ -238,7 +269,3 @@ def _distribute_post_table(block: htm.Block, dd: 
DistributeData) -> None:
         row("Version", dd.version),
     ]
     block.table(".table.table-striped.table-bordered")[tbody]
-
-
-def _page(title_str: str, *content: htpy.Element) -> htpy.Element:
-    return htpy.div[htpy.h1[title_str], *content]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to