-
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.
Merge branch '3.x' into sup-157-bk-pipeline-create
- Loading branch information
Showing
23 changed files
with
218 additions
and
20 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# This uses the upstream image without any changes intentionally. | ||
# This allows dependabot to keep this version up-to-date for us automatically, since it does not work with | ||
# docker-compose directly | ||
FROM goreleaser/goreleaser-pro:v1.26.2-pro@sha256:e3c5989f459122528766ec55ebcd77d8abd970500fe219936278aac2da077d71 | ||
FROM goreleaser/goreleaser-pro:v2.0.0-pro@sha256:3dcb9b7ebf61b7de4cff9f444695e3323c7dc56850ffb30dd89ebbd630dbad3e |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
project_name: bk | ||
version: 2 | ||
|
||
release: | ||
name_template: Buildkite CLI {{.Version}} | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
openai_token: jumanji | ||
selected_org: buildkite-org | ||
organizations: | ||
buildkite-test: | ||
api_token: test-token-abcd | ||
api_token: test-token-abcd |
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
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
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
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,87 @@ | ||
package job | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/buildkite/go-buildkite/v3/buildkite" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
func JobSummary(job *buildkite.Job) string { | ||
jobName := getJobName(*job) | ||
jobTotalTime, err := calculateTotalTime(job.StartedAt, job.FinishedAt) | ||
if err != nil { | ||
log.Fatal("Unable to calculate total job time", err) | ||
} | ||
|
||
jobInfo := fmt.Sprintf("%s %s (%s)", renderJobState(*job.State), jobName, lipgloss.NewStyle().Foreground(lipgloss.Color("#5A5A5A")).Render(jobTotalTime.String())) | ||
|
||
summary := lipgloss.JoinVertical(lipgloss.Top, | ||
lipgloss.NewStyle().Align(lipgloss.Left).Padding(0, 1).Render(), | ||
lipgloss.NewStyle().Bold(true).Padding(0, 1).Render(jobInfo), | ||
) | ||
return summary | ||
} | ||
|
||
func getJobName(job buildkite.Job) string { | ||
var jobName string | ||
|
||
switch { | ||
case job.Name != nil: | ||
jobName = *job.Name | ||
case job.Label != nil: | ||
jobName = *job.Label | ||
default: | ||
jobName = *job.Command | ||
} | ||
|
||
return jobName | ||
} | ||
|
||
func renderJobState(state string) string { | ||
var stateIcon string | ||
stateColor := getJobStateColor(state) | ||
|
||
switch state { | ||
case "passed": | ||
stateIcon = "✔" | ||
case "running": | ||
stateIcon = "▶" | ||
case "failed", "failing": | ||
stateIcon = "✖" | ||
case "canceled": | ||
stateIcon = "🚫" | ||
case "canceling": | ||
stateIcon = "🚫(cancelling...)" | ||
default: | ||
stateIcon = "❔" | ||
} | ||
|
||
return lipgloss.NewStyle().Foreground(stateColor).Render(stateIcon) | ||
} | ||
|
||
func getJobStateColor(state string) lipgloss.Color { | ||
var stateColor lipgloss.Color | ||
switch state { | ||
case "passed": | ||
stateColor = lipgloss.Color("#9dcc3a") // green | ||
case "running": | ||
stateColor = lipgloss.Color("#FF6E00") | ||
case "failed", "failing": | ||
stateColor = lipgloss.Color("#ff0000") | ||
default: | ||
stateColor = lipgloss.Color("#5A5A5A") // grey | ||
} | ||
return stateColor | ||
} | ||
|
||
func calculateTotalTime(startedAt, finishedAt *buildkite.Timestamp) (time.Duration, error) { | ||
if startedAt == nil || finishedAt == nil { | ||
return 0, errors.New("both startedAt and finishedAt must be non-nil") | ||
} | ||
|
||
return finishedAt.Time.Sub(startedAt.Time), nil | ||
} |
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
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
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,41 @@ | ||
package add | ||
|
||
import ( | ||
"github.com/AlecAivazis/survey/v2" | ||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdAIAdd(f *factory.Factory) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "add", | ||
Args: cobra.NoArgs, | ||
Short: "Add an OpenAI token.", | ||
Long: "Add an OpenAI token for use with CLI AI tooling", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return ConfigureRun(f) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func ConfigureRun(f *factory.Factory) error { | ||
qs := []*survey.Question{ | ||
{ | ||
Name: "token", | ||
Prompt: &survey.Password{Message: "Paste your OpenAI token:"}, | ||
Validate: survey.Required, | ||
}, | ||
} | ||
answers := struct{ Token string }{} | ||
|
||
err := survey.Ask(qs, &answers) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = f.Config.SetOpenAIToken(answers.Token) | ||
|
||
return err | ||
} |
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,23 @@ | ||
package ai | ||
|
||
import ( | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdAI(f *factory.Factory) *cobra.Command { | ||
cmd := cobra.Command{ | ||
Use: "ai <command>", | ||
Short: "Manage AI integration.", | ||
Long: "Work with Buildkite AI.", | ||
Example: heredoc.Doc(` | ||
# To configure your AI token | ||
$ bk ai configure | ||
`), | ||
} | ||
|
||
cmd.AddCommand(NewCmdAIConfigure(f)) | ||
|
||
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,34 @@ | ||
package ai | ||
|
||
import ( | ||
"errors" | ||
|
||
addCmd "github.com/buildkite/cli/v3/pkg/cmd/ai/add" | ||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmdAIConfigure(f *factory.Factory) *cobra.Command { | ||
var force bool | ||
|
||
cmd := &cobra.Command{ | ||
Use: "configure", | ||
Aliases: []string{"config"}, | ||
Args: cobra.NoArgs, | ||
Short: "Configure OpenAI token.", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// if the token already exists and --force is not used | ||
if !force && f.Config.GetOpenAIToken() != "" { | ||
return errors.New("OpenAI token already configured. You must use --force.") | ||
} | ||
|
||
return addCmd.ConfigureRun(f) | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&force, "force", false, "Force setting a new token") | ||
|
||
cmd.AddCommand(addCmd.NewCmdAIAdd(f)) | ||
|
||
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
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
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
Oops, something went wrong.