Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions pkg/cmd/build/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewCmdBuildNew(f *factory.Factory) *cobra.Command {
envMap := make(map[string]string)
metaDataMap := make(map[string]string)
var envFile string
var author string

cmd := cobra.Command{
DisableFlagsInUseLine: true,
Expand Down Expand Up @@ -143,7 +144,7 @@ func NewCmdBuildNew(f *factory.Factory) *cobra.Command {
}
}

return newBuild(cmd.Context(), resolvedPipeline.Org, resolvedPipeline.Name, f, message, commit, branch, web, envMap, metaDataMap, ignoreBranchFilters)
return newBuild(cmd.Context(), resolvedPipeline.Org, resolvedPipeline.Name, f, message, commit, branch, web, envMap, metaDataMap, ignoreBranchFilters, author)
} else {
// User chose not to proceed - provide feedback
fmt.Fprintf(cmd.OutOrStdout(), "Build creation canceled\n")
Expand All @@ -159,6 +160,7 @@ func NewCmdBuildNew(f *factory.Factory) *cobra.Command {
cmd.Flags().StringVarP(&message, "message", "m", "", "Description of the build. If left blank, the commit message will be used once the build starts.")
cmd.Flags().StringVarP(&commit, "commit", "c", "HEAD", "The commit to build.")
cmd.Flags().StringVarP(&branch, "branch", "b", "", "The branch to build. Defaults to the default branch of the pipeline.")
cmd.Flags().StringVarP(&author, "author", "a", "", "Author of the build. Supports: \"Name <email>\", \"email@domain.com\", \"Full Name\", or \"username\"")
cmd.Flags().BoolVarP(&web, "web", "w", false, "Open the build in a web browser after it has been created.")
cmd.Flags().StringVarP(&pipeline, "pipeline", "p", "", "The pipeline to build. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}.\n"+
"If omitted, it will be resolved using the current directory.",
Expand All @@ -175,7 +177,38 @@ func NewCmdBuildNew(f *factory.Factory) *cobra.Command {
return &cmd
}

func newBuild(ctx context.Context, org string, pipeline string, f *factory.Factory, message string, commit string, branch string, web bool, env map[string]string, metaData map[string]string, ignoreBranchFilters bool) error {
func parseAuthor(author string) buildkite.Author {
if author == "" {
return buildkite.Author{}
}

// Check for Git-style format: "Name <email@domain.com>"
if strings.Contains(author, "<") && strings.Contains(author, ">") {
parts := strings.Split(author, "<")
if len(parts) == 2 {
name := strings.TrimSpace(parts[0])
email := strings.TrimSpace(strings.Trim(parts[1], ">"))
if name != "" && email != "" {
return buildkite.Author{Name: name, Email: email}
}
}
}

// Check for email-only format
if strings.Contains(author, "@") && strings.Contains(author, ".") && !strings.Contains(author, " ") {
return buildkite.Author{Email: author}
}

// Check for name format (contains spaces but no email)
if strings.Contains(author, " ") {
return buildkite.Author{Name: author}
}

// Default to username
return buildkite.Author{Username: author}
}

func newBuild(ctx context.Context, org string, pipeline string, f *factory.Factory, message string, commit string, branch string, web bool, env map[string]string, metaData map[string]string, ignoreBranchFilters bool, author string) error {
var actionErr error
var build buildkite.Build
spinErr := bk_io.SpinWhile(fmt.Sprintf("Starting new build for %s", pipeline), func() {
Expand Down Expand Up @@ -204,6 +237,7 @@ func newBuild(ctx context.Context, org string, pipeline string, f *factory.Facto
Message: message,
Commit: commit,
Branch: branch,
Author: parseAuthor(author),
Env: env,
MetaData: metaData,
IgnorePipelineBranchFilters: ignoreBranchFilters,
Expand Down