Skip to content

Commit

Permalink
Merge branch 'manage-deploys'
Browse files Browse the repository at this point in the history
  • Loading branch information
cwarden committed Aug 25, 2023
2 parents 5656ebf + 0818f76 commit 5faef9c
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 2 deletions.
154 changes: 154 additions & 0 deletions command/deploys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package command

import (
"os"
"strconv"
"strings"

. "github.com/ForceCLI/force/error"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)

func init() {
defaultOutputFormat := "console"
if !terminal.IsTerminal(int(os.Stdout.Fd())) {
defaultOutputFormat = "csv"
}
cancelDeployCmd.Flags().StringP("deploy-id", "d", "", "Deploy Id to cancel")
cancelDeployCmd.MarkFlagRequired("deploy-id")

listDeploysCmd.Flags().StringP("format", "f", defaultOutputFormat, "output format: csv, json, json-pretty, console")

listDeployErrorsCmd.Flags().StringP("deploy-id", "d", "", "Deploy Id to cancel")
listDeployErrorsCmd.MarkFlagRequired("deploy-id")

deploysCmd.AddCommand(listDeploysCmd)
deploysCmd.AddCommand(cancelDeployCmd)
deploysCmd.AddCommand(listDeployErrorsCmd)

RootCmd.AddCommand(deploysCmd)
}

var deploysCmd = &cobra.Command{
Use: "deploys",
Short: "Manage metadata deployments",
Long: `
List and cancel metadata deployments.
`,

Example: `
force deploys list
force deploys cancel -d 0Af000000000000000
`,
DisableFlagsInUseLine: false,
}

var listDeploysCmd = &cobra.Command{
Use: "list",
Short: "List metadata deploys",
DisableFlagsInUseLine: false,
Run: func(cmd *cobra.Command, args []string) {
format, _ := cmd.Flags().GetString("format")
queryDeployRequests(format)
},
}

var listDeployErrorsCmd = &cobra.Command{
Use: "errors",
Short: "List metadata deploy errors",
DisableFlagsInUseLine: false,
Run: func(cmd *cobra.Command, args []string) {
deployId, _ := cmd.Flags().GetString("deploy-id")
displayErrors(deployId)
},
}

func queryDeployRequests(format string) {
fields := []string{
"Id",
"Status",
"StartDate",
"CompletedDate",
"NumberComponentsDeployed",
"NumberComponentErrors",
// "NumberComponentsTotal",
"NumberTestsCompleted",
"NumberTestErrors",
// "NumberTestsTotal",
"CheckOnly",
// "IgnoreWarnings",
// "RollbackOnError",
// "Type",
// "CanceledBy.Name",
// "RunTestsEnabled",
// "ChangeSetName",
// "ErrorStatusCode",
// "StateDetail",
// "ErrorMessage",
// "AllowMissingFiles",
// "AutoUpdatePackage",
// "PurgeOnDelete",
// "SinglePackage",
// "TestLevel",
}
query := `
SELECT
` + strings.Join(fields, ",") + `
FROM
DeployRequest
ORDER BY
CompletedDate DESC
`
queryAll := false
useTooling := true
explain := false
runQuery(query, format, queryAll, useTooling, explain)
}

var cancelDeployCmd = &cobra.Command{
Use: "cancel -d <deploy id>",
Short: "Cancel deploy",
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
deployId, _ := cmd.Flags().GetString("deploy-id")
_, err := force.Metadata.CancelDeploy(deployId)
if err != nil {
ErrorAndExit("Error canceling job: " + err.Error())
}
},
}

func displayErrors(deployId string) {
result, err := force.Metadata.CheckDeployStatus(deployId)
if err != nil {
ErrorAndExit("Error checking deploy status: " + err.Error())
}
if !result.Done {
ErrorAndExit("Deploy not done: " + result.Status)
}
table := tablewriter.NewWriter(os.Stdout)
table.SetRowLine(true)
table.SetHeader([]string{
"Component Type",
"Name",
// "File Name",
"Line Number",
"Problem Type",
"Problem",
})
for _, f := range result.Details.ComponentFailures {
table.Append([]string{
f.ComponentType,
f.FullName,
// f.FileName,
strconv.Itoa(f.LineNumber),
f.ProblemType,
f.Problem,
})
}
if table.NumLines() > 0 {
table.Render()
}
}
1 change: 1 addition & 0 deletions docs/force.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ force
* [force bulk](force_bulk.md) - Load csv file or query data using Bulk API
* [force create](force_create.md) - Creates a new, empty Apex Class, Trigger, Visualforce page, or Component.
* [force datapipe](force_datapipe.md) - Manage DataPipes
* [force deploys](force_deploys.md) - Manage metadata deployments
* [force describe](force_describe.md) - Describe the types of metadata available in the org
* [force eventlogfile](force_eventlogfile.md) - List and fetch event log file
* [force export](force_export.md) - Export metadata to a local directory
Expand Down
2 changes: 1 addition & 1 deletion docs/force_bulk.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Load csv file or query data using Bulk API
force bulk insert Account [csv file]
force bulk update Account [csv file]
force bulk delete Account [csv file]
force bulk upsert ExternalIdField__c Account [csv file]
force bulk upsert -e ExternalIdField__c Account [csv file]
force bulk job [job id]
force bulk batches [job id]
force Bulk batch [job id] [batch id]
Expand Down
2 changes: 1 addition & 1 deletion docs/force_bulk_upsert.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Upsert records from csv file using Bulk API

```
force bulk upsert <External_Id_Field__c> <object> <file> [flags]
force bulk upsert -e <External_Id_Field__c> <object> <file> [flags]
```

### Options
Expand Down
39 changes: 39 additions & 0 deletions docs/force_deploys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## force deploys

Manage metadata deployments

### Synopsis


List and cancel metadata deployments.


### Examples

```
force deploys list
force deploys cancel -d 0Af000000000000000
```

### Options

```
-h, --help help for deploys
```

### Options inherited from parent commands

```
-a, --account username account username to use
-V, --apiversion string API version to use
```

### SEE ALSO

* [force](force.md) - force CLI
* [force deploys cancel](force_deploys_cancel.md) - Cancel deploy
* [force deploys errors](force_deploys_errors.md) - List metadata deploy errors
* [force deploys list](force_deploys_list.md) - List metadata deploys

26 changes: 26 additions & 0 deletions docs/force_deploys_cancel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## force deploys cancel

Cancel deploy

```
force deploys cancel -d <deploy id>
```

### Options

```
-d, --deploy-id string Deploy Id to cancel
-h, --help help for cancel
```

### Options inherited from parent commands

```
-a, --account username account username to use
-V, --apiversion string API version to use
```

### SEE ALSO

* [force deploys](force_deploys.md) - Manage metadata deployments

26 changes: 26 additions & 0 deletions docs/force_deploys_errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## force deploys errors

List metadata deploy errors

```
force deploys errors [flags]
```

### Options

```
-d, --deploy-id string Deploy Id to cancel
-h, --help help for errors
```

### Options inherited from parent commands

```
-a, --account username account username to use
-V, --apiversion string API version to use
```

### SEE ALSO

* [force deploys](force_deploys.md) - Manage metadata deployments

26 changes: 26 additions & 0 deletions docs/force_deploys_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## force deploys list

List metadata deploys

```
force deploys list [flags]
```

### Options

```
-f, --format string output format: csv, json, json-pretty, console (default "console")
-h, --help help for list
```

### Options inherited from parent commands

```
-a, --account username account username to use
-V, --apiversion string API version to use
```

### SEE ALSO

* [force deploys](force_deploys.md) - Manage metadata deployments

0 comments on commit 5faef9c

Please sign in to comment.