npm-update-package 0.55.0 → 0.58.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.
Files changed (38) hide show
  1. package/README.md +72 -4
  2. package/dist/package.json +9 -7
  3. package/dist/src/bin.js +5 -8
  4. package/dist/src/core/Create.js +62 -0
  5. package/dist/src/core/OutdatedPackageProcessor.js +0 -74
  6. package/dist/src/core/OutdatedPackageProcessorCreator.js +48 -0
  7. package/dist/src/core/OutdatedPackagesProcessor.js +3 -3
  8. package/dist/src/core/OutdatedPullRequestStrategy.js +11 -0
  9. package/dist/src/core/Recreate.js +67 -0
  10. package/dist/src/core/Skip.js +72 -0
  11. package/dist/src/core/index.js +2 -0
  12. package/dist/src/git/GitTransaction.js +33 -0
  13. package/dist/src/git/index.js +1 -0
  14. package/dist/src/github/GitHub.js +6 -3
  15. package/dist/src/github/label/creator/LabelCreator.js +5 -5
  16. package/dist/src/github/pull-request/closer/PullRequestsCloser.js +3 -3
  17. package/dist/src/github/pull-request/creator/AssigneesAdder.js +23 -0
  18. package/dist/src/github/pull-request/creator/PullRequestCreator.js +16 -17
  19. package/dist/src/github/pull-request/creator/ReviewersAdder.js +23 -0
  20. package/dist/src/github/pull-request/creator/index.js +2 -0
  21. package/dist/src/logger/index.js +1 -2
  22. package/dist/src/logger/logger.js +5 -0
  23. package/dist/src/main.js +36 -40
  24. package/dist/src/ncu/Ncu.js +4 -4
  25. package/dist/src/options/Options.js +9 -1
  26. package/dist/src/options/cliOptions.js +25 -0
  27. package/dist/src/package-manager/PackageManagerCreator.js +10 -10
  28. package/dist/src/package-manager/index.js +2 -2
  29. package/dist/src/package-manager/{Npm.js → npm/Npm.js} +0 -0
  30. package/dist/src/package-manager/{NpmVersions.js → npm/NpmVersions.js} +0 -0
  31. package/dist/src/{number → package-manager/npm}/index.js +1 -1
  32. package/dist/src/package-manager/{Yarn.js → yarn/Yarn.js} +0 -0
  33. package/dist/src/package-manager/{YarnVersions.js → yarn/YarnVersions.js} +0 -0
  34. package/dist/src/package-manager/yarn/index.js +17 -0
  35. package/package.json +9 -7
  36. package/dist/src/logger/Logger.js +0 -2
  37. package/dist/src/logger/createLogger.js +0 -10
  38. package/dist/src/number/range.js +0 -10
package/README.md CHANGED
@@ -17,6 +17,7 @@ CLI tool for creating pull requests to update npm packages
17
17
  - [Supported platforms](#supported-platforms)
18
18
  - [Options](#options)
19
19
  - [assignees](#assignees)
20
+ - [assigneesSampleSize](#assigneessamplesize)
20
21
  - [commitMessage](#commitmessage)
21
22
  - [fetchReleaseNotes](#fetchreleasenotes)
22
23
  - [fetchSleepTime](#fetchsleeptime)
@@ -25,11 +26,13 @@ CLI tool for creating pull requests to update npm packages
25
26
  - [githubToken](#githubtoken)
26
27
  - [ignorePackages](#ignorepackages)
27
28
  - [logLevel](#loglevel)
29
+ - [outdatedPrStrategy](#outdatedprstrategy)
28
30
  - [packageManager](#packagemanager)
29
31
  - [prBodyGithubHost](#prbodygithubhost)
30
32
  - [prBodyNotes](#prbodynotes)
31
33
  - [prTitle](#prtitle)
32
34
  - [reviewers](#reviewers)
35
+ - [reviewersSampleSize](#reviewerssamplesize)
33
36
  - [GitHub token](#github-token)
34
37
  - [Examples](#examples)
35
38
  - [Use token of GitHub Actions](#use-token-of-github-actions)
@@ -80,7 +83,26 @@ Example:
80
83
  ```sh
81
84
  npx npm-update-package \
82
85
  --github-token $GITHUB_TOKEN \
83
- --assignees octocat mona
86
+ --assignees alice bob
87
+ ```
88
+
89
+ ### assigneesSampleSize
90
+
91
+ How many members to be assigned to assignees.
92
+
93
+ |Name|Value|
94
+ |---|---|
95
+ |cli|`--assignees-sample-size`|
96
+ |type|number|
97
+ |required|false|
98
+
99
+ Example:
100
+
101
+ ```sh
102
+ npx npm-update-package \
103
+ --github-token $GITHUB_TOKEN \
104
+ --assignees alice bob \
105
+ --assignees-sample-size 1
84
106
  ```
85
107
 
86
108
  ### commitMessage
@@ -165,7 +187,7 @@ Example:
165
187
  ```sh
166
188
  npx npm-update-package \
167
189
  --github-token $GITHUB_TOKEN \
168
- --git-user-email octocat@example.com
190
+ --git-user-email alice@example.com
169
191
  ```
170
192
 
171
193
  ### gitUserName
@@ -183,7 +205,7 @@ Example:
183
205
  ```sh
184
206
  npx npm-update-package \
185
207
  --github-token $GITHUB_TOKEN \
186
- --git-user-name octocat
208
+ --git-user-name alice
187
209
  ```
188
210
 
189
211
  ### githubToken
@@ -245,6 +267,33 @@ npx npm-update-package \
245
267
  --log-level debug
246
268
  ```
247
269
 
270
+ ### outdatedPrStrategy
271
+
272
+ What to do when outdated pull requests exist.
273
+
274
+ |Name|Value|
275
+ |---|---|
276
+ |cli|`--outdated-pr-strategy`|
277
+ |type|string|
278
+ |required|false|
279
+ |default|`recreate`|
280
+
281
+ Allowed values:
282
+
283
+ |Value|Description|
284
+ |---|---|
285
+ |`create`|Create new pull request.|
286
+ |`recreate`|Close old pull requests and create new pull request.|
287
+ |`skip`|Skip creating pull request.|
288
+
289
+ Example:
290
+
291
+ ```sh
292
+ npx npm-update-package \
293
+ --github-token $GITHUB_TOKEN \
294
+ --outdated-pr-strategy create
295
+ ```
296
+
248
297
  ### packageManager
249
298
 
250
299
  Package manager of your project.
@@ -352,7 +401,26 @@ Example:
352
401
  ```sh
353
402
  npx npm-update-package \
354
403
  --github-token $GITHUB_TOKEN \
355
- --reviewers octocat mona
404
+ --reviewers alice bob
405
+ ```
406
+
407
+ ### reviewersSampleSize
408
+
409
+ How many members to be assigned to reviewers.
410
+
411
+ |Name|Value|
412
+ |---|---|
413
+ |cli|`--reviewers-sample-size`|
414
+ |type|number|
415
+ |required|false|
416
+
417
+ Example:
418
+
419
+ ```sh
420
+ npx npm-update-package \
421
+ --github-token $GITHUB_TOKEN \
422
+ --reviewers alice bob \
423
+ --reviewers-sample-size 1
356
424
  ```
357
425
 
358
426
  ## GitHub token
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.55.0",
3
+ "version": "0.58.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",
@@ -20,12 +20,13 @@
20
20
  "fp-ts": "2.11.9",
21
21
  "http-status-codes": "2.2.0",
22
22
  "io-ts": "2.2.16",
23
+ "lodash": "4.14.2",
23
24
  "log4js": "6.4.4",
24
25
  "mustache": "4.1.0",
25
26
  "node-fetch": "2.6.7",
26
- "npm-check-updates": "12.5.7",
27
+ "npm-check-updates": "12.5.8",
27
28
  "parse-github-url": "1.0.2",
28
- "semver": "7.3.5",
29
+ "semver": "7.3.6",
29
30
  "sleep-promise": "9.1.0",
30
31
  "type-guards": "0.15.0"
31
32
  },
@@ -33,19 +34,20 @@
33
34
  "@jest/types": "27.4.2",
34
35
  "@tsconfig/node12": "1.0.9",
35
36
  "@types/jest": "27.4.1",
37
+ "@types/lodash": "4.14.181",
36
38
  "@types/mustache": "4.1.2",
37
39
  "@types/node": "12.20.47",
38
40
  "@types/node-fetch": "2.6.1",
39
41
  "@types/parse-github-url": "1.0.0",
40
42
  "@types/semver": "7.3.9",
41
43
  "@typescript-eslint/eslint-plugin": "5.18.0",
42
- "eslint": "8.12.0",
44
+ "eslint": "8.13.0",
43
45
  "eslint-config-standard-with-typescript": "21.0.1",
44
- "eslint-plugin-import": "2.25.4",
45
- "eslint-plugin-jest": "26.1.3",
46
+ "eslint-plugin-import": "2.26.0",
47
+ "eslint-plugin-jest": "26.1.4",
46
48
  "eslint-plugin-node": "11.1.0",
47
49
  "eslint-plugin-promise": "6.0.0",
48
- "eslint-plugin-tsdoc": "0.2.14",
50
+ "eslint-plugin-tsdoc": "0.2.16",
49
51
  "husky": "7.0.4",
50
52
  "jest": "27.4.7",
51
53
  "lint-staged": "12.3.7",
package/dist/src/bin.js CHANGED
@@ -9,16 +9,13 @@ const logger_1 = require("./logger");
9
9
  const main_1 = require("./main");
10
10
  const options_1 = require("./options");
11
11
  const options = (0, options_1.initOptions)();
12
- const logger = (0, logger_1.createLogger)(options.logLevel);
13
- logger.info(`Start ${package_json_1.default.name} v${package_json_1.default.version}`);
14
- (0, main_1.main)({
15
- options,
16
- logger
17
- })
12
+ logger_1.logger.level = options.logLevel;
13
+ logger_1.logger.info(`Start ${package_json_1.default.name} v${package_json_1.default.version}`);
14
+ (0, main_1.main)(options)
18
15
  .then(() => {
19
- logger.info(`End ${package_json_1.default.name} v${package_json_1.default.version}`);
16
+ logger_1.logger.info(`End ${package_json_1.default.name} v${package_json_1.default.version}`);
20
17
  })
21
18
  .catch((error) => {
22
- logger.fatal(error);
19
+ logger_1.logger.fatal(error);
23
20
  throw error;
24
21
  });
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Create = void 0;
4
+ const Either_1 = require("fp-ts/lib/Either");
5
+ const git_1 = require("../git");
6
+ const logger_1 = require("../logger");
7
+ // TODO: Add test
8
+ class Create {
9
+ constructor({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, packageUpdater }) {
10
+ this.git = git;
11
+ this.packageManager = packageManager;
12
+ this.pullRequestCreator = pullRequestCreator;
13
+ this.branchFinder = branchFinder;
14
+ this.commitMessageCreator = commitMessageCreator;
15
+ this.packageUpdater = packageUpdater;
16
+ }
17
+ async process(outdatedPackage) {
18
+ const branchName = (0, git_1.createBranchName)(outdatedPackage);
19
+ logger_1.logger.trace(`branchName=${branchName}`);
20
+ if (this.branchFinder.findByName(branchName) !== undefined) {
21
+ logger_1.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
22
+ return (0, Either_1.right)({
23
+ outdatedPackage,
24
+ skipped: true
25
+ });
26
+ }
27
+ const transaction = new git_1.GitTransaction({
28
+ git: this.git,
29
+ branchName,
30
+ files: [this.packageManager.packageFile, this.packageManager.lockFile]
31
+ });
32
+ return await transaction.run(async ({ git, branchName }) => {
33
+ try {
34
+ await this.packageUpdater.update(outdatedPackage);
35
+ }
36
+ catch (error) {
37
+ logger_1.logger.error(error);
38
+ return (0, Either_1.left)({
39
+ outdatedPackage,
40
+ error
41
+ });
42
+ }
43
+ logger_1.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
44
+ await git.add(this.packageManager.packageFile, this.packageManager.lockFile);
45
+ const message = this.commitMessageCreator.create(outdatedPackage);
46
+ logger_1.logger.trace(`message=${message}`);
47
+ await git.commit(message);
48
+ await git.push(branchName);
49
+ const pullRequest = await this.pullRequestCreator.create({
50
+ outdatedPackage,
51
+ branchName
52
+ });
53
+ logger_1.logger.trace(`pullRequest=${JSON.stringify(pullRequest)}`);
54
+ logger_1.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
55
+ return (0, Either_1.right)({
56
+ outdatedPackage,
57
+ created: true
58
+ });
59
+ });
60
+ }
61
+ }
62
+ exports.Create = Create;
@@ -1,76 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OutdatedPackageProcessor = void 0;
4
- const Either_1 = require("fp-ts/lib/Either");
5
- const git_1 = require("../git");
6
- // TODO: Add test
7
- // TODO: Split into multiple classes and functions
8
- class OutdatedPackageProcessor {
9
- constructor({ git, packageManager, pullRequestCreator, branchFinder, logger, commitMessageCreator, pullRequestFinder, pullRequestsCloser, packageUpdater }) {
10
- this.git = git;
11
- this.packageManager = packageManager;
12
- this.pullRequestCreator = pullRequestCreator;
13
- this.branchFinder = branchFinder;
14
- this.logger = logger;
15
- this.commitMessageCreator = commitMessageCreator;
16
- this.pullRequestFinder = pullRequestFinder;
17
- this.pullRequestsCloser = pullRequestsCloser;
18
- this.packageUpdater = packageUpdater;
19
- }
20
- /**
21
- * Don't run in parallel because it includes file operations.
22
- */
23
- async process(outdatedPackage) {
24
- const branchName = (0, git_1.createBranchName)(outdatedPackage);
25
- this.logger.debug(`branchName=${branchName}`);
26
- if (this.branchFinder.findByName(branchName) !== undefined) {
27
- this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
28
- return (0, Either_1.right)({
29
- outdatedPackage,
30
- skipped: true
31
- });
32
- }
33
- await this.git.createBranch(branchName);
34
- this.logger.info(`${branchName} branch has created.`);
35
- try {
36
- try {
37
- await this.packageUpdater.update(outdatedPackage);
38
- }
39
- catch (error) {
40
- this.logger.error(error);
41
- return (0, Either_1.left)({
42
- outdatedPackage,
43
- error
44
- });
45
- }
46
- this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
47
- await this.git.add(this.packageManager.packageFile, this.packageManager.lockFile);
48
- const message = this.commitMessageCreator.create(outdatedPackage);
49
- this.logger.debug(`message=${message}`);
50
- await this.git.commit(message);
51
- await this.git.push(branchName);
52
- const pullRequest = await this.pullRequestCreator.create({
53
- outdatedPackage,
54
- branchName
55
- });
56
- this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
57
- await this.closeOldPullRequests(outdatedPackage);
58
- return (0, Either_1.right)({
59
- outdatedPackage,
60
- created: true
61
- });
62
- }
63
- finally {
64
- await this.git.restore(this.packageManager.packageFile, this.packageManager.lockFile);
65
- await this.git.switch('-');
66
- await this.git.removeBranch(branchName);
67
- this.logger.info(`${branchName} branch has removed.`);
68
- }
69
- }
70
- async closeOldPullRequests(outdatedPackage) {
71
- const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
72
- this.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
73
- await this.pullRequestsCloser.close(pullRequests);
74
- }
75
- }
76
- exports.OutdatedPackageProcessor = OutdatedPackageProcessor;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutdatedPackageProcessorCreator = void 0;
4
+ const Create_1 = require("./Create");
5
+ const OutdatedPullRequestStrategy_1 = require("./OutdatedPullRequestStrategy");
6
+ const Recreate_1 = require("./Recreate");
7
+ const Skip_1 = require("./Skip");
8
+ // TODO: Add test
9
+ class OutdatedPackageProcessorCreator {
10
+ constructor(options) {
11
+ this.options = options;
12
+ }
13
+ create({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, pullRequestFinder, pullRequestsCloser, packageUpdater }) {
14
+ switch (this.options.outdatedPrStrategy) {
15
+ case OutdatedPullRequestStrategy_1.OutdatedPullRequestStrategy.Create:
16
+ return new Create_1.Create({
17
+ git,
18
+ packageManager,
19
+ pullRequestCreator,
20
+ branchFinder,
21
+ commitMessageCreator,
22
+ packageUpdater
23
+ });
24
+ case OutdatedPullRequestStrategy_1.OutdatedPullRequestStrategy.Recreate:
25
+ return new Recreate_1.Recreate({
26
+ git,
27
+ packageManager,
28
+ pullRequestCreator,
29
+ branchFinder,
30
+ commitMessageCreator,
31
+ pullRequestFinder,
32
+ pullRequestsCloser,
33
+ packageUpdater
34
+ });
35
+ case OutdatedPullRequestStrategy_1.OutdatedPullRequestStrategy.Skip:
36
+ return new Skip_1.Skip({
37
+ git,
38
+ packageManager,
39
+ pullRequestCreator,
40
+ branchFinder,
41
+ commitMessageCreator,
42
+ pullRequestFinder,
43
+ packageUpdater
44
+ });
45
+ }
46
+ }
47
+ }
48
+ exports.OutdatedPackageProcessorCreator = OutdatedPackageProcessorCreator;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OutdatedPackagesProcessor = void 0;
4
+ const logger_1 = require("../logger");
4
5
  class OutdatedPackagesProcessor {
5
- constructor({ outdatedPackageProcessor, logger }) {
6
+ constructor(outdatedPackageProcessor) {
6
7
  this.outdatedPackageProcessor = outdatedPackageProcessor;
7
- this.logger = logger;
8
8
  }
9
9
  async process(outdatedPackages) {
10
10
  const results = [];
11
11
  for (const outdatedPackage of outdatedPackages) {
12
- this.logger.debug(`outdatedPackage=${JSON.stringify(outdatedPackage)}`);
12
+ logger_1.logger.debug(`outdatedPackage=${JSON.stringify(outdatedPackage)}`);
13
13
  const result = await this.outdatedPackageProcessor.process(outdatedPackage);
14
14
  results.push(result);
15
15
  }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOutdatedPullRequestStrategy = exports.OutdatedPullRequestStrategy = void 0;
4
+ exports.OutdatedPullRequestStrategy = {
5
+ Create: 'create',
6
+ Recreate: 'recreate',
7
+ Skip: 'skip'
8
+ };
9
+ const outdatedPullRequestStrategies = Object.values(exports.OutdatedPullRequestStrategy);
10
+ const isOutdatedPullRequestStrategy = (value) => outdatedPullRequestStrategies.includes(value);
11
+ exports.isOutdatedPullRequestStrategy = isOutdatedPullRequestStrategy;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Recreate = void 0;
4
+ const Either_1 = require("fp-ts/lib/Either");
5
+ const git_1 = require("../git");
6
+ const logger_1 = require("../logger");
7
+ // TODO: Add test
8
+ class Recreate {
9
+ constructor({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, packageUpdater, pullRequestFinder, pullRequestsCloser }) {
10
+ this.git = git;
11
+ this.packageManager = packageManager;
12
+ this.pullRequestCreator = pullRequestCreator;
13
+ this.branchFinder = branchFinder;
14
+ this.commitMessageCreator = commitMessageCreator;
15
+ this.packageUpdater = packageUpdater;
16
+ this.pullRequestFinder = pullRequestFinder;
17
+ this.pullRequestsCloser = pullRequestsCloser;
18
+ }
19
+ async process(outdatedPackage) {
20
+ const branchName = (0, git_1.createBranchName)(outdatedPackage);
21
+ logger_1.logger.trace(`branchName=${branchName}`);
22
+ if (this.branchFinder.findByName(branchName) !== undefined) {
23
+ logger_1.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
24
+ return (0, Either_1.right)({
25
+ outdatedPackage,
26
+ skipped: true
27
+ });
28
+ }
29
+ const transaction = new git_1.GitTransaction({
30
+ git: this.git,
31
+ branchName,
32
+ files: [this.packageManager.packageFile, this.packageManager.lockFile]
33
+ });
34
+ return await transaction.run(async ({ git, branchName }) => {
35
+ try {
36
+ await this.packageUpdater.update(outdatedPackage);
37
+ }
38
+ catch (error) {
39
+ logger_1.logger.error(error);
40
+ return (0, Either_1.left)({
41
+ outdatedPackage,
42
+ error
43
+ });
44
+ }
45
+ logger_1.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
46
+ await git.add(this.packageManager.packageFile, this.packageManager.lockFile);
47
+ const message = this.commitMessageCreator.create(outdatedPackage);
48
+ logger_1.logger.trace(`message=${message}`);
49
+ await git.commit(message);
50
+ await git.push(branchName);
51
+ const pullRequest = await this.pullRequestCreator.create({
52
+ outdatedPackage,
53
+ branchName
54
+ });
55
+ logger_1.logger.trace(`pullRequest=${JSON.stringify(pullRequest)}`);
56
+ logger_1.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
57
+ const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
58
+ logger_1.logger.trace(`pullRequests=${JSON.stringify(pullRequests)}`);
59
+ await this.pullRequestsCloser.close(pullRequests);
60
+ return (0, Either_1.right)({
61
+ outdatedPackage,
62
+ created: true
63
+ });
64
+ });
65
+ }
66
+ }
67
+ exports.Recreate = Recreate;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Skip = void 0;
4
+ const Either_1 = require("fp-ts/lib/Either");
5
+ const git_1 = require("../git");
6
+ const logger_1 = require("../logger");
7
+ // TODO: Add test
8
+ class Skip {
9
+ constructor({ git, packageManager, pullRequestCreator, branchFinder, commitMessageCreator, packageUpdater, pullRequestFinder }) {
10
+ this.git = git;
11
+ this.packageManager = packageManager;
12
+ this.pullRequestCreator = pullRequestCreator;
13
+ this.branchFinder = branchFinder;
14
+ this.commitMessageCreator = commitMessageCreator;
15
+ this.packageUpdater = packageUpdater;
16
+ this.pullRequestFinder = pullRequestFinder;
17
+ }
18
+ async process(outdatedPackage) {
19
+ const branchName = (0, git_1.createBranchName)(outdatedPackage);
20
+ logger_1.logger.trace(`branchName=${branchName}`);
21
+ if (this.branchFinder.findByName(branchName) !== undefined) {
22
+ logger_1.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
23
+ return (0, Either_1.right)({
24
+ outdatedPackage,
25
+ skipped: true
26
+ });
27
+ }
28
+ const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
29
+ logger_1.logger.trace(`pullRequests=${JSON.stringify(pullRequests)}`);
30
+ if (pullRequests.length > 0) {
31
+ logger_1.logger.info(`Skip ${outdatedPackage.name} because outdated pull requests exist.`);
32
+ return (0, Either_1.right)({
33
+ outdatedPackage,
34
+ skipped: true
35
+ });
36
+ }
37
+ const transaction = new git_1.GitTransaction({
38
+ git: this.git,
39
+ branchName,
40
+ files: [this.packageManager.packageFile, this.packageManager.lockFile]
41
+ });
42
+ return await transaction.run(async ({ git, branchName }) => {
43
+ try {
44
+ await this.packageUpdater.update(outdatedPackage);
45
+ }
46
+ catch (error) {
47
+ logger_1.logger.error(error);
48
+ return (0, Either_1.left)({
49
+ outdatedPackage,
50
+ error
51
+ });
52
+ }
53
+ logger_1.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
54
+ await git.add(this.packageManager.packageFile, this.packageManager.lockFile);
55
+ const message = this.commitMessageCreator.create(outdatedPackage);
56
+ logger_1.logger.trace(`message=${message}`);
57
+ await git.commit(message);
58
+ await git.push(branchName);
59
+ const pullRequest = await this.pullRequestCreator.create({
60
+ outdatedPackage,
61
+ branchName
62
+ });
63
+ logger_1.logger.trace(`pullRequest=${JSON.stringify(pullRequest)}`);
64
+ logger_1.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
65
+ return (0, Either_1.right)({
66
+ outdatedPackage,
67
+ created: true
68
+ });
69
+ });
70
+ }
71
+ }
72
+ exports.Skip = Skip;
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./FailedResult"), exports);
18
18
  __exportStar(require("./OutdatedPackage"), exports);
19
19
  __exportStar(require("./OutdatedPackageProcessor"), exports);
20
+ __exportStar(require("./OutdatedPackageProcessorCreator"), exports);
20
21
  __exportStar(require("./OutdatedPackagesProcessor"), exports);
22
+ __exportStar(require("./OutdatedPullRequestStrategy"), exports);
21
23
  __exportStar(require("./PackageUpdater"), exports);
22
24
  __exportStar(require("./SucceededResult"), exports);
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitTransaction = void 0;
4
+ const logger_1 = require("../logger");
5
+ // TODO: Add test
6
+ class GitTransaction {
7
+ constructor({ git, branchName, files }) {
8
+ this.git = git;
9
+ this.branchName = branchName;
10
+ this.files = files;
11
+ }
12
+ async run(operation) {
13
+ await this.git.createBranch(this.branchName);
14
+ logger_1.logger.info(`${this.branchName} branch has created.`);
15
+ try {
16
+ return await operation({
17
+ git: this.git,
18
+ branchName: this.branchName,
19
+ files: this.files
20
+ });
21
+ }
22
+ finally {
23
+ await this.rollback();
24
+ }
25
+ }
26
+ async rollback() {
27
+ await this.git.restore(...this.files);
28
+ await this.git.switch('-');
29
+ await this.git.removeBranch(this.branchName);
30
+ logger_1.logger.info(`${this.branchName} branch has removed.`);
31
+ }
32
+ }
33
+ exports.GitTransaction = GitTransaction;
@@ -19,3 +19,4 @@ __exportStar(require("./createBranchName"), exports);
19
19
  __exportStar(require("./Git"), exports);
20
20
  __exportStar(require("./GitConfigInitializer"), exports);
21
21
  __exportStar(require("./GitRepository"), exports);
22
+ __exportStar(require("./GitTransaction"), exports);
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.GitHub = void 0;
4
- const number_1 = require("../number");
7
+ const range_1 = __importDefault(require("lodash/range"));
5
8
  class GitHub {
6
9
  constructor(octokit) {
7
10
  this.octokit = octokit;
@@ -59,7 +62,7 @@ class GitHub {
59
62
  }
60
63
  async fetchBranches({ owner, repo }) {
61
64
  const branches = [];
62
- for (const page of (0, number_1.range)(1, 11)) {
65
+ for (const page of (0, range_1.default)(1, 11)) {
63
66
  const { data } = await this.octokit.repos.listBranches({
64
67
  owner,
65
68
  repo,
@@ -83,7 +86,7 @@ class GitHub {
83
86
  }
84
87
  async fetchPullRequests({ owner, repo }) {
85
88
  const pullRequests = [];
86
- for (const page of (0, number_1.range)(1, 11)) {
89
+ for (const page of (0, range_1.default)(1, 11)) {
87
90
  const { data } = await this.octokit.pulls.list({
88
91
  owner,
89
92
  repo,