npm-update-package 0.1.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 (140) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.js +23 -0
  3. package/.github/renovate.json +15 -0
  4. package/.github/workflows/eslint.yml +14 -0
  5. package/.github/workflows/test.yml +19 -0
  6. package/.husky/pre-commit +4 -0
  7. package/.nvmrc +1 -0
  8. package/LICENSE +22 -0
  9. package/README.md +43 -0
  10. package/dist/app.js +8 -0
  11. package/dist/bin.js +18 -0
  12. package/dist/enums/LogLevel.js +10 -0
  13. package/dist/enums/PackageManagerName.js +10 -0
  14. package/dist/enums/UpdateType.js +11 -0
  15. package/dist/enums/index.js +12 -0
  16. package/dist/git/Committer.js +31 -0
  17. package/dist/git/Git.js +48 -0
  18. package/dist/git/GitRepository.js +41 -0
  19. package/dist/git/index.js +7 -0
  20. package/dist/github/Branch.js +2 -0
  21. package/dist/github/GitHub.js +22 -0
  22. package/dist/github/PullRequest.js +2 -0
  23. package/dist/github/PullRequestCreator.js +31 -0
  24. package/dist/github/RemoteBranchExistenceChecker.js +17 -0
  25. package/dist/github/Repository.js +2 -0
  26. package/dist/github/createGitHub.js +14 -0
  27. package/dist/github/createOctokit.js +24 -0
  28. package/dist/github/createPullRequestBody.js +19 -0
  29. package/dist/github/createPullRequestTitle.js +10 -0
  30. package/dist/github/index.js +11 -0
  31. package/dist/logger/Logger.js +2 -0
  32. package/dist/logger/createLogger.js +11 -0
  33. package/dist/logger/index.js +5 -0
  34. package/dist/main.js +83 -0
  35. package/dist/ncu/Ncu.js +38 -0
  36. package/dist/ncu/NcuOutdatedPackages.js +2 -0
  37. package/dist/ncu/NcuOutdatedPackagesConverter.js +26 -0
  38. package/dist/ncu/index.js +5 -0
  39. package/dist/ncu/isNcuOutdatedPackages.js +8 -0
  40. package/dist/ncu/toUpdateType.js +17 -0
  41. package/dist/options/Options.js +16 -0
  42. package/dist/options/index.js +5 -0
  43. package/dist/options/initOptions.js +27 -0
  44. package/dist/outdated-package-processor/OutdatedPackageProcessor.js +56 -0
  45. package/dist/outdated-package-processor/createBranchName.js +9 -0
  46. package/dist/outdated-package-processor/createCommitMessage.js +10 -0
  47. package/dist/outdated-package-processor/index.js +5 -0
  48. package/dist/outdated-packages-processor/OutdatedPackagesProcessor.js +19 -0
  49. package/dist/outdated-packages-processor/index.js +5 -0
  50. package/dist/package-manager/Npm.js +20 -0
  51. package/dist/package-manager/PackageManager.js +2 -0
  52. package/dist/package-manager/Yarn.js +20 -0
  53. package/dist/package-manager/createPackageManager.js +15 -0
  54. package/dist/package-manager/index.js +9 -0
  55. package/dist/read-package-json/Package.js +18 -0
  56. package/dist/read-package-json/PackageDependencies.js +6 -0
  57. package/dist/read-package-json/index.js +5 -0
  58. package/dist/read-package-json/parsePackageJson.js +15 -0
  59. package/dist/read-package-json/readFile.js +12 -0
  60. package/dist/read-package-json/readPackageJson.js +11 -0
  61. package/dist/terminal/Terminal.js +29 -0
  62. package/dist/terminal/index.js +5 -0
  63. package/dist/terminal/isExecaReturnValue.js +24 -0
  64. package/dist/types/OutdatedPackage.js +2 -0
  65. package/dist/types/Result.js +2 -0
  66. package/dist/types/index.js +2 -0
  67. package/dist/values/PackageVersion.js +25 -0
  68. package/dist/values/index.js +5 -0
  69. package/jest.config.ts +11 -0
  70. package/lint-staged.config.js +4 -0
  71. package/package.json +59 -0
  72. package/src/app.ts +5 -0
  73. package/src/bin.ts +19 -0
  74. package/src/enums/LogLevel.ts +8 -0
  75. package/src/enums/PackageManagerName.ts +8 -0
  76. package/src/enums/UpdateType.ts +9 -0
  77. package/src/enums/index.ts +12 -0
  78. package/src/git/Committer.ts +49 -0
  79. package/src/git/Git.ts +55 -0
  80. package/src/git/GitRepository.test.ts +61 -0
  81. package/src/git/GitRepository.ts +57 -0
  82. package/src/git/index.ts +3 -0
  83. package/src/github/Branch.ts +4 -0
  84. package/src/github/GitHub.ts +27 -0
  85. package/src/github/PullRequest.ts +3 -0
  86. package/src/github/PullRequestCreator.ts +57 -0
  87. package/src/github/RemoteBranchExistenceChecker.ts +15 -0
  88. package/src/github/Repository.ts +3 -0
  89. package/src/github/createGitHub.ts +18 -0
  90. package/src/github/createOctokit.ts +28 -0
  91. package/src/github/createPullRequestBody.test.ts +62 -0
  92. package/src/github/createPullRequestBody.ts +17 -0
  93. package/src/github/createPullRequestTitle.test.ts +43 -0
  94. package/src/github/createPullRequestTitle.ts +8 -0
  95. package/src/github/index.ts +7 -0
  96. package/src/logger/Logger.ts +1 -0
  97. package/src/logger/createLogger.ts +10 -0
  98. package/src/logger/index.ts +2 -0
  99. package/src/main.ts +105 -0
  100. package/src/ncu/Ncu.ts +41 -0
  101. package/src/ncu/NcuOutdatedPackages.ts +6 -0
  102. package/src/ncu/NcuOutdatedPackagesConverter.ts +25 -0
  103. package/src/ncu/index.ts +1 -0
  104. package/src/ncu/isNcuOutdatedPackages.ts +6 -0
  105. package/src/ncu/toUpdateType.test.ts +21 -0
  106. package/src/ncu/toUpdateType.ts +18 -0
  107. package/src/options/Options.ts +24 -0
  108. package/src/options/index.ts +2 -0
  109. package/src/options/initOptions.ts +34 -0
  110. package/src/outdated-package-processor/OutdatedPackageProcessor.ts +101 -0
  111. package/src/outdated-package-processor/createBranchName.test.ts +14 -0
  112. package/src/outdated-package-processor/createBranchName.ts +7 -0
  113. package/src/outdated-package-processor/createCommitMessage.test.ts +43 -0
  114. package/src/outdated-package-processor/createCommitMessage.ts +8 -0
  115. package/src/outdated-package-processor/index.ts +1 -0
  116. package/src/outdated-packages-processor/OutdatedPackagesProcessor.ts +34 -0
  117. package/src/outdated-packages-processor/index.ts +1 -0
  118. package/src/package-manager/Npm.ts +19 -0
  119. package/src/package-manager/PackageManager.ts +4 -0
  120. package/src/package-manager/Yarn.ts +19 -0
  121. package/src/package-manager/createPackageManager.ts +21 -0
  122. package/src/package-manager/index.ts +4 -0
  123. package/src/read-package-json/Package.ts +24 -0
  124. package/src/read-package-json/PackageDependencies.ts +10 -0
  125. package/src/read-package-json/index.ts +2 -0
  126. package/src/read-package-json/parsePackageJson.ts +13 -0
  127. package/src/read-package-json/readFile.ts +6 -0
  128. package/src/read-package-json/readPackageJson.ts +9 -0
  129. package/src/terminal/Terminal.ts +30 -0
  130. package/src/terminal/index.ts +1 -0
  131. package/src/terminal/isExecaReturnValue.ts +30 -0
  132. package/src/types/OutdatedPackage.ts +9 -0
  133. package/src/types/Result.ts +7 -0
  134. package/src/types/index.ts +2 -0
  135. package/src/values/PackageVersion.test.ts +25 -0
  136. package/src/values/PackageVersion.ts +40 -0
  137. package/src/values/index.ts +1 -0
  138. package/tsconfig.base.json +3 -0
  139. package/tsconfig.build.json +13 -0
  140. package/tsconfig.json +9 -0
@@ -0,0 +1,8 @@
1
+ export const PackageManagerName = {
2
+ Npm: 'npm',
3
+ Yarn: 'yarn'
4
+ } as const
5
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
6
+ export type PackageManagerName = typeof PackageManagerName[keyof typeof PackageManagerName]
7
+ const packageManagerNames = Object.values(PackageManagerName)
8
+ export const isPackageManagerName = (value: any): value is PackageManagerName => packageManagerNames.includes(value)
@@ -0,0 +1,9 @@
1
+ export const UpdateType = {
2
+ Major: 'major',
3
+ Minor: 'minor',
4
+ Patch: 'patch'
5
+ } as const
6
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
7
+ export type UpdateType = typeof UpdateType[keyof typeof UpdateType]
8
+ const updateTypes = Object.values(UpdateType)
9
+ export const isUpdateType = (value: any): value is UpdateType => updateTypes.includes(value)
@@ -0,0 +1,12 @@
1
+ export {
2
+ isLogLevel,
3
+ LogLevel
4
+ } from './LogLevel'
5
+ export {
6
+ isPackageManagerName,
7
+ PackageManagerName
8
+ } from './PackageManagerName'
9
+ export {
10
+ isUpdateType,
11
+ UpdateType
12
+ } from './UpdateType'
@@ -0,0 +1,49 @@
1
+ import type { Git } from './Git'
2
+
3
+ export interface User {
4
+ name?: string
5
+ email?: string
6
+ }
7
+
8
+ // TODO: add test
9
+ export class Committer {
10
+ private readonly git: Git
11
+ private readonly user: User | undefined
12
+
13
+ constructor ({
14
+ git,
15
+ user
16
+ }: {
17
+ git: Git
18
+ user?: User
19
+ }) {
20
+ this.git = git
21
+ this.user = user
22
+ }
23
+
24
+ async commit (message: string): Promise<void> {
25
+ let name: string | undefined
26
+
27
+ if (this.user?.name !== undefined) {
28
+ name = await this.git.getConfig('user.name')
29
+ await this.git.setConfig('user.name', this.user.name)
30
+ }
31
+
32
+ let email: string | undefined
33
+
34
+ if (this.user?.email !== undefined) {
35
+ email = await this.git.getConfig('user.email')
36
+ await this.git.setConfig('user.email', this.user.email)
37
+ }
38
+
39
+ await this.git.commit(message)
40
+
41
+ if (name !== undefined) {
42
+ await this.git.setConfig('user.name', name)
43
+ }
44
+
45
+ if (email !== undefined) {
46
+ await this.git.setConfig('user.email', email)
47
+ }
48
+ }
49
+ }
package/src/git/Git.ts ADDED
@@ -0,0 +1,55 @@
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 checkout (branchName: string): Promise<void> {
13
+ await this.terminal.run('git', 'checkout', branchName)
14
+ }
15
+
16
+ async commit (message: string): Promise<void> {
17
+ await this.terminal.run('git', 'commit', '--message', message)
18
+ }
19
+
20
+ async createBranch (branchName: string): Promise<void> {
21
+ await this.terminal.run('git', 'checkout', '-b', branchName)
22
+ }
23
+
24
+ async getConfig (key: string): Promise<string> {
25
+ const { stdout } = await this.terminal.run('git', 'config', key)
26
+ return stdout.trim()
27
+ }
28
+
29
+ async getCurrentBranch (): Promise<string> {
30
+ const { stdout } = await this.terminal.run('git', 'rev-parse', '--abbrev-ref', 'HEAD')
31
+ return stdout.trim()
32
+ }
33
+
34
+ async getRemoteUrl (): Promise<string> {
35
+ const { stdout } = await this.terminal.run('git', 'remote', 'get-url', '--push', 'origin')
36
+ return stdout.trim()
37
+ }
38
+
39
+ async getRepository (): Promise<GitRepository> {
40
+ const url = await this.getRemoteUrl()
41
+ return GitRepository.of(url)
42
+ }
43
+
44
+ async push (branchName: string): Promise<void> {
45
+ await this.terminal.run('git', 'push', 'origin', branchName)
46
+ }
47
+
48
+ async removeBranch (branchName: string): Promise<void> {
49
+ await this.terminal.run('git', 'branch', '-D', branchName)
50
+ }
51
+
52
+ async setConfig (key: string, value: string): Promise<void> {
53
+ await this.terminal.run('git', 'config', key, value)
54
+ }
55
+ }
@@ -0,0 +1,61 @@
1
+ import { GitRepository } from './GitRepository'
2
+
3
+ describe('GitRepository', () => {
4
+ describe('of', () => {
5
+ describe('if URL is HTTPS', () => {
6
+ describe('if URL is github.com', () => {
7
+ const url = 'https://github.com/munierujp/npm-update-package.git'
8
+
9
+ it('returns new GitRepository instance', () => {
10
+ const repo = GitRepository.of(url)
11
+ expect(repo.host).toBe('github.com')
12
+ expect(repo.owner).toBe('munierujp')
13
+ expect(repo.name).toBe('npm-update-package')
14
+ expect(repo.apiEndPoint).toBe('https://api.github.com')
15
+ expect(repo.isGitHubDotCom).toBe(true)
16
+ })
17
+ })
18
+
19
+ describe('if URL is not github.com', () => {
20
+ const url = 'https://git.example.com/munierujp/npm-update-package.git'
21
+
22
+ it('returns new GitRepository instance', () => {
23
+ const repo = GitRepository.of(url)
24
+ expect(repo.host).toBe('git.example.com')
25
+ expect(repo.owner).toBe('munierujp')
26
+ expect(repo.name).toBe('npm-update-package')
27
+ expect(repo.apiEndPoint).toBe('https://git.example.com/api/v3')
28
+ expect(repo.isGitHubDotCom).toBe(false)
29
+ })
30
+ })
31
+ })
32
+
33
+ describe('if URL is SSH', () => {
34
+ describe('if URL is github.com', () => {
35
+ const url = 'git@github.com:munierujp/npm-update-package.git'
36
+
37
+ it('returns new GitRepository instance', () => {
38
+ const repo = GitRepository.of(url)
39
+ expect(repo.host).toBe('github.com')
40
+ expect(repo.owner).toBe('munierujp')
41
+ expect(repo.name).toBe('npm-update-package')
42
+ expect(repo.apiEndPoint).toBe('https://api.github.com')
43
+ expect(repo.isGitHubDotCom).toBe(true)
44
+ })
45
+ })
46
+
47
+ describe('if URL is not github.com', () => {
48
+ const url = 'git@git.example.com:munierujp/npm-update-package.git'
49
+
50
+ it('returns new GitRepository instance', () => {
51
+ const repo = GitRepository.of(url)
52
+ expect(repo.host).toBe('git.example.com')
53
+ expect(repo.owner).toBe('munierujp')
54
+ expect(repo.name).toBe('npm-update-package')
55
+ expect(repo.apiEndPoint).toBe('https://git.example.com/api/v3')
56
+ expect(repo.isGitHubDotCom).toBe(false)
57
+ })
58
+ })
59
+ })
60
+ })
61
+ })
@@ -0,0 +1,57 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ export { Committer } from './Committer'
2
+ export { Git } from './Git'
3
+ export type { GitRepository } from './GitRepository'
@@ -0,0 +1,4 @@
1
+ import type { RestEndpointMethodTypes } from '@octokit/rest'
2
+ import type { ValuesType } from 'utility-types'
3
+
4
+ export type Branch = ValuesType<RestEndpointMethodTypes['repos']['listBranches']['response']['data']>
@@ -0,0 +1,27 @@
1
+ import type {
2
+ Octokit,
3
+ RestEndpointMethodTypes
4
+ } from '@octokit/rest'
5
+ import type { Branch } from './Branch'
6
+ import type { PullRequest } from './PullRequest'
7
+ import type { Repository } from './Repository'
8
+
9
+ // TODO: add test
10
+ export class GitHub {
11
+ constructor (private readonly octokit: Octokit) {}
12
+
13
+ async createPullRequest (params: RestEndpointMethodTypes['pulls']['create']['parameters']): Promise<PullRequest> {
14
+ const { data } = await this.octokit.pulls.create(params)
15
+ return data
16
+ }
17
+
18
+ async fetchBranches (params: RestEndpointMethodTypes['repos']['listBranches']['parameters']): Promise<Branch[]> {
19
+ const { data } = await this.octokit.repos.listBranches(params)
20
+ return data
21
+ }
22
+
23
+ async fetchRepository (params: RestEndpointMethodTypes['repos']['get']['parameters']): Promise<Repository> {
24
+ const { data } = await this.octokit.repos.get(params)
25
+ return data
26
+ }
27
+ }
@@ -0,0 +1,3 @@
1
+ import type { RestEndpointMethodTypes } from '@octokit/rest'
2
+
3
+ export type PullRequest = RestEndpointMethodTypes['pulls']['create']['response']['data']
@@ -0,0 +1,57 @@
1
+ import type { GitRepository } from '../git'
2
+ import type { Logger } from '../logger'
3
+ import type { OutdatedPackage } from '../types'
4
+ import { createPullRequestBody } from './createPullRequestBody'
5
+ import { createPullRequestTitle } from './createPullRequestTitle'
6
+ import type { GitHub } from './GitHub'
7
+ import type { Repository as GitHubRepository } from './Repository'
8
+
9
+ // TODO: add test
10
+ export class PullRequestCreator {
11
+ private readonly github: GitHub
12
+ private readonly gitRepo: GitRepository
13
+ private readonly githubRepo: GitHubRepository
14
+ private readonly logger: Logger
15
+
16
+ constructor ({
17
+ github,
18
+ gitRepo,
19
+ githubRepo,
20
+ logger
21
+ }: {
22
+ github: GitHub
23
+ gitRepo: GitRepository
24
+ githubRepo: GitHubRepository
25
+ logger: Logger
26
+ }) {
27
+ this.github = github
28
+ this.gitRepo = gitRepo
29
+ this.githubRepo = githubRepo
30
+ this.logger = logger
31
+ }
32
+
33
+ async create ({
34
+ outdatedPackage,
35
+ branchName
36
+ }: {
37
+ outdatedPackage: OutdatedPackage
38
+ branchName: string
39
+ }): Promise<void> {
40
+ const title = createPullRequestTitle(outdatedPackage)
41
+ this.logger.debug(`title=${title}`)
42
+
43
+ const body = createPullRequestBody(outdatedPackage)
44
+ this.logger.debug(`body=${body}`)
45
+
46
+ const createdPullRequest = await this.github.createPullRequest({
47
+ owner: this.gitRepo.owner,
48
+ repo: this.gitRepo.name,
49
+ base: this.githubRepo.default_branch,
50
+ head: branchName,
51
+ title,
52
+ body
53
+ })
54
+ this.logger.debug(`createdPullRequest=${JSON.stringify(createdPullRequest)}`)
55
+ this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${createdPullRequest.html_url}`)
56
+ }
57
+ }
@@ -0,0 +1,15 @@
1
+ import type { Branch } from './Branch'
2
+
3
+ // TODO: add test
4
+ export class RemoteBranchExistenceChecker {
5
+ constructor (private readonly remoteBranchNames: string[]) {}
6
+
7
+ static of (remoteBranches: Branch[]): RemoteBranchExistenceChecker {
8
+ const remoteBranchNames = remoteBranches.map(({ name }) => name)
9
+ return new RemoteBranchExistenceChecker(remoteBranchNames)
10
+ }
11
+
12
+ check (branchName: string): boolean {
13
+ return this.remoteBranchNames.includes(branchName)
14
+ }
15
+ }
@@ -0,0 +1,3 @@
1
+ import type { RestEndpointMethodTypes } from '@octokit/rest'
2
+
3
+ export type Repository = RestEndpointMethodTypes['repos']['get']['response']['data']
@@ -0,0 +1,18 @@
1
+ import type { GitRepository } from '../git'
2
+ import { createOctokit } from './createOctokit'
3
+ import { GitHub } from './GitHub'
4
+
5
+ // TODO: add test
6
+ export const createGitHub = ({
7
+ repository,
8
+ token
9
+ }: {
10
+ repository: GitRepository
11
+ token: string
12
+ }): GitHub => {
13
+ const octokit = createOctokit({
14
+ repository,
15
+ token
16
+ })
17
+ return new GitHub(octokit)
18
+ }
@@ -0,0 +1,28 @@
1
+ import { Octokit } from '@octokit/rest'
2
+ import { app } from '../app'
3
+ import type { GitRepository } from '../git'
4
+
5
+ // TODO: add test
6
+ export const createOctokit = ({
7
+ repository,
8
+ token
9
+ }: {
10
+ repository: GitRepository
11
+ token: string
12
+ }): Octokit => {
13
+ const auth = `token ${token}`
14
+ const userAgent = `${app.name}/${app.version}`
15
+
16
+ if (repository.isGitHubDotCom) {
17
+ return new Octokit({
18
+ auth,
19
+ userAgent
20
+ })
21
+ } else {
22
+ return new Octokit({
23
+ auth,
24
+ userAgent,
25
+ baseUrl: repository.apiEndPoint
26
+ })
27
+ }
28
+ }
@@ -0,0 +1,62 @@
1
+ import { UpdateType } from '../enums'
2
+ import { PackageVersion } from '../values'
3
+ import { createPullRequestBody } from './createPullRequestBody'
4
+
5
+ describe('createPullRequestBody', () => {
6
+ describe('if update type is patch', () => {
7
+ it('returns pull request body', () => {
8
+ const actual = createPullRequestBody({
9
+ name: '@typescript-eslint/eslint-plugin',
10
+ currentVersion: PackageVersion.of('1.0.0'),
11
+ newVersion: PackageVersion.of('1.0.1'),
12
+ type: UpdateType.Patch
13
+ })
14
+ expect(actual).toBe(`This PR updates these packages:
15
+
16
+ |package|type|current version|new version|
17
+ |---|---|---|---|
18
+ |[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|patch|\`1.0.0\`|\`1.0.1\`|
19
+
20
+ ---
21
+ This PR has been generated by [npm-update-package](https://github.com/munierujp/npm-update-package)`)
22
+ })
23
+ })
24
+
25
+ describe('if update type is minor', () => {
26
+ it('returns pull request body', () => {
27
+ const actual = createPullRequestBody({
28
+ name: '@typescript-eslint/eslint-plugin',
29
+ currentVersion: PackageVersion.of('1.0.0'),
30
+ newVersion: PackageVersion.of('1.1.0'),
31
+ type: UpdateType.Minor
32
+ })
33
+ expect(actual).toBe(`This PR updates these packages:
34
+
35
+ |package|type|current version|new version|
36
+ |---|---|---|---|
37
+ |[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|minor|\`1.0.0\`|\`1.1.0\`|
38
+
39
+ ---
40
+ This PR has been generated by [npm-update-package](https://github.com/munierujp/npm-update-package)`)
41
+ })
42
+ })
43
+
44
+ describe('if update type is major', () => {
45
+ it('returns pull request body', () => {
46
+ const actual = createPullRequestBody({
47
+ name: '@typescript-eslint/eslint-plugin',
48
+ currentVersion: PackageVersion.of('1.0.0'),
49
+ newVersion: PackageVersion.of('2.0.0'),
50
+ type: UpdateType.Major
51
+ })
52
+ expect(actual).toBe(`This PR updates these packages:
53
+
54
+ |package|type|current version|new version|
55
+ |---|---|---|---|
56
+ |[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|major|\`1.0.0\`|\`2.0.0\`|
57
+
58
+ ---
59
+ This PR has been generated by [npm-update-package](https://github.com/munierujp/npm-update-package)`)
60
+ })
61
+ })
62
+ })
@@ -0,0 +1,17 @@
1
+ import { app } from '../app'
2
+ import type { OutdatedPackage } from '../types'
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
+ }
@@ -0,0 +1,43 @@
1
+ import { UpdateType } from '../enums'
2
+ import { PackageVersion } from '../values'
3
+ import { createPullRequestTitle } from './createPullRequestTitle'
4
+
5
+ describe('createPullRequestTitle', () => {
6
+ const currentVersion = PackageVersion.of('1.0.0')
7
+
8
+ describe('if update type is patch', () => {
9
+ it('returns pull request title', () => {
10
+ const actual = createPullRequestTitle({
11
+ name: '@typescript-eslint/eslint-plugin',
12
+ currentVersion,
13
+ newVersion: PackageVersion.of('1.0.1'),
14
+ type: UpdateType.Patch
15
+ })
16
+ expect(actual).toBe('chore(deps): patch update @typescript-eslint/eslint-plugin to v1.0.1')
17
+ })
18
+ })
19
+
20
+ describe('if update type is minor', () => {
21
+ it('returns pull request title', () => {
22
+ const actual = createPullRequestTitle({
23
+ name: '@typescript-eslint/eslint-plugin',
24
+ currentVersion,
25
+ newVersion: PackageVersion.of('1.1.0'),
26
+ type: UpdateType.Minor
27
+ })
28
+ expect(actual).toBe('chore(deps): minor update @typescript-eslint/eslint-plugin to v1.1.0')
29
+ })
30
+ })
31
+
32
+ describe('if update type is major', () => {
33
+ it('returns pull request title', () => {
34
+ const actual = createPullRequestTitle({
35
+ name: '@typescript-eslint/eslint-plugin',
36
+ currentVersion,
37
+ newVersion: PackageVersion.of('2.0.0'),
38
+ type: UpdateType.Major
39
+ })
40
+ expect(actual).toBe('chore(deps): major update @typescript-eslint/eslint-plugin to v2.0.0')
41
+ })
42
+ })
43
+ })
@@ -0,0 +1,8 @@
1
+ import type { OutdatedPackage } from '../types'
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
+ }
@@ -0,0 +1,7 @@
1
+ export type { Branch } from './Branch'
2
+ export { createGitHub } from './createGitHub'
3
+ export { GitHub } from './GitHub'
4
+ export type { PullRequest } from './PullRequest'
5
+ export { PullRequestCreator } from './PullRequestCreator'
6
+ export { RemoteBranchExistenceChecker } from './RemoteBranchExistenceChecker'
7
+ export type { Repository } from './Repository'
@@ -0,0 +1 @@
1
+ export type { Logger } from 'log4js'
@@ -0,0 +1,10 @@
1
+ import { getLogger } from 'log4js'
2
+ import type { LogLevel } from '../enums'
3
+ import type { Logger } from './Logger'
4
+
5
+ // TODO: add test
6
+ export const createLogger = (logLevel: LogLevel): Logger => {
7
+ const logger = getLogger()
8
+ logger.level = logLevel
9
+ return logger
10
+ }
@@ -0,0 +1,2 @@
1
+ export { createLogger } from './createLogger'
2
+ export type { Logger } from './Logger'