npm-update-package 0.31.3 → 0.33.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/README.md +1 -1
- package/dist/package.json +7 -7
- package/dist/src/options/cliOptions.js +1 -1
- package/package.json +7 -7
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -23
- package/.github/renovate.json +0 -15
- package/.github/workflows/eslint.yml +0 -14
- package/.github/workflows/test.yml +0 -20
- package/.husky/pre-commit +0 -4
- package/.nvmrc +0 -1
- package/jest.config.ts +0 -12
- package/lint-staged.config.js +0 -4
- package/npm-update-package.code-workspace +0 -10
- package/src/bin.ts +0 -22
- package/src/core/FailedResult.ts +0 -6
- package/src/core/OutdatedPackage.ts +0 -11
- package/src/core/OutdatedPackageProcessor.ts +0 -136
- package/src/core/OutdatedPackagesProcessor.ts +0 -35
- package/src/core/SucceededResult.ts +0 -7
- package/src/core/index.ts +0 -5
- package/src/file/index.ts +0 -1
- package/src/file/readFile.ts +0 -6
- package/src/git/CommitMessageCreator.test.ts +0 -17
- package/src/git/CommitMessageCreator.ts +0 -19
- package/src/git/Git.ts +0 -59
- package/src/git/GitRepository.test.ts +0 -82
- package/src/git/GitRepository.ts +0 -57
- package/src/git/createBranchName.test.ts +0 -14
- package/src/git/createBranchName.ts +0 -7
- package/src/git/index.ts +0 -4
- package/src/github/GitHub.ts +0 -198
- package/src/github/branch/finder/BranchFinder.test.ts +0 -21
- package/src/github/branch/finder/BranchFinder.ts +0 -9
- package/src/github/branch/finder/index.ts +0 -1
- package/src/github/branch/index.ts +0 -1
- package/src/github/createGitHub.test.ts +0 -16
- package/src/github/createGitHub.ts +0 -17
- package/src/github/createOctokit.test.ts +0 -27
- package/src/github/createOctokit.ts +0 -27
- package/src/github/errors/NotFoundError.ts +0 -11
- package/src/github/errors/index.ts +0 -1
- package/src/github/index.ts +0 -5
- package/src/github/label/creator/LabelCreator.ts +0 -71
- package/src/github/label/creator/index.ts +0 -1
- package/src/github/label/index.ts +0 -1
- package/src/github/pull-request/closer/PullRequestCloser.test.ts +0 -53
- package/src/github/pull-request/closer/PullRequestCloser.ts +0 -21
- package/src/github/pull-request/closer/index.ts +0 -1
- package/src/github/pull-request/creator/PullRequestCreator.test.ts +0 -98
- package/src/github/pull-request/creator/PullRequestCreator.ts +0 -84
- package/src/github/pull-request/creator/PullRequestTitleCreator.test.ts +0 -17
- package/src/github/pull-request/creator/PullRequestTitleCreator.ts +0 -19
- package/src/github/pull-request/creator/createPullRequestBody.test.ts +0 -47
- package/src/github/pull-request/creator/createPullRequestBody.ts +0 -35
- package/src/github/pull-request/creator/index.ts +0 -2
- package/src/github/pull-request/finder/PullRequestFinder.ts +0 -27
- package/src/github/pull-request/finder/index.ts +0 -1
- package/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.test.ts +0 -24
- package/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.ts +0 -5
- package/src/github/pull-request/index.ts +0 -3
- package/src/github/pull-request/metadata/PullRequestMetadata.ts +0 -22
- package/src/github/pull-request/metadata/createPullRequestMetadata.test.ts +0 -31
- package/src/github/pull-request/metadata/createPullRequestMetadata.ts +0 -21
- package/src/github/pull-request/metadata/extractPullRequestMetadata.test.ts +0 -53
- package/src/github/pull-request/metadata/extractPullRequestMetadata.ts +0 -21
- package/src/github/pull-request/metadata/index.ts +0 -3
- package/src/json/index.ts +0 -1
- package/src/json/toJSON.test.ts +0 -65
- package/src/json/toJSON.ts +0 -13
- package/src/logger/LogLevel.ts +0 -13
- package/src/logger/Logger.ts +0 -1
- package/src/logger/createLogger.ts +0 -10
- package/src/logger/index.ts +0 -3
- package/src/main.ts +0 -149
- package/src/ncu/Ncu.ts +0 -84
- package/src/ncu/NcuResult.ts +0 -10
- package/src/ncu/index.ts +0 -1
- package/src/options/CLIOption.ts +0 -19
- package/src/options/OptionType.ts +0 -8
- package/src/options/Options.ts +0 -40
- package/src/options/cliOptions.ts +0 -60
- package/src/options/index.ts +0 -2
- package/src/options/initOptions.ts +0 -24
- package/src/options/toCommanderOption.ts +0 -35
- package/src/package-json/PackageMetadata.ts +0 -24
- package/src/package-json/PackageMetadataDependencies.ts +0 -10
- package/src/package-json/index.ts +0 -2
- package/src/package-json/parsePackageJson.ts +0 -15
- package/src/package-manager/Npm.ts +0 -17
- package/src/package-manager/PackageManager.ts +0 -5
- package/src/package-manager/PackageManagerName.ts +0 -8
- package/src/package-manager/Yarn.ts +0 -17
- package/src/package-manager/createPackageManager.test.ts +0 -27
- package/src/package-manager/createPackageManager.ts +0 -20
- package/src/package-manager/index.ts +0 -5
- package/src/semver/SemVer.test.ts +0 -17
- package/src/semver/SemVer.ts +0 -40
- package/src/semver/SemVerLevel.ts +0 -9
- package/src/semver/compareSemVers.test.ts +0 -21
- package/src/semver/compareSemVers.ts +0 -16
- package/src/semver/index.ts +0 -3
- package/src/terminal/Terminal.ts +0 -12
- package/src/terminal/index.ts +0 -1
- package/tsconfig.base.json +0 -7
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -9
package/src/git/GitRepository.ts
DELETED
|
@@ -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
|
-
})
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { OutdatedPackage } from '../core'
|
|
2
|
-
|
|
3
|
-
export const createBranchName = (outdatedPackage: OutdatedPackage): string => {
|
|
4
|
-
const packageName = outdatedPackage.name
|
|
5
|
-
const newVersion = outdatedPackage.newVersion.version
|
|
6
|
-
return `npm-update-package/${packageName}/v${newVersion}`
|
|
7
|
-
}
|
package/src/git/index.ts
DELETED
package/src/github/GitHub.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Octokit,
|
|
3
|
-
RestEndpointMethodTypes
|
|
4
|
-
} from '@octokit/rest'
|
|
5
|
-
import type { ValuesType } from 'utility-types'
|
|
6
|
-
|
|
7
|
-
export type Branch = ValuesType<RestEndpointMethodTypes['repos']['listBranches']['response']['data']>
|
|
8
|
-
export type CreatedPullRequest = RestEndpointMethodTypes['pulls']['create']['response']['data']
|
|
9
|
-
export type Label = RestEndpointMethodTypes['issues']['getLabel']['response']['data']
|
|
10
|
-
export type PullRequest = ValuesType<RestEndpointMethodTypes['pulls']['list']['response']['data']>
|
|
11
|
-
export type Repository = RestEndpointMethodTypes['repos']['get']['response']['data']
|
|
12
|
-
|
|
13
|
-
// TODO: add test
|
|
14
|
-
export class GitHub {
|
|
15
|
-
constructor (private readonly octokit: Octokit) {}
|
|
16
|
-
|
|
17
|
-
async addLabels ({
|
|
18
|
-
owner,
|
|
19
|
-
repo,
|
|
20
|
-
issueNumber,
|
|
21
|
-
labels
|
|
22
|
-
}: {
|
|
23
|
-
owner: string
|
|
24
|
-
repo: string
|
|
25
|
-
issueNumber: number
|
|
26
|
-
labels: string[]
|
|
27
|
-
}): Promise<void> {
|
|
28
|
-
await this.octokit.issues.addLabels({
|
|
29
|
-
owner,
|
|
30
|
-
repo,
|
|
31
|
-
issue_number: issueNumber,
|
|
32
|
-
labels
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async closePullRequest ({
|
|
37
|
-
owner,
|
|
38
|
-
repo,
|
|
39
|
-
pullNumber
|
|
40
|
-
}: {
|
|
41
|
-
owner: string
|
|
42
|
-
repo: string
|
|
43
|
-
pullNumber: number
|
|
44
|
-
}): Promise<void> {
|
|
45
|
-
await this.octokit.pulls.update({
|
|
46
|
-
owner,
|
|
47
|
-
repo,
|
|
48
|
-
pull_number: pullNumber,
|
|
49
|
-
state: 'closed'
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async createLabel ({
|
|
54
|
-
owner,
|
|
55
|
-
repo,
|
|
56
|
-
name,
|
|
57
|
-
description,
|
|
58
|
-
color
|
|
59
|
-
}: {
|
|
60
|
-
owner: string
|
|
61
|
-
repo: string
|
|
62
|
-
name: string
|
|
63
|
-
description?: string
|
|
64
|
-
color?: string
|
|
65
|
-
}): Promise<void> {
|
|
66
|
-
await this.octokit.issues.createLabel({
|
|
67
|
-
owner,
|
|
68
|
-
repo,
|
|
69
|
-
name,
|
|
70
|
-
description,
|
|
71
|
-
color
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async createPullRequest ({
|
|
76
|
-
owner,
|
|
77
|
-
repo,
|
|
78
|
-
baseBranch,
|
|
79
|
-
headBranch,
|
|
80
|
-
title,
|
|
81
|
-
body
|
|
82
|
-
}: {
|
|
83
|
-
owner: string
|
|
84
|
-
repo: string
|
|
85
|
-
baseBranch: string
|
|
86
|
-
headBranch: string
|
|
87
|
-
title: string
|
|
88
|
-
body: string
|
|
89
|
-
}): Promise<CreatedPullRequest> {
|
|
90
|
-
const { data } = await this.octokit.pulls.create({
|
|
91
|
-
owner,
|
|
92
|
-
repo,
|
|
93
|
-
base: baseBranch,
|
|
94
|
-
head: headBranch,
|
|
95
|
-
title,
|
|
96
|
-
body
|
|
97
|
-
})
|
|
98
|
-
return data
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async deleteBranch ({
|
|
102
|
-
owner,
|
|
103
|
-
repo,
|
|
104
|
-
branch
|
|
105
|
-
}: {
|
|
106
|
-
owner: string
|
|
107
|
-
repo: string
|
|
108
|
-
branch: string
|
|
109
|
-
}): Promise<void> {
|
|
110
|
-
await this.octokit.git.deleteRef({
|
|
111
|
-
owner,
|
|
112
|
-
repo,
|
|
113
|
-
ref: `heads/${branch}`
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// TODO: fetch all branches with page option
|
|
118
|
-
async fetchBranches ({
|
|
119
|
-
owner,
|
|
120
|
-
repo
|
|
121
|
-
}: {
|
|
122
|
-
owner: string
|
|
123
|
-
repo: string
|
|
124
|
-
}): Promise<Branch[]> {
|
|
125
|
-
const { data } = await this.octokit.repos.listBranches({
|
|
126
|
-
owner,
|
|
127
|
-
repo,
|
|
128
|
-
per_page: 100
|
|
129
|
-
})
|
|
130
|
-
return data
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async fetchLabel ({
|
|
134
|
-
owner,
|
|
135
|
-
repo,
|
|
136
|
-
name
|
|
137
|
-
}: {
|
|
138
|
-
owner: string
|
|
139
|
-
repo: string
|
|
140
|
-
name: string
|
|
141
|
-
}): Promise<Label> {
|
|
142
|
-
const { data } = await this.octokit.issues.getLabel({
|
|
143
|
-
owner,
|
|
144
|
-
repo,
|
|
145
|
-
name
|
|
146
|
-
})
|
|
147
|
-
return data
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// TODO: fetch all pull requests with page option
|
|
151
|
-
async fetchPullRequests ({
|
|
152
|
-
owner,
|
|
153
|
-
repo
|
|
154
|
-
}: {
|
|
155
|
-
owner: string
|
|
156
|
-
repo: string
|
|
157
|
-
}): Promise<PullRequest[]> {
|
|
158
|
-
const { data } = await this.octokit.pulls.list({
|
|
159
|
-
owner,
|
|
160
|
-
repo,
|
|
161
|
-
per_page: 100
|
|
162
|
-
})
|
|
163
|
-
return data
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async fetchRepository ({
|
|
167
|
-
owner,
|
|
168
|
-
repo
|
|
169
|
-
}: {
|
|
170
|
-
owner: string
|
|
171
|
-
repo: string
|
|
172
|
-
}): Promise<Repository> {
|
|
173
|
-
const { data } = await this.octokit.repos.get({
|
|
174
|
-
owner,
|
|
175
|
-
repo
|
|
176
|
-
})
|
|
177
|
-
return data
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async requestReviewers ({
|
|
181
|
-
owner,
|
|
182
|
-
repo,
|
|
183
|
-
pullNumber,
|
|
184
|
-
reviewers
|
|
185
|
-
}: {
|
|
186
|
-
owner: string
|
|
187
|
-
repo: string
|
|
188
|
-
pullNumber: number
|
|
189
|
-
reviewers: string[]
|
|
190
|
-
}): Promise<void> {
|
|
191
|
-
await this.octokit.pulls.requestReviewers({
|
|
192
|
-
owner,
|
|
193
|
-
repo,
|
|
194
|
-
pull_number: pullNumber,
|
|
195
|
-
reviewers
|
|
196
|
-
})
|
|
197
|
-
}
|
|
198
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Branch } from '../../GitHub'
|
|
2
|
-
import { BranchFinder } from './BranchFinder'
|
|
3
|
-
|
|
4
|
-
describe('BranchFinder', () => {
|
|
5
|
-
describe('findByName', () => {
|
|
6
|
-
const branch = {
|
|
7
|
-
name: 'test_branch_name'
|
|
8
|
-
} as unknown as Branch
|
|
9
|
-
const branchFinder = new BranchFinder([branch])
|
|
10
|
-
|
|
11
|
-
it('returns branch if exists', () => {
|
|
12
|
-
const actual = branchFinder.findByName('test_branch_name')
|
|
13
|
-
expect(actual).toBe(branch)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('returns undefined if does not exists', () => {
|
|
17
|
-
const actual = branchFinder.findByName('not_test_branch_name')
|
|
18
|
-
expect(actual).toBeUndefined()
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BranchFinder'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './finder'
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { GitRepository } from '../git'
|
|
2
|
-
import { createGitHub } from './createGitHub'
|
|
3
|
-
import { GitHub } from './GitHub'
|
|
4
|
-
|
|
5
|
-
describe('createGitHub', () => {
|
|
6
|
-
it('returns new GitHub instance', () => {
|
|
7
|
-
const repository = GitRepository.of('https://github.com/npm-update-package/npm-update-package.git')
|
|
8
|
-
const token = 'token'
|
|
9
|
-
const github = createGitHub({
|
|
10
|
-
repository,
|
|
11
|
-
token
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
expect(github).toBeInstanceOf(GitHub)
|
|
15
|
-
})
|
|
16
|
-
})
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { GitRepository } from '../git'
|
|
2
|
-
import { createOctokit } from './createOctokit'
|
|
3
|
-
import { GitHub } from './GitHub'
|
|
4
|
-
|
|
5
|
-
export const createGitHub = ({
|
|
6
|
-
repository,
|
|
7
|
-
token
|
|
8
|
-
}: {
|
|
9
|
-
repository: GitRepository
|
|
10
|
-
token: string
|
|
11
|
-
}): GitHub => {
|
|
12
|
-
const octokit = createOctokit({
|
|
13
|
-
repository,
|
|
14
|
-
token
|
|
15
|
-
})
|
|
16
|
-
return new GitHub(octokit)
|
|
17
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Octokit } from '@octokit/rest'
|
|
2
|
-
import { GitRepository } from '../git'
|
|
3
|
-
import { createOctokit } from './createOctokit'
|
|
4
|
-
|
|
5
|
-
describe('createOctokit', () => {
|
|
6
|
-
const token = 'token'
|
|
7
|
-
|
|
8
|
-
it('returns new Octokit instance for GitHub.com if repository is GitHub.com', () => {
|
|
9
|
-
const repository = GitRepository.of('https://github.com/npm-update-package/npm-update-package.git')
|
|
10
|
-
const octokit = createOctokit({
|
|
11
|
-
repository,
|
|
12
|
-
token
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
expect(octokit).toBeInstanceOf(Octokit)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('returns new Octokit instance for GitHub Enterprise if repository is not GitHub.com', () => {
|
|
19
|
-
const repository = GitRepository.of('https://git.example.com/npm-update-package/npm-update-package.git')
|
|
20
|
-
const octokit = createOctokit({
|
|
21
|
-
repository,
|
|
22
|
-
token
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
expect(octokit).toBeInstanceOf(Octokit)
|
|
26
|
-
})
|
|
27
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Octokit } from '@octokit/rest'
|
|
2
|
-
import pkg from '../../package.json'
|
|
3
|
-
import type { GitRepository } from '../git'
|
|
4
|
-
|
|
5
|
-
export const createOctokit = ({
|
|
6
|
-
repository,
|
|
7
|
-
token
|
|
8
|
-
}: {
|
|
9
|
-
repository: GitRepository
|
|
10
|
-
token: string
|
|
11
|
-
}): Octokit => {
|
|
12
|
-
const auth = `token ${token}`
|
|
13
|
-
const userAgent = `${pkg.name}/${pkg.version}`
|
|
14
|
-
|
|
15
|
-
if (repository.isGitHubDotCom) {
|
|
16
|
-
return new Octokit({
|
|
17
|
-
auth,
|
|
18
|
-
userAgent
|
|
19
|
-
})
|
|
20
|
-
} else {
|
|
21
|
-
return new Octokit({
|
|
22
|
-
auth,
|
|
23
|
-
userAgent,
|
|
24
|
-
baseUrl: repository.apiEndPoint
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { RequestError } from '@octokit/request-error'
|
|
2
|
-
import { StatusCodes } from 'http-status-codes'
|
|
3
|
-
|
|
4
|
-
export interface NotFoundError extends RequestError {
|
|
5
|
-
status: StatusCodes.NOT_FOUND
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// TODO: Add test
|
|
9
|
-
export const isNotFoundError = (value: unknown): value is NotFoundError => {
|
|
10
|
-
return value instanceof RequestError && value.status === StatusCodes.NOT_FOUND
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './NotFoundError'
|
package/src/github/index.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { GitRepository } from '../../../git'
|
|
2
|
-
import type { Logger } from '../../../logger'
|
|
3
|
-
import { isNotFoundError } from '../../errors'
|
|
4
|
-
import type {
|
|
5
|
-
GitHub,
|
|
6
|
-
Label
|
|
7
|
-
} from '../../GitHub'
|
|
8
|
-
|
|
9
|
-
// TODO: Add test
|
|
10
|
-
export class LabelCreator {
|
|
11
|
-
private readonly github: GitHub
|
|
12
|
-
private readonly gitRepo: GitRepository
|
|
13
|
-
private readonly logger: Logger
|
|
14
|
-
|
|
15
|
-
constructor ({
|
|
16
|
-
github,
|
|
17
|
-
gitRepo,
|
|
18
|
-
logger
|
|
19
|
-
}: {
|
|
20
|
-
github: GitHub
|
|
21
|
-
gitRepo: GitRepository
|
|
22
|
-
logger: Logger
|
|
23
|
-
}) {
|
|
24
|
-
this.github = github
|
|
25
|
-
this.gitRepo = gitRepo
|
|
26
|
-
this.logger = logger
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async create ({
|
|
30
|
-
name,
|
|
31
|
-
description,
|
|
32
|
-
color
|
|
33
|
-
}: {
|
|
34
|
-
name: string
|
|
35
|
-
description?: string
|
|
36
|
-
color?: string
|
|
37
|
-
}): Promise<void> {
|
|
38
|
-
const label = await this.fetchLabel(name)
|
|
39
|
-
|
|
40
|
-
if (label !== undefined) {
|
|
41
|
-
this.logger.info(`Skip creating ${name} label because it already exists.`)
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
await this.github.createLabel({
|
|
46
|
-
owner: this.gitRepo.owner,
|
|
47
|
-
repo: this.gitRepo.name,
|
|
48
|
-
name,
|
|
49
|
-
description,
|
|
50
|
-
color
|
|
51
|
-
})
|
|
52
|
-
this.logger.info(`${name} label has created.`)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private async fetchLabel (name: string): Promise<Label | undefined> {
|
|
56
|
-
try {
|
|
57
|
-
return await this.github.fetchLabel({
|
|
58
|
-
owner: this.gitRepo.owner,
|
|
59
|
-
repo: this.gitRepo.name,
|
|
60
|
-
name
|
|
61
|
-
})
|
|
62
|
-
} catch (e) {
|
|
63
|
-
if (isNotFoundError(e)) {
|
|
64
|
-
this.logger.warn(e)
|
|
65
|
-
return undefined
|
|
66
|
-
} else {
|
|
67
|
-
throw e
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './LabelCreator'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './creator'
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
GitHub,
|
|
3
|
-
PullRequest
|
|
4
|
-
} from '../../GitHub'
|
|
5
|
-
import { PullRequestCloser } from './PullRequestCloser'
|
|
6
|
-
|
|
7
|
-
describe('PullRequestCloser', () => {
|
|
8
|
-
describe('close', () => {
|
|
9
|
-
const githubClosePullRequestMock = jest.fn()
|
|
10
|
-
const githubDeleteBranchMock = jest.fn()
|
|
11
|
-
|
|
12
|
-
const github = {
|
|
13
|
-
closePullRequest: githubClosePullRequestMock,
|
|
14
|
-
deleteBranch: githubDeleteBranchMock
|
|
15
|
-
} as unknown as GitHub
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
githubClosePullRequestMock.mockReset()
|
|
19
|
-
githubDeleteBranchMock.mockReset()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('closes pull request', async () => {
|
|
23
|
-
const pullRequest = {
|
|
24
|
-
number: 1,
|
|
25
|
-
head: {
|
|
26
|
-
ref: 'new-topic'
|
|
27
|
-
},
|
|
28
|
-
base: {
|
|
29
|
-
repo: {
|
|
30
|
-
name: 'npm-update-package',
|
|
31
|
-
owner: {
|
|
32
|
-
login: 'npm-update-package'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
} as unknown as PullRequest
|
|
37
|
-
|
|
38
|
-
const pullRequestCreator = new PullRequestCloser(github)
|
|
39
|
-
await pullRequestCreator.close(pullRequest)
|
|
40
|
-
|
|
41
|
-
expect(githubClosePullRequestMock).toBeCalledWith({
|
|
42
|
-
owner: pullRequest.base.repo.owner.login,
|
|
43
|
-
repo: pullRequest.base.repo.name,
|
|
44
|
-
pullNumber: pullRequest.number
|
|
45
|
-
})
|
|
46
|
-
expect(githubDeleteBranchMock).toBeCalledWith({
|
|
47
|
-
owner: pullRequest.base.repo.owner.login,
|
|
48
|
-
repo: pullRequest.base.repo.name,
|
|
49
|
-
branch: pullRequest.head.ref
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
GitHub,
|
|
3
|
-
PullRequest
|
|
4
|
-
} from '../../GitHub'
|
|
5
|
-
|
|
6
|
-
export class PullRequestCloser {
|
|
7
|
-
constructor (private readonly github: GitHub) {}
|
|
8
|
-
|
|
9
|
-
async close (pullRequest: PullRequest): Promise<void> {
|
|
10
|
-
await this.github.closePullRequest({
|
|
11
|
-
owner: pullRequest.base.repo.owner.login,
|
|
12
|
-
repo: pullRequest.base.repo.name,
|
|
13
|
-
pullNumber: pullRequest.number
|
|
14
|
-
})
|
|
15
|
-
await this.github.deleteBranch({
|
|
16
|
-
owner: pullRequest.base.repo.owner.login,
|
|
17
|
-
repo: pullRequest.base.repo.name,
|
|
18
|
-
branch: pullRequest.head.ref
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './PullRequestCloser'
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import type { OutdatedPackage } from '../../../core'
|
|
2
|
-
import type { GitRepository } from '../../../git'
|
|
3
|
-
import {
|
|
4
|
-
createLogger,
|
|
5
|
-
LogLevel
|
|
6
|
-
} from '../../../logger'
|
|
7
|
-
import type {
|
|
8
|
-
GitHub,
|
|
9
|
-
Repository as GitHubRepository
|
|
10
|
-
} from '../../GitHub'
|
|
11
|
-
import * as createPullRequestBodyModule from './createPullRequestBody'
|
|
12
|
-
import { PullRequestCreator } from './PullRequestCreator'
|
|
13
|
-
import type { PullRequestTitleCreator } from './PullRequestTitleCreator'
|
|
14
|
-
|
|
15
|
-
describe('PullRequestCreator', () => {
|
|
16
|
-
describe('create', () => {
|
|
17
|
-
const pullRequestTitleCreatorCreateMock = jest.fn()
|
|
18
|
-
const githubCreatePullRequestMock = jest.fn()
|
|
19
|
-
const githubAddLabelsMock = jest.fn()
|
|
20
|
-
const githubRequestReviewersMock = jest.fn()
|
|
21
|
-
const createPullRequestBodySpy = jest.spyOn(createPullRequestBodyModule, 'createPullRequestBody')
|
|
22
|
-
|
|
23
|
-
const github = {
|
|
24
|
-
createPullRequest: githubCreatePullRequestMock,
|
|
25
|
-
addLabels: githubAddLabelsMock,
|
|
26
|
-
requestReviewers: githubRequestReviewersMock
|
|
27
|
-
} as unknown as GitHub
|
|
28
|
-
const gitRepo = {
|
|
29
|
-
owner: 'repository owner',
|
|
30
|
-
name: 'repository name'
|
|
31
|
-
} as unknown as GitRepository
|
|
32
|
-
const githubRepo = {
|
|
33
|
-
default_branch: 'master'
|
|
34
|
-
} as unknown as GitHubRepository
|
|
35
|
-
const pullRequestTitleCreator = {
|
|
36
|
-
create: pullRequestTitleCreatorCreateMock
|
|
37
|
-
} as unknown as PullRequestTitleCreator
|
|
38
|
-
const logger = createLogger(LogLevel.Off)
|
|
39
|
-
const outdatedPackage = {} as unknown as OutdatedPackage
|
|
40
|
-
const branchName = 'branch name'
|
|
41
|
-
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
pullRequestTitleCreatorCreateMock.mockReset()
|
|
44
|
-
githubCreatePullRequestMock.mockReset()
|
|
45
|
-
githubAddLabelsMock.mockReset()
|
|
46
|
-
githubRequestReviewersMock.mockReset()
|
|
47
|
-
createPullRequestBodySpy.mockReset()
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('creates pull request', async () => {
|
|
51
|
-
const title = 'pull request title'
|
|
52
|
-
pullRequestTitleCreatorCreateMock.mockReturnValue(title)
|
|
53
|
-
const body = 'pull request body'
|
|
54
|
-
createPullRequestBodySpy.mockReturnValue(body)
|
|
55
|
-
const pullRequest = {
|
|
56
|
-
number: 1
|
|
57
|
-
}
|
|
58
|
-
githubCreatePullRequestMock.mockResolvedValue(pullRequest)
|
|
59
|
-
|
|
60
|
-
const reviewers = ['npm-update-package']
|
|
61
|
-
const pullRequestCreator = new PullRequestCreator({
|
|
62
|
-
github,
|
|
63
|
-
gitRepo,
|
|
64
|
-
githubRepo,
|
|
65
|
-
pullRequestTitleCreator,
|
|
66
|
-
logger,
|
|
67
|
-
reviewers
|
|
68
|
-
})
|
|
69
|
-
await pullRequestCreator.create({
|
|
70
|
-
outdatedPackage,
|
|
71
|
-
branchName
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
expect(pullRequestTitleCreatorCreateMock).toBeCalledWith(outdatedPackage)
|
|
75
|
-
expect(createPullRequestBodySpy).toBeCalledWith(outdatedPackage)
|
|
76
|
-
expect(githubCreatePullRequestMock).toBeCalledWith({
|
|
77
|
-
owner: gitRepo.owner,
|
|
78
|
-
repo: gitRepo.name,
|
|
79
|
-
baseBranch: githubRepo.default_branch,
|
|
80
|
-
headBranch: branchName,
|
|
81
|
-
title,
|
|
82
|
-
body
|
|
83
|
-
})
|
|
84
|
-
expect(githubAddLabelsMock).toBeCalledWith({
|
|
85
|
-
owner: gitRepo.owner,
|
|
86
|
-
repo: gitRepo.name,
|
|
87
|
-
issueNumber: pullRequest.number,
|
|
88
|
-
labels: ['npm-update-package']
|
|
89
|
-
})
|
|
90
|
-
expect(githubRequestReviewersMock).toBeCalledWith({
|
|
91
|
-
owner: gitRepo.owner,
|
|
92
|
-
repo: gitRepo.name,
|
|
93
|
-
pullNumber: pullRequest.number,
|
|
94
|
-
reviewers
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
})
|