npm-update-package 0.25.0 → 0.28.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 TS Examples
3
+ Copyright (c) 2020 TS Templates
4
4
  Copyright (c) 2021 npm-update-package
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
package/README.md CHANGED
@@ -44,9 +44,10 @@ Log level to show
44
44
  - required: false
45
45
  - allowed values
46
46
  - `off`: Do not output any logs.
47
- - `error`: Output error logs.
48
- - `info`: Output error/info logs.
49
- - `debug`: Output error/info/debug logs.
47
+ - `fatal`: Output fatal logs.
48
+ - `error`: Output fatal/error logs.
49
+ - `info`: Output fatal/error/info logs.
50
+ - `debug`: Output fatal/error/info/debug logs.
50
51
  - default: `info`
51
52
 
52
53
  ### `--package-manager`
@@ -60,13 +61,6 @@ Package manager of your project
60
61
  - `yarn`: Yarn
61
62
  - default: `npm`
62
63
 
63
- ### `--pull-request-reviewers`
64
-
65
- Reviewers of pull request
66
-
67
- - type: string[]
68
- - required: false
69
-
70
64
  ### `--pull-request-title`
71
65
 
72
66
  Pull request title template
@@ -80,6 +74,13 @@ Pull request title template
80
74
  - `level`: semver level (major/minor/patch)
81
75
  - default: `chore(deps): {{level}} update {{{packageName}}} to v{{newVersion}}`
82
76
 
77
+ ### `--reviewers`
78
+
79
+ User names to request reviews
80
+
81
+ - type: string[]
82
+ - required: false
83
+
83
84
  ## GitHub token
84
85
 
85
86
  GitHub token is required to run npm-update-package.
@@ -159,9 +160,9 @@ jobs:
159
160
  npx npm-update-package --github-token $GITHUB_TOKEN
160
161
  env:
161
162
  # TODO: Replace with your GitHub App's email
162
- GIT_USER_EMAIL: 97396142+npm-update-package-bot[bot]@users.noreply.github.com
163
+ GIT_USER_EMAIL: 97396142+npm-update-package[bot]@users.noreply.github.com
163
164
  # TODO: Replace with your GitHub App's user name
164
- GIT_USER_NAME: npm-update-package-bot[bot]
165
+ GIT_USER_NAME: npm-update-package[bot]
165
166
  GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
166
167
  ```
167
168
 
@@ -215,9 +216,9 @@ jobs:
215
216
  npx npm-update-package --github-token $GITHUB_TOKEN --package-manager yarn
216
217
  env:
217
218
  # TODO: Replace with your GitHub App's email
218
- GIT_USER_EMAIL: 97396142+npm-update-package-bot[bot]@users.noreply.github.com
219
+ GIT_USER_EMAIL: 97396142+npm-update-package[bot]@users.noreply.github.com
219
220
  # TODO: Replace with your GitHub App's user name
220
- GIT_USER_NAME: npm-update-package-bot[bot]
221
+ GIT_USER_NAME: npm-update-package[bot]
221
222
  GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
222
223
  ```
223
224
 
@@ -237,8 +238,9 @@ if (All packages are up-to-date) then (yes)
237
238
  else (no)
238
239
  endif
239
240
 
240
- :Get remote branches;
241
- :Get pull requests;
241
+ :Fetch remote branches;
242
+ :Fetch pull requests;
243
+ :Create label;
242
244
 
243
245
  group OutdatedPackagesProcessor
244
246
  while (Package exists) is (yes)
@@ -262,7 +264,7 @@ end
262
264
  ```
263
265
  -->
264
266
 
265
- [![](http://www.plantuml.com/plantuml/svg/RL0vSiCm3EpnYYsbmX-m6cTIf8mdCta08y4M9n39yCZn-uYYJ4kPD3omm1uuXQXyJ9FGyg2hjybXKjhGyOaZR8g3YZp0gVvTNJbqHFg2va6abg0y8xb3j8VSsoAERD3yS6W9O3CGIs0qnhOq__I52hVdoKR6crUc7sVcKdL919u_4eUOrOgZvzN7UTKyUzjp2DRJrwY5qQm0-5lFSorqg0x-PRWJ03dGozPCPTadgIa0uFZeMTM9hjHUNTQuRQRRDkw2tH2nWM5b-9EweDdIvrPWMLwvIwYypf9_iKLtW7OzT9gFDCal)](http://www.plantuml.com/plantuml/uml/RL0vSiCm3EpnYYsbmX-m6cTIf8mdCta08y4M9n39yCZn-uYYJ4kPD3omm1uuXQXyJ9FGyg2hjybXKjhGyOaZR8g3YZp0gVvTNJbqHFg2va6abg0y8xb3j8VSsoAERD3yS6W9O3CGIs0qnhOq__I52hVdoKR6crUc7sVcKdL919u_4eUOrOgZvzN7UTKyUzjp2DRJrwY5qQm0-5lFSorqg0x-PRWJ03dGozPCPTadgIa0uFZeMTM9hjHUNTQuRQRRDkw2tH2nWM5b-9EweDdIvrPWMLwvIwYypf9_iKLtW7OzT9gFDCal)
267
+ [![](http://www.plantuml.com/plantuml/svg/RP3DReCm48Jl-nHpX4DU85nILMgFZIhr0HpO1AiBTkrrVzw-E3W4f5pusLcFlvb3L1Cq3KBN3xe4bpm6OqVQlxB29UsCSWTlsazpuTWGsJEg9v5b11COoU_KxV9k3UrvHFN7iIQ0nuvO8gCQNKtJdpqJxLzOsnw11wUCKp1ZssVlClT9P1A_4aVDq-V0HXbYJYmD5SYtWdOi6CVWMexH1VhfhJ2g8e1_xMHJmyO5wg73tG386T_NT8lBDjmI300APpdHpBCFd--ubTLi5jSvRuguo73IRKieQaRwNbymztbzpw5omoL_ngAxG9iTEaoFDCW_)](http://www.plantuml.com/plantuml/uml/RP3DReCm48Jl-nHpX4DU85nILMgFZIhr0HpO1AiBTkrrVzw-E3W4f5pusLcFlvb3L1Cq3KBN3xe4bpm6OqVQlxB29UsCSWTlsazpuTWGsJEg9v5b11COoU_KxV9k3UrvHFN7iIQ0nuvO8gCQNKtJdpqJxLzOsnw11wUCKp1ZssVlClT9P1A_4aVDq-V0HXbYJYmD5SYtWdOi6CVWMexH1VhfhJ2g8e1_xMHJmyO5wg73tG386T_NT8lBDjmI300APpdHpBCFd--ubTLi5jSvRuguo73IRKieQaRwNbymztbzpw5omoL_ngAxG9iTEaoFDCW_)
266
268
 
267
269
  ## FAQ
268
270
 
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.25.0',
6
+ version: '0.28.0',
7
7
  web: 'https://github.com/npm-update-package/npm-update-package'
8
8
  };
@@ -6,18 +6,40 @@ 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);
11
- return data;
9
+ async addLabels({ owner, repo, issueNumber, labels }) {
10
+ await this.octokit.issues.addLabels({
11
+ owner,
12
+ repo,
13
+ issue_number: issueNumber,
14
+ labels
15
+ });
12
16
  }
13
- async closePullRequest(params) {
17
+ async closePullRequest({ owner, repo, pullNumber }) {
14
18
  await this.octokit.pulls.update({
15
- ...params,
19
+ owner,
20
+ repo,
21
+ pull_number: pullNumber,
16
22
  state: 'closed'
17
23
  });
18
24
  }
19
- async createPullRequest(params) {
20
- const { data } = await this.octokit.pulls.create(params);
25
+ async createLabel({ owner, repo, name, description, color }) {
26
+ await this.octokit.issues.createLabel({
27
+ owner,
28
+ repo,
29
+ name,
30
+ description,
31
+ color
32
+ });
33
+ }
34
+ async createPullRequest({ owner, repo, baseBranch, headBranch, title, body }) {
35
+ const { data } = await this.octokit.pulls.create({
36
+ owner,
37
+ repo,
38
+ base: baseBranch,
39
+ head: headBranch,
40
+ title,
41
+ body
42
+ });
21
43
  return data;
22
44
  }
23
45
  async deleteBranch({ owner, repo, branch }) {
@@ -28,23 +50,36 @@ class GitHub {
28
50
  });
29
51
  }
30
52
  // TODO: fetch all branches with page option
31
- async fetchBranches(params) {
53
+ async fetchBranches({ owner, repo }) {
32
54
  const { data } = await this.octokit.repos.listBranches({
33
- ...params,
55
+ owner,
56
+ repo,
34
57
  per_page: 100
35
58
  });
36
59
  return data;
37
60
  }
61
+ async fetchLabel({ owner, repo, name }) {
62
+ const { data } = await this.octokit.issues.getLabel({
63
+ owner,
64
+ repo,
65
+ name
66
+ });
67
+ return data;
68
+ }
38
69
  // TODO: fetch all pull requests with page option
39
- async fetchPullRequests(params) {
70
+ async fetchPullRequests({ owner, repo }) {
40
71
  const { data } = await this.octokit.pulls.list({
41
- ...params,
72
+ owner,
73
+ repo,
42
74
  per_page: 100
43
75
  });
44
76
  return data;
45
77
  }
46
- async fetchRepository(params) {
47
- const { data } = await this.octokit.repos.get(params);
78
+ async fetchRepository({ owner, repo }) {
79
+ const { data } = await this.octokit.repos.get({
80
+ owner,
81
+ repo
82
+ });
48
83
  return data;
49
84
  }
50
85
  async requestReviewers({ owner, repo, pullNumber, reviewers }) {
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNotFoundError = void 0;
4
+ const request_error_1 = require("@octokit/request-error");
5
+ const http_status_codes_1 = require("http-status-codes");
6
+ // TODO: Add test
7
+ const isNotFoundError = (value) => {
8
+ return value instanceof request_error_1.RequestError && value.status === http_status_codes_1.StatusCodes.NOT_FOUND;
9
+ };
10
+ exports.isNotFoundError = isNotFoundError;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./NotFoundError"), exports);
@@ -12,4 +12,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./branch"), exports);
14
14
  __exportStar(require("./createGitHub"), exports);
15
+ __exportStar(require("./errors"), exports);
16
+ __exportStar(require("./label"), exports);
15
17
  __exportStar(require("./pull-request"), exports);
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LabelCreator = void 0;
4
+ const errors_1 = require("../../errors");
5
+ // TODO: Add test
6
+ class LabelCreator {
7
+ constructor({ github, gitRepo, logger }) {
8
+ this.github = github;
9
+ this.gitRepo = gitRepo;
10
+ this.logger = logger;
11
+ }
12
+ async create({ name, description, color }) {
13
+ try {
14
+ await this.github.fetchLabel({
15
+ owner: this.gitRepo.owner,
16
+ repo: this.gitRepo.name,
17
+ name
18
+ });
19
+ }
20
+ catch (e) {
21
+ if ((0, errors_1.isNotFoundError)(e)) {
22
+ await this.github.createLabel({
23
+ owner: this.gitRepo.owner,
24
+ repo: this.gitRepo.name,
25
+ name,
26
+ description,
27
+ color
28
+ });
29
+ this.logger.info(`${name} label has created.`);
30
+ }
31
+ else {
32
+ throw e;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ exports.LabelCreator = LabelCreator;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./LabelCreator"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./creator"), exports);
@@ -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,
@@ -19,8 +19,8 @@ class PullRequestCreator {
19
19
  const pullRequest = await this.github.createPullRequest({
20
20
  owner: this.gitRepo.owner,
21
21
  repo: this.gitRepo.name,
22
- base: this.githubRepo.default_branch,
23
- head: branchName,
22
+ baseBranch: this.githubRepo.default_branch,
23
+ headBranch: branchName,
24
24
  title,
25
25
  body
26
26
  });
@@ -28,7 +28,7 @@ class PullRequestCreator {
28
28
  await this.github.addLabels({
29
29
  owner: this.gitRepo.owner,
30
30
  repo: this.gitRepo.name,
31
- issue_number: pullRequest.number,
31
+ issueNumber: pullRequest.number,
32
32
  labels: ['npm-update-package']
33
33
  });
34
34
  if (this.reviewers !== undefined) {
@@ -4,6 +4,7 @@ exports.isLogLevel = exports.LogLevel = void 0;
4
4
  exports.LogLevel = {
5
5
  Debug: 'debug',
6
6
  Error: 'error',
7
+ Fatal: 'fatal',
7
8
  Info: 'info',
8
9
  Off: 'off'
9
10
  };
package/dist/main.js CHANGED
@@ -45,6 +45,16 @@ const main = async ({ options, logger }) => {
45
45
  repo: gitRepo.name
46
46
  });
47
47
  logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
48
+ const labelCreator = new github_1.LabelCreator({
49
+ github,
50
+ gitRepo,
51
+ logger
52
+ });
53
+ await labelCreator.create({
54
+ name: 'npm-update-package',
55
+ description: 'Created by npm-update-package',
56
+ color: 'A00F21'
57
+ });
48
58
  const branchFinder = new github_1.BranchFinder(branches);
49
59
  const packageManager = (0, package_manager_1.createPackageManager)({
50
60
  terminal,
@@ -57,7 +67,7 @@ const main = async ({ options, logger }) => {
57
67
  githubRepo,
58
68
  pullRequestTitleCreator,
59
69
  logger,
60
- reviewers: options.pullRequestReviewers
70
+ reviewers: options.reviewers
61
71
  });
62
72
  const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
63
73
  const pullRequestFinder = new github_1.PullRequestFinder(pullRequests);
@@ -8,12 +8,12 @@ const Options = (0, io_ts_1.intersection)([
8
8
  (0, io_ts_1.type)({
9
9
  commitMessage: io_ts_1.string,
10
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)]),
11
+ logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Off), (0, io_ts_1.literal)(logger_1.LogLevel.Fatal), (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
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
13
  pullRequestTitle: io_ts_1.string
14
14
  }),
15
15
  (0, io_ts_1.partial)({
16
- pullRequestReviewers: (0, io_ts_1.array)(io_ts_1.string)
16
+ reviewers: (0, io_ts_1.array)(io_ts_1.string)
17
17
  })
18
18
  ]);
19
19
  exports.isOptions = Options.is;
@@ -25,6 +25,7 @@ exports.cliOptions = [
25
25
  required: false,
26
26
  choices: [
27
27
  logger_1.LogLevel.Off,
28
+ logger_1.LogLevel.Fatal,
28
29
  logger_1.LogLevel.Error,
29
30
  logger_1.LogLevel.Info,
30
31
  logger_1.LogLevel.Debug
@@ -42,17 +43,17 @@ exports.cliOptions = [
42
43
  ],
43
44
  default: package_manager_1.PackageManagerName.Npm
44
45
  },
45
- {
46
- name: 'pull-request-reviewers',
47
- description: 'Reviewers of pull request',
48
- type: OptionType_1.OptionType.StringArray,
49
- required: false
50
- },
51
46
  {
52
47
  name: 'pull-request-title',
53
48
  description: 'Pull request title template',
54
49
  type: OptionType_1.OptionType.String,
55
50
  required: false,
56
51
  default: 'chore(deps): {{level}} update {{{packageName}}} to v{{newVersion}}'
52
+ },
53
+ {
54
+ name: 'reviewers',
55
+ description: 'User names to request reviews',
56
+ type: OptionType_1.OptionType.StringArray,
57
+ required: false
57
58
  }
58
59
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.25.0",
3
+ "version": "0.28.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",
@@ -21,10 +21,11 @@
21
21
  "commander": "8.3.0",
22
22
  "execa": "5.1.1",
23
23
  "fp-ts": "2.11.8",
24
+ "http-status-codes": "2.2.0",
24
25
  "io-ts": "2.2.16",
25
- "log4js": "6.3.0",
26
+ "log4js": "6.4.0",
26
27
  "mustache": "4.1.0",
27
- "npm-check-updates": "12.1.0",
28
+ "npm-check-updates": "12.2.0",
28
29
  "parse-github-url": "1.0.2",
29
30
  "semver": "7.3.5",
30
31
  "type-guards": "0.15.0"
@@ -47,12 +48,12 @@
47
48
  "eslint-plugin-tsdoc": "0.2.14",
48
49
  "husky": "7.0.4",
49
50
  "jest": "27.4.7",
50
- "lint-staged": "12.2.0",
51
+ "lint-staged": "12.2.2",
51
52
  "npm-run-all": "4.1.5",
52
53
  "rimraf": "3.0.2",
53
54
  "ts-jest": "27.1.3",
54
55
  "ts-node": "10.4.0",
55
- "typescript": "4.5.4",
56
+ "typescript": "4.5.5",
56
57
  "utility-types": "3.10.0"
57
58
  },
58
59
  "repository": {