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.
- package/dist/package.json +4 -4
- package/package.json +4 -4
- 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
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { OutdatedPackage } from '../../../core'
|
|
2
|
-
import type { GitRepository } from '../../../git'
|
|
3
|
-
import type { Logger } from '../../../logger'
|
|
4
|
-
import type {
|
|
5
|
-
CreatedPullRequest,
|
|
6
|
-
GitHub,
|
|
7
|
-
Repository as GitHubRepository
|
|
8
|
-
} from '../../GitHub'
|
|
9
|
-
import { createPullRequestBody } from './createPullRequestBody'
|
|
10
|
-
import type { PullRequestTitleCreator } from './PullRequestTitleCreator'
|
|
11
|
-
|
|
12
|
-
export class PullRequestCreator {
|
|
13
|
-
private readonly github: GitHub
|
|
14
|
-
private readonly gitRepo: GitRepository
|
|
15
|
-
private readonly githubRepo: GitHubRepository
|
|
16
|
-
private readonly pullRequestTitleCreator: PullRequestTitleCreator
|
|
17
|
-
private readonly logger: Logger
|
|
18
|
-
private readonly reviewers: string[] | undefined
|
|
19
|
-
|
|
20
|
-
constructor ({
|
|
21
|
-
github,
|
|
22
|
-
gitRepo,
|
|
23
|
-
githubRepo,
|
|
24
|
-
pullRequestTitleCreator,
|
|
25
|
-
logger,
|
|
26
|
-
reviewers
|
|
27
|
-
}: {
|
|
28
|
-
github: GitHub
|
|
29
|
-
gitRepo: GitRepository
|
|
30
|
-
githubRepo: GitHubRepository
|
|
31
|
-
pullRequestTitleCreator: PullRequestTitleCreator
|
|
32
|
-
logger: Logger
|
|
33
|
-
reviewers?: string[]
|
|
34
|
-
}) {
|
|
35
|
-
this.github = github
|
|
36
|
-
this.gitRepo = gitRepo
|
|
37
|
-
this.githubRepo = githubRepo
|
|
38
|
-
this.pullRequestTitleCreator = pullRequestTitleCreator
|
|
39
|
-
this.logger = logger
|
|
40
|
-
this.reviewers = reviewers
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async create ({
|
|
44
|
-
outdatedPackage,
|
|
45
|
-
branchName
|
|
46
|
-
}: {
|
|
47
|
-
outdatedPackage: OutdatedPackage
|
|
48
|
-
branchName: string
|
|
49
|
-
}): Promise<CreatedPullRequest> {
|
|
50
|
-
const title = this.pullRequestTitleCreator.create(outdatedPackage)
|
|
51
|
-
this.logger.debug(`title=${title}`)
|
|
52
|
-
|
|
53
|
-
const body = createPullRequestBody(outdatedPackage)
|
|
54
|
-
this.logger.debug(`body=${body}`)
|
|
55
|
-
|
|
56
|
-
const pullRequest = await this.github.createPullRequest({
|
|
57
|
-
owner: this.gitRepo.owner,
|
|
58
|
-
repo: this.gitRepo.name,
|
|
59
|
-
baseBranch: this.githubRepo.default_branch,
|
|
60
|
-
headBranch: branchName,
|
|
61
|
-
title,
|
|
62
|
-
body
|
|
63
|
-
})
|
|
64
|
-
this.logger.debug(`pullRequest=${JSON.stringify(pullRequest)}`)
|
|
65
|
-
|
|
66
|
-
await this.github.addLabels({
|
|
67
|
-
owner: this.gitRepo.owner,
|
|
68
|
-
repo: this.gitRepo.name,
|
|
69
|
-
issueNumber: pullRequest.number,
|
|
70
|
-
labels: ['npm-update-package']
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
if (this.reviewers !== undefined) {
|
|
74
|
-
await this.github.requestReviewers({
|
|
75
|
-
owner: this.gitRepo.owner,
|
|
76
|
-
repo: this.gitRepo.name,
|
|
77
|
-
pullNumber: pullRequest.number,
|
|
78
|
-
reviewers: this.reviewers
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return pullRequest
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SemVer } from '../../../semver'
|
|
2
|
-
import { PullRequestTitleCreator } from './PullRequestTitleCreator'
|
|
3
|
-
|
|
4
|
-
describe('PullRequestTitleCreator', () => {
|
|
5
|
-
describe('create', () => {
|
|
6
|
-
it('returns pull request title', () => {
|
|
7
|
-
const pullRequestTitleCreator = new PullRequestTitleCreator('chore(deps): {{level}} update {{{packageName}}} from {{currentVersion}} to v{{newVersion}}')
|
|
8
|
-
const actual = pullRequestTitleCreator.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 PullRequestTitleCreator {
|
|
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
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import pkg from '../../../../package.json'
|
|
3
|
-
import { SemVer } from '../../../semver'
|
|
4
|
-
import { createPullRequestBody } from './createPullRequestBody'
|
|
5
|
-
|
|
6
|
-
describe('createPullRequestBody', () => {
|
|
7
|
-
it('returns pull request body', () => {
|
|
8
|
-
const actual = createPullRequestBody({
|
|
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(`This PR updates these packages:
|
|
15
|
-
|
|
16
|
-
|Package|Level|Current version|New version|
|
|
17
|
-
|---|---|---|---|
|
|
18
|
-
|[@npm-update-package/example](https://www.npmjs.com/package/@npm-update-package/example)|major|\`1.0.0\`|\`2.0.0\`|
|
|
19
|
-
|
|
20
|
-
<details>
|
|
21
|
-
<summary>Metadata</summary>
|
|
22
|
-
|
|
23
|
-
**Don't remove or edit this section because it will be used by npm-update-package.**
|
|
24
|
-
|
|
25
|
-
<div id="npm-update-package-metadata">
|
|
26
|
-
|
|
27
|
-
\`\`\`json
|
|
28
|
-
{
|
|
29
|
-
"version": "${pkg.version}",
|
|
30
|
-
"packages": [
|
|
31
|
-
{
|
|
32
|
-
"name": "@npm-update-package/example",
|
|
33
|
-
"currentVersion": "1.0.0",
|
|
34
|
-
"newVersion": "2.0.0",
|
|
35
|
-
"level": "major"
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
\`\`\`
|
|
40
|
-
|
|
41
|
-
</div>
|
|
42
|
-
</details>
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
This PR has been generated by [${pkg.name}](${pkg.homepage}) v${pkg.version}`)
|
|
46
|
-
})
|
|
47
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import pkg from '../../../../package.json'
|
|
3
|
-
import type { OutdatedPackage } from '../../../core'
|
|
4
|
-
import { toJSON } from '../../../json'
|
|
5
|
-
import { createPullRequestMetadata } from '../metadata'
|
|
6
|
-
|
|
7
|
-
export const createPullRequestBody = (outdatedPackage: OutdatedPackage): string => {
|
|
8
|
-
const currentVersion = outdatedPackage.currentVersion.version
|
|
9
|
-
const newVersion = outdatedPackage.newVersion.version
|
|
10
|
-
const packageName = outdatedPackage.name
|
|
11
|
-
const level = outdatedPackage.level
|
|
12
|
-
const metadata = toJSON(createPullRequestMetadata([outdatedPackage]), { pretty: true })
|
|
13
|
-
return `This PR updates these packages:
|
|
14
|
-
|
|
15
|
-
|Package|Level|Current version|New version|
|
|
16
|
-
|---|---|---|---|
|
|
17
|
-
|[${packageName}](https://www.npmjs.com/package/${packageName})|${level}|\`${currentVersion}\`|\`${newVersion}\`|
|
|
18
|
-
|
|
19
|
-
<details>
|
|
20
|
-
<summary>Metadata</summary>
|
|
21
|
-
|
|
22
|
-
**Don't remove or edit this section because it will be used by npm-update-package.**
|
|
23
|
-
|
|
24
|
-
<div id="npm-update-package-metadata">
|
|
25
|
-
|
|
26
|
-
\`\`\`json
|
|
27
|
-
${metadata}
|
|
28
|
-
\`\`\`
|
|
29
|
-
|
|
30
|
-
</div>
|
|
31
|
-
</details>
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
This PR has been generated by [${pkg.name}](${pkg.homepage}) v${pkg.version}`
|
|
35
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { PullRequest } from '../../GitHub'
|
|
2
|
-
import { extractPullRequestMetadata } from '../metadata'
|
|
3
|
-
import { isPullRequestByNpmUpdatePackage } from './isPullRequestByNpmUpdatePackage'
|
|
4
|
-
|
|
5
|
-
// TODO: Add test
|
|
6
|
-
export class PullRequestFinder {
|
|
7
|
-
constructor (private readonly pullRequests: PullRequest[]) {}
|
|
8
|
-
|
|
9
|
-
findByPackageName (packageName: string): PullRequest[] {
|
|
10
|
-
return this.pullRequests
|
|
11
|
-
.filter(isPullRequestByNpmUpdatePackage)
|
|
12
|
-
.filter(({ body }) => {
|
|
13
|
-
if (body === null) {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const metadata = extractPullRequestMetadata(body)
|
|
18
|
-
|
|
19
|
-
if (metadata === undefined) {
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const { packages } = metadata
|
|
24
|
-
return packages.some(({ name }) => name === packageName)
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './PullRequestFinder'
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { PullRequest } from '../../GitHub'
|
|
2
|
-
import { isPullRequestByNpmUpdatePackage } from './isPullRequestByNpmUpdatePackage'
|
|
3
|
-
|
|
4
|
-
describe('isPullRequestByNpmUpdatePackage', () => {
|
|
5
|
-
it('returns true if pull request has label `npm-update-package`', () => {
|
|
6
|
-
const pullRequest = {
|
|
7
|
-
labels: [
|
|
8
|
-
{
|
|
9
|
-
name: 'npm-update-package'
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
} as unknown as PullRequest
|
|
13
|
-
|
|
14
|
-
expect(isPullRequestByNpmUpdatePackage(pullRequest)).toBe(true)
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('returns false if pull request does not have label `npm-update-package`', () => {
|
|
18
|
-
const pullRequest = {
|
|
19
|
-
labels: []
|
|
20
|
-
} as unknown as PullRequest
|
|
21
|
-
|
|
22
|
-
expect(isPullRequestByNpmUpdatePackage(pullRequest)).toBe(false)
|
|
23
|
-
})
|
|
24
|
-
})
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
array,
|
|
3
|
-
literal,
|
|
4
|
-
string,
|
|
5
|
-
type,
|
|
6
|
-
union,
|
|
7
|
-
type TypeOf
|
|
8
|
-
} from 'io-ts'
|
|
9
|
-
import { SemVerLevel } from '../../../semver'
|
|
10
|
-
|
|
11
|
-
const PullRequestMetadata = type({
|
|
12
|
-
version: string,
|
|
13
|
-
packages: array(type({
|
|
14
|
-
name: string,
|
|
15
|
-
currentVersion: string,
|
|
16
|
-
newVersion: string,
|
|
17
|
-
level: union([literal(SemVerLevel.Major), literal(SemVerLevel.Minor), literal(SemVerLevel.Patch)])
|
|
18
|
-
}))
|
|
19
|
-
})
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
21
|
-
export type PullRequestMetadata = TypeOf<typeof PullRequestMetadata>
|
|
22
|
-
export const isPullRequestMetadata = PullRequestMetadata.is
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import pkg from '../../../../package.json'
|
|
3
|
-
import type { OutdatedPackage } from '../../../core'
|
|
4
|
-
import { SemVer } from '../../../semver'
|
|
5
|
-
import { createPullRequestMetadata } from './createPullRequestMetadata'
|
|
6
|
-
|
|
7
|
-
describe('createPullRequestMetadata', () => {
|
|
8
|
-
it('returns PullRequestMetadata', () => {
|
|
9
|
-
const outdatedPackages: OutdatedPackage[] = [
|
|
10
|
-
{
|
|
11
|
-
name: '@npm-update-package/example',
|
|
12
|
-
currentVersion: SemVer.of('1.0.0'),
|
|
13
|
-
newVersion: SemVer.of('2.0.0'),
|
|
14
|
-
level: 'major'
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
const metadata = createPullRequestMetadata(outdatedPackages)
|
|
18
|
-
|
|
19
|
-
expect(metadata).toEqual({
|
|
20
|
-
version: pkg.version,
|
|
21
|
-
packages: [
|
|
22
|
-
{
|
|
23
|
-
name: '@npm-update-package/example',
|
|
24
|
-
currentVersion: '1.0.0',
|
|
25
|
-
newVersion: '2.0.0',
|
|
26
|
-
level: 'major'
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import pkg from '../../../../package.json'
|
|
3
|
-
import type { OutdatedPackage } from '../../../core'
|
|
4
|
-
import type { PullRequestMetadata } from './PullRequestMetadata'
|
|
5
|
-
|
|
6
|
-
export const createPullRequestMetadata = (outdatedPackages: OutdatedPackage[]): PullRequestMetadata => {
|
|
7
|
-
return {
|
|
8
|
-
version: pkg.version,
|
|
9
|
-
packages: outdatedPackages.map(({
|
|
10
|
-
name,
|
|
11
|
-
currentVersion,
|
|
12
|
-
newVersion,
|
|
13
|
-
level
|
|
14
|
-
}) => ({
|
|
15
|
-
name,
|
|
16
|
-
currentVersion: currentVersion.version,
|
|
17
|
-
newVersion: newVersion.version,
|
|
18
|
-
level
|
|
19
|
-
}))
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { extractPullRequestMetadata } from './extractPullRequestMetadata'
|
|
2
|
-
|
|
3
|
-
describe('extractPullRequestMetadata', () => {
|
|
4
|
-
it('returns PullRequestMetadata if body contains metadata', () => {
|
|
5
|
-
const body = `<div id="npm-update-package-metadata">
|
|
6
|
-
|
|
7
|
-
\`\`\`json
|
|
8
|
-
{
|
|
9
|
-
"version": "1.0.0",
|
|
10
|
-
"packages": [
|
|
11
|
-
{
|
|
12
|
-
"name": "@npm-update-package/example",
|
|
13
|
-
"level": "major",
|
|
14
|
-
"currentVersion": "1.0.0",
|
|
15
|
-
"newVersion": "2.0.0"
|
|
16
|
-
}
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
\`\`\`
|
|
20
|
-
|
|
21
|
-
</div>`
|
|
22
|
-
const metadata = extractPullRequestMetadata(body)
|
|
23
|
-
expect(metadata).toEqual({
|
|
24
|
-
version: '1.0.0',
|
|
25
|
-
packages: [
|
|
26
|
-
{
|
|
27
|
-
name: '@npm-update-package/example',
|
|
28
|
-
level: 'major',
|
|
29
|
-
currentVersion: '1.0.0',
|
|
30
|
-
newVersion: '2.0.0'
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it('returns undefined if body does not contain metadata', () => {
|
|
37
|
-
const body = ''
|
|
38
|
-
const metadata = extractPullRequestMetadata(body)
|
|
39
|
-
expect(metadata).toBeUndefined()
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('returns undefined if metadata is invalid', () => {
|
|
43
|
-
const body = `<div id="npm-update-package-metadata">
|
|
44
|
-
|
|
45
|
-
\`\`\`json
|
|
46
|
-
{}
|
|
47
|
-
\`\`\`
|
|
48
|
-
|
|
49
|
-
</div>`
|
|
50
|
-
const metadata = extractPullRequestMetadata(body)
|
|
51
|
-
expect(metadata).toBeUndefined()
|
|
52
|
-
})
|
|
53
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isPullRequestMetadata,
|
|
3
|
-
type PullRequestMetadata
|
|
4
|
-
} from './PullRequestMetadata'
|
|
5
|
-
|
|
6
|
-
export const extractPullRequestMetadata = (pullRequestBody: string): PullRequestMetadata | undefined => {
|
|
7
|
-
const matched = pullRequestBody.match(/<div id="npm-update-package-metadata">\s*```json\s*([\s\S]+?)\s*```\s*<\/div>/)
|
|
8
|
-
const json = matched?.[1]
|
|
9
|
-
|
|
10
|
-
if (json === undefined) {
|
|
11
|
-
return undefined
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const metadata: unknown = JSON.parse(json)
|
|
15
|
-
|
|
16
|
-
if (!isPullRequestMetadata(metadata)) {
|
|
17
|
-
return undefined
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return metadata
|
|
21
|
-
}
|
package/src/json/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './toJSON'
|
package/src/json/toJSON.test.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { toJSON } from './toJSON'
|
|
2
|
-
|
|
3
|
-
type TestCase = [unknown, string]
|
|
4
|
-
|
|
5
|
-
describe('toJSON', () => {
|
|
6
|
-
describe('returns not indented JSON string if pretty option is false', () => {
|
|
7
|
-
const cases: TestCase[] = [
|
|
8
|
-
[
|
|
9
|
-
{
|
|
10
|
-
number: 1,
|
|
11
|
-
string: 'string'
|
|
12
|
-
},
|
|
13
|
-
'{"number":1,"string":"string"}'
|
|
14
|
-
],
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
{
|
|
18
|
-
number: 1,
|
|
19
|
-
string: 'string'
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
'[{"number":1,"string":"string"}]'
|
|
23
|
-
]
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
it.each<TestCase>(cases)('value=%j', (value, expected) => {
|
|
27
|
-
const json = toJSON(value)
|
|
28
|
-
expect(json).toBe(expected)
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
describe('returns indented JSON string if pretty option is true', () => {
|
|
33
|
-
const cases: TestCase[] = [
|
|
34
|
-
[
|
|
35
|
-
{
|
|
36
|
-
number: 1,
|
|
37
|
-
string: 'string'
|
|
38
|
-
},
|
|
39
|
-
`{
|
|
40
|
-
"number": 1,
|
|
41
|
-
"string": "string"
|
|
42
|
-
}`
|
|
43
|
-
],
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
{
|
|
47
|
-
number: 1,
|
|
48
|
-
string: 'string'
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
`[
|
|
52
|
-
{
|
|
53
|
-
"number": 1,
|
|
54
|
-
"string": "string"
|
|
55
|
-
}
|
|
56
|
-
]`
|
|
57
|
-
]
|
|
58
|
-
]
|
|
59
|
-
|
|
60
|
-
it.each<TestCase>(cases)('value=%j', (value, expected) => {
|
|
61
|
-
const json = toJSON(value, { pretty: true })
|
|
62
|
-
expect(json).toBe(expected)
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
})
|
package/src/json/toJSON.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
interface Options {
|
|
2
|
-
pretty?: boolean
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export const toJSON = (value: unknown, options?: Options): string => {
|
|
6
|
-
const pretty = options?.pretty ?? false
|
|
7
|
-
|
|
8
|
-
if (pretty) {
|
|
9
|
-
return JSON.stringify(value, null, 2)
|
|
10
|
-
} else {
|
|
11
|
-
return JSON.stringify(value)
|
|
12
|
-
}
|
|
13
|
-
}
|
package/src/logger/LogLevel.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const LogLevel = {
|
|
2
|
-
Debug: 'debug',
|
|
3
|
-
Error: 'error',
|
|
4
|
-
Fatal: 'fatal',
|
|
5
|
-
Info: 'info',
|
|
6
|
-
Off: 'off',
|
|
7
|
-
Trace: 'trace',
|
|
8
|
-
Warn: 'warn'
|
|
9
|
-
} as const
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
11
|
-
export type LogLevel = typeof LogLevel[keyof typeof LogLevel]
|
|
12
|
-
const logLevels = Object.values(LogLevel)
|
|
13
|
-
export const isLogLevel = (value: any): value is LogLevel => logLevels.includes(value)
|
package/src/logger/Logger.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { Logger } from 'log4js'
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getLogger } from 'log4js'
|
|
2
|
-
import type { Logger } from './Logger'
|
|
3
|
-
import type { LogLevel } from './LogLevel'
|
|
4
|
-
|
|
5
|
-
// TODO: add test
|
|
6
|
-
export const createLogger = (logLevel: LogLevel): Logger => {
|
|
7
|
-
const logger = getLogger()
|
|
8
|
-
logger.level = logLevel
|
|
9
|
-
return logger
|
|
10
|
-
}
|
package/src/logger/index.ts
DELETED