-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
178 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package util | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func GenerateGraphQLID(prefix, uuid string) string { | ||
var graphqlID strings.Builder | ||
wr := base64.NewEncoder(base64.StdEncoding, &graphqlID) | ||
fmt.Fprintf(wr, "%s%s", prefix, uuid) | ||
wr.Close() | ||
|
||
return graphqlID.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package job | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
"github.com/buildkite/cli/v3/internal/graphql" | ||
"github.com/buildkite/cli/v3/internal/util" | ||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
"github.com/charmbracelet/huh/spinner" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const jobCommandPrefix = "JobTypeCommand---" | ||
|
||
func NewCmdJobRetry(f *factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "retry <job id>", | ||
DisableFlagsInUseLine: true, | ||
Short: "Retry a job", | ||
Long: heredoc.Doc(` | ||
Use this command to retry build jobs. | ||
`), | ||
Args: cobra.ExactArgs(1), | ||
Example: "$ bk job retry 0190046e-e199-453b-a302-a21a4d649d31", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// given a job UUID argument, we need to generate the GraphQL ID matching | ||
uuid := args[0] | ||
graphqlID := util.GenerateGraphQLID(jobCommandPrefix, uuid) | ||
|
||
var err error | ||
var j *graphql.RetryJobResponse | ||
spinErr := spinner.New(). | ||
Title("Retrying job"). | ||
Action(func() { | ||
j, err = graphql.RetryJob(cmd.Context(), f.GraphQLClient, graphqlID) | ||
}). | ||
Run() | ||
if spinErr != nil { | ||
return spinErr | ||
} | ||
|
||
_, err = fmt.Fprintln(cmd.OutOrStdout(), "Successfully retried job: "+j.JobTypeCommandRetry.JobTypeCommand.Url) | ||
|
||
return err | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mutation RetryJob($id: ID!) { | ||
jobTypeCommandRetry(input: {id: $id}) { | ||
jobTypeCommand { | ||
id | ||
state | ||
url | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters