forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
52 lines (44 loc) · 1.08 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/drone/drone/client"
)
// NewStatusCommand returns the CLI command for "status".
func NewStatusCommand() cli.Command {
return cli.Command{
Name: "status",
Usage: "display a repository build status",
Flags: []cli.Flag{
cli.StringFlag{
Name: "b, branch",
Usage: "branch to display",
},
},
Action: func(c *cli.Context) {
handle(c, statusCommandFunc)
},
}
}
// statusCommandFunc executes the "status" command.
func statusCommandFunc(c *cli.Context, client *client.Client) error {
var host, owner, repo, branch string
var args = c.Args()
if len(args) != 0 {
host, owner, repo = parseRepo(args[0])
}
if c.IsSet("branch") {
branch = c.String("branch")
} else {
branch = "master"
}
builds, err := client.Commits.ListBranch(host, owner, repo, branch)
if err != nil {
return err
} else if len(builds) == 0 {
return nil
}
var build = builds[len(builds)-1]
fmt.Printf("%s\t%s\t%s\t%s\t%v", build.Status, build.ShaShort(), build.Timestamp, build.Author, build.Message)
return nil
}