~emersion/hut

721092e97a7bcf33dd472b87d12ac71246c48c2e — Thorben Günther 2 months ago bfff4bb
builds list: Support other owners
4 files changed, 53 insertions(+), 17 deletions(-)

M builds.go
M doc/hut.1.scd
M srht/buildssrht/gql.go
M srht/buildssrht/operations.graphql
M builds.go => builds.go +21 -7
@@ 309,9 309,22 @@ func newBuildsListCommand() *cobra.Command {
		ctx := cmd.Context()
		c := createClient("builds", cmd)

		jobs, err := buildssrht.Jobs(c.Client, ctx)
		if err != nil {
			log.Fatal(err)
		var jobs *buildssrht.JobCursor
		if len(args) > 0 {
			username := strings.TrimLeft(args[0], ownerPrefixes)
			user, err := buildssrht.JobsByUser(c.Client, ctx, username)
			if err != nil {
				log.Fatal(err)
			} else if user == nil {
				log.Fatal("no such user")
			}
			jobs = user.Jobs
		} else {
			var err error
			jobs, err = buildssrht.Jobs(c.Client, ctx)
			if err != nil {
				log.Fatal(err)
			}
		}

		for _, job := range jobs.Results {


@@ 320,10 333,11 @@ func newBuildsListCommand() *cobra.Command {
	}

	cmd := &cobra.Command{
		Use:   "list",
		Short: "List jobs",
		Args:  cobra.ExactArgs(0),
		Run:   run,
		Use:               "list [owner]",
		Short:             "List jobs",
		Args:              cobra.MaximumNArgs(1),
		ValidArgsFunction: cobra.NoFileCompletions,
		Run:               run,
	}
	return cmd
}

M doc/hut.1.scd => doc/hut.1.scd +1 -1
@@ 79,7 79,7 @@ hut is a CLI companion utility to interact with sr.ht.
*cancel* <IDs...>
	Cancel jobs.

*list*
*list* [owner]
	List jobs.

*resubmit* <ID>

M srht/buildssrht/gql.go => srht/buildssrht/gql.go +11 -1
@@ 308,7 308,7 @@ func JobIDs(client *gqlclient.Client, ctx context.Context) (jobs *JobCursor, err
}

func Jobs(client *gqlclient.Client, ctx context.Context) (jobs *JobCursor, err error) {
	op := gqlclient.NewOperation("query jobs {\n\tjobs {\n\t\tresults {\n\t\t\tid\n\t\t\tstatus\n\t\t\tnote\n\t\t\ttags\n\t\t\ttasks {\n\t\t\t\tname\n\t\t\t\tstatus\n\t\t\t}\n\t\t}\n\t}\n}\n")
	op := gqlclient.NewOperation("query jobs {\n\tjobs {\n\t\t... jobs\n\t}\n}\nfragment jobs on JobCursor {\n\tresults {\n\t\tid\n\t\tstatus\n\t\tnote\n\t\ttags\n\t\ttasks {\n\t\t\tname\n\t\t\tstatus\n\t\t}\n\t}\n}\n")
	var respData struct {
		Jobs *JobCursor
	}


@@ 316,6 316,16 @@ func Jobs(client *gqlclient.Client, ctx context.Context) (jobs *JobCursor, err e
	return respData.Jobs, err
}

func JobsByUser(client *gqlclient.Client, ctx context.Context, username string) (userByName *User, err error) {
	op := gqlclient.NewOperation("query jobsByUser ($username: String!) {\n\tuserByName(username: $username) {\n\t\tjobs {\n\t\t\t... jobs\n\t\t}\n\t}\n}\nfragment jobs on JobCursor {\n\tresults {\n\t\tid\n\t\tstatus\n\t\tnote\n\t\ttags\n\t\ttasks {\n\t\t\tname\n\t\t\tstatus\n\t\t}\n\t}\n}\n")
	op.Var("username", username)
	var respData struct {
		UserByName *User
	}
	err = client.Execute(ctx, op, &respData)
	return respData.UserByName, err
}

func ExportJobs(client *gqlclient.Client, ctx context.Context) (jobs *JobCursor, err error) {
	op := gqlclient.NewOperation("query exportJobs {\n\tjobs {\n\t\tresults {\n\t\t\tid\n\t\t\tstatus\n\t\t\tnote\n\t\t\ttags\n\t\t\tlog {\n\t\t\t\tfullURL\n\t\t\t}\n\t\t\ttasks {\n\t\t\t\tname\n\t\t\t\tstatus\n\t\t\t\tlog {\n\t\t\t\t\tfullURL\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n")
	var respData struct {

M srht/buildssrht/operations.graphql => srht/buildssrht/operations.graphql +20 -8
@@ 44,15 44,27 @@ query jobIDs {

query jobs {
    jobs {
        results {
            id
        ...jobs
    }
}

query jobsByUser($username: String!) {
    userByName(username: $username) {
        jobs {
            ...jobs
        }
    }
}

fragment jobs on JobCursor {
    results {
        id
        status
        note
        tags
        tasks {
            name
            status
            note
            tags
            tasks {
                name
                status
            }
        }
    }
}