npm-update-package 0.5.1 → 0.8.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 +1 -1
- package/README.md +98 -16
- package/dist/app.js +1 -1
- package/dist/github/PullRequestBodyCreator.js +29 -0
- package/dist/github/PullRequestCreator.js +5 -5
- package/dist/github/PullRequestTitleCreator.js +22 -0
- package/dist/github/index.js +5 -1
- package/dist/main.js +4 -0
- package/dist/options/Options.js +6 -2
- package/dist/options/initOptions.js +10 -1
- package/package.json +2 -2
- package/src/app.ts +1 -1
- package/src/github/PullRequestBodyCreator.test.ts +32 -0
- package/src/github/PullRequestBodyCreator.ts +26 -0
- package/src/github/PullRequestCreator.ts +12 -4
- package/src/github/PullRequestTitleCreator.test.ts +17 -0
- package/src/github/PullRequestTitleCreator.ts +19 -0
- package/src/github/index.ts +2 -0
- package/src/main.ts +6 -0
- package/src/options/Options.ts +6 -2
- package/src/options/initOptions.ts +9 -0
- package/dist/github/createPullRequestBody.js +0 -19
- package/dist/github/createPullRequestTitle.js +0 -10
- package/src/github/createPullRequestBody.test.ts +0 -64
- package/src/github/createPullRequestBody.ts +0 -17
- package/src/github/createPullRequestTitle.test.ts +0 -42
- package/src/github/createPullRequestTitle.ts +0 -8
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2020 TS Examples
|
|
4
|
-
Copyright (c) 2021
|
|
4
|
+
Copyright (c) 2021 npm-update-package
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -33,30 +33,112 @@ npm-update-package --github-token $GITHUB_TOKEN
|
|
|
33
33
|
|
|
34
34
|
## Options
|
|
35
35
|
|
|
36
|
-
You can customize behavior via command-line options.
|
|
36
|
+
You can customize behavior via command-line options.
|
|
37
|
+
Template strings such as `--branch-name` can embed variables like `{{packageName}}`(HTML-escaped) or `{{{packageName}}}`(not HTML-escaped).
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|---|---|---|---|---|
|
|
40
|
-
|`--branch-name`|Branch name template|-|string|`npm-update-package/{{{packageName}}}/v{{newVersion}}`|
|
|
41
|
-
|`--commit-message`|Commit message template|-|string|`chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`|
|
|
42
|
-
|`--git-user-email`|User email of commit|-|string|-|
|
|
43
|
-
|`--git-user-name`|User name of commit|-|string|-|
|
|
44
|
-
|`--github-token`|GitHub token|✓|string|-|
|
|
45
|
-
|`--log-level`|Log level to show|-|`info`, `debug`|`info`|
|
|
46
|
-
|`--package-manager`|Package manager of your project|-|`npm`, `yarn`|`npm`|
|
|
39
|
+
### `--branch-name`
|
|
47
40
|
|
|
48
|
-
|
|
41
|
+
Branch name template
|
|
49
42
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
-
|
|
43
|
+
- value: template string
|
|
44
|
+
- embeddable variables:
|
|
45
|
+
- `currentVersion`
|
|
46
|
+
- `newVersion`
|
|
54
47
|
- `packageName`
|
|
48
|
+
- `updateType`
|
|
49
|
+
- required: false
|
|
50
|
+
- default: `npm-update-package/{{{packageName}}}/v{{newVersion}}`
|
|
51
|
+
|
|
52
|
+
### `--commit-message`
|
|
53
|
+
|
|
54
|
+
Commit message template
|
|
55
|
+
|
|
56
|
+
- value: template string
|
|
57
|
+
- embeddable variables:
|
|
55
58
|
- `currentVersion`
|
|
56
59
|
- `newVersion`
|
|
60
|
+
- `packageName`
|
|
57
61
|
- `updateType`
|
|
58
|
-
-
|
|
62
|
+
- required: false
|
|
63
|
+
- default: `chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`
|
|
64
|
+
|
|
65
|
+
### `--git-user-email`
|
|
66
|
+
|
|
67
|
+
User email of commit
|
|
68
|
+
|
|
69
|
+
- value: string
|
|
70
|
+
- required: false
|
|
71
|
+
|
|
72
|
+
### `--git-user-name`
|
|
73
|
+
|
|
74
|
+
User name of commit
|
|
75
|
+
|
|
76
|
+
- value: string
|
|
77
|
+
- required: false
|
|
78
|
+
|
|
79
|
+
### `--github-token`
|
|
80
|
+
|
|
81
|
+
GitHub token
|
|
82
|
+
|
|
83
|
+
- value: string
|
|
84
|
+
- required: true
|
|
85
|
+
|
|
86
|
+
### `--log-level`
|
|
87
|
+
|
|
88
|
+
Log level to show
|
|
89
|
+
|
|
90
|
+
- value: string
|
|
91
|
+
- `info`
|
|
92
|
+
- `debug`
|
|
93
|
+
- required: false
|
|
94
|
+
- default: `info`
|
|
95
|
+
|
|
96
|
+
### `--package-manager`
|
|
97
|
+
|
|
98
|
+
Package manager of your project
|
|
99
|
+
|
|
100
|
+
- value: string
|
|
101
|
+
- `npm`
|
|
102
|
+
- `yarn`
|
|
103
|
+
- required: false
|
|
104
|
+
- default: `npm`
|
|
105
|
+
|
|
106
|
+
### `--pull-request-body`
|
|
107
|
+
|
|
108
|
+
Pull request body template
|
|
109
|
+
|
|
110
|
+
- value: template string
|
|
111
|
+
- embeddable variables:
|
|
112
|
+
- `appName`
|
|
113
|
+
- `appVersion`
|
|
114
|
+
- `appWeb`
|
|
115
|
+
- `currentVersion`
|
|
116
|
+
- `newVersion`
|
|
59
117
|
- `packageName`
|
|
118
|
+
- `updateType`
|
|
119
|
+
- required: false
|
|
120
|
+
- default:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
This PR updates these packages:
|
|
124
|
+
|
|
125
|
+
|package|type|current version|new version|
|
|
126
|
+
|---|---|---|---|
|
|
127
|
+
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### `--pull-request-title`
|
|
134
|
+
|
|
135
|
+
Pull request title template
|
|
136
|
+
|
|
137
|
+
- value: template string
|
|
138
|
+
- embeddable variables:
|
|
60
139
|
- `currentVersion`
|
|
61
140
|
- `newVersion`
|
|
141
|
+
- `packageName`
|
|
62
142
|
- `updateType`
|
|
143
|
+
- required: false
|
|
144
|
+
- default: `chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`
|
package/dist/app.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PullRequestCreator = void 0;
|
|
4
|
-
const createPullRequestBody_1 = require("./createPullRequestBody");
|
|
5
|
-
const createPullRequestTitle_1 = require("./createPullRequestTitle");
|
|
6
4
|
// TODO: add test
|
|
7
5
|
class PullRequestCreator {
|
|
8
|
-
constructor({ github, gitRepo, githubRepo, logger }) {
|
|
6
|
+
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger }) {
|
|
9
7
|
this.github = github;
|
|
10
8
|
this.gitRepo = gitRepo;
|
|
11
9
|
this.githubRepo = githubRepo;
|
|
10
|
+
this.pullRequestTitleCreator = pullRequestTitleCreator;
|
|
11
|
+
this.pullRequestBodyCreator = pullRequestBodyCreator;
|
|
12
12
|
this.logger = logger;
|
|
13
13
|
}
|
|
14
14
|
async create({ outdatedPackage, branchName }) {
|
|
15
|
-
const title =
|
|
15
|
+
const title = this.pullRequestTitleCreator.create(outdatedPackage);
|
|
16
16
|
this.logger.debug(`title=${title}`);
|
|
17
|
-
const body =
|
|
17
|
+
const body = this.pullRequestBodyCreator.create(outdatedPackage);
|
|
18
18
|
this.logger.debug(`body=${body}`);
|
|
19
19
|
const createdPullRequest = await this.github.createPullRequest({
|
|
20
20
|
owner: this.gitRepo.owner,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PullRequestTitleCreator = void 0;
|
|
4
|
+
const mustache_1 = require("mustache");
|
|
5
|
+
class PullRequestTitleCreator {
|
|
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.PullRequestTitleCreator = PullRequestTitleCreator;
|
package/dist/github/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RemoteBranchExistenceChecker = exports.PullRequestCreator = exports.GitHub = exports.createGitHub = void 0;
|
|
3
|
+
exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestCreator = exports.PullRequestBodyCreator = 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 PullRequestBodyCreator_1 = require("./PullRequestBodyCreator");
|
|
9
|
+
Object.defineProperty(exports, "PullRequestBodyCreator", { enumerable: true, get: function () { return PullRequestBodyCreator_1.PullRequestBodyCreator; } });
|
|
8
10
|
var PullRequestCreator_1 = require("./PullRequestCreator");
|
|
9
11
|
Object.defineProperty(exports, "PullRequestCreator", { enumerable: true, get: function () { return PullRequestCreator_1.PullRequestCreator; } });
|
|
12
|
+
var PullRequestTitleCreator_1 = require("./PullRequestTitleCreator");
|
|
13
|
+
Object.defineProperty(exports, "PullRequestTitleCreator", { enumerable: true, get: function () { return PullRequestTitleCreator_1.PullRequestTitleCreator; } });
|
|
10
14
|
var RemoteBranchExistenceChecker_1 = require("./RemoteBranchExistenceChecker");
|
|
11
15
|
Object.defineProperty(exports, "RemoteBranchExistenceChecker", { enumerable: true, get: function () { return RemoteBranchExistenceChecker_1.RemoteBranchExistenceChecker; } });
|
package/dist/main.js
CHANGED
|
@@ -54,10 +54,14 @@ const main = async ({ options, logger }) => {
|
|
|
54
54
|
terminal,
|
|
55
55
|
packageManager: options.packageManager
|
|
56
56
|
});
|
|
57
|
+
const pullRequestTitleCreator = new github_1.PullRequestTitleCreator(options.pullRequestTitle);
|
|
58
|
+
const pullRequestBodyCreator = new github_1.PullRequestBodyCreator(options.pullRequestBody);
|
|
57
59
|
const pullRequestCreator = new github_1.PullRequestCreator({
|
|
58
60
|
github,
|
|
59
61
|
gitRepo,
|
|
60
62
|
githubRepo,
|
|
63
|
+
pullRequestTitleCreator,
|
|
64
|
+
pullRequestBodyCreator,
|
|
61
65
|
logger
|
|
62
66
|
});
|
|
63
67
|
const branchNameCreator = new git_1.BranchNameCreator(options.branchName);
|
package/dist/options/Options.js
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isOptions = void 0;
|
|
4
4
|
const io_ts_1 = require("io-ts");
|
|
5
|
+
const logger_1 = require("../logger");
|
|
6
|
+
const package_manager_1 = require("../package-manager");
|
|
5
7
|
const Options = (0, io_ts_1.intersection)([
|
|
6
8
|
(0, io_ts_1.type)({
|
|
7
9
|
branchName: io_ts_1.string,
|
|
8
10
|
commitMessage: io_ts_1.string,
|
|
9
11
|
githubToken: io_ts_1.string,
|
|
10
|
-
logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(
|
|
11
|
-
packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)(
|
|
12
|
+
logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Info), (0, io_ts_1.literal)(logger_1.LogLevel.Debug)]),
|
|
13
|
+
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)]),
|
|
14
|
+
pullRequestBody: io_ts_1.string,
|
|
15
|
+
pullRequestTitle: io_ts_1.string
|
|
12
16
|
}),
|
|
13
17
|
(0, io_ts_1.partial)({
|
|
14
18
|
gitUserEmail: io_ts_1.string,
|
|
@@ -26,7 +26,16 @@ const initOptions = () => {
|
|
|
26
26
|
package_manager_1.PackageManagerName.Npm,
|
|
27
27
|
package_manager_1.PackageManagerName.Yarn
|
|
28
28
|
])
|
|
29
|
-
.default(package_manager_1.PackageManagerName.Npm))
|
|
29
|
+
.default(package_manager_1.PackageManagerName.Npm))
|
|
30
|
+
.option('--pull-request-body <value>', 'Pull request body template', `This PR updates these packages:
|
|
31
|
+
|
|
32
|
+
|package|type|current version|new version|
|
|
33
|
+
|---|---|---|---|
|
|
34
|
+
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`)
|
|
38
|
+
.option('--pull-request-title <value>', 'Pull request title template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}');
|
|
30
39
|
commander_1.program.parse(process.argv);
|
|
31
40
|
const options = commander_1.program.opts();
|
|
32
41
|
if (!(0, Options_1.isOptions)(options)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"lint": "eslint '**/*.{js,ts}'",
|
|
9
9
|
"prepare": "husky install",
|
|
10
10
|
"prepublish": "npm-run-all clean lint test build",
|
|
11
|
-
"start": "ts-node src/
|
|
11
|
+
"start": "ts-node src/bin.ts",
|
|
12
12
|
"test": "jest --passWithNoTests"
|
|
13
13
|
},
|
|
14
14
|
"bin": "dist/bin.js",
|
package/src/app.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { app } from '../app'
|
|
2
|
+
import { PackageVersion } from '../ncu'
|
|
3
|
+
import { PullRequestBodyCreator } from './PullRequestBodyCreator'
|
|
4
|
+
|
|
5
|
+
describe('PullRequestBodyCreator', () => {
|
|
6
|
+
describe('create', () => {
|
|
7
|
+
it('returns pull request body', () => {
|
|
8
|
+
const pullRequestBodyCreator = new PullRequestBodyCreator(`This PR updates these packages:
|
|
9
|
+
|
|
10
|
+
|package|type|current version|new version|
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`)
|
|
16
|
+
const actual = pullRequestBodyCreator.create({
|
|
17
|
+
name: '@typescript-eslint/eslint-plugin',
|
|
18
|
+
currentVersion: PackageVersion.of('1.0.0'),
|
|
19
|
+
newVersion: PackageVersion.of('2.0.0'),
|
|
20
|
+
type: 'major'
|
|
21
|
+
})
|
|
22
|
+
expect(actual).toBe(`This PR updates these packages:
|
|
23
|
+
|
|
24
|
+
|package|type|current version|new version|
|
|
25
|
+
|---|---|---|---|
|
|
26
|
+
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|major|\`1.0.0\`|\`2.0.0\`|
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
This PR has been generated by [${app.name}](${app.web}) v${app.version}`)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { render } from 'mustache'
|
|
2
|
+
import { app } from '../app'
|
|
3
|
+
import type { OutdatedPackage } from '../ncu'
|
|
4
|
+
|
|
5
|
+
export class PullRequestBodyCreator {
|
|
6
|
+
constructor (private readonly template: string) {}
|
|
7
|
+
|
|
8
|
+
create (outdatedPackage: OutdatedPackage): string {
|
|
9
|
+
const appName = app.name
|
|
10
|
+
const appVersion = app.version
|
|
11
|
+
const appWeb = app.web
|
|
12
|
+
const currentVersion = outdatedPackage.currentVersion.version
|
|
13
|
+
const newVersion = outdatedPackage.newVersion.version
|
|
14
|
+
const packageName = outdatedPackage.name
|
|
15
|
+
const updateType = outdatedPackage.type
|
|
16
|
+
return render(this.template, {
|
|
17
|
+
appName,
|
|
18
|
+
appVersion,
|
|
19
|
+
appWeb,
|
|
20
|
+
currentVersion,
|
|
21
|
+
newVersion,
|
|
22
|
+
packageName,
|
|
23
|
+
updateType
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { GitRepository } from '../git'
|
|
2
2
|
import type { Logger } from '../logger'
|
|
3
3
|
import type { OutdatedPackage } from '../ncu'
|
|
4
|
-
import { createPullRequestBody } from './createPullRequestBody'
|
|
5
|
-
import { createPullRequestTitle } from './createPullRequestTitle'
|
|
6
4
|
import type { GitHub } from './GitHub'
|
|
5
|
+
import type { PullRequestBodyCreator } from './PullRequestBodyCreator'
|
|
6
|
+
import type { PullRequestTitleCreator } from './PullRequestTitleCreator'
|
|
7
7
|
import type { Repository as GitHubRepository } from './Repository'
|
|
8
8
|
|
|
9
9
|
// TODO: add test
|
|
@@ -11,22 +11,30 @@ export class PullRequestCreator {
|
|
|
11
11
|
private readonly github: GitHub
|
|
12
12
|
private readonly gitRepo: GitRepository
|
|
13
13
|
private readonly githubRepo: GitHubRepository
|
|
14
|
+
private readonly pullRequestTitleCreator: PullRequestTitleCreator
|
|
15
|
+
private readonly pullRequestBodyCreator: PullRequestBodyCreator
|
|
14
16
|
private readonly logger: Logger
|
|
15
17
|
|
|
16
18
|
constructor ({
|
|
17
19
|
github,
|
|
18
20
|
gitRepo,
|
|
19
21
|
githubRepo,
|
|
22
|
+
pullRequestTitleCreator,
|
|
23
|
+
pullRequestBodyCreator,
|
|
20
24
|
logger
|
|
21
25
|
}: {
|
|
22
26
|
github: GitHub
|
|
23
27
|
gitRepo: GitRepository
|
|
24
28
|
githubRepo: GitHubRepository
|
|
29
|
+
pullRequestTitleCreator: PullRequestTitleCreator
|
|
30
|
+
pullRequestBodyCreator: PullRequestBodyCreator
|
|
25
31
|
logger: Logger
|
|
26
32
|
}) {
|
|
27
33
|
this.github = github
|
|
28
34
|
this.gitRepo = gitRepo
|
|
29
35
|
this.githubRepo = githubRepo
|
|
36
|
+
this.pullRequestTitleCreator = pullRequestTitleCreator
|
|
37
|
+
this.pullRequestBodyCreator = pullRequestBodyCreator
|
|
30
38
|
this.logger = logger
|
|
31
39
|
}
|
|
32
40
|
|
|
@@ -37,10 +45,10 @@ export class PullRequestCreator {
|
|
|
37
45
|
outdatedPackage: OutdatedPackage
|
|
38
46
|
branchName: string
|
|
39
47
|
}): Promise<void> {
|
|
40
|
-
const title =
|
|
48
|
+
const title = this.pullRequestTitleCreator.create(outdatedPackage)
|
|
41
49
|
this.logger.debug(`title=${title}`)
|
|
42
50
|
|
|
43
|
-
const body =
|
|
51
|
+
const body = this.pullRequestBodyCreator.create(outdatedPackage)
|
|
44
52
|
this.logger.debug(`body=${body}`)
|
|
45
53
|
|
|
46
54
|
const createdPullRequest = await this.github.createPullRequest({
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PackageVersion } from '../ncu'
|
|
2
|
+
import { PullRequestTitleCreator } from './PullRequestTitleCreator'
|
|
3
|
+
|
|
4
|
+
describe('PullRequestTitleCreator', () => {
|
|
5
|
+
describe('create', () => {
|
|
6
|
+
it('returns pull request title', () => {
|
|
7
|
+
const pullRequestTitleCreator = new PullRequestTitleCreator('chore(deps): {{updateType}} update {{{packageName}}} from {{currentVersion}} to v{{newVersion}}')
|
|
8
|
+
const actual = pullRequestTitleCreator.create({
|
|
9
|
+
name: '@typescript-eslint/eslint-plugin',
|
|
10
|
+
currentVersion: PackageVersion.of('1.0.0'),
|
|
11
|
+
newVersion: PackageVersion.of('2.0.0'),
|
|
12
|
+
type: 'major'
|
|
13
|
+
})
|
|
14
|
+
expect(actual).toBe('chore(deps): major update @typescript-eslint/eslint-plugin from 1.0.0 to v2.0.0')
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { render } from 'mustache'
|
|
2
|
+
import type { OutdatedPackage } from '../ncu'
|
|
3
|
+
|
|
4
|
+
export class PullRequestTitleCreator {
|
|
5
|
+
constructor (private readonly template: string) {}
|
|
6
|
+
|
|
7
|
+
create (outdatedPackage: OutdatedPackage): string {
|
|
8
|
+
const packageName = outdatedPackage.name
|
|
9
|
+
const currentVersion = outdatedPackage.currentVersion.version
|
|
10
|
+
const newVersion = outdatedPackage.newVersion.version
|
|
11
|
+
const updateType = outdatedPackage.type
|
|
12
|
+
return render(this.template, {
|
|
13
|
+
packageName,
|
|
14
|
+
currentVersion,
|
|
15
|
+
newVersion,
|
|
16
|
+
updateType
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/github/index.ts
CHANGED
|
@@ -2,6 +2,8 @@ export type { Branch } from './Branch'
|
|
|
2
2
|
export { createGitHub } from './createGitHub'
|
|
3
3
|
export { GitHub } from './GitHub'
|
|
4
4
|
export type { PullRequest } from './PullRequest'
|
|
5
|
+
export { PullRequestBodyCreator } from './PullRequestBodyCreator'
|
|
5
6
|
export { PullRequestCreator } from './PullRequestCreator'
|
|
7
|
+
export { PullRequestTitleCreator } from './PullRequestTitleCreator'
|
|
6
8
|
export { RemoteBranchExistenceChecker } from './RemoteBranchExistenceChecker'
|
|
7
9
|
export type { Repository } from './Repository'
|
package/src/main.ts
CHANGED
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
} from './git'
|
|
7
7
|
import {
|
|
8
8
|
createGitHub,
|
|
9
|
+
PullRequestBodyCreator,
|
|
9
10
|
PullRequestCreator,
|
|
11
|
+
PullRequestTitleCreator,
|
|
10
12
|
RemoteBranchExistenceChecker
|
|
11
13
|
} from './github'
|
|
12
14
|
import type { Logger } from './logger'
|
|
@@ -82,10 +84,14 @@ export const main = async ({
|
|
|
82
84
|
terminal,
|
|
83
85
|
packageManager: options.packageManager
|
|
84
86
|
})
|
|
87
|
+
const pullRequestTitleCreator = new PullRequestTitleCreator(options.pullRequestTitle)
|
|
88
|
+
const pullRequestBodyCreator = new PullRequestBodyCreator(options.pullRequestBody)
|
|
85
89
|
const pullRequestCreator = new PullRequestCreator({
|
|
86
90
|
github,
|
|
87
91
|
gitRepo,
|
|
88
92
|
githubRepo,
|
|
93
|
+
pullRequestTitleCreator,
|
|
94
|
+
pullRequestBodyCreator,
|
|
89
95
|
logger
|
|
90
96
|
})
|
|
91
97
|
const branchNameCreator = new BranchNameCreator(options.branchName)
|
package/src/options/Options.ts
CHANGED
|
@@ -7,14 +7,18 @@ import {
|
|
|
7
7
|
union
|
|
8
8
|
} from 'io-ts'
|
|
9
9
|
import type { TypeOf } from 'io-ts'
|
|
10
|
+
import { LogLevel } from '../logger'
|
|
11
|
+
import { PackageManagerName } from '../package-manager'
|
|
10
12
|
|
|
11
13
|
const Options = intersection([
|
|
12
14
|
type({
|
|
13
15
|
branchName: string,
|
|
14
16
|
commitMessage: string,
|
|
15
17
|
githubToken: string,
|
|
16
|
-
logLevel: union([literal(
|
|
17
|
-
packageManager: union([literal(
|
|
18
|
+
logLevel: union([literal(LogLevel.Info), literal(LogLevel.Debug)]),
|
|
19
|
+
packageManager: union([literal(PackageManagerName.Npm), literal(PackageManagerName.Yarn)]),
|
|
20
|
+
pullRequestBody: string,
|
|
21
|
+
pullRequestTitle: string
|
|
18
22
|
}),
|
|
19
23
|
partial({
|
|
20
24
|
gitUserEmail: string,
|
|
@@ -33,6 +33,15 @@ export const initOptions = (): Options => {
|
|
|
33
33
|
])
|
|
34
34
|
.default(PackageManagerName.Npm)
|
|
35
35
|
)
|
|
36
|
+
.option('--pull-request-body <value>', 'Pull request body template', `This PR updates these packages:
|
|
37
|
+
|
|
38
|
+
|package|type|current version|new version|
|
|
39
|
+
|---|---|---|---|
|
|
40
|
+
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`)
|
|
44
|
+
.option('--pull-request-title <value>', 'Pull request title template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}')
|
|
36
45
|
program.parse(process.argv)
|
|
37
46
|
const options = program.opts()
|
|
38
47
|
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPullRequestBody = void 0;
|
|
4
|
-
const app_1 = require("../app");
|
|
5
|
-
const createPullRequestBody = (outdatedPackage) => {
|
|
6
|
-
const packageName = outdatedPackage.name;
|
|
7
|
-
const currentVersion = outdatedPackage.currentVersion.version;
|
|
8
|
-
const newVersion = outdatedPackage.newVersion.version;
|
|
9
|
-
const updateType = outdatedPackage.type;
|
|
10
|
-
return `This PR updates these packages:
|
|
11
|
-
|
|
12
|
-
|package|type|current version|new version|
|
|
13
|
-
|---|---|---|---|
|
|
14
|
-
|[${packageName}](https://www.npmjs.com/package/${packageName})|${updateType}|\`${currentVersion}\`|\`${newVersion}\`|
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
This PR has been generated by [${app_1.app.name}](${app_1.app.web})`;
|
|
18
|
-
};
|
|
19
|
-
exports.createPullRequestBody = createPullRequestBody;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPullRequestTitle = void 0;
|
|
4
|
-
const createPullRequestTitle = (outdatedPackage) => {
|
|
5
|
-
const packageName = outdatedPackage.name;
|
|
6
|
-
const newVersion = outdatedPackage.newVersion.version;
|
|
7
|
-
const updateType = outdatedPackage.type;
|
|
8
|
-
return `chore(deps): ${updateType} update ${packageName} to v${newVersion}`;
|
|
9
|
-
};
|
|
10
|
-
exports.createPullRequestTitle = createPullRequestTitle;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PackageVersion,
|
|
3
|
-
UpdateType
|
|
4
|
-
} from '../ncu'
|
|
5
|
-
import { createPullRequestBody } from './createPullRequestBody'
|
|
6
|
-
|
|
7
|
-
describe('createPullRequestBody', () => {
|
|
8
|
-
describe('if update type is patch', () => {
|
|
9
|
-
it('returns pull request body', () => {
|
|
10
|
-
const actual = createPullRequestBody({
|
|
11
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
12
|
-
currentVersion: PackageVersion.of('1.0.0'),
|
|
13
|
-
newVersion: PackageVersion.of('1.0.1'),
|
|
14
|
-
type: UpdateType.Patch
|
|
15
|
-
})
|
|
16
|
-
expect(actual).toBe(`This PR updates these packages:
|
|
17
|
-
|
|
18
|
-
|package|type|current version|new version|
|
|
19
|
-
|---|---|---|---|
|
|
20
|
-
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|patch|\`1.0.0\`|\`1.0.1\`|
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
describe('if update type is minor', () => {
|
|
28
|
-
it('returns pull request body', () => {
|
|
29
|
-
const actual = createPullRequestBody({
|
|
30
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
31
|
-
currentVersion: PackageVersion.of('1.0.0'),
|
|
32
|
-
newVersion: PackageVersion.of('1.1.0'),
|
|
33
|
-
type: UpdateType.Minor
|
|
34
|
-
})
|
|
35
|
-
expect(actual).toBe(`This PR updates these packages:
|
|
36
|
-
|
|
37
|
-
|package|type|current version|new version|
|
|
38
|
-
|---|---|---|---|
|
|
39
|
-
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|minor|\`1.0.0\`|\`1.1.0\`|
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
describe('if update type is major', () => {
|
|
47
|
-
it('returns pull request body', () => {
|
|
48
|
-
const actual = createPullRequestBody({
|
|
49
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
50
|
-
currentVersion: PackageVersion.of('1.0.0'),
|
|
51
|
-
newVersion: PackageVersion.of('2.0.0'),
|
|
52
|
-
type: UpdateType.Major
|
|
53
|
-
})
|
|
54
|
-
expect(actual).toBe(`This PR updates these packages:
|
|
55
|
-
|
|
56
|
-
|package|type|current version|new version|
|
|
57
|
-
|---|---|---|---|
|
|
58
|
-
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|major|\`1.0.0\`|\`2.0.0\`|
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
})
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { app } from '../app'
|
|
2
|
-
import type { OutdatedPackage } from '../ncu'
|
|
3
|
-
|
|
4
|
-
export const createPullRequestBody = (outdatedPackage: OutdatedPackage): string => {
|
|
5
|
-
const packageName = outdatedPackage.name
|
|
6
|
-
const currentVersion = outdatedPackage.currentVersion.version
|
|
7
|
-
const newVersion = outdatedPackage.newVersion.version
|
|
8
|
-
const updateType = outdatedPackage.type
|
|
9
|
-
return `This PR updates these packages:
|
|
10
|
-
|
|
11
|
-
|package|type|current version|new version|
|
|
12
|
-
|---|---|---|---|
|
|
13
|
-
|[${packageName}](https://www.npmjs.com/package/${packageName})|${updateType}|\`${currentVersion}\`|\`${newVersion}\`|
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
This PR has been generated by [${app.name}](${app.web})`
|
|
17
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { UpdateType, PackageVersion } from '../ncu'
|
|
2
|
-
import { createPullRequestTitle } from './createPullRequestTitle'
|
|
3
|
-
|
|
4
|
-
describe('createPullRequestTitle', () => {
|
|
5
|
-
const currentVersion = PackageVersion.of('1.0.0')
|
|
6
|
-
|
|
7
|
-
describe('if update type is patch', () => {
|
|
8
|
-
it('returns pull request title', () => {
|
|
9
|
-
const actual = createPullRequestTitle({
|
|
10
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
11
|
-
currentVersion,
|
|
12
|
-
newVersion: PackageVersion.of('1.0.1'),
|
|
13
|
-
type: UpdateType.Patch
|
|
14
|
-
})
|
|
15
|
-
expect(actual).toBe('chore(deps): patch update @typescript-eslint/eslint-plugin to v1.0.1')
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe('if update type is minor', () => {
|
|
20
|
-
it('returns pull request title', () => {
|
|
21
|
-
const actual = createPullRequestTitle({
|
|
22
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
23
|
-
currentVersion,
|
|
24
|
-
newVersion: PackageVersion.of('1.1.0'),
|
|
25
|
-
type: UpdateType.Minor
|
|
26
|
-
})
|
|
27
|
-
expect(actual).toBe('chore(deps): minor update @typescript-eslint/eslint-plugin to v1.1.0')
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('if update type is major', () => {
|
|
32
|
-
it('returns pull request title', () => {
|
|
33
|
-
const actual = createPullRequestTitle({
|
|
34
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
35
|
-
currentVersion,
|
|
36
|
-
newVersion: PackageVersion.of('2.0.0'),
|
|
37
|
-
type: UpdateType.Major
|
|
38
|
-
})
|
|
39
|
-
expect(actual).toBe('chore(deps): major update @typescript-eslint/eslint-plugin to v2.0.0')
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
})
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { OutdatedPackage } from '../ncu'
|
|
2
|
-
|
|
3
|
-
export const createPullRequestTitle = (outdatedPackage: OutdatedPackage): string => {
|
|
4
|
-
const packageName = outdatedPackage.name
|
|
5
|
-
const newVersion = outdatedPackage.newVersion.version
|
|
6
|
-
const updateType = outdatedPackage.type
|
|
7
|
-
return `chore(deps): ${updateType} update ${packageName} to v${newVersion}`
|
|
8
|
-
}
|