npm-update-package 0.24.2 → 0.26.1

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
@@ -57,7 +57,7 @@ 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
63
  ### `--pull-request-title`
@@ -73,6 +73,13 @@ Pull request title template
73
73
  - `level`: semver level (major/minor/patch)
74
74
  - default: `chore(deps): {{level}} update {{{packageName}}} to v{{newVersion}}`
75
75
 
76
+ ### `--reviewers`
77
+
78
+ User names to request reviews
79
+
80
+ - type: string[]
81
+ - required: false
82
+
76
83
  ## GitHub token
77
84
 
78
85
  GitHub token is required to run npm-update-package.
@@ -152,9 +159,9 @@ jobs:
152
159
  npx npm-update-package --github-token $GITHUB_TOKEN
153
160
  env:
154
161
  # TODO: Replace with your GitHub App's email
155
- GIT_USER_EMAIL: 97396142+npm-update-package-bot[bot]@users.noreply.github.com
162
+ GIT_USER_EMAIL: 97396142+npm-update-package[bot]@users.noreply.github.com
156
163
  # TODO: Replace with your GitHub App's user name
157
- GIT_USER_NAME: npm-update-package-bot[bot]
164
+ GIT_USER_NAME: npm-update-package[bot]
158
165
  GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
159
166
  ```
160
167
 
@@ -183,6 +190,37 @@ jobs:
183
190
  GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
184
191
  ```
185
192
 
193
+ - [Use Yarn](https://github.com/npm-update-package/example-yarn)
194
+
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]@users.noreply.github.com
219
+ # TODO: Replace with your GitHub App's user name
220
+ GIT_USER_NAME: npm-update-package[bot]
221
+ GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
222
+ ```
223
+
186
224
  ## Flow
187
225
 
188
226
  The following shows the process flow of npm-update-package.
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.2',
6
+ version: '0.26.1',
7
7
  web: 'https://github.com/npm-update-package/npm-update-package'
8
8
  };
@@ -6,18 +6,32 @@ class GitHub {
6
6
  constructor(octokit) {
7
7
  this.octokit = octokit;
8
8
  }
9
- async addLabels(params) {
10
- const { data } = await this.octokit.issues.addLabels(params);
9
+ async addLabels({ owner, repo, issueNumber, labels }) {
10
+ const { data } = await this.octokit.issues.addLabels({
11
+ owner,
12
+ repo,
13
+ issue_number: issueNumber,
14
+ labels
15
+ });
11
16
  return data;
12
17
  }
13
- async closePullRequest(params) {
18
+ async closePullRequest({ owner, repo, pullNumber }) {
14
19
  await this.octokit.pulls.update({
15
- ...params,
20
+ owner,
21
+ repo,
22
+ pull_number: pullNumber,
16
23
  state: 'closed'
17
24
  });
18
25
  }
19
- async createPullRequest(params) {
20
- const { data } = await this.octokit.pulls.create(params);
26
+ async createPullRequest({ owner, repo, baseBranch, headBranch, title, body }) {
27
+ const { data } = await this.octokit.pulls.create({
28
+ owner,
29
+ repo,
30
+ base: baseBranch,
31
+ head: headBranch,
32
+ title,
33
+ body
34
+ });
21
35
  return data;
22
36
  }
23
37
  async deleteBranch({ owner, repo, branch }) {
@@ -28,24 +42,37 @@ class GitHub {
28
42
  });
29
43
  }
30
44
  // TODO: fetch all branches with page option
31
- async fetchBranches(params) {
45
+ async fetchBranches({ owner, repo }) {
32
46
  const { data } = await this.octokit.repos.listBranches({
33
- ...params,
47
+ owner,
48
+ repo,
34
49
  per_page: 100
35
50
  });
36
51
  return data;
37
52
  }
38
53
  // TODO: fetch all pull requests with page option
39
- async fetchPullRequests(params) {
54
+ async fetchPullRequests({ owner, repo }) {
40
55
  const { data } = await this.octokit.pulls.list({
41
- ...params,
56
+ owner,
57
+ repo,
42
58
  per_page: 100
43
59
  });
44
60
  return data;
45
61
  }
46
- async fetchRepository(params) {
47
- const { data } = await this.octokit.repos.get(params);
62
+ async fetchRepository({ owner, repo }) {
63
+ const { data } = await this.octokit.repos.get({
64
+ owner,
65
+ repo
66
+ });
48
67
  return data;
49
68
  }
69
+ async requestReviewers({ owner, repo, pullNumber, reviewers }) {
70
+ await this.octokit.pulls.requestReviewers({
71
+ owner,
72
+ repo,
73
+ pull_number: pullNumber,
74
+ reviewers
75
+ });
76
+ }
50
77
  }
51
78
  exports.GitHub = GitHub;
@@ -9,7 +9,7 @@ class PullRequestCloser {
9
9
  await this.github.closePullRequest({
10
10
  owner: pullRequest.base.repo.owner.login,
11
11
  repo: pullRequest.base.repo.name,
12
- pull_number: pullRequest.number
12
+ pullNumber: pullRequest.number
13
13
  });
14
14
  await this.github.deleteBranch({
15
15
  owner: pullRequest.base.repo.owner.login,
@@ -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);
@@ -18,8 +19,8 @@ class PullRequestCreator {
18
19
  const pullRequest = await this.github.createPullRequest({
19
20
  owner: this.gitRepo.owner,
20
21
  repo: this.gitRepo.name,
21
- base: this.githubRepo.default_branch,
22
- head: branchName,
22
+ baseBranch: this.githubRepo.default_branch,
23
+ headBranch: branchName,
23
24
  title,
24
25
  body
25
26
  });
@@ -27,9 +28,17 @@ class PullRequestCreator {
27
28
  await this.github.addLabels({
28
29
  owner: this.gitRepo.owner,
29
30
  repo: this.gitRepo.name,
30
- issue_number: pullRequest.number,
31
+ issueNumber: 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.reviewers
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
+ reviewers: (0, io_ts_1.array)(io_ts_1.string)
17
+ })
18
+ ]);
14
19
  exports.isOptions = Options.is;
@@ -48,5 +48,11 @@ exports.cliOptions = [
48
48
  type: OptionType_1.OptionType.String,
49
49
  required: false,
50
50
  default: 'chore(deps): {{level}} update {{{packageName}}} to v{{newVersion}}'
51
+ },
52
+ {
53
+ name: 'reviewers',
54
+ description: 'User names to request reviews',
55
+ type: OptionType_1.OptionType.StringArray,
56
+ required: false
51
57
  }
52
58
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.24.2",
3
+ "version": "0.26.1",
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.2.0",
50
+ "lint-staged": "12.2.1",
51
51
  "npm-run-all": "4.1.5",
52
52
  "rimraf": "3.0.2",
53
53
  "ts-jest": "27.1.3",