npm-update-package 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@ npx npm-update-package --github-token $GITHUB_TOKEN
14
14
  ## Options
15
15
 
16
16
  You can customize behavior via command-line options.
17
- Template strings such as `--commit-message` can embed variables like `{{packageName}}`(HTML-escaped) or `{{{packageName}}}`(not HTML-escaped).
17
+ Some options can embed variables like `{{packageName}}`(HTML-escaped) or `{{{packageName}}}`(not HTML-escaped).
18
18
 
19
19
  ### `--commit-message`
20
20
 
@@ -31,7 +31,7 @@ Commit message template
31
31
 
32
32
  ### `--github-token`
33
33
 
34
- [GitHub token](#github-token).
34
+ [GitHub token](#github-token)
35
35
 
36
36
  - type: string
37
37
  - required: true
@@ -57,9 +57,16 @@ Package manager of your project
57
57
  - required: false
58
58
  - allowed values
59
59
  - `npm`: npm
60
- - `yarn`: Yarn (**It has not been tested yet.**)
60
+ - `yarn`: Yarn
61
61
  - default: `npm`
62
62
 
63
+ ### `--pull-request-reviewers`
64
+
65
+ Reviewers of pull request
66
+
67
+ - type: string[]
68
+ - required: false
69
+
63
70
  ### `--pull-request-title`
64
71
 
65
72
  Pull request title template
@@ -80,7 +87,7 @@ Available tokens and permissions required for each token are as follows.
80
87
 
81
88
  - [GitHub Actions](https://docs.github.com/en/actions/security-guides/automatic-token-authentication)
82
89
  - [GitHub App](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps)
83
- - Contents: Read-only
90
+ - Contents: Read & write
84
91
  - Metadata: Read-only
85
92
  - Pull requests: Read & write
86
93
  - [Personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
@@ -104,7 +111,7 @@ Creating a GitHub App may be tedious, but you only have to do it once the first
104
111
 
105
112
  ## Examples
106
113
 
107
- - Use token of GitHub Actions
114
+ - [Use token of GitHub Actions](https://github.com/npm-update-package/example-github-actions)
108
115
 
109
116
  ```yaml
110
117
  name: npm-update-package
@@ -127,8 +134,7 @@ jobs:
127
134
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128
135
  ```
129
136
 
130
-
131
- - Use token of GitHub App
137
+ - [Use token of GitHub App](https://github.com/npm-update-package/example-github-app)
132
138
 
133
139
  ```yaml
134
140
  name: npm-update-package
@@ -159,12 +165,61 @@ jobs:
159
165
  GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
160
166
  ```
161
167
 
162
- Actual working examples can be seen in these repositories.
168
+ - [Use Personal access token](https://github.com/npm-update-package/example-pat)
169
+
170
+ ```yaml
171
+ name: npm-update-package
172
+ on:
173
+ schedule:
174
+ - cron: '0 0 * * *'
175
+ jobs:
176
+ npm-update-package:
177
+ runs-on: ubuntu-latest
178
+ steps:
179
+ - uses: actions/checkout@v2
180
+ - uses: actions/setup-node@v2
181
+ - run: |
182
+ git config user.name $GIT_USER_NAME
183
+ git config user.email $GIT_USER_EMAIL
184
+ npx npm-update-package --github-token $GITHUB_TOKEN
185
+ env:
186
+ # TODO: Replace with your email
187
+ GIT_USER_EMAIL: 97961304+npm-update-package-bot@users.noreply.github.com
188
+ # TODO: Replace with your name
189
+ GIT_USER_NAME: npm-update-package-bot
190
+ GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
191
+ ```
192
+
193
+ - [Use Yarn](https://github.com/npm-update-package/example-yarn)
163
194
 
164
- |Repository|Package manager|GitHub token|
165
- |---|---|---|
166
- |[example-github-actions](https://github.com/npm-update-package/example-github-actions)|npm|GitHub Actions|
167
- |[example-github-app](https://github.com/npm-update-package/example-github-app)|npm|GitHub App|
195
+ ```yaml
196
+ name: npm-update-package
197
+ on:
198
+ schedule:
199
+ - cron: '0 0 * * *'
200
+ jobs:
201
+ npm-update-package:
202
+ runs-on: ubuntu-latest
203
+ steps:
204
+ - uses: actions/checkout@v2
205
+ - uses: actions/setup-node@v2
206
+ - name: Generate token
207
+ id: generate_token
208
+ uses: tibdex/github-app-token@v1
209
+ with:
210
+ app_id: ${{ secrets.APP_ID }}
211
+ private_key: ${{ secrets.PRIVATE_KEY }}
212
+ - run: |
213
+ git config user.name $GIT_USER_NAME
214
+ git config user.email $GIT_USER_EMAIL
215
+ npx npm-update-package --github-token $GITHUB_TOKEN --package-manager yarn
216
+ env:
217
+ # TODO: Replace with your GitHub App's email
218
+ GIT_USER_EMAIL: 97396142+npm-update-package-bot[bot]@users.noreply.github.com
219
+ # TODO: Replace with your GitHub App's user name
220
+ GIT_USER_NAME: npm-update-package-bot[bot]
221
+ GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
222
+ ```
168
223
 
169
224
  ## Flow
170
225
 
package/dist/app.js CHANGED
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.app = void 0;
4
4
  exports.app = {
5
5
  name: 'npm-update-package',
6
- version: '0.24.0',
6
+ version: '0.25.0',
7
7
  web: 'https://github.com/npm-update-package/npm-update-package'
8
8
  };
@@ -47,5 +47,13 @@ class GitHub {
47
47
  const { data } = await this.octokit.repos.get(params);
48
48
  return data;
49
49
  }
50
+ async requestReviewers({ owner, repo, pullNumber, reviewers }) {
51
+ await this.octokit.pulls.requestReviewers({
52
+ owner,
53
+ repo,
54
+ pull_number: pullNumber,
55
+ reviewers
56
+ });
57
+ }
50
58
  }
51
59
  exports.GitHub = GitHub;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PullRequestCreator = void 0;
4
4
  const createPullRequestBody_1 = require("./createPullRequestBody");
5
5
  class PullRequestCreator {
6
- constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, logger }) {
6
+ constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, logger, reviewers }) {
7
7
  this.github = github;
8
8
  this.gitRepo = gitRepo;
9
9
  this.githubRepo = githubRepo;
10
10
  this.pullRequestTitleCreator = pullRequestTitleCreator;
11
11
  this.logger = logger;
12
+ this.reviewers = reviewers;
12
13
  }
13
14
  async create({ outdatedPackage, branchName }) {
14
15
  const title = this.pullRequestTitleCreator.create(outdatedPackage);
@@ -30,6 +31,14 @@ class PullRequestCreator {
30
31
  issue_number: pullRequest.number,
31
32
  labels: ['npm-update-package']
32
33
  });
34
+ if (this.reviewers !== undefined) {
35
+ await this.github.requestReviewers({
36
+ owner: this.gitRepo.owner,
37
+ repo: this.gitRepo.name,
38
+ pullNumber: pullRequest.number,
39
+ reviewers: this.reviewers
40
+ });
41
+ }
33
42
  return pullRequest;
34
43
  }
35
44
  }
package/dist/main.js CHANGED
@@ -56,7 +56,8 @@ const main = async ({ options, logger }) => {
56
56
  gitRepo,
57
57
  githubRepo,
58
58
  pullRequestTitleCreator,
59
- logger
59
+ logger,
60
+ reviewers: options.pullRequestReviewers
60
61
  });
61
62
  const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
62
63
  const pullRequestFinder = new github_1.PullRequestFinder(pullRequests);
@@ -4,11 +4,16 @@ exports.isOptions = void 0;
4
4
  const io_ts_1 = require("io-ts");
5
5
  const logger_1 = require("../logger");
6
6
  const package_manager_1 = require("../package-manager");
7
- const Options = (0, io_ts_1.type)({
8
- commitMessage: io_ts_1.string,
9
- githubToken: io_ts_1.string,
10
- logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Off), (0, io_ts_1.literal)(logger_1.LogLevel.Error), (0, io_ts_1.literal)(logger_1.LogLevel.Info), (0, io_ts_1.literal)(logger_1.LogLevel.Debug)]),
11
- packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)(package_manager_1.PackageManagerName.Npm), (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Yarn)]),
12
- pullRequestTitle: io_ts_1.string
13
- });
7
+ const Options = (0, io_ts_1.intersection)([
8
+ (0, io_ts_1.type)({
9
+ commitMessage: io_ts_1.string,
10
+ githubToken: io_ts_1.string,
11
+ logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Off), (0, io_ts_1.literal)(logger_1.LogLevel.Error), (0, io_ts_1.literal)(logger_1.LogLevel.Info), (0, io_ts_1.literal)(logger_1.LogLevel.Debug)]),
12
+ packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)(package_manager_1.PackageManagerName.Npm), (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Yarn)]),
13
+ pullRequestTitle: io_ts_1.string
14
+ }),
15
+ (0, io_ts_1.partial)({
16
+ pullRequestReviewers: (0, io_ts_1.array)(io_ts_1.string)
17
+ })
18
+ ]);
14
19
  exports.isOptions = Options.is;
@@ -42,6 +42,12 @@ exports.cliOptions = [
42
42
  ],
43
43
  default: package_manager_1.PackageManagerName.Npm
44
44
  },
45
+ {
46
+ name: 'pull-request-reviewers',
47
+ description: 'Reviewers of pull request',
48
+ type: OptionType_1.OptionType.StringArray,
49
+ required: false
50
+ },
45
51
  {
46
52
  name: 'pull-request-title',
47
53
  description: 'Pull request title template',
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isPackageManagerName = exports.PackageManagerName = void 0;
4
4
  exports.PackageManagerName = {
5
5
  Npm: 'npm',
6
- Yarn: 'Yarn'
6
+ Yarn: 'yarn'
7
7
  };
8
8
  const packageManagerNames = Object.values(exports.PackageManagerName);
9
9
  const isPackageManagerName = (value) => packageManagerNames.includes(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "CLI tool for creating pull requests to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -47,7 +47,7 @@
47
47
  "eslint-plugin-tsdoc": "0.2.14",
48
48
  "husky": "7.0.4",
49
49
  "jest": "27.4.7",
50
- "lint-staged": "12.1.7",
50
+ "lint-staged": "12.2.0",
51
51
  "npm-run-all": "4.1.5",
52
52
  "rimraf": "3.0.2",
53
53
  "ts-jest": "27.1.3",