Skip to content

Commit f022984

Browse files
committed
feat(simple-github-release): drop git-url-parse dependency in favor of @simple-libs/hosted-git-info
1 parent 54bbff6 commit f022984

File tree

10 files changed

+192
-257
lines changed

10 files changed

+192
-257
lines changed

packages/simple-github-release/.eslintrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"project": ["./tsconfig.json"]
1010
},
1111
"rules": {
12-
"no-template-curly-in-string": "off",
13-
"no-console": "off"
12+
"no-console": "off",
13+
"no-template-curly-in-string": "off"
1414
}
1515
}

packages/simple-github-release/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,12 @@
5656
},
5757
"dependencies": {
5858
"@octokit/rest": "^20.0.0",
59-
"@types/git-url-parse": "^9.0.1",
59+
"@simple-libs/child-process-utils": "^1.0.0",
60+
"@simple-libs/hosted-git-info": "^1.0.0",
6061
"argue-cli": "^2.1.0",
61-
"git-url-parse": "^13.0.0",
6262
"lilconfig": "^3.0.0",
6363
"new-github-release-url": "^2.0.0",
6464
"open": "^10.0.0",
6565
"picocolors": "^1.0.0"
66-
},
67-
"devDependencies": {
68-
"@types/node": "^22.15.23"
6966
}
7067
}

packages/simple-github-release/src/changelog.spec.ts

Lines changed: 80 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,84 +7,86 @@ import { readLastChangesFromStream } from './changelog.js'
77
const dirname = fileURLToPath(new URL('.', import.meta.url))
88
const mocks = path.join(dirname, '..', 'test', 'mocks')
99

10-
describe('changelog', () => {
11-
describe('readLastChangesFromStream', () => {
12-
it('should read last changes from file', async () => {
13-
const stream = fs.createReadStream(path.join(mocks, 'CHANGELOG_0.md'))
14-
15-
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
16-
[
17-
"8.0.0-alpha.2",
18-
"### Bug Fixes
19-
20-
* **deps:** update dependency dotenv to v11 ([#16](https://github.com/TrigenSoftware/scripts/issues/16)) ([27e4ce7](https://github.com/TrigenSoftware/scripts/commit/27e4ce7414f6d50fec9fe363238d771cf49b4cd7))
21-
22-
### Features
23-
24-
* **browserslist-config:** update queries, add esm queries ([3031c6b](https://github.com/TrigenSoftware/scripts/commit/3031c6b322330be57654bdebc1012bddc20e7972))
25-
",
26-
]
27-
`)
28-
})
29-
30-
it('should read last changes from file with header', async () => {
31-
const stream = fs.createReadStream(path.join(mocks, 'CHANGELOG_0.md'))
32-
const options = {
33-
includeTitle: true
34-
}
35-
36-
expect(await readLastChangesFromStream(stream, options)).toMatchInlineSnapshot(`
37-
[
38-
"8.0.0-alpha.2",
39-
"# [8.0.0-alpha.2](https://github.com/TrigenSoftware/scripts/compare/v8.0.0-alpha.1...v8.0.0-alpha.2) (2022-01-14)
40-
41-
### Bug Fixes
42-
43-
* **deps:** update dependency dotenv to v11 ([#16](https://github.com/TrigenSoftware/scripts/issues/16)) ([27e4ce7](https://github.com/TrigenSoftware/scripts/commit/27e4ce7414f6d50fec9fe363238d771cf49b4cd7))
44-
45-
### Features
46-
47-
* **browserslist-config:** update queries, add esm queries ([3031c6b](https://github.com/TrigenSoftware/scripts/commit/3031c6b322330be57654bdebc1012bddc20e7972))
48-
",
49-
]
50-
`)
51-
})
52-
53-
it('should split titile without link', async () => {
54-
const stream = fs.createReadStream(path.join(mocks, 'CHANGELOG_1.md'))
55-
56-
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
57-
[
58-
"0.0.1-1",
59-
"### Bug Fixes
60-
61-
* **cli:** fix config file loading ([8603c2f](https://github.com/TrigenSoftware/simple-github-release/commit/8603c2fde4aeb53619fae8bb9feba53093f51c65))
62-
",
63-
]
64-
`)
65-
})
66-
67-
it('should read keep a changelog', async () => {
68-
const stream = fs.createReadStream(path.join(mocks, 'CHANGELOG_2.md'))
69-
70-
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
71-
[
72-
"1.0.0",
73-
"### Added
74-
- Version navigation.
75-
- Links to latest released version in previous versions.
76-
- "Why keep a changelog?" section.
77-
78-
### Changed
79-
- Start using "changelog" over "change log" since it's the common usage.
80-
- Start versioning based on the current English version at 0.3.0 to help
81-
translation authors keep things up-to-date.
82-
83-
### Removed
84-
- Section about "changelog" vs "CHANGELOG".
85-
",
86-
]
87-
`)
10+
describe('simple-github-release', () => {
11+
describe('changelog', () => {
12+
describe('readLastChangesFromStream', () => {
13+
it('should read last changes from file', async () => {
14+
const stream = fs.createReadStream(path.join(mocks, 'CHANGELOG_0.md'))
15+
16+
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
17+
[
18+
"8.0.0-alpha.2",
19+
"### Bug Fixes
20+
21+
* **deps:** update dependency dotenv to v11 ([#16](https://github.com/TrigenSoftware/scripts/issues/16)) ([27e4ce7](https://github.com/TrigenSoftware/scripts/commit/27e4ce7414f6d50fec9fe363238d771cf49b4cd7))
22+
23+
### Features
24+
25+
* **browserslist-config:** update queries, add esm queries ([3031c6b](https://github.com/TrigenSoftware/scripts/commit/3031c6b322330be57654bdebc1012bddc20e7972))
26+
",
27+
]
28+
`)
29+
})
30+
31+
it('should read last changes from file with header', async () => {
32+
const stream = fs.createReadStream(path.join(mocks, 'CHANGELOG_0.md'))
33+
const options = {
34+
includeTitle: true
35+
}
36+
37+
expect(await readLastChangesFromStream(stream, options)).toMatchInlineSnapshot(`
38+
[
39+
"8.0.0-alpha.2",
40+
"# [8.0.0-alpha.2](https://github.com/TrigenSoftware/scripts/compare/v8.0.0-alpha.1...v8.0.0-alpha.2) (2022-01-14)
41+
42+
### Bug Fixes
43+
44+
* **deps:** update dependency dotenv to v11 ([#16](https://github.com/TrigenSoftware/scripts/issues/16)) ([27e4ce7](https://github.com/TrigenSoftware/scripts/commit/27e4ce7414f6d50fec9fe363238d771cf49b4cd7))
45+
46+
### Features
47+
48+
* **browserslist-config:** update queries, add esm queries ([3031c6b](https://github.com/TrigenSoftware/scripts/commit/3031c6b322330be57654bdebc1012bddc20e7972))
49+
",
50+
]
51+
`)
52+
})
53+
54+
it('should split titile without link', async () => {
55+
const stream = fs.createReadStream(path.join(mocks, 'CHANGELOG_1.md'))
56+
57+
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
58+
[
59+
"0.0.1-1",
60+
"### Bug Fixes
61+
62+
* **cli:** fix config file loading ([8603c2f](https://github.com/TrigenSoftware/simple-github-release/commit/8603c2fde4aeb53619fae8bb9feba53093f51c65))
63+
",
64+
]
65+
`)
66+
})
67+
68+
it('should read keep a changelog', async () => {
69+
const stream = fs.createReadStream(path.join(mocks, 'CHANGELOG_2.md'))
70+
71+
expect(await readLastChangesFromStream(stream)).toMatchInlineSnapshot(`
72+
[
73+
"1.0.0",
74+
"### Added
75+
- Version navigation.
76+
- Links to latest released version in previous versions.
77+
- "Why keep a changelog?" section.
78+
79+
### Changed
80+
- Start using "changelog" over "change log" since it's the common usage.
81+
- Start versioning based on the current English version at 0.3.0 to help
82+
translation authors keep things up-to-date.
83+
84+
### Removed
85+
- Section about "changelog" vs "CHANGELOG".
86+
",
87+
]
88+
`)
89+
})
8890
})
8991
})
9092
})

packages/simple-github-release/src/git.spec.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { describe, it, expect } from 'vitest'
22
import { getRemoteUrl, parseGitUrl } from './git.js'
33

4-
describe('git', () => {
5-
describe('getRemoteUrl', () => {
6-
it('should get remote url', async () => {
7-
expect(['[email protected]:TrigenSoftware/simple-release-tools.git', 'https://github.com/TrigenSoftware/simple-release-tools']).toContain(await getRemoteUrl())
4+
describe('simple-github-release', () => {
5+
describe('git', () => {
6+
describe('getRemoteUrl', () => {
7+
it('should get remote url', async () => {
8+
expect(['[email protected]:TrigenSoftware/simple-release-tools.git', 'https://github.com/TrigenSoftware/simple-release-tools']).toContain(await getRemoteUrl())
9+
})
810
})
9-
})
1011

11-
describe('parseGitUrl', () => {
12-
it('should parse git url', () => {
13-
expect(parseGitUrl('[email protected]:TrigenSoftware/simple-release-tools.git')).toEqual({
14-
host: 'github.com',
15-
owner: 'TrigenSoftware',
16-
project: 'simple-release-tools',
17-
protocol: 'ssh',
18-
remote: '[email protected]:TrigenSoftware/simple-release-tools.git',
19-
repository: 'TrigenSoftware/simple-release-tools'
12+
describe('parseGitUrl', () => {
13+
it('should parse git url', () => {
14+
expect(parseGitUrl('[email protected]:TrigenSoftware/simple-release-tools.git')).toEqual({
15+
host: 'github.com',
16+
owner: 'TrigenSoftware',
17+
project: 'simple-release-tools'
18+
})
2019
})
2120
})
2221
})

packages/simple-github-release/src/git.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import gitUrlParse from 'git-url-parse'
1+
import { parseHostedGitUrl } from '@simple-libs/hosted-git-info'
22
import type { Repository } from './types.js'
33
import { spawn } from './spawn.js'
44

@@ -101,26 +101,12 @@ export async function getRemoteUrl() {
101101
*/
102102
export function parseGitUrl(remoteUrl: string): Repository {
103103
const url = (remoteUrl || '').replace(/\\/g, '/')
104-
const parsedUrl = gitUrlParse(url)
105-
const {
106-
protocol,
107-
resource: host,
108-
href: remote,
109-
owner: parsedOwner,
110-
name: project
111-
} = parsedUrl
112-
const owner = protocol === 'file'
113-
? parsedUrl.owner.split('/').pop() ?? ''
114-
: parsedOwner
115-
const repository = `${owner}/${project}`
104+
const parsedUrl = parseHostedGitUrl(url)
116105

117106
return {
118-
host,
119-
owner,
120-
project,
121-
protocol,
122-
remote,
123-
repository
107+
host: parsedUrl?.host?.replace(/^.*:\/\//, '') || '',
108+
owner: parsedUrl?.owner || '',
109+
project: parsedUrl?.project || ''
124110
}
125111
}
126112

packages/simple-github-release/src/github.spec.ts

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,75 @@ import { octokit } from '../test/mocks/octokit.mock.js'
33
import { GitHubClient } from './github.js'
44
import { parseGitUrl } from './git.js'
55

6-
describe('github', () => {
7-
describe('GitHubClient', () => {
8-
let client: GitHubClient
6+
describe('simple-github-release', () => {
7+
describe('github', () => {
8+
describe('GitHubClient', () => {
9+
let client: GitHubClient
910

10-
it('should create instance', () => {
11-
client = new GitHubClient({
12-
repo: parseGitUrl('[email protected]:TrigenSoftware/simple-github-release.git')
13-
})
11+
it('should create instance', () => {
12+
client = new GitHubClient({
13+
repo: parseGitUrl('[email protected]:TrigenSoftware/simple-github-release.git')
14+
})
1415

15-
// @ts-expect-error Inject mock client for tests.
16-
client.client = octokit
17-
})
16+
// @ts-expect-error Inject mock client for tests.
17+
client.client = octokit
18+
})
1819

19-
describe('getLatestRelease', () => {
20-
it('should return latest release if exist', async () => {
21-
expect(await client.getLatestRelease()).toEqual({
22-
id: 1,
23-
tag: 'v1.0.0'
20+
describe('getLatestRelease', () => {
21+
it('should return latest release if exist', async () => {
22+
expect(await client.getLatestRelease()).toEqual({
23+
id: 1,
24+
tag: 'v1.0.0'
25+
})
2426
})
25-
})
2627

27-
it('should return null if no any releases', async () => {
28-
octokit.shouldThrowError = true
28+
it('should return null if no any releases', async () => {
29+
octokit.shouldThrowError = true
2930

30-
expect(await client.getLatestRelease()).toBe(null)
31+
expect(await client.getLatestRelease()).toBe(null)
32+
})
3133
})
32-
})
3334

34-
describe('createRelease', () => {
35-
it('should create release', async () => {
36-
expect(await client.createRelease({
37-
name: 'v1.0.0',
38-
tag: 'v1.0.0'
39-
})).toEqual({
40-
id: 1,
41-
releaseUrl: 'https://github.com/release'
35+
describe('createRelease', () => {
36+
it('should create release', async () => {
37+
expect(await client.createRelease({
38+
name: 'v1.0.0',
39+
tag: 'v1.0.0'
40+
})).toEqual({
41+
id: 1,
42+
releaseUrl: 'https://github.com/release'
43+
})
4244
})
4345
})
44-
})
4546

46-
describe('updateRelease', () => {
47-
it('should update release', async () => {
48-
expect(await client.updateRelease(1, {
49-
name: 'v1.0.0',
50-
tag: 'v1.0.0'
51-
})).toEqual({
52-
id: 1,
53-
releaseUrl: 'https://github.com/release'
47+
describe('updateRelease', () => {
48+
it('should update release', async () => {
49+
expect(await client.updateRelease(1, {
50+
name: 'v1.0.0',
51+
tag: 'v1.0.0'
52+
})).toEqual({
53+
id: 1,
54+
releaseUrl: 'https://github.com/release'
55+
})
5456
})
5557
})
56-
})
5758

58-
describe('createReleaseUrl', () => {
59-
it('should create url', () => {
60-
expect(client.createReleaseUrl({
61-
name: 'v1.0.0',
62-
tag: 'v1.0.0'
63-
})).toBe('https://github.com/TrigenSoftware/simple-github-release/releases/tag/v1.0.0')
59+
describe('createReleaseUrl', () => {
60+
it('should create url', () => {
61+
expect(client.createReleaseUrl({
62+
name: 'v1.0.0',
63+
tag: 'v1.0.0'
64+
})).toBe('https://github.com/TrigenSoftware/simple-github-release/releases/tag/v1.0.0')
65+
})
6466
})
65-
})
6667

67-
describe('createBrowserReleaseUrl', () => {
68-
it('should create url', () => {
69-
expect(client.createBrowserReleaseUrl({
70-
name: 'v1.0.0',
71-
tag: 'v1.0.0'
72-
})).toBe('https://github.com/TrigenSoftware/simple-github-release/releases/new?tag=v1.0.0&title=v1.0.0&prerelease=false')
68+
describe('createBrowserReleaseUrl', () => {
69+
it('should create url', () => {
70+
expect(client.createBrowserReleaseUrl({
71+
name: 'v1.0.0',
72+
tag: 'v1.0.0'
73+
})).toBe('https://github.com/TrigenSoftware/simple-github-release/releases/new?tag=v1.0.0&title=v1.0.0&prerelease=false')
74+
})
7375
})
7476
})
7577
})

0 commit comments

Comments
 (0)