|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strconv" |
| 6 | + |
| 7 | + "github.com/urfave/cli/v2" |
| 8 | + |
| 9 | + "github.com/gitploy-io/gitploy/pkg/api" |
| 10 | +) |
| 11 | + |
| 12 | +var deploymentStatusCreateCommand = &cli.Command{ |
| 13 | + Name: "create", |
| 14 | + Usage: "Create the remote deployment status under the deployment.", |
| 15 | + ArgsUsage: "<owner>/<repo> <number>", |
| 16 | + Flags: []cli.Flag{ |
| 17 | + &cli.StringFlag{ |
| 18 | + Name: "status", |
| 19 | + Usage: "The remote deployment status. For GitHub, Can be one of error, failure, in_progress, queued, or success.", |
| 20 | + Required: true, |
| 21 | + }, |
| 22 | + &cli.StringFlag{ |
| 23 | + Name: "description", |
| 24 | + Usage: "A short description of the status.", |
| 25 | + DefaultText: "USER_LOGIN updated the status manually.", |
| 26 | + }, |
| 27 | + }, |
| 28 | + Action: func(cli *cli.Context) error { |
| 29 | + ns, n, err := splitFullName(cli.Args().First()) |
| 30 | + if err != nil { |
| 31 | + return err |
| 32 | + } |
| 33 | + |
| 34 | + number, err := strconv.Atoi(cli.Args().Get(1)) |
| 35 | + if err != nil { |
| 36 | + return err |
| 37 | + } |
| 38 | + |
| 39 | + // Build the request. |
| 40 | + c := buildClient(cli) |
| 41 | + req := &api.DeploymentStatusCreateRemoteRequest{ |
| 42 | + Status: cli.String("status"), |
| 43 | + Description: cli.String("description"), |
| 44 | + } |
| 45 | + if cli.String("description") == "" { |
| 46 | + req.Description = buildDescription(cli) |
| 47 | + } |
| 48 | + |
| 49 | + dss, err := c.DeploymentStatus.CreateRemote(cli.Context, ns, n, number, req) |
| 50 | + if err != nil { |
| 51 | + return err |
| 52 | + } |
| 53 | + |
| 54 | + return printJson(cli, dss) |
| 55 | + }, |
| 56 | +} |
| 57 | + |
| 58 | +func buildDescription(cli *cli.Context) string { |
| 59 | + c := buildClient(cli) |
| 60 | + |
| 61 | + me, err := c.User.GetMe(cli.Context) |
| 62 | + if err != nil { |
| 63 | + return "Updated the status manually." |
| 64 | + } |
| 65 | + |
| 66 | + return fmt.Sprintf("%s updated the status manually.", me.Login) |
| 67 | +} |
0 commit comments