npm-update-package 0.20.1 → 0.22.2
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 +74 -55
- package/dist/app.js +1 -1
- package/dist/git/createBranchName.js +18 -0
- package/dist/git/index.js +3 -3
- package/dist/github/CreatedPullRequest.js +2 -0
- package/dist/github/GitHub.js +19 -1
- package/dist/github/PullRequestCloser.js +17 -0
- package/dist/github/PullRequestCreator.js +10 -14
- package/dist/github/PullRequestFinder.js +26 -0
- package/dist/github/PullRequestMetadata.js +15 -0
- package/dist/github/createPullRequestBody.js +56 -0
- package/dist/github/extractPullRequestMetadata.js +17 -0
- package/dist/github/index.js +5 -3
- package/dist/github/isPullRequestByNpmUpdatePackage.js +7 -0
- package/dist/main.js +11 -7
- package/dist/options/Options.js +7 -14
- package/dist/options/cliOptions.js +0 -27
- package/dist/processors/OutdatedPackageProcessor.js +13 -4
- package/package.json +7 -7
- package/dist/git/BranchNameCreator.js +0 -22
- package/dist/github/PullRequestBodyCreator.js +0 -29
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# npm-update-package
|
|
5
5
|
|
|
6
|
-
CLI tool for creating pull
|
|
6
|
+
CLI tool for creating pull requests to update npm packages
|
|
7
7
|
|
|
8
8
|
## Usage
|
|
9
9
|
|
|
@@ -14,37 +14,25 @@ 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
|
|
|
34
21
|
Commit message template
|
|
35
22
|
|
|
36
23
|
- type: string
|
|
24
|
+
- required: false
|
|
37
25
|
- variables:
|
|
38
26
|
- `currentVersion`
|
|
39
27
|
- `newVersion`
|
|
40
28
|
- `packageName`
|
|
41
29
|
- `updateType`
|
|
42
|
-
- required: false
|
|
43
30
|
- default: `chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`
|
|
44
31
|
|
|
45
32
|
### `--github-token`
|
|
46
33
|
|
|
47
|
-
GitHub token
|
|
34
|
+
GitHub token.
|
|
35
|
+
See more in [GitHub token](#github-token) section.
|
|
48
36
|
|
|
49
37
|
- type: string
|
|
50
38
|
- required: true
|
|
@@ -54,12 +42,12 @@ GitHub token
|
|
|
54
42
|
Log level to show
|
|
55
43
|
|
|
56
44
|
- type: string
|
|
45
|
+
- required: false
|
|
57
46
|
- allowed values:
|
|
58
47
|
- `off`: Do not output any logs.
|
|
59
48
|
- `error`: Output error logs.
|
|
60
49
|
- `info`: Output error/info logs.
|
|
61
50
|
- `debug`: Output error/info/debug logs.
|
|
62
|
-
- required: false
|
|
63
51
|
- default: `info`
|
|
64
52
|
|
|
65
53
|
### `--package-manager`
|
|
@@ -67,62 +55,53 @@ Log level to show
|
|
|
67
55
|
Package manager of your project
|
|
68
56
|
|
|
69
57
|
- type: string
|
|
58
|
+
- required: false
|
|
70
59
|
- allowed values:
|
|
71
60
|
- `npm`
|
|
72
61
|
- `yarn`
|
|
73
|
-
- required: false
|
|
74
62
|
- default: `npm`
|
|
75
63
|
|
|
76
|
-
### `--pull-request-
|
|
64
|
+
### `--pull-request-title`
|
|
77
65
|
|
|
78
|
-
Pull request
|
|
66
|
+
Pull request title template
|
|
79
67
|
|
|
80
68
|
- type: string
|
|
69
|
+
- required: false
|
|
81
70
|
- variables:
|
|
82
|
-
- `appName`
|
|
83
|
-
- `appVersion`
|
|
84
|
-
- `appWeb`
|
|
85
71
|
- `currentVersion`
|
|
86
72
|
- `newVersion`
|
|
87
73
|
- `packageName`
|
|
88
74
|
- `updateType`
|
|
89
|
-
-
|
|
90
|
-
- default:
|
|
75
|
+
- default: `chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`
|
|
91
76
|
|
|
92
|
-
|
|
93
|
-
This PR updates these packages:
|
|
77
|
+
## GitHub token
|
|
94
78
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
79
|
+
To run npm-update-package, GitHub token is required.
|
|
80
|
+
For example, the following tokens can be used.
|
|
98
81
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
82
|
+
|GitHub token|Pull request author|Trigger other action|
|
|
83
|
+
|---|---|---|
|
|
84
|
+
|[GitHub Actions](https://docs.github.com/en/actions/security-guides/automatic-token-authentication)|`github-actions`||
|
|
85
|
+
|[GitHub App](https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps)|GitHub App which issued the token|✓|
|
|
86
|
+
|[Personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)|user who issued the token|✓|
|
|
102
87
|
|
|
103
|
-
###
|
|
88
|
+
### Token of GitHub App
|
|
104
89
|
|
|
105
|
-
|
|
90
|
+
These permissions are required.
|
|
106
91
|
|
|
107
|
-
-
|
|
108
|
-
-
|
|
92
|
+
- Contents: Read-only
|
|
93
|
+
- Metadata: Read-only
|
|
94
|
+
- Pull requests: Read & write
|
|
109
95
|
|
|
110
|
-
###
|
|
96
|
+
### Personal access token
|
|
111
97
|
|
|
112
|
-
|
|
98
|
+
These permissions are required.
|
|
113
99
|
|
|
114
|
-
-
|
|
115
|
-
- variables:
|
|
116
|
-
- `currentVersion`
|
|
117
|
-
- `newVersion`
|
|
118
|
-
- `packageName`
|
|
119
|
-
- `updateType`
|
|
120
|
-
- required: false
|
|
121
|
-
- default: `chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`
|
|
100
|
+
- repo
|
|
122
101
|
|
|
123
102
|
## Examples
|
|
124
103
|
|
|
125
|
-
|
|
104
|
+
- Use token of GitHub Actions
|
|
126
105
|
|
|
127
106
|
```yaml
|
|
128
107
|
name: npm-update-package
|
|
@@ -145,9 +124,44 @@ jobs:
|
|
|
145
124
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
146
125
|
```
|
|
147
126
|
|
|
127
|
+
|
|
128
|
+
- Use token of GitHub App
|
|
129
|
+
|
|
130
|
+
```yaml
|
|
131
|
+
name: npm-update-package
|
|
132
|
+
on:
|
|
133
|
+
schedule:
|
|
134
|
+
- cron: '0 0 * * *'
|
|
135
|
+
jobs:
|
|
136
|
+
npm-update-package:
|
|
137
|
+
runs-on: ubuntu-latest
|
|
138
|
+
steps:
|
|
139
|
+
- uses: actions/checkout@v2
|
|
140
|
+
- uses: actions/setup-node@v2
|
|
141
|
+
- name: Generate token
|
|
142
|
+
id: generate_token
|
|
143
|
+
uses: tibdex/github-app-token@v1
|
|
144
|
+
with:
|
|
145
|
+
app_id: ${{ secrets.APP_ID }}
|
|
146
|
+
private_key: ${{ secrets.PRIVATE_KEY }}
|
|
147
|
+
- run: |
|
|
148
|
+
git config user.name $GIT_USER_NAME
|
|
149
|
+
git config user.email $GIT_USER_EMAIL
|
|
150
|
+
npx npm-update-package --github-token $GITHUB_TOKEN
|
|
151
|
+
env:
|
|
152
|
+
# TODO: Replace with your GitHub App's email
|
|
153
|
+
GIT_USER_EMAIL: 97396142+npm-update-package-bot[bot]@users.noreply.github.com
|
|
154
|
+
# TODO: Replace with your GitHub App's user name
|
|
155
|
+
GIT_USER_NAME: npm-update-package-bot[bot]
|
|
156
|
+
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
|
|
157
|
+
```
|
|
158
|
+
|
|
148
159
|
Actual working examples can be seen in these repositories.
|
|
149
160
|
|
|
150
|
-
|
|
161
|
+
|Repository|Package manager|GitHub token|
|
|
162
|
+
|---|---|---|
|
|
163
|
+
|[example-npm](https://github.com/npm-update-package/example-npm)|npm|GitHub Actions|
|
|
164
|
+
|[example-github-app](https://github.com/npm-update-package/example-github-app)|npm|GitHub App|
|
|
151
165
|
|
|
152
166
|
## Flow
|
|
153
167
|
|
|
@@ -165,18 +179,23 @@ if (All packages are up-to-date) then (yes)
|
|
|
165
179
|
else (no)
|
|
166
180
|
endif
|
|
167
181
|
|
|
182
|
+
:Get remote branches;
|
|
183
|
+
:Get pull requests;
|
|
184
|
+
|
|
168
185
|
group OutdatedPackagesProcessor
|
|
169
|
-
|
|
186
|
+
while (Package exists) is (yes)
|
|
170
187
|
group OutdatedPackageProcessor
|
|
171
188
|
if (Remote branch exists) then (yes)
|
|
172
189
|
else (no)
|
|
173
190
|
:Create branch;
|
|
174
191
|
:Update package;
|
|
175
192
|
:Create pull request;
|
|
193
|
+
:Close old pull requests;
|
|
176
194
|
:Remove branch;
|
|
177
195
|
endif
|
|
178
196
|
end group
|
|
179
|
-
|
|
197
|
+
endwhile (no)
|
|
198
|
+
|
|
180
199
|
end group
|
|
181
200
|
|
|
182
201
|
end group
|
|
@@ -185,7 +204,7 @@ end
|
|
|
185
204
|
```
|
|
186
205
|
-->
|
|
187
206
|
|
|
188
|
-
[](http://www.plantuml.com/plantuml/uml/RL0vSiCm3EpnYYsbmX-m6cTIf8mdCta08y4M9n39yCZn-uYYJ4kPD3omm1uuXQXyJ9FGyg2hjybXKjhGyOaZR8g3YZp0gVvTNJbqHFg2va6abg0y8xb3j8VSsoAERD3yS6W9O3CGIs0qnhOq__I52hVdoKR6crUc7sVcKdL919u_4eUOrOgZvzN7UTKyUzjp2DRJrwY5qQm0-5lFSorqg0x-PRWJ03dGozPCPTadgIa0uFZeMTM9hjHUNTQuRQRRDkw2tH2nWM5b-9EweDdIvrPWMLwvIwYypf9_iKLtW7OzT9gFDCal)
|
|
189
208
|
|
|
190
209
|
## FAQ
|
|
191
210
|
|
|
@@ -193,6 +212,6 @@ end
|
|
|
193
212
|
|
|
194
213
|
npm-update-package can be used in environments where Renovate cannot be used for some reason.
|
|
195
214
|
|
|
196
|
-
### Conflicts have occurred in
|
|
215
|
+
### Conflicts have occurred in pull request. What should I do?
|
|
197
216
|
|
|
198
|
-
If conflicts have occurred in
|
|
217
|
+
If conflicts have occurred in pull request, close it and run npm-update-package again.
|
package/dist/app.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBranchName = void 0;
|
|
4
|
+
const mustache_1 = require("mustache");
|
|
5
|
+
const TEMPLATE = 'npm-update-package/{{{packageName}}}/v{{newVersion}}';
|
|
6
|
+
const createBranchName = (outdatedPackage) => {
|
|
7
|
+
const packageName = outdatedPackage.name;
|
|
8
|
+
const currentVersion = outdatedPackage.currentVersion.version;
|
|
9
|
+
const newVersion = outdatedPackage.newVersion.version;
|
|
10
|
+
const updateType = outdatedPackage.type;
|
|
11
|
+
return (0, mustache_1.render)(TEMPLATE, {
|
|
12
|
+
packageName,
|
|
13
|
+
currentVersion,
|
|
14
|
+
newVersion,
|
|
15
|
+
updateType
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.createBranchName = createBranchName;
|
package/dist/git/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GitRepository = exports.Git = exports.CommitMessageCreator = exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.GitRepository = exports.Git = exports.CommitMessageCreator = exports.createBranchName = void 0;
|
|
4
|
+
var createBranchName_1 = require("./createBranchName");
|
|
5
|
+
Object.defineProperty(exports, "createBranchName", { enumerable: true, get: function () { return createBranchName_1.createBranchName; } });
|
|
6
6
|
var CommitMessageCreator_1 = require("./CommitMessageCreator");
|
|
7
7
|
Object.defineProperty(exports, "CommitMessageCreator", { enumerable: true, get: function () { return CommitMessageCreator_1.CommitMessageCreator; } });
|
|
8
8
|
var Git_1 = require("./Git");
|
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) {
|
|
@@ -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;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PullRequestCreator = void 0;
|
|
4
|
+
const createPullRequestBody_1 = require("./createPullRequestBody");
|
|
4
5
|
class PullRequestCreator {
|
|
5
|
-
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator,
|
|
6
|
+
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, logger }) {
|
|
6
7
|
this.github = github;
|
|
7
8
|
this.gitRepo = gitRepo;
|
|
8
9
|
this.githubRepo = githubRepo;
|
|
9
10
|
this.pullRequestTitleCreator = pullRequestTitleCreator;
|
|
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);
|
|
16
15
|
this.logger.debug(`title=${title}`);
|
|
17
|
-
const body =
|
|
16
|
+
const body = (0, createPullRequestBody_1.createPullRequestBody)(outdatedPackage);
|
|
18
17
|
this.logger.debug(`body=${body}`);
|
|
19
18
|
const pullRequest = await this.github.createPullRequest({
|
|
20
19
|
owner: this.gitRepo.owner,
|
|
@@ -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,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPullRequestBody = void 0;
|
|
4
|
+
const mustache_1 = require("mustache");
|
|
5
|
+
const app_1 = require("../app");
|
|
6
|
+
const TEMPLATE = `This PR updates these packages:
|
|
7
|
+
|
|
8
|
+
|package|type|current version|new version|
|
|
9
|
+
|---|---|---|---|
|
|
10
|
+
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
11
|
+
|
|
12
|
+
<details>
|
|
13
|
+
<summary>Metadata</summary>
|
|
14
|
+
|
|
15
|
+
**Don't remove or edit this section because it will be used by npm-update-package.**
|
|
16
|
+
|
|
17
|
+
<div id="npm-update-package-metadata">
|
|
18
|
+
|
|
19
|
+
\`\`\`json
|
|
20
|
+
{
|
|
21
|
+
"version": "{{appVersion}}",
|
|
22
|
+
"packages": [
|
|
23
|
+
{
|
|
24
|
+
"name": "{{{packageName}}}",
|
|
25
|
+
"type": "{{updateType}}",
|
|
26
|
+
"currentVersion": "{{currentVersion}}",
|
|
27
|
+
"newVersion": "{{newVersion}}"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
\`\`\`
|
|
32
|
+
|
|
33
|
+
</div>
|
|
34
|
+
</details>
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`;
|
|
38
|
+
const createPullRequestBody = (outdatedPackage) => {
|
|
39
|
+
const appName = app_1.app.name;
|
|
40
|
+
const appVersion = app_1.app.version;
|
|
41
|
+
const appWeb = app_1.app.web;
|
|
42
|
+
const currentVersion = outdatedPackage.currentVersion.version;
|
|
43
|
+
const newVersion = outdatedPackage.newVersion.version;
|
|
44
|
+
const packageName = outdatedPackage.name;
|
|
45
|
+
const updateType = outdatedPackage.type;
|
|
46
|
+
return (0, mustache_1.render)(TEMPLATE, {
|
|
47
|
+
appName,
|
|
48
|
+
appVersion,
|
|
49
|
+
appWeb,
|
|
50
|
+
currentVersion,
|
|
51
|
+
newVersion,
|
|
52
|
+
packageName,
|
|
53
|
+
updateType
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
exports.createPullRequestBody = createPullRequestBody;
|
|
@@ -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,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestCreator = exports.
|
|
3
|
+
exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestFinder = exports.PullRequestCreator = 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
|
|
9
|
-
Object.defineProperty(exports, "
|
|
8
|
+
var PullRequestCloser_1 = require("./PullRequestCloser");
|
|
9
|
+
Object.defineProperty(exports, "PullRequestCloser", { enumerable: true, get: function () { return PullRequestCloser_1.PullRequestCloser; } });
|
|
10
10
|
var PullRequestCreator_1 = require("./PullRequestCreator");
|
|
11
11
|
Object.defineProperty(exports, "PullRequestCreator", { enumerable: true, get: function () { return PullRequestCreator_1.PullRequestCreator; } });
|
|
12
|
+
var PullRequestFinder_1 = require("./PullRequestFinder");
|
|
13
|
+
Object.defineProperty(exports, "PullRequestFinder", { enumerable: true, get: function () { return PullRequestFinder_1.PullRequestFinder; } });
|
|
12
14
|
var PullRequestTitleCreator_1 = require("./PullRequestTitleCreator");
|
|
13
15
|
Object.defineProperty(exports, "PullRequestTitleCreator", { enumerable: true, get: function () { return PullRequestTitleCreator_1.PullRequestTitleCreator; } });
|
|
14
16
|
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,24 +50,27 @@ 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,
|
|
56
61
|
packageManager: options.packageManager
|
|
57
62
|
});
|
|
58
63
|
const pullRequestTitleCreator = new github_1.PullRequestTitleCreator(options.pullRequestTitle);
|
|
59
|
-
const pullRequestBodyCreator = new github_1.PullRequestBodyCreator(options.pullRequestBody);
|
|
60
64
|
const pullRequestCreator = new github_1.PullRequestCreator({
|
|
61
65
|
github,
|
|
62
66
|
gitRepo,
|
|
63
67
|
githubRepo,
|
|
64
68
|
pullRequestTitleCreator,
|
|
65
|
-
|
|
66
|
-
logger,
|
|
67
|
-
labels: options.pullRequestLabels
|
|
69
|
+
logger
|
|
68
70
|
});
|
|
69
|
-
const branchNameCreator = new git_1.BranchNameCreator(options.branchName);
|
|
70
71
|
const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
|
|
72
|
+
const pullRequestFinder = new github_1.PullRequestFinder(pullRequests);
|
|
73
|
+
const pullRequestCloser = new github_1.PullRequestCloser(github);
|
|
71
74
|
const outdatedPackageProcessor = new processors_1.OutdatedPackageProcessor({
|
|
72
75
|
git,
|
|
73
76
|
ncu,
|
|
@@ -75,8 +78,9 @@ const main = async ({ options, logger }) => {
|
|
|
75
78
|
pullRequestCreator,
|
|
76
79
|
remoteBranchExistenceChecker,
|
|
77
80
|
logger,
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
commitMessageCreator,
|
|
82
|
+
pullRequestFinder,
|
|
83
|
+
pullRequestCloser
|
|
80
84
|
});
|
|
81
85
|
const outdatedPackagesProcessor = new processors_1.OutdatedPackagesProcessor({
|
|
82
86
|
outdatedPackageProcessor,
|
package/dist/options/Options.js
CHANGED
|
@@ -4,18 +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
|
-
pullRequestBody: io_ts_1.string,
|
|
15
|
-
pullRequestTitle: io_ts_1.string
|
|
16
|
-
}),
|
|
17
|
-
(0, io_ts_1.partial)({
|
|
18
|
-
pullRequestLabels: (0, io_ts_1.array)(io_ts_1.string)
|
|
19
|
-
})
|
|
20
|
-
]);
|
|
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
|
+
});
|
|
21
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,26 +42,6 @@ exports.cliOptions = [
|
|
|
49
42
|
],
|
|
50
43
|
default: package_manager_1.PackageManagerName.Npm
|
|
51
44
|
},
|
|
52
|
-
{
|
|
53
|
-
name: 'pull-request-body',
|
|
54
|
-
description: 'Pull request body template',
|
|
55
|
-
type: OptionType_1.OptionType.String,
|
|
56
|
-
required: false,
|
|
57
|
-
default: `This PR updates these packages:
|
|
58
|
-
|
|
59
|
-
|package|type|current version|new version|
|
|
60
|
-
|---|---|---|---|
|
|
61
|
-
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'pull-request-labels',
|
|
68
|
-
description: 'Pull request labels',
|
|
69
|
-
type: OptionType_1.OptionType.StringArray,
|
|
70
|
-
required: false
|
|
71
|
-
},
|
|
72
45
|
{
|
|
73
46
|
name: 'pull-request-title',
|
|
74
47
|
description: 'Pull request title template',
|
|
@@ -2,23 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OutdatedPackageProcessor = void 0;
|
|
4
4
|
const Either_1 = require("fp-ts/lib/Either");
|
|
5
|
+
const git_1 = require("../git");
|
|
5
6
|
// TODO: add test
|
|
6
7
|
class OutdatedPackageProcessor {
|
|
7
|
-
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger,
|
|
8
|
+
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, commitMessageCreator, pullRequestFinder, pullRequestCloser }) {
|
|
8
9
|
this.git = git;
|
|
9
10
|
this.ncu = ncu;
|
|
10
11
|
this.packageManager = packageManager;
|
|
11
12
|
this.pullRequestCreator = pullRequestCreator;
|
|
12
13
|
this.remoteBranchExistenceChecker = remoteBranchExistenceChecker;
|
|
13
14
|
this.logger = logger;
|
|
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.
|
|
19
21
|
*/
|
|
20
22
|
async process(outdatedPackage) {
|
|
21
|
-
const branchName =
|
|
23
|
+
const branchName = (0, git_1.createBranchName)(outdatedPackage);
|
|
22
24
|
this.logger.debug(`branchName=${branchName}`);
|
|
23
25
|
if (this.remoteBranchExistenceChecker.check(branchName)) {
|
|
24
26
|
this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "CLI tool for creating pull
|
|
3
|
+
"version": "0.22.2",
|
|
4
|
+
"description": "CLI tool for creating pull requests to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
7
7
|
"clean": "rimraf dist",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@octokit/rest": "18.12.0",
|
|
21
21
|
"commander": "8.3.0",
|
|
22
22
|
"execa": "5.1.1",
|
|
23
|
-
"fp-ts": "2.11.
|
|
23
|
+
"fp-ts": "2.11.7",
|
|
24
24
|
"io-ts": "2.2.16",
|
|
25
25
|
"log4js": "6.3.0",
|
|
26
26
|
"mustache": "4.1.0",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@types/node": "12.20.40",
|
|
38
38
|
"@types/parse-github-url": "1.0.0",
|
|
39
39
|
"@types/semver": "7.3.9",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
41
|
-
"eslint": "8.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "5.9.1",
|
|
41
|
+
"eslint": "8.6.0",
|
|
42
42
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
43
43
|
"eslint-plugin-import": "2.25.4",
|
|
44
44
|
"eslint-plugin-jest": "25.3.4",
|
|
@@ -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",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BranchNameCreator = void 0;
|
|
4
|
-
const mustache_1 = require("mustache");
|
|
5
|
-
class BranchNameCreator {
|
|
6
|
-
constructor(template) {
|
|
7
|
-
this.template = template;
|
|
8
|
-
}
|
|
9
|
-
create(outdatedPackage) {
|
|
10
|
-
const packageName = outdatedPackage.name;
|
|
11
|
-
const currentVersion = outdatedPackage.currentVersion.version;
|
|
12
|
-
const newVersion = outdatedPackage.newVersion.version;
|
|
13
|
-
const updateType = outdatedPackage.type;
|
|
14
|
-
return (0, mustache_1.render)(this.template, {
|
|
15
|
-
packageName,
|
|
16
|
-
currentVersion,
|
|
17
|
-
newVersion,
|
|
18
|
-
updateType
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.BranchNameCreator = BranchNameCreator;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PullRequestBodyCreator = void 0;
|
|
4
|
-
const mustache_1 = require("mustache");
|
|
5
|
-
const app_1 = require("../app");
|
|
6
|
-
class PullRequestBodyCreator {
|
|
7
|
-
constructor(template) {
|
|
8
|
-
this.template = template;
|
|
9
|
-
}
|
|
10
|
-
create(outdatedPackage) {
|
|
11
|
-
const appName = app_1.app.name;
|
|
12
|
-
const appVersion = app_1.app.version;
|
|
13
|
-
const appWeb = app_1.app.web;
|
|
14
|
-
const currentVersion = outdatedPackage.currentVersion.version;
|
|
15
|
-
const newVersion = outdatedPackage.newVersion.version;
|
|
16
|
-
const packageName = outdatedPackage.name;
|
|
17
|
-
const updateType = outdatedPackage.type;
|
|
18
|
-
return (0, mustache_1.render)(this.template, {
|
|
19
|
-
appName,
|
|
20
|
-
appVersion,
|
|
21
|
-
appWeb,
|
|
22
|
-
currentVersion,
|
|
23
|
-
newVersion,
|
|
24
|
-
packageName,
|
|
25
|
-
updateType
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.PullRequestBodyCreator = PullRequestBodyCreator;
|