~emersion/hut-dev

builds show: print job group status v2 APPLIED

Simon Ser: 1
 builds show: print job group status

 4 files changed, 21 insertions(+), 1 deletions(-)
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/~emersion/hut-dev/patches/44872/mbox | git am -3
Learn more about email & git

[PATCH v2] builds show: print job group status Export this patch

If a job is part of a group, print the IDs and statuses for other
jobs in the same group as well.

Requires a sr.ht patch [1] to work correctly.

[1]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/43728
---

v2: re-generate with correct gqlclientgen dep version
    (upstream sr.ht bug has been fixed)

 builds.go                          | 10 ++++++++++
 srht/buildssrht/gql.go             |  2 +-
 srht/buildssrht/operations.graphql |  6 ++++++
 srht/buildssrht/strings.go         |  4 ++++
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/builds.go b/builds.go
index 8894c2e553f4..6c0ca4dcd067 100644
--- a/builds.go
@@ -615,6 +615,16 @@ func printJob(w io.Writer, job *buildssrht.Job) {
	}
	fmt.Fprintln(w)

	if job.Group != nil && len(job.Group.Jobs) > 1 {
		fmt.Fprintf(w, "Group: ")
		for _, j := range job.Group.Jobs {
			if j.Id == job.Id {
				continue
			}
			fmt.Fprintf(w, "%s %s  ", job.Status.TermIcon(), termfmt.DarkYellow.Sprintf("#%d", j.Id))
		}
	}

	if job.Note != nil && *job.Note != "" {
		fmt.Fprintln(w, "\n"+indent(strings.TrimSpace(*job.Note), "  "))
	}
diff --git a/srht/buildssrht/gql.go b/srht/buildssrht/gql.go
index b76026271926..ef785847abf9 100644
--- a/srht/buildssrht/gql.go
+++ b/srht/buildssrht/gql.go
@@ -635,7 +635,7 @@ func ExportJobs(client *gqlclient.Client, ctx context.Context, cursor *Cursor) (
}

func Show(client *gqlclient.Client, ctx context.Context, id int32) (job *Job, err error) {
	op := gqlclient.NewOperation("query show ($id: Int!) {\n\tjob(id: $id) {\n\t\tid\n\t\trunner\n\t\tstatus\n\t\tnote\n\t\ttags\n\t\tlog {\n\t\t\tfullURL\n\t\t}\n\t\ttasks {\n\t\t\tname\n\t\t\tstatus\n\t\t\tlog {\n\t\t\t\tfullURL\n\t\t\t}\n\t\t}\n\t}\n}\n")
	op := gqlclient.NewOperation("query show ($id: Int!) {\n\tjob(id: $id) {\n\t\tid\n\t\trunner\n\t\tstatus\n\t\tnote\n\t\ttags\n\t\tlog {\n\t\t\tfullURL\n\t\t}\n\t\ttasks {\n\t\t\tname\n\t\t\tstatus\n\t\t\tlog {\n\t\t\t\tfullURL\n\t\t\t}\n\t\t}\n\t\tgroup {\n\t\t\tjobs {\n\t\t\t\tid\n\t\t\t\tstatus\n\t\t\t}\n\t\t}\n\t}\n}\n")
	op.Var("id", id)
	var respData struct {
		Job *Job
diff --git a/srht/buildssrht/operations.graphql b/srht/buildssrht/operations.graphql
index cccae73d00b2..2f9a446579e1 100644
--- a/srht/buildssrht/operations.graphql
+++ b/srht/buildssrht/operations.graphql
@@ -133,6 +133,12 @@ query show($id: Int!) {
                fullURL
            }
        }
        group {
            jobs {
                id
                status
            }
        }
    }
}

diff --git a/srht/buildssrht/strings.go b/srht/buildssrht/strings.go
index 3100c7de6656..f10ede7df7f1 100644
--- a/srht/buildssrht/strings.go
+++ b/srht/buildssrht/strings.go
@@ -41,6 +41,10 @@ func (status JobStatus) TermStyle() termfmt.Style {
	}
}

func (status JobStatus) TermIcon() string {
	return status.TermStyle().String(status.Icon())
}

func (status JobStatus) TermString() string {
	return status.TermStyle().Sprintf("%s %s", status.Icon(), string(status))
}
-- 
2.42.0
Thanks for the patch! There was one mistake/typo that I corrected before
pushing it.