npm-update-package 0.9.0 → 0.11.1
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 +37 -33
- package/dist/app.js +1 -1
- package/dist/bin.js +6 -4
- package/dist/git/Git.js +7 -4
- package/dist/git/index.js +1 -3
- package/dist/github/RemoteBranchExistenceChecker.js +0 -1
- package/dist/logger/LogLevel.js +3 -2
- package/dist/main.js +14 -11
- package/dist/options/Options.js +9 -15
- package/dist/options/initOptions.js +1 -2
- package/dist/processors/{Result.js → FailedResult.js} +0 -0
- package/dist/processors/OutdatedPackageProcessor.js +39 -25
- package/dist/processors/SucceededResult.js +2 -0
- package/package.json +5 -4
- package/dist/git/Committer.js +0 -31
package/README.md
CHANGED
|
@@ -5,31 +5,48 @@
|
|
|
5
5
|
|
|
6
6
|
CLI tool for creating pull request to update npm packages
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Caution
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
This package is currently under development, so the major version is 0 yet.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
npm i -g npm-update-package
|
|
14
|
-
```
|
|
12
|
+
## Requirements
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
- Git v2.23.0 or higher
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
|
-
|
|
19
|
+
npx npm-update-package --github-token $GITHUB_TOKEN
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
Example of running npm-update-package on GitHub Actions at 0:00 every day:
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
name: npm-update-package
|
|
28
|
+
on:
|
|
29
|
+
schedule:
|
|
30
|
+
- cron: '0 0 * * *'
|
|
31
|
+
jobs:
|
|
32
|
+
npm-update-package:
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v2
|
|
36
|
+
- uses: actions/setup-node@v2
|
|
37
|
+
- run: |
|
|
38
|
+
git config user.name $GIT_USER_NAME
|
|
39
|
+
git config user.email $GIT_USER_EMAIL
|
|
40
|
+
npx npm-update-package --github-token $GITHUB_TOKEN
|
|
41
|
+
env:
|
|
42
|
+
GIT_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
|
|
43
|
+
GIT_USER_NAME: github-actions[bot]
|
|
44
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
26
45
|
```
|
|
27
46
|
|
|
28
|
-
|
|
47
|
+
Actual working examples can be seen in these repositories.
|
|
29
48
|
|
|
30
|
-
|
|
31
|
-
npm-update-package --github-token $GITHUB_TOKEN
|
|
32
|
-
```
|
|
49
|
+
- [npm-update-package/example-npm](https://github.com/npm-update-package/example-npm)
|
|
33
50
|
|
|
34
51
|
## Options
|
|
35
52
|
|
|
@@ -41,7 +58,7 @@ Template strings such as `--branch-name` can embed variables like `{{packageName
|
|
|
41
58
|
Branch name template
|
|
42
59
|
|
|
43
60
|
- value: template string
|
|
44
|
-
-
|
|
61
|
+
- variables:
|
|
45
62
|
- `currentVersion`
|
|
46
63
|
- `newVersion`
|
|
47
64
|
- `packageName`
|
|
@@ -54,7 +71,7 @@ Branch name template
|
|
|
54
71
|
Commit message template
|
|
55
72
|
|
|
56
73
|
- value: template string
|
|
57
|
-
-
|
|
74
|
+
- variables:
|
|
58
75
|
- `currentVersion`
|
|
59
76
|
- `newVersion`
|
|
60
77
|
- `packageName`
|
|
@@ -62,20 +79,6 @@ Commit message template
|
|
|
62
79
|
- required: false
|
|
63
80
|
- default: `chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`
|
|
64
81
|
|
|
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
82
|
### `--github-token`
|
|
80
83
|
|
|
81
84
|
GitHub token
|
|
@@ -88,6 +91,7 @@ GitHub token
|
|
|
88
91
|
Log level to show
|
|
89
92
|
|
|
90
93
|
- value: string
|
|
94
|
+
- `error`
|
|
91
95
|
- `info`
|
|
92
96
|
- `debug`
|
|
93
97
|
- required: false
|
|
@@ -108,7 +112,7 @@ Package manager of your project
|
|
|
108
112
|
Pull request body template
|
|
109
113
|
|
|
110
114
|
- value: template string
|
|
111
|
-
-
|
|
115
|
+
- variables:
|
|
112
116
|
- `appName`
|
|
113
117
|
- `appVersion`
|
|
114
118
|
- `appWeb`
|
|
@@ -135,7 +139,7 @@ This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
|
|
|
135
139
|
Pull request title template
|
|
136
140
|
|
|
137
141
|
- value: template string
|
|
138
|
-
-
|
|
142
|
+
- variables:
|
|
139
143
|
- `currentVersion`
|
|
140
144
|
- `newVersion`
|
|
141
145
|
- `packageName`
|
package/dist/app.js
CHANGED
package/dist/bin.js
CHANGED
|
@@ -12,8 +12,10 @@ logger.info(`Start ${app_1.app.name} v${app_1.app.version}`);
|
|
|
12
12
|
options,
|
|
13
13
|
logger
|
|
14
14
|
})
|
|
15
|
-
.then(() =>
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
.then(() => {
|
|
16
|
+
logger.info(`End ${app_1.app.name} v${app_1.app.version}`);
|
|
17
|
+
})
|
|
18
|
+
.catch((error) => {
|
|
19
|
+
logger.fatal(error);
|
|
20
|
+
throw error;
|
|
19
21
|
});
|
package/dist/git/Git.js
CHANGED
|
@@ -10,14 +10,11 @@ class Git {
|
|
|
10
10
|
async add(...files) {
|
|
11
11
|
await this.terminal.run('git', 'add', ...files);
|
|
12
12
|
}
|
|
13
|
-
async checkout(branchName) {
|
|
14
|
-
await this.terminal.run('git', 'checkout', branchName);
|
|
15
|
-
}
|
|
16
13
|
async commit(message) {
|
|
17
14
|
await this.terminal.run('git', 'commit', '--message', message);
|
|
18
15
|
}
|
|
19
16
|
async createBranch(branchName) {
|
|
20
|
-
await this.terminal.run('git', '
|
|
17
|
+
await this.terminal.run('git', 'switch', '-c', branchName);
|
|
21
18
|
}
|
|
22
19
|
async getConfig(key) {
|
|
23
20
|
const { stdout } = await this.terminal.run('git', 'config', key);
|
|
@@ -41,8 +38,14 @@ class Git {
|
|
|
41
38
|
async removeBranch(branchName) {
|
|
42
39
|
await this.terminal.run('git', 'branch', '-D', branchName);
|
|
43
40
|
}
|
|
41
|
+
async restore(...files) {
|
|
42
|
+
await this.terminal.run('git', 'restore', '--worktree', '--staged', ...files);
|
|
43
|
+
}
|
|
44
44
|
async setConfig(key, value) {
|
|
45
45
|
await this.terminal.run('git', 'config', key, value);
|
|
46
46
|
}
|
|
47
|
+
async switch(branchName) {
|
|
48
|
+
await this.terminal.run('git', 'switch', branchName);
|
|
49
|
+
}
|
|
47
50
|
}
|
|
48
51
|
exports.Git = Git;
|
package/dist/git/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Git = exports.
|
|
3
|
+
exports.Git = exports.CommitMessageCreator = exports.BranchNameCreator = void 0;
|
|
4
4
|
var BranchNameCreator_1 = require("./BranchNameCreator");
|
|
5
5
|
Object.defineProperty(exports, "BranchNameCreator", { enumerable: true, get: function () { return BranchNameCreator_1.BranchNameCreator; } });
|
|
6
6
|
var CommitMessageCreator_1 = require("./CommitMessageCreator");
|
|
7
7
|
Object.defineProperty(exports, "CommitMessageCreator", { enumerable: true, get: function () { return CommitMessageCreator_1.CommitMessageCreator; } });
|
|
8
|
-
var Committer_1 = require("./Committer");
|
|
9
|
-
Object.defineProperty(exports, "Committer", { enumerable: true, get: function () { return Committer_1.Committer; } });
|
|
10
8
|
var Git_1 = require("./Git");
|
|
11
9
|
Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return Git_1.Git; } });
|
package/dist/logger/LogLevel.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isLogLevel = exports.LogLevel = void 0;
|
|
4
4
|
exports.LogLevel = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Debug: 'debug',
|
|
6
|
+
Error: 'error',
|
|
7
|
+
Info: 'info'
|
|
7
8
|
};
|
|
8
9
|
const logLevels = Object.values(exports.LogLevel);
|
|
9
10
|
const isLogLevel = (value) => logLevels.includes(value);
|
package/dist/main.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.main = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
4
5
|
const git_1 = require("./git");
|
|
5
6
|
const github_1 = require("./github");
|
|
6
7
|
const ncu_1 = require("./ncu");
|
|
@@ -43,13 +44,6 @@ const main = async ({ options, logger }) => {
|
|
|
43
44
|
});
|
|
44
45
|
logger.debug(`remoteBranches=${JSON.stringify(remoteBranches)}`);
|
|
45
46
|
const remoteBranchExistenceChecker = github_1.RemoteBranchExistenceChecker.of(remoteBranches);
|
|
46
|
-
const committer = new git_1.Committer({
|
|
47
|
-
git,
|
|
48
|
-
user: {
|
|
49
|
-
name: options.gitUserName,
|
|
50
|
-
email: options.gitUserEmail
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
47
|
const packageManager = (0, package_manager_1.createPackageManager)({
|
|
54
48
|
terminal,
|
|
55
49
|
packageManager: options.packageManager
|
|
@@ -67,7 +61,6 @@ const main = async ({ options, logger }) => {
|
|
|
67
61
|
const branchNameCreator = new git_1.BranchNameCreator(options.branchName);
|
|
68
62
|
const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
|
|
69
63
|
const outdatedPackageProcessor = new processors_1.OutdatedPackageProcessor({
|
|
70
|
-
committer,
|
|
71
64
|
git,
|
|
72
65
|
ncu,
|
|
73
66
|
packageManager,
|
|
@@ -83,14 +76,24 @@ const main = async ({ options, logger }) => {
|
|
|
83
76
|
});
|
|
84
77
|
const results = await outdatedPackagesProcessor.process(outdatedPackages);
|
|
85
78
|
logger.debug(`results=${JSON.stringify(results)}`);
|
|
86
|
-
const
|
|
79
|
+
const succeededResults = results.filter(Either_1.isRight).map(({ right }) => right);
|
|
80
|
+
logger.debug(`succeededResults=${JSON.stringify(succeededResults)}`);
|
|
81
|
+
const updatedPackages = succeededResults
|
|
87
82
|
.filter(({ updated }) => updated)
|
|
88
83
|
.map(({ outdatedPackage }) => outdatedPackage);
|
|
89
84
|
logger.debug(`updatedPackages=${JSON.stringify(updatedPackages)}`);
|
|
90
|
-
const skippedPackages =
|
|
85
|
+
const skippedPackages = succeededResults
|
|
91
86
|
.filter(({ skipped }) => skipped)
|
|
92
87
|
.map(({ outdatedPackage }) => outdatedPackage);
|
|
93
88
|
logger.debug(`skippedPackages=${JSON.stringify(skippedPackages)}`);
|
|
94
|
-
|
|
89
|
+
const failedResults = results.filter(Either_1.isLeft).map(({ left }) => left);
|
|
90
|
+
logger.debug(`failedResults=${JSON.stringify(failedResults)}`);
|
|
91
|
+
const failedPackages = failedResults.map(({ outdatedPackage }) => outdatedPackage);
|
|
92
|
+
logger.debug(`failedPackages=${JSON.stringify(failedPackages)}`);
|
|
93
|
+
// TODO: show as table
|
|
94
|
+
logger.info(`Processed ${succeededResults.length + failedPackages.length} packages:
|
|
95
|
+
- ${updatedPackages.length} packages has updated: ${updatedPackages.map(({ name }) => name).join(',')}
|
|
96
|
+
- ${skippedPackages.length} packages has skipped: ${skippedPackages.map(({ name }) => name).join(',')}
|
|
97
|
+
- ${failedPackages.length} packages has failed: ${failedPackages.map(({ name }) => name).join(',')}`);
|
|
95
98
|
};
|
|
96
99
|
exports.main = main;
|
package/dist/options/Options.js
CHANGED
|
@@ -4,19 +4,13 @@ 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
|
-
|
|
15
|
-
|
|
16
|
-
}),
|
|
17
|
-
(0, io_ts_1.partial)({
|
|
18
|
-
gitUserEmail: io_ts_1.string,
|
|
19
|
-
gitUserName: io_ts_1.string
|
|
20
|
-
})
|
|
21
|
-
]);
|
|
7
|
+
const Options = (0, io_ts_1.type)({
|
|
8
|
+
branchName: io_ts_1.string,
|
|
9
|
+
commitMessage: io_ts_1.string,
|
|
10
|
+
githubToken: io_ts_1.string,
|
|
11
|
+
logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Error), (0, io_ts_1.literal)(logger_1.LogLevel.Info), (0, io_ts_1.literal)(logger_1.LogLevel.Debug)]),
|
|
12
|
+
packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)(package_manager_1.PackageManagerName.Npm), (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Yarn)]),
|
|
13
|
+
pullRequestBody: io_ts_1.string,
|
|
14
|
+
pullRequestTitle: io_ts_1.string
|
|
15
|
+
});
|
|
22
16
|
exports.isOptions = Options.is;
|
|
@@ -12,11 +12,10 @@ const initOptions = () => {
|
|
|
12
12
|
.version(app_1.app.version)
|
|
13
13
|
.option('--branch-name <value>', 'Branch name template', 'npm-update-package/{{{packageName}}}/v{{newVersion}}')
|
|
14
14
|
.option('--commit-message <value>', 'Commit message template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}')
|
|
15
|
-
.option('--git-user-email <value>', 'User email of commit')
|
|
16
|
-
.option('--git-user-name <value>', 'User name of commit')
|
|
17
15
|
.requiredOption('--github-token <value>', 'GitHub token')
|
|
18
16
|
.addOption(new commander_1.Option('--log-level <value>', 'Log level to show')
|
|
19
17
|
.choices([
|
|
18
|
+
logger_1.LogLevel.Error,
|
|
20
19
|
logger_1.LogLevel.Info,
|
|
21
20
|
logger_1.LogLevel.Debug
|
|
22
21
|
])
|
|
File without changes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OutdatedPackageProcessor = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
4
5
|
// TODO: add test
|
|
5
6
|
class OutdatedPackageProcessor {
|
|
6
|
-
constructor({
|
|
7
|
-
this.committer = committer;
|
|
7
|
+
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator }) {
|
|
8
8
|
this.git = git;
|
|
9
9
|
this.ncu = ncu;
|
|
10
10
|
this.packageManager = packageManager;
|
|
@@ -22,35 +22,49 @@ class OutdatedPackageProcessor {
|
|
|
22
22
|
this.logger.debug(`branchName=${branchName}`);
|
|
23
23
|
if (this.remoteBranchExistenceChecker.check(branchName)) {
|
|
24
24
|
this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
25
|
-
return {
|
|
25
|
+
return (0, Either_1.right)({
|
|
26
26
|
outdatedPackage,
|
|
27
27
|
skipped: true
|
|
28
|
-
};
|
|
28
|
+
});
|
|
29
29
|
}
|
|
30
30
|
await this.git.createBranch(branchName);
|
|
31
31
|
this.logger.info(`${branchName} branch has created.`);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
try {
|
|
33
|
+
try {
|
|
34
|
+
const updatedPackages = await this.ncu.update(outdatedPackage);
|
|
35
|
+
if (updatedPackages.length !== 1) {
|
|
36
|
+
throw new Error(`Failed to update ${outdatedPackage.name}.`);
|
|
37
|
+
}
|
|
38
|
+
await this.packageManager.install();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
this.logger.error(error);
|
|
42
|
+
return (0, Either_1.left)({
|
|
43
|
+
outdatedPackage,
|
|
44
|
+
error
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
48
|
+
await this.git.add(...this.packageManager.packageFiles);
|
|
49
|
+
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
50
|
+
this.logger.debug(`message=${message}`);
|
|
51
|
+
await this.git.commit(message);
|
|
52
|
+
await this.git.push(branchName);
|
|
53
|
+
await this.pullRequestCreator.create({
|
|
54
|
+
outdatedPackage,
|
|
55
|
+
branchName
|
|
56
|
+
});
|
|
57
|
+
return (0, Either_1.right)({
|
|
58
|
+
outdatedPackage,
|
|
59
|
+
updated: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await this.git.restore(...this.packageManager.packageFiles);
|
|
64
|
+
await this.git.switch('-');
|
|
65
|
+
await this.git.removeBranch(branchName);
|
|
66
|
+
this.logger.info(`${branchName} branch has removed.`);
|
|
35
67
|
}
|
|
36
|
-
await this.packageManager.install();
|
|
37
|
-
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
38
|
-
await this.git.add(...this.packageManager.packageFiles);
|
|
39
|
-
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
40
|
-
this.logger.debug(`message=${message}`);
|
|
41
|
-
await this.committer.commit(message);
|
|
42
|
-
await this.git.push(branchName);
|
|
43
|
-
await this.pullRequestCreator.create({
|
|
44
|
-
outdatedPackage,
|
|
45
|
-
branchName
|
|
46
|
-
});
|
|
47
|
-
await this.git.checkout('-');
|
|
48
|
-
await this.git.removeBranch(branchName);
|
|
49
|
-
this.logger.info(`${branchName} branch has removed.`);
|
|
50
|
-
return {
|
|
51
|
-
outdatedPackage,
|
|
52
|
-
updated: true
|
|
53
|
-
};
|
|
54
68
|
}
|
|
55
69
|
}
|
|
56
70
|
exports.OutdatedPackageProcessor = OutdatedPackageProcessor;
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "CLI tool for creating pull request to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
7
7
|
"clean": "rimraf dist",
|
|
8
8
|
"lint": "eslint '**/*.{js,ts}'",
|
|
9
|
+
"prebuild": "npm run clean",
|
|
9
10
|
"prepare": "husky install",
|
|
10
|
-
"prepublish": "npm-run-all
|
|
11
|
+
"prepublish": "npm-run-all lint test build",
|
|
11
12
|
"start": "ts-node src/bin.ts",
|
|
12
13
|
"test": "jest --passWithNoTests"
|
|
13
14
|
},
|
|
@@ -35,13 +36,13 @@
|
|
|
35
36
|
"@types/node": "12.20.15",
|
|
36
37
|
"@types/parse-github-url": "1.0.0",
|
|
37
38
|
"@types/semver": "7.3.9",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "5.5.0",
|
|
39
40
|
"eslint": "8.3.0",
|
|
40
41
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
41
42
|
"eslint-plugin-import": "2.25.3",
|
|
42
43
|
"eslint-plugin-jest": "25.3.0",
|
|
43
44
|
"eslint-plugin-node": "11.1.0",
|
|
44
|
-
"eslint-plugin-promise": "5.
|
|
45
|
+
"eslint-plugin-promise": "5.2.0",
|
|
45
46
|
"eslint-plugin-tsdoc": "0.2.14",
|
|
46
47
|
"husky": "7.0.4",
|
|
47
48
|
"jest": "27.0.6",
|
package/dist/git/Committer.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Committer = void 0;
|
|
4
|
-
// TODO: add test
|
|
5
|
-
class Committer {
|
|
6
|
-
constructor({ git, user }) {
|
|
7
|
-
this.git = git;
|
|
8
|
-
this.user = user;
|
|
9
|
-
}
|
|
10
|
-
async commit(message) {
|
|
11
|
-
var _a, _b;
|
|
12
|
-
let name;
|
|
13
|
-
if (((_a = this.user) === null || _a === void 0 ? void 0 : _a.name) !== undefined) {
|
|
14
|
-
name = await this.git.getConfig('user.name');
|
|
15
|
-
await this.git.setConfig('user.name', this.user.name);
|
|
16
|
-
}
|
|
17
|
-
let email;
|
|
18
|
-
if (((_b = this.user) === null || _b === void 0 ? void 0 : _b.email) !== undefined) {
|
|
19
|
-
email = await this.git.getConfig('user.email');
|
|
20
|
-
await this.git.setConfig('user.email', this.user.email);
|
|
21
|
-
}
|
|
22
|
-
await this.git.commit(message);
|
|
23
|
-
if (name !== undefined) {
|
|
24
|
-
await this.git.setConfig('user.name', name);
|
|
25
|
-
}
|
|
26
|
-
if (email !== undefined) {
|
|
27
|
-
await this.git.setConfig('user.email', email);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.Committer = Committer;
|