npm-update-package 0.31.3 → 0.31.4

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 (105) hide show
  1. package/dist/package.json +4 -4
  2. package/package.json +4 -4
  3. package/.eslintignore +0 -3
  4. package/.eslintrc.js +0 -23
  5. package/.github/renovate.json +0 -15
  6. package/.github/workflows/eslint.yml +0 -14
  7. package/.github/workflows/test.yml +0 -20
  8. package/.husky/pre-commit +0 -4
  9. package/.nvmrc +0 -1
  10. package/jest.config.ts +0 -12
  11. package/lint-staged.config.js +0 -4
  12. package/npm-update-package.code-workspace +0 -10
  13. package/src/bin.ts +0 -22
  14. package/src/core/FailedResult.ts +0 -6
  15. package/src/core/OutdatedPackage.ts +0 -11
  16. package/src/core/OutdatedPackageProcessor.ts +0 -136
  17. package/src/core/OutdatedPackagesProcessor.ts +0 -35
  18. package/src/core/SucceededResult.ts +0 -7
  19. package/src/core/index.ts +0 -5
  20. package/src/file/index.ts +0 -1
  21. package/src/file/readFile.ts +0 -6
  22. package/src/git/CommitMessageCreator.test.ts +0 -17
  23. package/src/git/CommitMessageCreator.ts +0 -19
  24. package/src/git/Git.ts +0 -59
  25. package/src/git/GitRepository.test.ts +0 -82
  26. package/src/git/GitRepository.ts +0 -57
  27. package/src/git/createBranchName.test.ts +0 -14
  28. package/src/git/createBranchName.ts +0 -7
  29. package/src/git/index.ts +0 -4
  30. package/src/github/GitHub.ts +0 -198
  31. package/src/github/branch/finder/BranchFinder.test.ts +0 -21
  32. package/src/github/branch/finder/BranchFinder.ts +0 -9
  33. package/src/github/branch/finder/index.ts +0 -1
  34. package/src/github/branch/index.ts +0 -1
  35. package/src/github/createGitHub.test.ts +0 -16
  36. package/src/github/createGitHub.ts +0 -17
  37. package/src/github/createOctokit.test.ts +0 -27
  38. package/src/github/createOctokit.ts +0 -27
  39. package/src/github/errors/NotFoundError.ts +0 -11
  40. package/src/github/errors/index.ts +0 -1
  41. package/src/github/index.ts +0 -5
  42. package/src/github/label/creator/LabelCreator.ts +0 -71
  43. package/src/github/label/creator/index.ts +0 -1
  44. package/src/github/label/index.ts +0 -1
  45. package/src/github/pull-request/closer/PullRequestCloser.test.ts +0 -53
  46. package/src/github/pull-request/closer/PullRequestCloser.ts +0 -21
  47. package/src/github/pull-request/closer/index.ts +0 -1
  48. package/src/github/pull-request/creator/PullRequestCreator.test.ts +0 -98
  49. package/src/github/pull-request/creator/PullRequestCreator.ts +0 -84
  50. package/src/github/pull-request/creator/PullRequestTitleCreator.test.ts +0 -17
  51. package/src/github/pull-request/creator/PullRequestTitleCreator.ts +0 -19
  52. package/src/github/pull-request/creator/createPullRequestBody.test.ts +0 -47
  53. package/src/github/pull-request/creator/createPullRequestBody.ts +0 -35
  54. package/src/github/pull-request/creator/index.ts +0 -2
  55. package/src/github/pull-request/finder/PullRequestFinder.ts +0 -27
  56. package/src/github/pull-request/finder/index.ts +0 -1
  57. package/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.test.ts +0 -24
  58. package/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.ts +0 -5
  59. package/src/github/pull-request/index.ts +0 -3
  60. package/src/github/pull-request/metadata/PullRequestMetadata.ts +0 -22
  61. package/src/github/pull-request/metadata/createPullRequestMetadata.test.ts +0 -31
  62. package/src/github/pull-request/metadata/createPullRequestMetadata.ts +0 -21
  63. package/src/github/pull-request/metadata/extractPullRequestMetadata.test.ts +0 -53
  64. package/src/github/pull-request/metadata/extractPullRequestMetadata.ts +0 -21
  65. package/src/github/pull-request/metadata/index.ts +0 -3
  66. package/src/json/index.ts +0 -1
  67. package/src/json/toJSON.test.ts +0 -65
  68. package/src/json/toJSON.ts +0 -13
  69. package/src/logger/LogLevel.ts +0 -13
  70. package/src/logger/Logger.ts +0 -1
  71. package/src/logger/createLogger.ts +0 -10
  72. package/src/logger/index.ts +0 -3
  73. package/src/main.ts +0 -149
  74. package/src/ncu/Ncu.ts +0 -84
  75. package/src/ncu/NcuResult.ts +0 -10
  76. package/src/ncu/index.ts +0 -1
  77. package/src/options/CLIOption.ts +0 -19
  78. package/src/options/OptionType.ts +0 -8
  79. package/src/options/Options.ts +0 -40
  80. package/src/options/cliOptions.ts +0 -60
  81. package/src/options/index.ts +0 -2
  82. package/src/options/initOptions.ts +0 -24
  83. package/src/options/toCommanderOption.ts +0 -35
  84. package/src/package-json/PackageMetadata.ts +0 -24
  85. package/src/package-json/PackageMetadataDependencies.ts +0 -10
  86. package/src/package-json/index.ts +0 -2
  87. package/src/package-json/parsePackageJson.ts +0 -15
  88. package/src/package-manager/Npm.ts +0 -17
  89. package/src/package-manager/PackageManager.ts +0 -5
  90. package/src/package-manager/PackageManagerName.ts +0 -8
  91. package/src/package-manager/Yarn.ts +0 -17
  92. package/src/package-manager/createPackageManager.test.ts +0 -27
  93. package/src/package-manager/createPackageManager.ts +0 -20
  94. package/src/package-manager/index.ts +0 -5
  95. package/src/semver/SemVer.test.ts +0 -17
  96. package/src/semver/SemVer.ts +0 -40
  97. package/src/semver/SemVerLevel.ts +0 -9
  98. package/src/semver/compareSemVers.test.ts +0 -21
  99. package/src/semver/compareSemVers.ts +0 -16
  100. package/src/semver/index.ts +0 -3
  101. package/src/terminal/Terminal.ts +0 -12
  102. package/src/terminal/index.ts +0 -1
  103. package/tsconfig.base.json +0 -7
  104. package/tsconfig.build.json +0 -12
  105. package/tsconfig.json +0 -9
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.31.3",
3
+ "version": "0.31.4",
4
4
  "description": "CLI tool for creating pull requests to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -35,8 +35,8 @@
35
35
  "@types/node": "12.20.40",
36
36
  "@types/parse-github-url": "1.0.0",
37
37
  "@types/semver": "7.3.9",
38
- "@typescript-eslint/eslint-plugin": "5.10.1",
39
- "eslint": "8.7.0",
38
+ "@typescript-eslint/eslint-plugin": "5.10.2",
39
+ "eslint": "8.8.0",
40
40
  "eslint-config-standard-with-typescript": "21.0.1",
41
41
  "eslint-plugin-import": "2.25.4",
42
42
  "eslint-plugin-jest": "26.0.0",
@@ -45,7 +45,7 @@
45
45
  "eslint-plugin-tsdoc": "0.2.14",
46
46
  "husky": "7.0.4",
47
47
  "jest": "27.4.7",
48
- "lint-staged": "12.3.1",
48
+ "lint-staged": "12.3.2",
49
49
  "npm-run-all": "4.1.5",
50
50
  "rimraf": "3.0.2",
51
51
  "ts-jest": "27.1.3",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.31.3",
3
+ "version": "0.31.4",
4
4
  "description": "CLI tool for creating pull requests to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -35,8 +35,8 @@
35
35
  "@types/node": "12.20.40",
36
36
  "@types/parse-github-url": "1.0.0",
37
37
  "@types/semver": "7.3.9",
38
- "@typescript-eslint/eslint-plugin": "5.10.1",
39
- "eslint": "8.7.0",
38
+ "@typescript-eslint/eslint-plugin": "5.10.2",
39
+ "eslint": "8.8.0",
40
40
  "eslint-config-standard-with-typescript": "21.0.1",
41
41
  "eslint-plugin-import": "2.25.4",
42
42
  "eslint-plugin-jest": "26.0.0",
@@ -45,7 +45,7 @@
45
45
  "eslint-plugin-tsdoc": "0.2.14",
46
46
  "husky": "7.0.4",
47
47
  "jest": "27.4.7",
48
- "lint-staged": "12.3.1",
48
+ "lint-staged": "12.3.2",
49
49
  "npm-run-all": "4.1.5",
50
50
  "rimraf": "3.0.2",
51
51
  "ts-jest": "27.1.3",
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- /coverage
2
- /dist
3
- /node_modules
package/.eslintrc.js DELETED
@@ -1,23 +0,0 @@
1
- module.exports = {
2
- extends: [
3
- 'standard-with-typescript',
4
- 'plugin:jest/recommended'
5
- ],
6
- plugins: [
7
- 'eslint-plugin-tsdoc'
8
- ],
9
- parserOptions: {
10
- project: './tsconfig.json'
11
- },
12
- rules: {
13
- 'import/order': ['error', {
14
- alphabetize: {
15
- order: 'asc',
16
- caseInsensitive: true
17
- }
18
- }],
19
- 'no-console': 'error',
20
- 'sort-imports': 'off',
21
- 'tsdoc/syntax': 'warn'
22
- }
23
- }
@@ -1,15 +0,0 @@
1
- {
2
- "extends": [
3
- "config:base"
4
- ],
5
- "packageRules": [
6
- {
7
- "matchPackageNames": ["@types/node"],
8
- "allowedVersions": "<13"
9
- },
10
- {
11
- "matchPackageNames": ["node"],
12
- "allowedVersions": "<13"
13
- }
14
- ]
15
- }
@@ -1,14 +0,0 @@
1
- name: eslint
2
- on:
3
- pull_request:
4
- branches: [ master ]
5
- jobs:
6
- eslint:
7
- name: runner / eslint
8
- runs-on: ubuntu-latest
9
- steps:
10
- - uses: actions/checkout@v2
11
- - name: eslint
12
- uses: reviewdog/action-eslint@v1
13
- with:
14
- reporter: github-pr-check
@@ -1,20 +0,0 @@
1
- name: test
2
- on:
3
- pull_request:
4
- branches: [ master ]
5
- jobs:
6
- test:
7
- runs-on: ubuntu-latest
8
- strategy:
9
- matrix:
10
- # https://nodejs.org/en/about/releases/
11
- node-version: ['12', '14', '16']
12
- steps:
13
- - uses: actions/checkout@v2
14
- - name: Use Node.js ${{ matrix.node-version }}
15
- uses: actions/setup-node@v2
16
- with:
17
- node-version: ${{ matrix.node-version }}
18
- - run: npm ci
19
- - run: npm run build --if-present
20
- - run: npm test
package/.husky/pre-commit DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- npx lint-staged
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- 12.20.2
package/jest.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import type { Config } from '@jest/types'
2
-
3
- const config: Config.InitialOptions = {
4
- preset: 'ts-jest',
5
- collectCoverage: true,
6
- collectCoverageFrom: [
7
- 'src/**/*.ts',
8
- '!src/**/index.ts'
9
- ]
10
- }
11
-
12
- export default config
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- '*.js': 'eslint',
3
- '*.ts': 'eslint'
4
- }
@@ -1,10 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": "."
5
- }
6
- ],
7
- "settings": {
8
- "typescript.tsdk": "node_modules/typescript/lib"
9
- }
10
- }
package/src/bin.ts DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import pkg from '../package.json'
4
- import { createLogger } from './logger'
5
- import { main } from './main'
6
- import { initOptions } from './options'
7
-
8
- const options = initOptions()
9
- const logger = createLogger(options.logLevel)
10
- logger.info(`Start ${pkg.name} v${pkg.version}`)
11
-
12
- main({
13
- options,
14
- logger
15
- })
16
- .then(() => {
17
- logger.info(`End ${pkg.name} v${pkg.version}`)
18
- })
19
- .catch((error: unknown) => {
20
- logger.fatal(error)
21
- throw error
22
- })
@@ -1,6 +0,0 @@
1
- import type { OutdatedPackage } from './OutdatedPackage'
2
-
3
- export interface FailedResult {
4
- outdatedPackage: OutdatedPackage
5
- error: unknown
6
- }
@@ -1,11 +0,0 @@
1
- import type {
2
- SemVer,
3
- SemVerLevel
4
- } from '../semver'
5
-
6
- export interface OutdatedPackage {
7
- name: string
8
- currentVersion: SemVer
9
- newVersion: SemVer
10
- level: SemVerLevel
11
- }
@@ -1,136 +0,0 @@
1
- import {
2
- left,
3
- right,
4
- type Either
5
- } from 'fp-ts/lib/Either'
6
- import {
7
- createBranchName,
8
- type CommitMessageCreator,
9
- type Git
10
- } from '../git'
11
- import type {
12
- BranchFinder,
13
- PullRequestCloser,
14
- PullRequestCreator,
15
- PullRequestFinder
16
- } from '../github'
17
- import type { Logger } from '../logger'
18
- import type { Ncu } from '../ncu'
19
- import type { PackageManager } from '../package-manager'
20
- import type { FailedResult } from './FailedResult'
21
- import type { OutdatedPackage } from './OutdatedPackage'
22
- import type { SucceededResult } from './SucceededResult'
23
-
24
- // TODO: add test
25
- export class OutdatedPackageProcessor {
26
- private readonly git: Git
27
- private readonly ncu: Ncu
28
- private readonly packageManager: PackageManager
29
- private readonly pullRequestCreator: PullRequestCreator
30
- private readonly branchFinder: BranchFinder
31
- private readonly logger: Logger
32
- private readonly commitMessageCreator: CommitMessageCreator
33
- private readonly pullRequestFinder: PullRequestFinder
34
- private readonly pullRequestCloser: PullRequestCloser
35
-
36
- constructor ({
37
- git,
38
- ncu,
39
- packageManager,
40
- pullRequestCreator,
41
- branchFinder,
42
- logger,
43
- commitMessageCreator,
44
- pullRequestFinder,
45
- pullRequestCloser
46
- }: {
47
- git: Git
48
- ncu: Ncu
49
- packageManager: PackageManager
50
- pullRequestCreator: PullRequestCreator
51
- branchFinder: BranchFinder
52
- logger: Logger
53
- commitMessageCreator: CommitMessageCreator
54
- pullRequestFinder: PullRequestFinder
55
- pullRequestCloser: PullRequestCloser
56
- }) {
57
- this.git = git
58
- this.ncu = ncu
59
- this.packageManager = packageManager
60
- this.pullRequestCreator = pullRequestCreator
61
- this.branchFinder = branchFinder
62
- this.logger = logger
63
- this.commitMessageCreator = commitMessageCreator
64
- this.pullRequestFinder = pullRequestFinder
65
- this.pullRequestCloser = pullRequestCloser
66
- }
67
-
68
- /**
69
- * Don't run in parallel because it includes file operations.
70
- */
71
- async process (outdatedPackage: OutdatedPackage): Promise<Either<FailedResult, SucceededResult>> {
72
- const branchName = createBranchName(outdatedPackage)
73
- this.logger.debug(`branchName=${branchName}`)
74
-
75
- if (this.branchFinder.findByName(branchName) !== undefined) {
76
- this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`)
77
- return right({
78
- outdatedPackage,
79
- skipped: true
80
- })
81
- }
82
-
83
- await this.git.createBranch(branchName)
84
- this.logger.info(`${branchName} branch has created.`)
85
-
86
- try {
87
- try {
88
- const updatedPackages = await this.ncu.update(outdatedPackage)
89
-
90
- if (updatedPackages.length !== 1) {
91
- throw new Error(`Failed to update ${outdatedPackage.name}.`)
92
- }
93
-
94
- await this.packageManager.install()
95
- } catch (error) {
96
- this.logger.error(error)
97
- return left({
98
- outdatedPackage,
99
- error
100
- })
101
- }
102
-
103
- this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`)
104
-
105
- await this.git.add(this.packageManager.packageFile, this.packageManager.lockFile)
106
- const message = this.commitMessageCreator.create(outdatedPackage)
107
- this.logger.debug(`message=${message}`)
108
-
109
- await this.git.commit(message)
110
- await this.git.push(branchName)
111
-
112
- const pullRequest = await this.pullRequestCreator.create({
113
- outdatedPackage,
114
- branchName
115
- })
116
- this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`)
117
-
118
- const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name)
119
- this.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`)
120
-
121
- await Promise.all(pullRequests.map(async (pullRequest) => {
122
- await this.pullRequestCloser.close(pullRequest)
123
- this.logger.info(`Pull request for ${outdatedPackage.name} has closed. ${pullRequest.html_url}`)
124
- }))
125
- return right({
126
- outdatedPackage,
127
- created: true
128
- })
129
- } finally {
130
- await this.git.restore(this.packageManager.packageFile, this.packageManager.lockFile)
131
- await this.git.switch('-')
132
- await this.git.removeBranch(branchName)
133
- this.logger.info(`${branchName} branch has removed.`)
134
- }
135
- }
136
- }
@@ -1,35 +0,0 @@
1
- import type { Either } from 'fp-ts/lib/Either'
2
- import type { Logger } from '../logger'
3
- import type { FailedResult } from './FailedResult'
4
- import type { OutdatedPackage } from './OutdatedPackage'
5
- import type { OutdatedPackageProcessor } from './OutdatedPackageProcessor'
6
- import type { SucceededResult } from './SucceededResult'
7
-
8
- // TODO: add test
9
- export class OutdatedPackagesProcessor {
10
- private readonly outdatedPackageProcessor: OutdatedPackageProcessor
11
- private readonly logger: Logger
12
-
13
- constructor ({
14
- outdatedPackageProcessor,
15
- logger
16
- }: {
17
- outdatedPackageProcessor: OutdatedPackageProcessor
18
- logger: Logger
19
- }) {
20
- this.outdatedPackageProcessor = outdatedPackageProcessor
21
- this.logger = logger
22
- }
23
-
24
- async process (outdatedPackages: OutdatedPackage[]): Promise<Array<Either<FailedResult, SucceededResult>>> {
25
- const results: Array<Either<FailedResult, SucceededResult>> = []
26
-
27
- for (const outdatedPackage of outdatedPackages) {
28
- this.logger.debug(`outdatedPackage=${JSON.stringify(outdatedPackage)}`)
29
- const result = await this.outdatedPackageProcessor.process(outdatedPackage)
30
- results.push(result)
31
- }
32
-
33
- return results
34
- }
35
- }
@@ -1,7 +0,0 @@
1
- import type { OutdatedPackage } from './OutdatedPackage'
2
-
3
- export interface SucceededResult {
4
- outdatedPackage: OutdatedPackage
5
- created?: boolean
6
- skipped?: boolean
7
- }
package/src/core/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './FailedResult'
2
- export * from './OutdatedPackage'
3
- export * from './OutdatedPackageProcessor'
4
- export * from './OutdatedPackagesProcessor'
5
- export * from './SucceededResult'
package/src/file/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './readFile'
@@ -1,6 +0,0 @@
1
- import fs from 'fs'
2
-
3
- // TODO: add test
4
- export const readFile = async (path: string): Promise<string> => {
5
- return await fs.promises.readFile(path, 'utf8')
6
- }
@@ -1,17 +0,0 @@
1
- import { SemVer } from '../semver'
2
- import { CommitMessageCreator } from './CommitMessageCreator'
3
-
4
- describe('CommitMessageCreator', () => {
5
- describe('create', () => {
6
- it('returns commit message', () => {
7
- const commitMessageCreator = new CommitMessageCreator('chore(deps): {{level}} update {{{packageName}}} from {{currentVersion}} to v{{newVersion}}')
8
- const actual = commitMessageCreator.create({
9
- name: '@npm-update-package/example',
10
- currentVersion: SemVer.of('1.0.0'),
11
- newVersion: SemVer.of('2.0.0'),
12
- level: 'major'
13
- })
14
- expect(actual).toBe('chore(deps): major update @npm-update-package/example from 1.0.0 to v2.0.0')
15
- })
16
- })
17
- })
@@ -1,19 +0,0 @@
1
- import { render } from 'mustache'
2
- import type { OutdatedPackage } from '../core'
3
-
4
- export class CommitMessageCreator {
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 level = outdatedPackage.level
12
- return render(this.template, {
13
- packageName,
14
- currentVersion,
15
- newVersion,
16
- level
17
- })
18
- }
19
- }
package/src/git/Git.ts DELETED
@@ -1,59 +0,0 @@
1
- import type { Terminal } from '../terminal'
2
- import { GitRepository } from './GitRepository'
3
-
4
- // TODO: add test
5
- export class Git {
6
- constructor (private readonly terminal: Terminal) {}
7
-
8
- async add (...files: string[]): Promise<void> {
9
- await this.terminal.run('git', 'add', ...files)
10
- }
11
-
12
- async commit (message: string): Promise<void> {
13
- await this.terminal.run('git', 'commit', '--message', message)
14
- }
15
-
16
- async createBranch (branchName: string): Promise<void> {
17
- await this.terminal.run('git', 'checkout', '-b', branchName)
18
- }
19
-
20
- async getConfig (key: string): Promise<string> {
21
- const { stdout } = await this.terminal.run('git', 'config', key)
22
- return stdout.trim()
23
- }
24
-
25
- async getCurrentBranch (): Promise<string> {
26
- const { stdout } = await this.terminal.run('git', 'rev-parse', '--abbrev-ref', 'HEAD')
27
- return stdout.trim()
28
- }
29
-
30
- async getRemoteUrl (): Promise<string> {
31
- const { stdout } = await this.terminal.run('git', 'remote', 'get-url', '--push', 'origin')
32
- return stdout.trim()
33
- }
34
-
35
- async getRepository (): Promise<GitRepository> {
36
- const url = await this.getRemoteUrl()
37
- return GitRepository.of(url)
38
- }
39
-
40
- async push (branchName: string): Promise<void> {
41
- await this.terminal.run('git', 'push', 'origin', branchName)
42
- }
43
-
44
- async removeBranch (branchName: string): Promise<void> {
45
- await this.terminal.run('git', 'branch', '-D', branchName)
46
- }
47
-
48
- async restore (...files: string[]): Promise<void> {
49
- await this.terminal.run('git', 'checkout', ...files)
50
- }
51
-
52
- async setConfig (key: string, value: string): Promise<void> {
53
- await this.terminal.run('git', 'config', key, value)
54
- }
55
-
56
- async switch (branchName: string): Promise<void> {
57
- await this.terminal.run('git', 'checkout', branchName)
58
- }
59
- }
@@ -1,82 +0,0 @@
1
- import { GitRepository } from './GitRepository'
2
-
3
- describe('GitRepository', () => {
4
- describe('of', () => {
5
- describe('returns new GitRepository instance if URL is valid', () => {
6
- type TestCase = [
7
- string,
8
- {
9
- host: string
10
- owner: string
11
- name: string
12
- apiEndPoint: string
13
- isGitHubDotCom: boolean
14
- }
15
- ]
16
- const cases: TestCase[] = [
17
- [
18
- 'https://github.com/npm-update-package/npm-update-package.git',
19
- {
20
- host: 'github.com',
21
- owner: 'npm-update-package',
22
- name: 'npm-update-package',
23
- apiEndPoint: 'https://api.github.com',
24
- isGitHubDotCom: true
25
- }
26
- ],
27
- [
28
- 'git@github.com:npm-update-package/npm-update-package.git',
29
- {
30
- host: 'github.com',
31
- owner: 'npm-update-package',
32
- name: 'npm-update-package',
33
- apiEndPoint: 'https://api.github.com',
34
- isGitHubDotCom: true
35
- }
36
- ],
37
- [
38
- 'https://git.example.com/npm-update-package/npm-update-package.git',
39
- {
40
- host: 'git.example.com',
41
- owner: 'npm-update-package',
42
- name: 'npm-update-package',
43
- apiEndPoint: 'https://git.example.com/api/v3',
44
- isGitHubDotCom: false
45
- }
46
- ],
47
- [
48
- 'git@git.example.com:npm-update-package/npm-update-package.git',
49
- {
50
- host: 'git.example.com',
51
- owner: 'npm-update-package',
52
- name: 'npm-update-package',
53
- apiEndPoint: 'https://git.example.com/api/v3',
54
- isGitHubDotCom: false
55
- }
56
- ]
57
- ]
58
-
59
- it.each<TestCase>(cases)('url=%p', (url, expected) => {
60
- const actual = GitRepository.of(url)
61
- expect(actual).toBeInstanceOf(GitRepository)
62
- expect(actual.host).toBe(expected.host)
63
- expect(actual.owner).toBe(expected.owner)
64
- expect(actual.name).toBe(expected.name)
65
- expect(actual.apiEndPoint).toBe(expected.apiEndPoint)
66
- expect(actual.isGitHubDotCom).toBe(expected.isGitHubDotCom)
67
- })
68
- })
69
-
70
- describe('throws error if URL is invalid', () => {
71
- type TestCase = string
72
- const cases: TestCase[] = [
73
- '',
74
- 'https://example.com/'
75
- ]
76
-
77
- it.each<TestCase>(cases)('url=%p', (url) => {
78
- expect(() => GitRepository.of(url)).toThrow(Error)
79
- })
80
- })
81
- })
82
- })
@@ -1,57 +0,0 @@
1
- import parse from 'parse-github-url'
2
-
3
- export class GitRepository {
4
- readonly host: string
5
- readonly owner: string
6
- readonly name: string
7
-
8
- private constructor ({
9
- host,
10
- owner,
11
- name
12
- }: {
13
- host: string
14
- owner: string
15
- name: string
16
- }) {
17
- this.host = host
18
- this.owner = owner
19
- this.name = name
20
- }
21
-
22
- static of (url: string): GitRepository {
23
- const parsed = parse(url)
24
-
25
- if (parsed === null) {
26
- throw new Error(`Failed to parse url. url=${url}`)
27
- }
28
-
29
- const {
30
- host,
31
- owner,
32
- name
33
- } = parsed
34
-
35
- if (host === null || owner === null || name === null) {
36
- throw new Error(`Failed to parse url. url=${url}`)
37
- }
38
-
39
- return new GitRepository({
40
- host,
41
- owner,
42
- name
43
- })
44
- }
45
-
46
- get apiEndPoint (): string {
47
- if (this.isGitHubDotCom) {
48
- return 'https://api.github.com'
49
- } else {
50
- return `https://${this.host}/api/v3`
51
- }
52
- }
53
-
54
- get isGitHubDotCom (): boolean {
55
- return this.host === 'github.com'
56
- }
57
- }
@@ -1,14 +0,0 @@
1
- import { SemVer } from '../semver'
2
- import { createBranchName } from './createBranchName'
3
-
4
- describe('createBranchName', () => {
5
- it('returns branch name', () => {
6
- const actual = createBranchName({
7
- name: '@npm-update-package/example',
8
- currentVersion: SemVer.of('1.0.0'),
9
- newVersion: SemVer.of('1.2.3'),
10
- level: 'major'
11
- })
12
- expect(actual).toBe('npm-update-package/@npm-update-package/example/v1.2.3')
13
- })
14
- })