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.
- package/.eslintignore +3 -0
- package/.eslintrc.js +23 -0
- package/.github/renovate.json +15 -0
- package/.github/workflows/eslint.yml +14 -0
- package/.github/workflows/test.yml +19 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/LICENSE +22 -0
- package/README.md +43 -0
- package/dist/app.js +8 -0
- package/dist/bin.js +18 -0
- package/dist/enums/LogLevel.js +10 -0
- package/dist/enums/PackageManagerName.js +10 -0
- package/dist/enums/UpdateType.js +11 -0
- package/dist/enums/index.js +12 -0
- package/dist/git/Committer.js +31 -0
- package/dist/git/Git.js +48 -0
- package/dist/git/GitRepository.js +41 -0
- package/dist/git/index.js +7 -0
- package/dist/github/Branch.js +2 -0
- package/dist/github/GitHub.js +22 -0
- package/dist/github/PullRequest.js +2 -0
- package/dist/github/PullRequestCreator.js +31 -0
- package/dist/github/RemoteBranchExistenceChecker.js +17 -0
- package/dist/github/Repository.js +2 -0
- package/dist/github/createGitHub.js +14 -0
- package/dist/github/createOctokit.js +24 -0
- package/dist/github/createPullRequestBody.js +19 -0
- package/dist/github/createPullRequestTitle.js +10 -0
- package/dist/github/index.js +11 -0
- package/dist/logger/Logger.js +2 -0
- package/dist/logger/createLogger.js +11 -0
- package/dist/logger/index.js +5 -0
- package/dist/main.js +83 -0
- package/dist/ncu/Ncu.js +38 -0
- package/dist/ncu/NcuOutdatedPackages.js +2 -0
- package/dist/ncu/NcuOutdatedPackagesConverter.js +26 -0
- package/dist/ncu/index.js +5 -0
- package/dist/ncu/isNcuOutdatedPackages.js +8 -0
- package/dist/ncu/toUpdateType.js +17 -0
- package/dist/options/Options.js +16 -0
- package/dist/options/index.js +5 -0
- package/dist/options/initOptions.js +27 -0
- package/dist/outdated-package-processor/OutdatedPackageProcessor.js +56 -0
- package/dist/outdated-package-processor/createBranchName.js +9 -0
- package/dist/outdated-package-processor/createCommitMessage.js +10 -0
- package/dist/outdated-package-processor/index.js +5 -0
- package/dist/outdated-packages-processor/OutdatedPackagesProcessor.js +19 -0
- package/dist/outdated-packages-processor/index.js +5 -0
- package/dist/package-manager/Npm.js +20 -0
- package/dist/package-manager/PackageManager.js +2 -0
- package/dist/package-manager/Yarn.js +20 -0
- package/dist/package-manager/createPackageManager.js +15 -0
- package/dist/package-manager/index.js +9 -0
- package/dist/read-package-json/Package.js +18 -0
- package/dist/read-package-json/PackageDependencies.js +6 -0
- package/dist/read-package-json/index.js +5 -0
- package/dist/read-package-json/parsePackageJson.js +15 -0
- package/dist/read-package-json/readFile.js +12 -0
- package/dist/read-package-json/readPackageJson.js +11 -0
- package/dist/terminal/Terminal.js +29 -0
- package/dist/terminal/index.js +5 -0
- package/dist/terminal/isExecaReturnValue.js +24 -0
- package/dist/types/OutdatedPackage.js +2 -0
- package/dist/types/Result.js +2 -0
- package/dist/types/index.js +2 -0
- package/dist/values/PackageVersion.js +25 -0
- package/dist/values/index.js +5 -0
- package/jest.config.ts +11 -0
- package/lint-staged.config.js +4 -0
- package/package.json +59 -0
- package/src/app.ts +5 -0
- package/src/bin.ts +19 -0
- package/src/enums/LogLevel.ts +8 -0
- package/src/enums/PackageManagerName.ts +8 -0
- package/src/enums/UpdateType.ts +9 -0
- package/src/enums/index.ts +12 -0
- package/src/git/Committer.ts +49 -0
- package/src/git/Git.ts +55 -0
- package/src/git/GitRepository.test.ts +61 -0
- package/src/git/GitRepository.ts +57 -0
- package/src/git/index.ts +3 -0
- package/src/github/Branch.ts +4 -0
- package/src/github/GitHub.ts +27 -0
- package/src/github/PullRequest.ts +3 -0
- package/src/github/PullRequestCreator.ts +57 -0
- package/src/github/RemoteBranchExistenceChecker.ts +15 -0
- package/src/github/Repository.ts +3 -0
- package/src/github/createGitHub.ts +18 -0
- package/src/github/createOctokit.ts +28 -0
- package/src/github/createPullRequestBody.test.ts +62 -0
- package/src/github/createPullRequestBody.ts +17 -0
- package/src/github/createPullRequestTitle.test.ts +43 -0
- package/src/github/createPullRequestTitle.ts +8 -0
- package/src/github/index.ts +7 -0
- package/src/logger/Logger.ts +1 -0
- package/src/logger/createLogger.ts +10 -0
- package/src/logger/index.ts +2 -0
- package/src/main.ts +105 -0
- package/src/ncu/Ncu.ts +41 -0
- package/src/ncu/NcuOutdatedPackages.ts +6 -0
- package/src/ncu/NcuOutdatedPackagesConverter.ts +25 -0
- package/src/ncu/index.ts +1 -0
- package/src/ncu/isNcuOutdatedPackages.ts +6 -0
- package/src/ncu/toUpdateType.test.ts +21 -0
- package/src/ncu/toUpdateType.ts +18 -0
- package/src/options/Options.ts +24 -0
- package/src/options/index.ts +2 -0
- package/src/options/initOptions.ts +34 -0
- package/src/outdated-package-processor/OutdatedPackageProcessor.ts +101 -0
- package/src/outdated-package-processor/createBranchName.test.ts +14 -0
- package/src/outdated-package-processor/createBranchName.ts +7 -0
- package/src/outdated-package-processor/createCommitMessage.test.ts +43 -0
- package/src/outdated-package-processor/createCommitMessage.ts +8 -0
- package/src/outdated-package-processor/index.ts +1 -0
- package/src/outdated-packages-processor/OutdatedPackagesProcessor.ts +34 -0
- package/src/outdated-packages-processor/index.ts +1 -0
- package/src/package-manager/Npm.ts +19 -0
- package/src/package-manager/PackageManager.ts +4 -0
- package/src/package-manager/Yarn.ts +19 -0
- package/src/package-manager/createPackageManager.ts +21 -0
- package/src/package-manager/index.ts +4 -0
- package/src/read-package-json/Package.ts +24 -0
- package/src/read-package-json/PackageDependencies.ts +10 -0
- package/src/read-package-json/index.ts +2 -0
- package/src/read-package-json/parsePackageJson.ts +13 -0
- package/src/read-package-json/readFile.ts +6 -0
- package/src/read-package-json/readPackageJson.ts +9 -0
- package/src/terminal/Terminal.ts +30 -0
- package/src/terminal/index.ts +1 -0
- package/src/terminal/isExecaReturnValue.ts +30 -0
- package/src/types/OutdatedPackage.ts +9 -0
- package/src/types/Result.ts +7 -0
- package/src/types/index.ts +2 -0
- package/src/values/PackageVersion.test.ts +25 -0
- package/src/values/PackageVersion.ts +40 -0
- package/src/values/index.ts +1 -0
- package/tsconfig.base.json +3 -0
- package/tsconfig.build.json +13 -0
- 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,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
|
+
}
|
package/src/git/index.ts
ADDED
|
@@ -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,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,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
|
+
}
|