~gotmax23/sourcehutx

sourcehutx: builds: add runner and owner members to Job v1 APPLIED

Maxwell G: 1
 builds: add runner and owner members to Job

 2 files changed, 49 insertions(+), 52 deletions(-)
#1049472 main.yml success
#1049473 mockbuild.yml success
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/~gotmax23/sourcehutx/patches/44115/mbox | git am -3
Learn more about email & git

[PATCH sourcehutx] builds: add runner and owner members to Job Export this patch

---
 src/sourcehut/services/builds.py | 99 +++++++++++++++-----------------
 tests/unit/test_builds.py        |  2 +
 2 files changed, 49 insertions(+), 52 deletions(-)

diff --git a/src/sourcehut/services/builds.py b/src/sourcehut/services/builds.py
index df67f67..5a7d946 100644
--- a/src/sourcehut/services/builds.py
+++ b/src/sourcehut/services/builds.py
@@ -13,13 +13,29 @@ from datetime import datetime as DT
from enum import Enum
from typing import TYPE_CHECKING, List, Optional

from .._utils import get_locals
from .._utils import get_locals, v_submitter
from ..client import SRHT_SERVICE, VISIBILITY
from ._base import _Resource, _ServiceClient

if TYPE_CHECKING:
    pass

_JOB_MEMBERS = """
id
created
updated
status
manifest
note
tags
visibility
image
runner
owner {
    canonicalName
}
"""


class BuildsSrhtClient(_ServiceClient):
    SERVICE = SRHT_SERVICE.BUILDS
@@ -39,7 +55,8 @@ class BuildsSrhtClient(_ServiceClient):
        """

        inp = get_locals(**locals())
        query = """
        query = (
            """
        mutation submit(
          $manifest: String!
          $tags: [String!]
@@ -56,18 +73,12 @@ class BuildsSrhtClient(_ServiceClient):
            execute: $execute
            visibility: $visibility
          ) {
            id
            created
            updated
            status
            manifest
            note
            tags
            visibility
            image
              %s
          }
        }
        """
            % _JOB_MEMBERS
        )
        json = await self.query(query, inp)
        return Job(**json["submit"], client=self)

@@ -76,21 +87,16 @@ class BuildsSrhtClient(_ServiceClient):
        Start a job that was submited with `execute=False`
        """
        inp = get_locals(**locals())
        query = """
        query = (
            """
        mutation start($jobid: Int!) {
          start(jobID: $jobid) {
            id
            created
            updated
            status
            manifest
            note
            tags
            visibility
            image
              %s
          }
        }
        """
            % _JOB_MEMBERS
        )
        json = await self.query(query, inp)
        return Job(**json["start"], client=self)

@@ -99,41 +105,31 @@ class BuildsSrhtClient(_ServiceClient):
        Cancel a job
        """
        inp = get_locals(**locals())
        query = """
        query = (
            """
        mutation cancel($jobid: Int!) {
          cancel(jobId: $jobid) {
            id
            created
            updated
            status
            manifest
            note
            tags
            visibility
            image
              %s
          }
        }
        """
            % _JOB_MEMBERS
        )
        json = await self.query(query, inp)
        return Job(**json["cancel"], client=self)

    async def get_job(self, jobid: int | Job) -> Job:
        inp = get_locals(**locals())
        query = """
        query = (
            """
        query getJob($jobid: Int!) {
          job(id: $jobid) {
            id
            created
            updated
            status
            manifest
            note
            tags
            visibility
            image
              %s
          }
        }
        """
            % _JOB_MEMBERS
        )
        json = await self.query(query, inp)
        return Job(**json["job"], client=self)

@@ -159,24 +155,19 @@ class BuildsSrhtClient(_ServiceClient):
        of data.
        Set `max_pages` to a higher number or `None` for unlimited.
        """
        query = """
        query = (
            """
        query getJobs($cursor: Cursor) {
          jobs(cursor: $cursor) {
            cursor
            results {
              id
              created
              updated
              status
              manifest
              note
              tags
              visibility
              image
                %s
            }
          }
        }
        """
            % _JOB_MEMBERS
        )
        return self._cursorit("jobs", Job, query, max_pages)


@@ -206,14 +197,18 @@ class JOB_STATUS(str, Enum):


class Job(_Resource[BuildsSrhtClient]):
    status: JOB_STATUS
    created: DT
    updated: DT
    status: JOB_STATUS
    manifest: str
    note: Optional[str]
    tags: List[str]
    visibility: VISIBILITY
    image: str
    runner: Optional[str]
    owner: str

    _v_owner = v_submitter("owner")

    async def cancel(self) -> Job:
        """
diff --git a/tests/unit/test_builds.py b/tests/unit/test_builds.py
index 463d5e8..705992e 100644
--- a/tests/unit/test_builds.py
+++ b/tests/unit/test_builds.py
@@ -21,6 +21,8 @@ JOB_DATA_1: dict[str, Any] = {
    "tags": ["fedora-scripts", "scheduled", "go-leaves"],
    "visibility": "PUBLIC",
    "image": "fedora/rawhide",
    "runner": None,
    "owner": {"canonicalName": "~person"},
}


-- 
2.41.0
sourcehutx/patches: SUCCESS in 7m20s

[builds: add runner and owner members to Job][0] from [Maxwell G][1]

[0]: https://lists.sr.ht/~gotmax23/sourcehutx/patches/44115
[1]: mailto:maxwell@gtmx.me

✓ #1049472 SUCCESS sourcehutx/patches/main.yml      https://builds.sr.ht/~gotmax23/job/1049472
✓ #1049473 SUCCESS sourcehutx/patches/mockbuild.yml https://builds.sr.ht/~gotmax23/job/1049473
Applied.