-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(dron-124) Add new command for build incomplete V2
- Loading branch information
TP Honey
committed
Oct 4, 2021
1 parent
f535034
commit 55243a7
Showing
4 changed files
with
92 additions
and
3 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 |
---|---|---|
|
@@ -18,5 +18,6 @@ var Command = cli.Command{ | |
buildPromoteCmd, | ||
buildRollbackCmd, | ||
buildQueueCmd, | ||
buildQueueV2Cmd, | ||
}, | ||
} |
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,88 @@ | ||
package build | ||
|
||
import ( | ||
"os" | ||
"text/template" | ||
|
||
"github.com/drone/drone-cli/drone/internal" | ||
"github.com/drone/funcmap" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var buildQueueV2Cmd = cli.Command{ | ||
Name: "queue_v2", | ||
Usage: "show build queue", | ||
ArgsUsage: "", | ||
Action: buildQueueV2, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "format", | ||
Usage: "format output", | ||
Value: tmplQueueV2Status, | ||
}, | ||
cli.StringFlag{ | ||
Name: "repo", | ||
Usage: "repo filter", | ||
}, | ||
}, | ||
} | ||
|
||
func buildQueueV2(c *cli.Context) error { | ||
client, err := internal.NewClient(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
instances, err := client.IncompleteV2() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
slug := c.String("repo") | ||
|
||
for _, instance := range instances { | ||
if slug != "" && instance.RepoSlug != slug { | ||
continue | ||
} | ||
templateErr := tmpl.Execute(os.Stdout, instance) | ||
if templateErr != nil { | ||
return templateErr | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// template for build queue v2 information | ||
var tmplQueueV2Status = "\x1b[33m{{ .RepoSlug }}#{{ .BuildNumber }} \x1b[0m" + ` | ||
Repo Namespace: {{ .RepoNamespace }} | ||
Repo Name: {{ .RepoName }} | ||
Repo Slug: {{ .RepoSlug }} | ||
Build Number: {{ .BuildNumber }} | ||
Build Author: {{ .BuildAuthor }} | ||
Build Author Name : {{ .BuildAuthorName }} | ||
Build Author Email: {{ .BuildAuthorEmail }} | ||
Build Author Avatar : {{ .BuildAuthorAvatar }} | ||
Build Sender: {{ .BuildSender }} | ||
Build Started: {{ .BuildStarted | time }} | ||
Build Finished: {{ .BuildFinished | time}} | ||
Build Created: {{ .BuildCreated | time}} | ||
Build Updated: {{ .BuildUpdated | time }} | ||
Stage Name: {{ .StageName }} | ||
Stage Kind: {{ .StageKind }} | ||
Stage Type: {{ .StageType }} | ||
Stage Status: {{ .StageStatus }} | ||
Stage Machine: {{ .StageMachine }} | ||
Stage OS: {{ .StageOS }} | ||
Stage Arch: {{ .StageArch }} | ||
Stage Variant: {{ .StageVariant }} | ||
Stage Kernel: {{ .StageKernel }} | ||
Stage Limit: {{ .StageLimit }} | ||
Stage Limit Repo: {{ .StageLimitRepo }} | ||
Stage Started: {{ .StageStarted | time }} | ||
Stage Stopped: {{ .StageStopped | time }} | ||
` |
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