Skip to content

Commit 5fd887b

Browse files
authored
cleanup the "update" subcommand (dependabot#78)
1 parent 997ba0d commit 5fd887b

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Usage:
3939
dependabot [command]
4040

4141
Examples:
42-
$ dependabot update go_modules rsc/quote --dry-run
42+
$ dependabot update go_modules rsc/quote
4343
$ dependabot test -f scenario.yaml
4444

4545
Available Commands:
@@ -56,12 +56,11 @@ Use "dependabot [command] --help" for more information about a command.
5656

5757
### `dependabot update`
5858

59-
Run the `update` subcommand with the `--dry-run` flag to
60-
simulate a Dependabot update job for the provided ecosystem and repo
61-
(without actually creating any PRs).
59+
Run the `update` subcommand to run a Dependabot update job for the provided ecosystem and repo.
60+
This does not create PRs, but outputs data that could be used to create PRs.
6261

6362
```console
64-
$ dependabot update go_modules rsc/quote --dry-run
63+
$ dependabot update go_modules rsc/quote
6564
# ...
6665
+----------------------------------------------------+
6766
| Changes to Dependabot Pull Requests |
@@ -103,7 +102,7 @@ using the `--file` / `-f` option
103102
(this replaces the package manager and repository name arguments).
104103

105104
```console
106-
dependabot update -f job.yaml --dry-run
105+
dependabot update -f job.yaml
107106
```
108107

109108
```yaml
@@ -265,7 +264,7 @@ To produce a scenario file that tests Dependabot behavior for a given repo,
265264
run the `update` subcommand and set the `--output` / `-o` option to a file path.
266265

267266
```console
268-
dependabot update go_modules rsc/quote --dry-run -o go-scenario.yml
267+
dependabot update go_modules rsc/quote -o go-scenario.yml
269268
```
270269

271270
Run the `test` subcommand for the generated scenario file,

cmd/dependabot/internal/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var rootCmd = &cobra.Command{
3131
Short: "Dependabot end-to-end runner",
3232
Long: `Run Dependabot jobs from the command line.`,
3333
Example: heredoc.Doc(`
34-
$ dependabot update go_modules rsc/quote --dry-run
34+
$ dependabot update go_modules rsc/quote
3535
$ dependabot test -f input.yml
3636
`),
3737
Version: Version(),

cmd/dependabot/internal/cmd/update.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ var (
2323
repo string
2424
directory string
2525

26-
dryRun bool
2726
inputServerPort int
2827
)
2928

3029
var updateCmd = &cobra.Command{
3130
Use: "update <package_manager> <repo> [flags]",
32-
Short: "Perform update job",
31+
Short: "Perform an update job",
3332
Example: heredoc.Doc(`
34-
$ dependabot update go_modules rsc/quote --dry-run
33+
$ dependabot update go_modules rsc/quote
3534
`),
3635
RunE: func(cmd *cobra.Command, args []string) error {
3736
var outFile *os.File
@@ -213,10 +212,9 @@ func processInput(input *model.Input) {
213212
}
214213

215214
func doesStdinHaveData() bool {
216-
file := os.Stdin
217-
fi, err := file.Stat()
215+
fi, err := os.Stdin.Stat()
218216
if err != nil {
219-
fmt.Println("file.Stat()", err)
217+
log.Println("file.Stat()", err)
220218
}
221219
return fi.Size() > 0
222220
}
@@ -229,9 +227,6 @@ func init() {
229227
updateCmd.Flags().StringVarP(&provider, "provider", "p", "github", "provider of the repository")
230228
updateCmd.Flags().StringVarP(&directory, "directory", "d", "/", "directory to update")
231229

232-
updateCmd.Flags().BoolVar(&dryRun, "dry-run", true, "perform update as a dry run")
233-
_ = updateCmd.MarkFlagRequired("dry-run")
234-
235230
updateCmd.Flags().StringVarP(&output, "output", "o", "", "write scenario to file")
236231
updateCmd.Flags().StringVar(&cache, "cache", "", "cache import/export directory")
237232
updateCmd.Flags().StringVar(&proxyCertPath, "proxy-cert", "", "path to a certificate the proxy will trust")

docs/debugging.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ This guide will help you debug issues with your Dependabot update using the Depe
44

55
## Getting started
66

7-
First, test to make sure you have a working Dependabot CLI by performing a simple update, like `dependabot update --dry-run go_modules rsc/quote -o out.yml`. This should complete without error, and you can examine the out.yml file which should contain two calls to `create_pull_request`.
7+
First, test to make sure you have a working Dependabot CLI by performing a simple update, like `dependabot update go_modules rsc/quote -o out.yml`. This should complete without error, and you can examine the out.yml file which should contain two calls to `create_pull_request`.
88

99
Next, clone https://github.com/dependabot/dependabot-core. This project contains all the source for the updater images, and a helpful script `script/dependabot` which will mount the ecosystems in the container that the CLI starts.
1010

11-
Try opening a terminal and run `script/dependabot update --dry-run go_modules rsc/quote --debug` in the `dependabot-core` project directory. This will drop you in an interactive session with the update ready to proceed.
11+
Try opening a terminal and run `script/dependabot update go_modules rsc/quote --debug` in the `dependabot-core` project directory. This will drop you in an interactive session with the update ready to proceed.
1212

1313
To perform the update, you need to run two commands:
1414

@@ -60,7 +60,7 @@ At this prompt, you can run [debugger commands](https://github.com/ruby/debug) t
6060

6161
If your Dependabot job is hanging and would like to figure out why, the CLI is the perfect tool for the job.
6262

63-
Start by running the update that recreates the hang with `dependabot update --dry-run <ecosystem> <org/repo>`. Once the hang is reproducible, run with the `--debug` flag and the run the `fetch_files` and `update_files` commands and wait until the job hangs.
63+
Start by running the update that recreates the hang with `dependabot update <ecosystem> <org/repo>`. Once the hang is reproducible, run with the `--debug` flag and the run the `fetch_files` and `update_files` commands and wait until the job hangs.
6464

6565
Once it does hang, hit CTL-C, and you'll get a stack trace leading you to the problematic code.
6666

internal/server/api.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,13 @@ func (a *API) ServeHTTP(_ http.ResponseWriter, r *http.Request) {
122122
}
123123

124124
if !a.hasExpectations {
125-
// When running an update, there's no way to see the error in the record_update_job_error,
126-
// but it's handy to see it in the logs for debugging.
127-
if kind == "record_update_job_error" {
128-
log.Println("update-job error:", actual.Data)
125+
// output the data received to stdout
126+
if err = json.NewEncoder(os.Stdout).Encode(map[string]any{
127+
"type": kind,
128+
"data": actual.Data,
129+
}); err != nil {
130+
// Fail so the user knows stdout is not working
131+
log.Panicln("Failed to write to stdout: ", err)
129132
}
130133
return
131134
}

0 commit comments

Comments
 (0)