Skip to content

Commit d4f6425

Browse files
author
Federico Builes
authored
Merge pull request #290 from actions/cn/scan_pr
Enable setting configuration options for local testing
2 parents 4538b29 + 49a61bd commit d4f6425

3 files changed

Lines changed: 58 additions & 20 deletions

File tree

.github/dependency-review-config.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

CONTRIBUTING.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Contributing
2+
23
[fork]: https://github.com/actions/dependency-review-action/fork
34
[pr]: https://github.com/actions/dependency-review-action/compare
45
[code-of-conduct]: CODE_OF_CONDUCT.md
@@ -9,7 +10,6 @@ Contributions to this project are
910
[released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license)
1011
to the public under the [project's open source license](LICENSE).
1112

12-
1313
Please note that this project is released with a [Contributor Code of
1414
Conduct][code-of-conduct]. By participating in this project you agree
1515
to abide by its terms.
@@ -20,7 +20,6 @@ This Action makes an authenticated query to the Dependency Graph Diff
2020
API endpoint (`GET /repos/{owner}/{repo}/dependency-graph/compare/{basehead}`)
2121
to find out the set of added and removed dependencies for each manifest.
2222

23-
2423
### Bootstrapping the project
2524

2625
```
@@ -35,7 +34,7 @@ npm install
3534
npm run test
3635
```
3736

38-
*Note*: We don't have any useful tests yet, contributions are welcome!
37+
_Note_: We don't have any useful tests yet, contributions are welcome!
3938

4039
## Local Development
4140

@@ -56,16 +55,24 @@ Like this:
5655
$ GITHUB_TOKEN=my-secret-token ./scripts/scan_pr https://github.com/actions/dependency-review-action/pull/3
5756
```
5857

58+
[Configuration options](README.md#configuration-options) can be set by
59+
passing an external YAML [configuration file](README.md#configuration-file) to the
60+
`scan_pr` script with the `-c`/`--config-file` option:
61+
62+
```sh
63+
$ GITHUB_TOKEN=<token> ./scripts/scan_pr --config-file my_custom_config.yml <pr_url>
64+
```
65+
5966
## Submitting a pull request
6067

6168
0. [Fork][fork] and clone the repository
62-
0. Configure and install the dependencies: `npm install`
63-
0. Make sure the tests pass on your machine: `npm run test`
64-
0. Create a new branch: `git checkout -b my-branch-name`
65-
0. Make your change, add tests, and make sure the tests still pass
66-
0. Make sure to build and package before pushing: `npm run build && npm run package`
67-
0. Push to your fork and [submit a pull request][pr]
68-
0. Pat your self on the back and wait for your pull request to be reviewed and merged.
69+
1. Configure and install the dependencies: `npm install`
70+
2. Make sure the tests pass on your machine: `npm run test`
71+
3. Create a new branch: `git checkout -b my-branch-name`
72+
4. Make your change, add tests, and make sure the tests still pass
73+
5. Make sure to build and package before pushing: `npm run build && npm run package`
74+
6. Push to your fork and [submit a pull request][pr]
75+
7. Pat your self on the back and wait for your pull request to be reviewed and merged.
6976

7077
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
7178

@@ -77,21 +84,21 @@ Here are a few things you can do that will increase the likelihood of your pull
7784

7885
1. Update the version number in [package.json](https://github.com/actions/dependency-review-action/blob/main/package.json).
7986
1. Go to [Draft a new
80-
release](https://github.com/actions/dependency-review-action/releases/new)
81-
in the Releases page.
82-
2. Make sure that the `Publish this Action to the GitHub Marketplace`
83-
checkbox is enabled
87+
release](https://github.com/actions/dependency-review-action/releases/new)
88+
in the Releases page.
89+
1. Make sure that the `Publish this Action to the GitHub Marketplace`
90+
checkbox is enabled
8491

8592
<img width="481" alt="Screenshot 2022-06-15 at 12 08 19" src="https://user-images.githubusercontent.com/2161/173822484-4b60d8b4-c674-4bff-b5ff-b0c4a3650ab7.png">
8693

8794
3. Click "Choose a tag" and then "Create new tag", where the tag name
88-
will be your version prefixed by a `v` (e.g. `v1.2.3`).
95+
will be your version prefixed by a `v` (e.g. `v1.2.3`).
8996
4. Use a version number for the release title (e.g. "1.2.3").
9097

9198
<img width="700" alt="Screenshot 2022-06-15 at 12 08 36" src="https://user-images.githubusercontent.com/2161/173822548-33ab3432-d679-4dc1-adf8-b50fdaf47de3.png">
9299

93100
5. Add your release notes. If this is a major version make sure to
94-
include a small description of the biggest changes in the new version.
101+
include a small description of the biggest changes in the new version.
95102
6. Click "Publish Release".
96103

97104
You now have a tag and release using the semver version you used
@@ -102,6 +109,7 @@ automatically getting all the
102109
minor/patch updates.
103110

104111
To do this just checkout `main`, force-create a new annotated tag, and push it:
112+
105113
```
106114
git tag -fa v2 -m "Updating v2 to 2.3.4"
107115
git push origin v2 --force

scripts/scan_pr

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,52 @@ require 'json'
33
require 'tempfile'
44
require 'open3'
55
require 'bundler/inline'
6+
require 'optparse'
67

78
gemfile do
89
source 'https://rubygems.org'
910
gem 'octokit'
1011
end
1112

13+
config_file = nil
1214
github_token = ENV["GITHUB_TOKEN"]
15+
1316
if !github_token || github_token.empty?
1417
puts "Please set the GITHUB_TOKEN environment variable"
1518
exit -1
1619
end
1720

18-
arg = /(?<repo_nwo>[\w\-]+\/[\w\-]+)\/pull\/(?<pr_number>\d+)/.match(ARGV[0])
21+
op = OptionParser.new do |opts|
22+
usage = <<EOF
23+
Run Dependency Review on a repository.
24+
25+
\e[1mUsage:\e[22m
26+
scripts/scan_pr [options] <pr_url>
27+
28+
\e[1mExample:\e[22m
29+
scripts/scan_pr https://github.com/actions/dependency-review-action/pull/294
30+
31+
EOF
32+
33+
opts.banner = usage
34+
35+
opts.on('-c', '--config-file <FILE>', 'Use an external configuration file') do |cf|
36+
config_file = cf
37+
end
38+
39+
opts.on("-h", "--help", "Prints this help") do
40+
puts opts
41+
exit
42+
end
43+
end
44+
45+
op.parse!
46+
47+
# make sure we have a NWO somewhere in the parameters
48+
arg = /(?<repo_nwo>[\w\-]+\/[\w\-]+)\/pull\/(?<pr_number>\d+)/.match(ARGV.join(" "))
1949

2050
if arg.nil?
21-
puts "Usage: script/scan_pr <pr_url>"
51+
puts op
2252
exit -1
2353
end
2454

@@ -33,7 +63,8 @@ event_file.write("{ \"pull_request\": #{pr.to_h.to_json}}")
3363
event_file.close
3464

3565
action_inputs = {
36-
"repo-token" => github_token
66+
"repo-token": github_token,
67+
"config-file": config_file
3768
}
3869

3970
dev_cmd_env = {

0 commit comments

Comments
 (0)