npm-update-package 0.21.0 → 0.22.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 +6 -22
- package/dist/app.js +1 -1
- package/dist/git/BranchNameCreator.js +2 -2
- package/dist/github/CreatedPullRequest.js +2 -0
- package/dist/github/GitHub.js +19 -1
- package/dist/github/PullRequestBodyCreator.js +24 -0
- package/dist/github/PullRequestCloser.js +17 -0
- package/dist/github/PullRequestCreator.js +8 -12
- package/dist/github/PullRequestFinder.js +26 -0
- package/dist/github/PullRequestMetadata.js +15 -0
- package/dist/github/extractPullRequestMetadata.js +17 -0
- package/dist/github/index.js +5 -1
- package/dist/github/isPullRequestByNpmUpdatePackage.js +7 -0
- package/dist/main.js +12 -4
- package/dist/options/Options.js +7 -13
- package/dist/options/cliOptions.js +0 -13
- package/dist/processors/OutdatedPackageProcessor.js +11 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,20 +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 `--
|
|
18
|
-
|
|
19
|
-
### `--branch-name`
|
|
20
|
-
|
|
21
|
-
Branch name template
|
|
22
|
-
|
|
23
|
-
- type: string
|
|
24
|
-
- variables:
|
|
25
|
-
- `currentVersion`
|
|
26
|
-
- `newVersion`
|
|
27
|
-
- `packageName`
|
|
28
|
-
- `updateType`
|
|
29
|
-
- required: false
|
|
30
|
-
- default: `npm-update-package/{{{packageName}}}/v{{newVersion}}`
|
|
17
|
+
Template strings such as `--commit-message` can embed variables like `{{packageName}}`(HTML-escaped) or `{{{packageName}}}`(not HTML-escaped).
|
|
31
18
|
|
|
32
19
|
### `--commit-message`
|
|
33
20
|
|
|
@@ -73,13 +60,6 @@ Package manager of your project
|
|
|
73
60
|
- required: false
|
|
74
61
|
- default: `npm`
|
|
75
62
|
|
|
76
|
-
### `--pull-request-labels`
|
|
77
|
-
|
|
78
|
-
Pull request labels
|
|
79
|
-
|
|
80
|
-
- type: string array
|
|
81
|
-
- required: false
|
|
82
|
-
|
|
83
63
|
### `--pull-request-title`
|
|
84
64
|
|
|
85
65
|
Pull request title template
|
|
@@ -138,6 +118,9 @@ if (All packages are up-to-date) then (yes)
|
|
|
138
118
|
else (no)
|
|
139
119
|
endif
|
|
140
120
|
|
|
121
|
+
:Get remote branches;
|
|
122
|
+
:Get pull requests;
|
|
123
|
+
|
|
141
124
|
group OutdatedPackagesProcessor
|
|
142
125
|
repeat
|
|
143
126
|
group OutdatedPackageProcessor
|
|
@@ -146,6 +129,7 @@ repeat
|
|
|
146
129
|
:Create branch;
|
|
147
130
|
:Update package;
|
|
148
131
|
:Create pull request;
|
|
132
|
+
:Close old pull requests;
|
|
149
133
|
:Remove branch;
|
|
150
134
|
endif
|
|
151
135
|
end group
|
|
@@ -158,7 +142,7 @@ end
|
|
|
158
142
|
```
|
|
159
143
|
-->
|
|
160
144
|
|
|
161
|
-
[](http://www.plantuml.com/plantuml/uml/RL0nKiCm4Epl5LlQHJuGDs4ew23330yGzYRs85j2Ea7uFNPanoP38vtsLhUxTuXgWgRUohMGSt39epVT8FidAbpInYWRU5D_c3DZ9TATK3nOUuDW0f7yJjrkufRGbWEA7yPI00wDq4QY65mfuwixIPuTs3ibteCPwdQSd56Vh4NWPsBK4PiTlSm-ZhFcCRYQCReWWPv61VYNkFA0oVVhLXEyTAF8dU7LB03i7mFDxKULiJS_QImBgBR4F_wNZdMHSBQv2vUxawMlhS1rH_dEeUQC-6uxInJFlEYYlKIGbRoMKoM7yKYz_GK0)
|
|
162
146
|
|
|
163
147
|
## FAQ
|
|
164
148
|
|
package/dist/app.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BranchNameCreator = void 0;
|
|
4
4
|
const mustache_1 = require("mustache");
|
|
5
5
|
class BranchNameCreator {
|
|
6
|
-
constructor(
|
|
7
|
-
this.template =
|
|
6
|
+
constructor() {
|
|
7
|
+
this.template = 'npm-update-package/{{{packageName}}}/v{{newVersion}}';
|
|
8
8
|
}
|
|
9
9
|
create(outdatedPackage) {
|
|
10
10
|
const packageName = outdatedPackage.name;
|
package/dist/github/GitHub.js
CHANGED
|
@@ -10,12 +10,30 @@ class GitHub {
|
|
|
10
10
|
const { data } = await this.octokit.issues.addLabels(params);
|
|
11
11
|
return data;
|
|
12
12
|
}
|
|
13
|
+
async closePullRequest(params) {
|
|
14
|
+
await this.octokit.pulls.update({
|
|
15
|
+
...params,
|
|
16
|
+
state: 'closed'
|
|
17
|
+
});
|
|
18
|
+
}
|
|
13
19
|
async createPullRequest(params) {
|
|
14
20
|
const { data } = await this.octokit.pulls.create(params);
|
|
15
21
|
return data;
|
|
16
22
|
}
|
|
23
|
+
// TODO: fetch all branches with page option
|
|
17
24
|
async fetchBranches(params) {
|
|
18
|
-
const { data } = await this.octokit.repos.listBranches(
|
|
25
|
+
const { data } = await this.octokit.repos.listBranches({
|
|
26
|
+
...params,
|
|
27
|
+
per_page: 100
|
|
28
|
+
});
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
// TODO: fetch all pull requests with page option
|
|
32
|
+
async fetchPullRequests(params) {
|
|
33
|
+
const { data } = await this.octokit.pulls.list({
|
|
34
|
+
...params,
|
|
35
|
+
per_page: 100
|
|
36
|
+
});
|
|
19
37
|
return data;
|
|
20
38
|
}
|
|
21
39
|
async fetchRepository(params) {
|
|
@@ -11,6 +11,30 @@ class PullRequestBodyCreator {
|
|
|
11
11
|
|---|---|---|---|
|
|
12
12
|
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
13
13
|
|
|
14
|
+
<details>
|
|
15
|
+
<summary>Metadata</summary>
|
|
16
|
+
|
|
17
|
+
**Don't remove or edit this section because it will be used by npm-update-package.**
|
|
18
|
+
|
|
19
|
+
<div id="npm-update-package-metadata">
|
|
20
|
+
|
|
21
|
+
\`\`\`json
|
|
22
|
+
{
|
|
23
|
+
"version": "{{appVersion}}",
|
|
24
|
+
"packages": [
|
|
25
|
+
{
|
|
26
|
+
"name": "{{{packageName}}}",
|
|
27
|
+
"type": "{{updateType}}",
|
|
28
|
+
"currentVersion": "{{currentVersion}}",
|
|
29
|
+
"newVersion": "{{newVersion}}"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
\`\`\`
|
|
34
|
+
|
|
35
|
+
</div>
|
|
36
|
+
</details>
|
|
37
|
+
|
|
14
38
|
---
|
|
15
39
|
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`;
|
|
16
40
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PullRequestCloser = void 0;
|
|
4
|
+
// TODO: Add test
|
|
5
|
+
class PullRequestCloser {
|
|
6
|
+
constructor(github) {
|
|
7
|
+
this.github = github;
|
|
8
|
+
}
|
|
9
|
+
async close(pullRequest) {
|
|
10
|
+
await this.github.closePullRequest({
|
|
11
|
+
owner: pullRequest.base.repo.owner.login,
|
|
12
|
+
repo: pullRequest.base.repo.name,
|
|
13
|
+
pull_number: pullRequest.number
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PullRequestCloser = PullRequestCloser;
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PullRequestCreator = void 0;
|
|
4
4
|
class PullRequestCreator {
|
|
5
|
-
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger
|
|
5
|
+
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger }) {
|
|
6
6
|
this.github = github;
|
|
7
7
|
this.gitRepo = gitRepo;
|
|
8
8
|
this.githubRepo = githubRepo;
|
|
9
9
|
this.pullRequestTitleCreator = pullRequestTitleCreator;
|
|
10
10
|
this.pullRequestBodyCreator = pullRequestBodyCreator;
|
|
11
11
|
this.logger = logger;
|
|
12
|
-
this.labels = labels;
|
|
13
12
|
}
|
|
14
13
|
async create({ outdatedPackage, branchName }) {
|
|
15
14
|
const title = this.pullRequestTitleCreator.create(outdatedPackage);
|
|
@@ -25,16 +24,13 @@ class PullRequestCreator {
|
|
|
25
24
|
body
|
|
26
25
|
});
|
|
27
26
|
this.logger.debug(`pullRequest=${JSON.stringify(pullRequest)}`);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.logger.debug(`labels=${JSON.stringify(labels)}`);
|
|
36
|
-
}
|
|
37
|
-
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
27
|
+
await this.github.addLabels({
|
|
28
|
+
owner: this.gitRepo.owner,
|
|
29
|
+
repo: this.gitRepo.name,
|
|
30
|
+
issue_number: pullRequest.number,
|
|
31
|
+
labels: ['npm-update-package']
|
|
32
|
+
});
|
|
33
|
+
return pullRequest;
|
|
38
34
|
}
|
|
39
35
|
}
|
|
40
36
|
exports.PullRequestCreator = PullRequestCreator;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PullRequestFinder = void 0;
|
|
4
|
+
const extractPullRequestMetadata_1 = require("./extractPullRequestMetadata");
|
|
5
|
+
const isPullRequestByNpmUpdatePackage_1 = require("./isPullRequestByNpmUpdatePackage");
|
|
6
|
+
// TODO: Add test
|
|
7
|
+
class PullRequestFinder {
|
|
8
|
+
constructor(pullRequests) {
|
|
9
|
+
this.pullRequests = pullRequests;
|
|
10
|
+
}
|
|
11
|
+
findByPackageName(packageName) {
|
|
12
|
+
return this.pullRequests
|
|
13
|
+
.filter(isPullRequestByNpmUpdatePackage_1.isPullRequestByNpmUpdatePackage)
|
|
14
|
+
.filter(({ body }) => {
|
|
15
|
+
if (body === null) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const metadata = (0, extractPullRequestMetadata_1.extractPullRequestMetadata)(body);
|
|
19
|
+
if (metadata === undefined) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return metadata.packages.some(({ name }) => name === packageName);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.PullRequestFinder = PullRequestFinder;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPullRequestMetadata = void 0;
|
|
4
|
+
const io_ts_1 = require("io-ts");
|
|
5
|
+
const ncu_1 = require("../ncu");
|
|
6
|
+
const PullRequestMetadata = (0, io_ts_1.type)({
|
|
7
|
+
version: io_ts_1.string,
|
|
8
|
+
packages: (0, io_ts_1.array)((0, io_ts_1.type)({
|
|
9
|
+
name: io_ts_1.string,
|
|
10
|
+
currentVersion: io_ts_1.string,
|
|
11
|
+
newVersion: io_ts_1.string,
|
|
12
|
+
type: (0, io_ts_1.union)([(0, io_ts_1.literal)(ncu_1.UpdateType.Major), (0, io_ts_1.literal)(ncu_1.UpdateType.Minor), (0, io_ts_1.literal)(ncu_1.UpdateType.Patch)])
|
|
13
|
+
}))
|
|
14
|
+
});
|
|
15
|
+
exports.isPullRequestMetadata = PullRequestMetadata.is;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractPullRequestMetadata = void 0;
|
|
4
|
+
const PullRequestMetadata_1 = require("./PullRequestMetadata");
|
|
5
|
+
const extractPullRequestMetadata = (pullRequestBody) => {
|
|
6
|
+
const matched = pullRequestBody.match(/<div id="npm-update-package-metadata">\s*```json\s*([\s\S]+?)\s*```\s*<\/div>/);
|
|
7
|
+
const json = matched === null || matched === void 0 ? void 0 : matched[1];
|
|
8
|
+
if (json === undefined) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
const metadata = JSON.parse(json);
|
|
12
|
+
if (!(0, PullRequestMetadata_1.isPullRequestMetadata)(metadata)) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return metadata;
|
|
16
|
+
};
|
|
17
|
+
exports.extractPullRequestMetadata = extractPullRequestMetadata;
|
package/dist/github/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestCreator = exports.PullRequestBodyCreator = exports.GitHub = exports.createGitHub = void 0;
|
|
3
|
+
exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestFinder = exports.PullRequestCreator = exports.PullRequestBodyCreator = exports.PullRequestCloser = exports.GitHub = exports.createGitHub = void 0;
|
|
4
4
|
var createGitHub_1 = require("./createGitHub");
|
|
5
5
|
Object.defineProperty(exports, "createGitHub", { enumerable: true, get: function () { return createGitHub_1.createGitHub; } });
|
|
6
6
|
var GitHub_1 = require("./GitHub");
|
|
7
7
|
Object.defineProperty(exports, "GitHub", { enumerable: true, get: function () { return GitHub_1.GitHub; } });
|
|
8
|
+
var PullRequestCloser_1 = require("./PullRequestCloser");
|
|
9
|
+
Object.defineProperty(exports, "PullRequestCloser", { enumerable: true, get: function () { return PullRequestCloser_1.PullRequestCloser; } });
|
|
8
10
|
var PullRequestBodyCreator_1 = require("./PullRequestBodyCreator");
|
|
9
11
|
Object.defineProperty(exports, "PullRequestBodyCreator", { enumerable: true, get: function () { return PullRequestBodyCreator_1.PullRequestBodyCreator; } });
|
|
10
12
|
var PullRequestCreator_1 = require("./PullRequestCreator");
|
|
11
13
|
Object.defineProperty(exports, "PullRequestCreator", { enumerable: true, get: function () { return PullRequestCreator_1.PullRequestCreator; } });
|
|
14
|
+
var PullRequestFinder_1 = require("./PullRequestFinder");
|
|
15
|
+
Object.defineProperty(exports, "PullRequestFinder", { enumerable: true, get: function () { return PullRequestFinder_1.PullRequestFinder; } });
|
|
12
16
|
var PullRequestTitleCreator_1 = require("./PullRequestTitleCreator");
|
|
13
17
|
Object.defineProperty(exports, "PullRequestTitleCreator", { enumerable: true, get: function () { return PullRequestTitleCreator_1.PullRequestTitleCreator; } });
|
|
14
18
|
var RemoteBranchExistenceChecker_1 = require("./RemoteBranchExistenceChecker");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPullRequestByNpmUpdatePackage = void 0;
|
|
4
|
+
const isPullRequestByNpmUpdatePackage = (pullRequest) => {
|
|
5
|
+
return pullRequest.labels.some(({ name }) => name === 'npm-update-package');
|
|
6
|
+
};
|
|
7
|
+
exports.isPullRequestByNpmUpdatePackage = isPullRequestByNpmUpdatePackage;
|
package/dist/main.js
CHANGED
|
@@ -50,6 +50,11 @@ const main = async ({ options, logger }) => {
|
|
|
50
50
|
repo: gitRepo.name
|
|
51
51
|
});
|
|
52
52
|
logger.debug(`remoteBranches=${JSON.stringify(remoteBranches)}`);
|
|
53
|
+
const pullRequests = await github.fetchPullRequests({
|
|
54
|
+
owner: gitRepo.owner,
|
|
55
|
+
repo: gitRepo.name
|
|
56
|
+
});
|
|
57
|
+
logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
53
58
|
const remoteBranchExistenceChecker = github_1.RemoteBranchExistenceChecker.of(remoteBranches);
|
|
54
59
|
const packageManager = (0, package_manager_1.createPackageManager)({
|
|
55
60
|
terminal,
|
|
@@ -63,11 +68,12 @@ const main = async ({ options, logger }) => {
|
|
|
63
68
|
githubRepo,
|
|
64
69
|
pullRequestTitleCreator,
|
|
65
70
|
pullRequestBodyCreator,
|
|
66
|
-
logger
|
|
67
|
-
labels: options.pullRequestLabels
|
|
71
|
+
logger
|
|
68
72
|
});
|
|
69
|
-
const branchNameCreator = new git_1.BranchNameCreator(
|
|
73
|
+
const branchNameCreator = new git_1.BranchNameCreator();
|
|
70
74
|
const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
|
|
75
|
+
const pullRequestFinder = new github_1.PullRequestFinder(pullRequests);
|
|
76
|
+
const pullRequestCloser = new github_1.PullRequestCloser(github);
|
|
71
77
|
const outdatedPackageProcessor = new processors_1.OutdatedPackageProcessor({
|
|
72
78
|
git,
|
|
73
79
|
ncu,
|
|
@@ -76,7 +82,9 @@ const main = async ({ options, logger }) => {
|
|
|
76
82
|
remoteBranchExistenceChecker,
|
|
77
83
|
logger,
|
|
78
84
|
branchNameCreator,
|
|
79
|
-
commitMessageCreator
|
|
85
|
+
commitMessageCreator,
|
|
86
|
+
pullRequestFinder,
|
|
87
|
+
pullRequestCloser
|
|
80
88
|
});
|
|
81
89
|
const outdatedPackagesProcessor = new processors_1.OutdatedPackagesProcessor({
|
|
82
90
|
outdatedPackageProcessor,
|
package/dist/options/Options.js
CHANGED
|
@@ -4,17 +4,11 @@ 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.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
pullRequestTitle: io_ts_1.string
|
|
15
|
-
}),
|
|
16
|
-
(0, io_ts_1.partial)({
|
|
17
|
-
pullRequestLabels: (0, io_ts_1.array)(io_ts_1.string)
|
|
18
|
-
})
|
|
19
|
-
]);
|
|
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
|
+
});
|
|
20
14
|
exports.isOptions = Options.is;
|
|
@@ -5,13 +5,6 @@ const logger_1 = require("../logger");
|
|
|
5
5
|
const package_manager_1 = require("../package-manager");
|
|
6
6
|
const OptionType_1 = require("./OptionType");
|
|
7
7
|
exports.cliOptions = [
|
|
8
|
-
{
|
|
9
|
-
name: 'branch-name',
|
|
10
|
-
description: 'Branch name template',
|
|
11
|
-
type: OptionType_1.OptionType.String,
|
|
12
|
-
required: false,
|
|
13
|
-
default: 'npm-update-package/{{{packageName}}}/v{{newVersion}}'
|
|
14
|
-
},
|
|
15
8
|
{
|
|
16
9
|
name: 'commit-message',
|
|
17
10
|
description: 'Commit message template',
|
|
@@ -49,12 +42,6 @@ exports.cliOptions = [
|
|
|
49
42
|
],
|
|
50
43
|
default: package_manager_1.PackageManagerName.Npm
|
|
51
44
|
},
|
|
52
|
-
{
|
|
53
|
-
name: 'pull-request-labels',
|
|
54
|
-
description: 'Pull request labels',
|
|
55
|
-
type: OptionType_1.OptionType.StringArray,
|
|
56
|
-
required: false
|
|
57
|
-
},
|
|
58
45
|
{
|
|
59
46
|
name: 'pull-request-title',
|
|
60
47
|
description: 'Pull request title template',
|
|
@@ -4,7 +4,7 @@ exports.OutdatedPackageProcessor = void 0;
|
|
|
4
4
|
const Either_1 = require("fp-ts/lib/Either");
|
|
5
5
|
// TODO: add test
|
|
6
6
|
class OutdatedPackageProcessor {
|
|
7
|
-
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator }) {
|
|
7
|
+
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator, pullRequestFinder, pullRequestCloser }) {
|
|
8
8
|
this.git = git;
|
|
9
9
|
this.ncu = ncu;
|
|
10
10
|
this.packageManager = packageManager;
|
|
@@ -13,6 +13,8 @@ class OutdatedPackageProcessor {
|
|
|
13
13
|
this.logger = logger;
|
|
14
14
|
this.branchNameCreator = branchNameCreator;
|
|
15
15
|
this.commitMessageCreator = commitMessageCreator;
|
|
16
|
+
this.pullRequestFinder = pullRequestFinder;
|
|
17
|
+
this.pullRequestCloser = pullRequestCloser;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Don't run in parallel because it includes file operations.
|
|
@@ -50,10 +52,17 @@ class OutdatedPackageProcessor {
|
|
|
50
52
|
this.logger.debug(`message=${message}`);
|
|
51
53
|
await this.git.commit(message);
|
|
52
54
|
await this.git.push(branchName);
|
|
53
|
-
await this.pullRequestCreator.create({
|
|
55
|
+
const pullRequest = await this.pullRequestCreator.create({
|
|
54
56
|
outdatedPackage,
|
|
55
57
|
branchName
|
|
56
58
|
});
|
|
59
|
+
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
60
|
+
const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
|
|
61
|
+
this.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
62
|
+
await Promise.all(pullRequests.map(async (pullRequest) => {
|
|
63
|
+
await this.pullRequestCloser.close(pullRequest);
|
|
64
|
+
this.logger.info(`Pull request for ${outdatedPackage.name} has closed. ${pullRequest.html_url}`);
|
|
65
|
+
}));
|
|
57
66
|
return (0, Either_1.right)({
|
|
58
67
|
outdatedPackage,
|
|
59
68
|
updated: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "CLI tool for creating pull request to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"eslint-plugin-promise": "6.0.0",
|
|
47
47
|
"eslint-plugin-tsdoc": "0.2.14",
|
|
48
48
|
"husky": "7.0.4",
|
|
49
|
-
"jest": "27.4.
|
|
50
|
-
"lint-staged": "12.1.
|
|
49
|
+
"jest": "27.4.7",
|
|
50
|
+
"lint-staged": "12.1.7",
|
|
51
51
|
"npm-run-all": "4.1.5",
|
|
52
52
|
"rimraf": "3.0.2",
|
|
53
53
|
"ts-jest": "27.1.2",
|