Skip to content

Commit b61b351

Browse files
authored
SUP-2321 Accept field data for bk job unblock (#298)
* Add fields to unblock mutation * Accept field data for unblock jobs
1 parent d6f2656 commit b61b351

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

genqlient.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ operations:
77
optional: pointer
88

99
generated: internal/graphql/generated.go
10+
11+
bindings:
12+
JSON:
13+
type: string

internal/graphql/generated.go

+10-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cmd/job/unblock.go

+31-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import (
44
"encoding/base64"
55
"errors"
66
"fmt"
7+
"io"
78
"strings"
89

910
"github.com/MakeNowJust/heredoc"
1011
"github.com/buildkite/cli/v3/internal/graphql"
12+
bk_io "github.com/buildkite/cli/v3/internal/io"
1113
"github.com/buildkite/cli/v3/pkg/cmd/factory"
1214
"github.com/charmbracelet/huh/spinner"
1315
"github.com/spf13/cobra"
@@ -17,9 +19,12 @@ import (
1719
const jobCommandPrefix = "JobTypeBlock---"
1820

1921
func NewCmdJobUnblock(f *factory.Factory) *cobra.Command {
20-
return &cobra.Command{
21-
Use: "unblock <job id>",
22-
Short: "Unblock a job",
22+
var data string
23+
24+
cmd := &cobra.Command{
25+
Use: "unblock <job id>",
26+
DisableFlagsInUseLine: true,
27+
Short: "Unblock a job",
2328
Long: heredoc.Doc(`
2429
Use this command to unblock build jobs.
2530
Currently, this does not support submitting fields to the step.
@@ -31,11 +36,29 @@ func NewCmdJobUnblock(f *factory.Factory) *cobra.Command {
3136
uuid := args[0]
3237
graphqlID := generateGraphQLID(uuid)
3338

39+
// get unblock step fields if available
40+
var fields *string
41+
if bk_io.HasDataAvailable(cmd.InOrStdin()) {
42+
stdin := new(strings.Builder)
43+
_, err := io.Copy(stdin, cmd.InOrStdin())
44+
if err != nil {
45+
return err
46+
}
47+
input := stdin.String()
48+
fields = &input
49+
} else if data != "" {
50+
fields = &data
51+
} else {
52+
// the graphql API errors if providing a null fields value so we need to provide and empty json object
53+
input := "{}"
54+
fields = &input
55+
}
56+
3457
var err error
3558
spinErr := spinner.New().
3659
Title("Unblocking job").
3760
Action(func() {
38-
_, err = graphql.UnblockJob(cmd.Context(), f.GraphQLClient, graphqlID)
61+
_, err = graphql.UnblockJob(cmd.Context(), f.GraphQLClient, graphqlID, fields)
3962
}).
4063
Run()
4164
if spinErr != nil {
@@ -61,6 +84,10 @@ func NewCmdJobUnblock(f *factory.Factory) *cobra.Command {
6184
return err
6285
},
6386
}
87+
88+
cmd.Flags().StringVar(&data, "data", "", "JSON formatted data to unblock the job.")
89+
90+
return cmd
6491
}
6592

6693
func generateGraphQLID(uuid string) string {

pkg/cmd/job/unblock.graphql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mutation UnblockJob($id: ID!) {
2-
jobTypeBlockUnblock(input: {id: $id}) {
1+
mutation UnblockJob($id: ID!, $fields: JSON) {
2+
jobTypeBlockUnblock(input: {id: $id, fields: $fields}) {
33
jobTypeBlock {
44
id
55
state

0 commit comments

Comments
 (0)