@@ -4,10 +4,12 @@ import (
4
4
"encoding/base64"
5
5
"errors"
6
6
"fmt"
7
+ "io"
7
8
"strings"
8
9
9
10
"github.com/MakeNowJust/heredoc"
10
11
"github.com/buildkite/cli/v3/internal/graphql"
12
+ bk_io "github.com/buildkite/cli/v3/internal/io"
11
13
"github.com/buildkite/cli/v3/pkg/cmd/factory"
12
14
"github.com/charmbracelet/huh/spinner"
13
15
"github.com/spf13/cobra"
@@ -17,9 +19,12 @@ import (
17
19
const jobCommandPrefix = "JobTypeBlock---"
18
20
19
21
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" ,
23
28
Long : heredoc .Doc (`
24
29
Use this command to unblock build jobs.
25
30
Currently, this does not support submitting fields to the step.
@@ -31,11 +36,29 @@ func NewCmdJobUnblock(f *factory.Factory) *cobra.Command {
31
36
uuid := args [0 ]
32
37
graphqlID := generateGraphQLID (uuid )
33
38
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
+
34
57
var err error
35
58
spinErr := spinner .New ().
36
59
Title ("Unblocking job" ).
37
60
Action (func () {
38
- _ , err = graphql .UnblockJob (cmd .Context (), f .GraphQLClient , graphqlID )
61
+ _ , err = graphql .UnblockJob (cmd .Context (), f .GraphQLClient , graphqlID , fields )
39
62
}).
40
63
Run ()
41
64
if spinErr != nil {
@@ -61,6 +84,10 @@ func NewCmdJobUnblock(f *factory.Factory) *cobra.Command {
61
84
return err
62
85
},
63
86
}
87
+
88
+ cmd .Flags ().StringVar (& data , "data" , "" , "JSON formatted data to unblock the job." )
89
+
90
+ return cmd
64
91
}
65
92
66
93
func generateGraphQLID (uuid string ) string {
0 commit comments