npm-update-package 0.31.2 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/package.json +7 -10
  2. package/dist/src/bin.js +24 -0
  3. package/dist/src/core/FailedResult.js +2 -0
  4. package/dist/src/core/OutdatedPackage.js +2 -0
  5. package/dist/src/core/OutdatedPackageProcessor.js +79 -0
  6. package/dist/src/core/OutdatedPackagesProcessor.js +20 -0
  7. package/dist/src/core/SucceededResult.js +2 -0
  8. package/dist/src/core/index.js +17 -0
  9. package/dist/src/file/index.js +13 -0
  10. package/dist/src/file/readFile.js +12 -0
  11. package/dist/src/git/CommitMessageCreator.js +22 -0
  12. package/dist/src/git/Git.js +51 -0
  13. package/dist/src/git/GitRepository.js +41 -0
  14. package/dist/src/git/createBranchName.js +9 -0
  15. package/dist/src/git/index.js +16 -0
  16. package/dist/src/github/GitHub.js +94 -0
  17. package/dist/src/github/branch/finder/BranchFinder.js +12 -0
  18. package/dist/src/github/branch/finder/index.js +13 -0
  19. package/dist/src/github/branch/index.js +13 -0
  20. package/dist/src/github/createGitHub.js +13 -0
  21. package/dist/src/github/createOctokit.js +26 -0
  22. package/dist/src/github/errors/NotFoundError.js +10 -0
  23. package/dist/src/github/errors/index.js +13 -0
  24. package/dist/src/github/index.js +17 -0
  25. package/dist/src/github/label/creator/LabelCreator.js +46 -0
  26. package/dist/src/github/label/creator/index.js +13 -0
  27. package/dist/src/github/label/index.js +13 -0
  28. package/dist/src/github/pull-request/closer/PullRequestCloser.js +21 -0
  29. package/dist/src/github/pull-request/closer/index.js +13 -0
  30. package/dist/src/github/pull-request/creator/PullRequestCreator.js +45 -0
  31. package/dist/src/github/pull-request/creator/PullRequestTitleCreator.js +22 -0
  32. package/dist/src/github/pull-request/creator/createPullRequestBody.js +39 -0
  33. package/dist/src/github/pull-request/creator/index.js +14 -0
  34. package/dist/src/github/pull-request/finder/PullRequestFinder.js +27 -0
  35. package/dist/src/github/pull-request/finder/index.js +13 -0
  36. package/dist/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.js +7 -0
  37. package/dist/src/github/pull-request/index.js +15 -0
  38. package/dist/src/github/pull-request/metadata/PullRequestMetadata.js +15 -0
  39. package/dist/src/github/pull-request/metadata/createPullRequestMetadata.js +19 -0
  40. package/dist/src/github/pull-request/metadata/extractPullRequestMetadata.js +17 -0
  41. package/dist/src/github/pull-request/metadata/index.js +15 -0
  42. package/dist/src/json/index.js +13 -0
  43. package/dist/src/json/toJSON.js +14 -0
  44. package/dist/src/logger/LogLevel.js +15 -0
  45. package/dist/src/logger/Logger.js +2 -0
  46. package/dist/src/logger/createLogger.js +11 -0
  47. package/dist/src/logger/index.js +15 -0
  48. package/dist/src/main.js +112 -0
  49. package/dist/src/ncu/Ncu.js +71 -0
  50. package/dist/src/ncu/NcuResult.js +6 -0
  51. package/dist/src/ncu/index.js +13 -0
  52. package/dist/src/options/CLIOption.js +2 -0
  53. package/dist/src/options/OptionType.js +10 -0
  54. package/dist/src/options/Options.js +30 -0
  55. package/dist/src/options/cliOptions.js +61 -0
  56. package/dist/src/options/index.js +14 -0
  57. package/dist/src/options/initOptions.js +25 -0
  58. package/dist/src/options/toCommanderOption.js +32 -0
  59. package/dist/src/package-json/PackageMetadata.js +18 -0
  60. package/dist/src/package-json/PackageMetadataDependencies.js +6 -0
  61. package/dist/src/package-json/index.js +14 -0
  62. package/dist/src/package-json/parsePackageJson.js +15 -0
  63. package/dist/src/package-manager/Npm.js +18 -0
  64. package/dist/src/package-manager/PackageManager.js +2 -0
  65. package/dist/src/package-manager/PackageManagerName.js +10 -0
  66. package/dist/src/package-manager/Yarn.js +18 -0
  67. package/dist/src/package-manager/createPackageManager.js +15 -0
  68. package/dist/src/package-manager/index.js +17 -0
  69. package/dist/src/semver/SemVer.js +25 -0
  70. package/dist/src/semver/SemVerLevel.js +11 -0
  71. package/dist/src/semver/compareSemVers.js +16 -0
  72. package/dist/src/semver/index.js +15 -0
  73. package/dist/src/terminal/Terminal.js +14 -0
  74. package/dist/src/terminal/index.js +13 -0
  75. package/package.json +7 -10
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.31.2",
3
+ "version": "0.32.0",
4
4
  "description": "CLI tool for creating pull requests to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -12,9 +12,6 @@
12
12
  "start": "ts-node src/bin.ts",
13
13
  "test": "jest --passWithNoTests"
14
14
  },
15
- "files": [
16
- "/dist"
17
- ],
18
15
  "bin": "dist/src/bin.js",
19
16
  "dependencies": {
20
17
  "@octokit/rest": "18.12.0",
@@ -25,7 +22,7 @@
25
22
  "io-ts": "2.2.16",
26
23
  "log4js": "6.4.1",
27
24
  "mustache": "4.1.0",
28
- "npm-check-updates": "12.2.1",
25
+ "npm-check-updates": "12.4.0",
29
26
  "parse-github-url": "1.0.2",
30
27
  "semver": "7.3.5",
31
28
  "type-guards": "0.15.0"
@@ -38,21 +35,21 @@
38
35
  "@types/node": "12.20.40",
39
36
  "@types/parse-github-url": "1.0.0",
40
37
  "@types/semver": "7.3.9",
41
- "@typescript-eslint/eslint-plugin": "5.10.1",
42
- "eslint": "8.7.0",
38
+ "@typescript-eslint/eslint-plugin": "5.12.0",
39
+ "eslint": "8.9.0",
43
40
  "eslint-config-standard-with-typescript": "21.0.1",
44
41
  "eslint-plugin-import": "2.25.4",
45
- "eslint-plugin-jest": "26.0.0",
42
+ "eslint-plugin-jest": "26.1.1",
46
43
  "eslint-plugin-node": "11.1.0",
47
44
  "eslint-plugin-promise": "6.0.0",
48
45
  "eslint-plugin-tsdoc": "0.2.14",
49
46
  "husky": "7.0.4",
50
47
  "jest": "27.4.7",
51
- "lint-staged": "12.3.1",
48
+ "lint-staged": "12.3.4",
52
49
  "npm-run-all": "4.1.5",
53
50
  "rimraf": "3.0.2",
54
51
  "ts-jest": "27.1.3",
55
- "ts-node": "10.4.0",
52
+ "ts-node": "10.5.0",
56
53
  "typescript": "4.5.5",
57
54
  "utility-types": "3.10.0"
58
55
  },
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const package_json_1 = __importDefault(require("../package.json"));
8
+ const logger_1 = require("./logger");
9
+ const main_1 = require("./main");
10
+ const options_1 = require("./options");
11
+ const options = (0, options_1.initOptions)();
12
+ const logger = (0, logger_1.createLogger)(options.logLevel);
13
+ logger.info(`Start ${package_json_1.default.name} v${package_json_1.default.version}`);
14
+ (0, main_1.main)({
15
+ options,
16
+ logger
17
+ })
18
+ .then(() => {
19
+ logger.info(`End ${package_json_1.default.name} v${package_json_1.default.version}`);
20
+ })
21
+ .catch((error) => {
22
+ logger.fatal(error);
23
+ throw error;
24
+ });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutdatedPackageProcessor = void 0;
4
+ const Either_1 = require("fp-ts/lib/Either");
5
+ const git_1 = require("../git");
6
+ // TODO: add test
7
+ class OutdatedPackageProcessor {
8
+ constructor({ git, ncu, packageManager, pullRequestCreator, branchFinder, logger, commitMessageCreator, pullRequestFinder, pullRequestCloser }) {
9
+ this.git = git;
10
+ this.ncu = ncu;
11
+ this.packageManager = packageManager;
12
+ this.pullRequestCreator = pullRequestCreator;
13
+ this.branchFinder = branchFinder;
14
+ this.logger = logger;
15
+ this.commitMessageCreator = commitMessageCreator;
16
+ this.pullRequestFinder = pullRequestFinder;
17
+ this.pullRequestCloser = pullRequestCloser;
18
+ }
19
+ /**
20
+ * Don't run in parallel because it includes file operations.
21
+ */
22
+ async process(outdatedPackage) {
23
+ const branchName = (0, git_1.createBranchName)(outdatedPackage);
24
+ this.logger.debug(`branchName=${branchName}`);
25
+ if (this.branchFinder.findByName(branchName) !== undefined) {
26
+ this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
27
+ return (0, Either_1.right)({
28
+ outdatedPackage,
29
+ skipped: true
30
+ });
31
+ }
32
+ await this.git.createBranch(branchName);
33
+ this.logger.info(`${branchName} branch has created.`);
34
+ try {
35
+ try {
36
+ const updatedPackages = await this.ncu.update(outdatedPackage);
37
+ if (updatedPackages.length !== 1) {
38
+ throw new Error(`Failed to update ${outdatedPackage.name}.`);
39
+ }
40
+ await this.packageManager.install();
41
+ }
42
+ catch (error) {
43
+ this.logger.error(error);
44
+ return (0, Either_1.left)({
45
+ outdatedPackage,
46
+ error
47
+ });
48
+ }
49
+ this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
50
+ await this.git.add(this.packageManager.packageFile, this.packageManager.lockFile);
51
+ const message = this.commitMessageCreator.create(outdatedPackage);
52
+ this.logger.debug(`message=${message}`);
53
+ await this.git.commit(message);
54
+ await this.git.push(branchName);
55
+ const pullRequest = await this.pullRequestCreator.create({
56
+ outdatedPackage,
57
+ branchName
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
+ }));
66
+ return (0, Either_1.right)({
67
+ outdatedPackage,
68
+ created: true
69
+ });
70
+ }
71
+ finally {
72
+ await this.git.restore(this.packageManager.packageFile, this.packageManager.lockFile);
73
+ await this.git.switch('-');
74
+ await this.git.removeBranch(branchName);
75
+ this.logger.info(`${branchName} branch has removed.`);
76
+ }
77
+ }
78
+ }
79
+ exports.OutdatedPackageProcessor = OutdatedPackageProcessor;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutdatedPackagesProcessor = void 0;
4
+ // TODO: add test
5
+ class OutdatedPackagesProcessor {
6
+ constructor({ outdatedPackageProcessor, logger }) {
7
+ this.outdatedPackageProcessor = outdatedPackageProcessor;
8
+ this.logger = logger;
9
+ }
10
+ async process(outdatedPackages) {
11
+ const results = [];
12
+ for (const outdatedPackage of outdatedPackages) {
13
+ this.logger.debug(`outdatedPackage=${JSON.stringify(outdatedPackage)}`);
14
+ const result = await this.outdatedPackageProcessor.process(outdatedPackage);
15
+ results.push(result);
16
+ }
17
+ return results;
18
+ }
19
+ }
20
+ exports.OutdatedPackagesProcessor = OutdatedPackagesProcessor;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./FailedResult"), exports);
14
+ __exportStar(require("./OutdatedPackage"), exports);
15
+ __exportStar(require("./OutdatedPackageProcessor"), exports);
16
+ __exportStar(require("./OutdatedPackagesProcessor"), exports);
17
+ __exportStar(require("./SucceededResult"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./readFile"), exports);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readFile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ // TODO: add test
9
+ const readFile = async (path) => {
10
+ return await fs_1.default.promises.readFile(path, 'utf8');
11
+ };
12
+ exports.readFile = readFile;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommitMessageCreator = void 0;
4
+ const mustache_1 = require("mustache");
5
+ class CommitMessageCreator {
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 level = outdatedPackage.level;
14
+ return (0, mustache_1.render)(this.template, {
15
+ packageName,
16
+ currentVersion,
17
+ newVersion,
18
+ level
19
+ });
20
+ }
21
+ }
22
+ exports.CommitMessageCreator = CommitMessageCreator;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Git = void 0;
4
+ const GitRepository_1 = require("./GitRepository");
5
+ // TODO: add test
6
+ class Git {
7
+ constructor(terminal) {
8
+ this.terminal = terminal;
9
+ }
10
+ async add(...files) {
11
+ await this.terminal.run('git', 'add', ...files);
12
+ }
13
+ async commit(message) {
14
+ await this.terminal.run('git', 'commit', '--message', message);
15
+ }
16
+ async createBranch(branchName) {
17
+ await this.terminal.run('git', 'checkout', '-b', branchName);
18
+ }
19
+ async getConfig(key) {
20
+ const { stdout } = await this.terminal.run('git', 'config', key);
21
+ return stdout.trim();
22
+ }
23
+ async getCurrentBranch() {
24
+ const { stdout } = await this.terminal.run('git', 'rev-parse', '--abbrev-ref', 'HEAD');
25
+ return stdout.trim();
26
+ }
27
+ async getRemoteUrl() {
28
+ const { stdout } = await this.terminal.run('git', 'remote', 'get-url', '--push', 'origin');
29
+ return stdout.trim();
30
+ }
31
+ async getRepository() {
32
+ const url = await this.getRemoteUrl();
33
+ return GitRepository_1.GitRepository.of(url);
34
+ }
35
+ async push(branchName) {
36
+ await this.terminal.run('git', 'push', 'origin', branchName);
37
+ }
38
+ async removeBranch(branchName) {
39
+ await this.terminal.run('git', 'branch', '-D', branchName);
40
+ }
41
+ async restore(...files) {
42
+ await this.terminal.run('git', 'checkout', ...files);
43
+ }
44
+ async setConfig(key, value) {
45
+ await this.terminal.run('git', 'config', key, value);
46
+ }
47
+ async switch(branchName) {
48
+ await this.terminal.run('git', 'checkout', branchName);
49
+ }
50
+ }
51
+ exports.Git = Git;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GitRepository = void 0;
7
+ const parse_github_url_1 = __importDefault(require("parse-github-url"));
8
+ class GitRepository {
9
+ constructor({ host, owner, name }) {
10
+ this.host = host;
11
+ this.owner = owner;
12
+ this.name = name;
13
+ }
14
+ static of(url) {
15
+ const parsed = (0, parse_github_url_1.default)(url);
16
+ if (parsed === null) {
17
+ throw new Error(`Failed to parse url. url=${url}`);
18
+ }
19
+ const { host, owner, name } = parsed;
20
+ if (host === null || owner === null || name === null) {
21
+ throw new Error(`Failed to parse url. url=${url}`);
22
+ }
23
+ return new GitRepository({
24
+ host,
25
+ owner,
26
+ name
27
+ });
28
+ }
29
+ get apiEndPoint() {
30
+ if (this.isGitHubDotCom) {
31
+ return 'https://api.github.com';
32
+ }
33
+ else {
34
+ return `https://${this.host}/api/v3`;
35
+ }
36
+ }
37
+ get isGitHubDotCom() {
38
+ return this.host === 'github.com';
39
+ }
40
+ }
41
+ exports.GitRepository = GitRepository;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBranchName = void 0;
4
+ const createBranchName = (outdatedPackage) => {
5
+ const packageName = outdatedPackage.name;
6
+ const newVersion = outdatedPackage.newVersion.version;
7
+ return `npm-update-package/${packageName}/v${newVersion}`;
8
+ };
9
+ exports.createBranchName = createBranchName;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./CommitMessageCreator"), exports);
14
+ __exportStar(require("./createBranchName"), exports);
15
+ __exportStar(require("./Git"), exports);
16
+ __exportStar(require("./GitRepository"), exports);
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitHub = void 0;
4
+ // TODO: add test
5
+ class GitHub {
6
+ constructor(octokit) {
7
+ this.octokit = octokit;
8
+ }
9
+ async addLabels({ owner, repo, issueNumber, labels }) {
10
+ await this.octokit.issues.addLabels({
11
+ owner,
12
+ repo,
13
+ issue_number: issueNumber,
14
+ labels
15
+ });
16
+ }
17
+ async closePullRequest({ owner, repo, pullNumber }) {
18
+ await this.octokit.pulls.update({
19
+ owner,
20
+ repo,
21
+ pull_number: pullNumber,
22
+ state: 'closed'
23
+ });
24
+ }
25
+ async createLabel({ owner, repo, name, description, color }) {
26
+ await this.octokit.issues.createLabel({
27
+ owner,
28
+ repo,
29
+ name,
30
+ description,
31
+ color
32
+ });
33
+ }
34
+ async createPullRequest({ owner, repo, baseBranch, headBranch, title, body }) {
35
+ const { data } = await this.octokit.pulls.create({
36
+ owner,
37
+ repo,
38
+ base: baseBranch,
39
+ head: headBranch,
40
+ title,
41
+ body
42
+ });
43
+ return data;
44
+ }
45
+ async deleteBranch({ owner, repo, branch }) {
46
+ await this.octokit.git.deleteRef({
47
+ owner,
48
+ repo,
49
+ ref: `heads/${branch}`
50
+ });
51
+ }
52
+ // TODO: fetch all branches with page option
53
+ async fetchBranches({ owner, repo }) {
54
+ const { data } = await this.octokit.repos.listBranches({
55
+ owner,
56
+ repo,
57
+ per_page: 100
58
+ });
59
+ return data;
60
+ }
61
+ async fetchLabel({ owner, repo, name }) {
62
+ const { data } = await this.octokit.issues.getLabel({
63
+ owner,
64
+ repo,
65
+ name
66
+ });
67
+ return data;
68
+ }
69
+ // TODO: fetch all pull requests with page option
70
+ async fetchPullRequests({ owner, repo }) {
71
+ const { data } = await this.octokit.pulls.list({
72
+ owner,
73
+ repo,
74
+ per_page: 100
75
+ });
76
+ return data;
77
+ }
78
+ async fetchRepository({ owner, repo }) {
79
+ const { data } = await this.octokit.repos.get({
80
+ owner,
81
+ repo
82
+ });
83
+ return data;
84
+ }
85
+ async requestReviewers({ owner, repo, pullNumber, reviewers }) {
86
+ await this.octokit.pulls.requestReviewers({
87
+ owner,
88
+ repo,
89
+ pull_number: pullNumber,
90
+ reviewers
91
+ });
92
+ }
93
+ }
94
+ exports.GitHub = GitHub;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BranchFinder = void 0;
4
+ class BranchFinder {
5
+ constructor(branches) {
6
+ this.branches = branches;
7
+ }
8
+ findByName(branchName) {
9
+ return this.branches.find(({ name }) => name === branchName);
10
+ }
11
+ }
12
+ exports.BranchFinder = BranchFinder;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./BranchFinder"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./finder"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createGitHub = void 0;
4
+ const createOctokit_1 = require("./createOctokit");
5
+ const GitHub_1 = require("./GitHub");
6
+ const createGitHub = ({ repository, token }) => {
7
+ const octokit = (0, createOctokit_1.createOctokit)({
8
+ repository,
9
+ token
10
+ });
11
+ return new GitHub_1.GitHub(octokit);
12
+ };
13
+ exports.createGitHub = createGitHub;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createOctokit = void 0;
7
+ const rest_1 = require("@octokit/rest");
8
+ const package_json_1 = __importDefault(require("../../package.json"));
9
+ const createOctokit = ({ repository, token }) => {
10
+ const auth = `token ${token}`;
11
+ const userAgent = `${package_json_1.default.name}/${package_json_1.default.version}`;
12
+ if (repository.isGitHubDotCom) {
13
+ return new rest_1.Octokit({
14
+ auth,
15
+ userAgent
16
+ });
17
+ }
18
+ else {
19
+ return new rest_1.Octokit({
20
+ auth,
21
+ userAgent,
22
+ baseUrl: repository.apiEndPoint
23
+ });
24
+ }
25
+ };
26
+ exports.createOctokit = createOctokit;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNotFoundError = void 0;
4
+ const request_error_1 = require("@octokit/request-error");
5
+ const http_status_codes_1 = require("http-status-codes");
6
+ // TODO: Add test
7
+ const isNotFoundError = (value) => {
8
+ return value instanceof request_error_1.RequestError && value.status === http_status_codes_1.StatusCodes.NOT_FOUND;
9
+ };
10
+ exports.isNotFoundError = isNotFoundError;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./NotFoundError"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./branch"), exports);
14
+ __exportStar(require("./createGitHub"), exports);
15
+ __exportStar(require("./errors"), exports);
16
+ __exportStar(require("./label"), exports);
17
+ __exportStar(require("./pull-request"), exports);
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LabelCreator = void 0;
4
+ const errors_1 = require("../../errors");
5
+ // TODO: Add test
6
+ class LabelCreator {
7
+ constructor({ github, gitRepo, logger }) {
8
+ this.github = github;
9
+ this.gitRepo = gitRepo;
10
+ this.logger = logger;
11
+ }
12
+ async create({ name, description, color }) {
13
+ const label = await this.fetchLabel(name);
14
+ if (label !== undefined) {
15
+ this.logger.info(`Skip creating ${name} label because it already exists.`);
16
+ return;
17
+ }
18
+ await this.github.createLabel({
19
+ owner: this.gitRepo.owner,
20
+ repo: this.gitRepo.name,
21
+ name,
22
+ description,
23
+ color
24
+ });
25
+ this.logger.info(`${name} label has created.`);
26
+ }
27
+ async fetchLabel(name) {
28
+ try {
29
+ return await this.github.fetchLabel({
30
+ owner: this.gitRepo.owner,
31
+ repo: this.gitRepo.name,
32
+ name
33
+ });
34
+ }
35
+ catch (e) {
36
+ if ((0, errors_1.isNotFoundError)(e)) {
37
+ this.logger.warn(e);
38
+ return undefined;
39
+ }
40
+ else {
41
+ throw e;
42
+ }
43
+ }
44
+ }
45
+ }
46
+ exports.LabelCreator = LabelCreator;