@hadl-labs/changelog-github 0.1.0 → 0.3.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/dist/index.d.ts +3 -0
- package/dist/index.js +579 -0
- package/package.json +14 -6
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/bun.lock +0 -734
- package/prettier.config.js +0 -8
- package/src/index.test.ts +0 -109
- package/src/index.ts +0 -113
- package/tsconfig.json +0 -29
package/prettier.config.js
DELETED
package/src/index.test.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import changelogFunctions from "./index"
|
|
2
|
-
import parse from "@changesets/parse"
|
|
3
|
-
import type { getInfo, getInfoFromPullRequest } from "@changesets/get-github-info"
|
|
4
|
-
|
|
5
|
-
type GetInfoRequest = Parameters<typeof getInfo>[0]
|
|
6
|
-
type GetInfoFromPullRequestRequest = Parameters<typeof getInfoFromPullRequest>[0]
|
|
7
|
-
|
|
8
|
-
const getReleaseLine = changelogFunctions.getReleaseLine
|
|
9
|
-
|
|
10
|
-
const mockData = {
|
|
11
|
-
commit: "a085003",
|
|
12
|
-
user: "Andarist",
|
|
13
|
-
pull: 1613,
|
|
14
|
-
repo: "emotion-js/emotion",
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const mockLinks = {
|
|
18
|
-
user: `[@${mockData.user}](https://github.com/${mockData.user})`,
|
|
19
|
-
pull: `[#${mockData.pull}](https://github.com/${mockData.repo}/pull/${mockData.pull})`,
|
|
20
|
-
commit: `[\`${mockData.commit}\`](https://github.com/${mockData.repo}/commit/${mockData.commit})`,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
jest.mock("@changesets/get-github-info", () => ({
|
|
24
|
-
getInfo: ({ commit, repo }: GetInfoRequest) => {
|
|
25
|
-
expect(commit).toBe(mockData.commit)
|
|
26
|
-
expect(repo).toBe(mockData.repo)
|
|
27
|
-
return Promise.resolve({
|
|
28
|
-
pull: mockData.pull,
|
|
29
|
-
user: mockData.user,
|
|
30
|
-
links: mockLinks,
|
|
31
|
-
})
|
|
32
|
-
},
|
|
33
|
-
getInfoFromPullRequest: ({ pull, repo }: GetInfoFromPullRequestRequest) => {
|
|
34
|
-
expect(pull).toBe(mockData.pull)
|
|
35
|
-
expect(repo).toBe(mockData.repo)
|
|
36
|
-
return Promise.resolve({
|
|
37
|
-
commit: mockData.commit,
|
|
38
|
-
user: mockData.user,
|
|
39
|
-
links: mockLinks,
|
|
40
|
-
})
|
|
41
|
-
},
|
|
42
|
-
}))
|
|
43
|
-
|
|
44
|
-
const getChangeset = (content: string, commit: string | undefined) => {
|
|
45
|
-
return [
|
|
46
|
-
{
|
|
47
|
-
...parse(
|
|
48
|
-
`---
|
|
49
|
-
pkg: "minor"
|
|
50
|
-
---
|
|
51
|
-
something
|
|
52
|
-
${content}
|
|
53
|
-
`,
|
|
54
|
-
),
|
|
55
|
-
id: "some-id",
|
|
56
|
-
commit,
|
|
57
|
-
},
|
|
58
|
-
"minor",
|
|
59
|
-
{ repo: mockData.repo },
|
|
60
|
-
] as const
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
describe.each([mockData.commit, "wrongcommit", undefined])(
|
|
64
|
-
"with commit from changeset of %s",
|
|
65
|
-
(commitFromChangeset) => {
|
|
66
|
-
describe.each(["pr", "pull request", "pull"])("override pr with %s keyword", (keyword) => {
|
|
67
|
-
test.each(["with #", "without #"] as const)(" %s", async (kind) => {
|
|
68
|
-
const result = await getReleaseLine(
|
|
69
|
-
...getChangeset(
|
|
70
|
-
`${keyword}: ${kind === "with #" ? "#" : ""}${mockData.pull}`,
|
|
71
|
-
commitFromChangeset,
|
|
72
|
-
),
|
|
73
|
-
)
|
|
74
|
-
expect(result).toEqual(
|
|
75
|
-
`\n\n- [#1613](https://github.com/emotion-js/emotion/pull/1613) [\`a085003\`](https://github.com/emotion-js/emotion/commit/a085003) Thanks [@Andarist](https://github.com/Andarist)! - something\n`,
|
|
76
|
-
)
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test("override commit with commit keyword", async () => {
|
|
81
|
-
const result = await getReleaseLine(
|
|
82
|
-
...getChangeset(`commit: ${mockData.commit}`, commitFromChangeset),
|
|
83
|
-
)
|
|
84
|
-
expect(result).toEqual(
|
|
85
|
-
`\n\n- [#1613](https://github.com/emotion-js/emotion/pull/1613) [\`a085003\`](https://github.com/emotion-js/emotion/commit/a085003) Thanks [@Andarist](https://github.com/Andarist)! - something\n`,
|
|
86
|
-
)
|
|
87
|
-
})
|
|
88
|
-
},
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
describe.each(["author", "user"])("override author with %s keyword", (keyword) => {
|
|
92
|
-
test.each(["with @", "without @"] as const)(" %s", async (kind) => {
|
|
93
|
-
const result = await getReleaseLine(
|
|
94
|
-
...getChangeset(`${keyword}: ${kind === "with @" ? "@" : ""}other`, mockData.commit),
|
|
95
|
-
)
|
|
96
|
-
expect(result).toEqual(
|
|
97
|
-
`\n\n- [#1613](https://github.com/emotion-js/emotion/pull/1613) [\`a085003\`](https://github.com/emotion-js/emotion/commit/a085003) Thanks [@other](https://github.com/other)! - something\n`,
|
|
98
|
-
)
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it("with multiple authors", async () => {
|
|
103
|
-
const result = await getReleaseLine(
|
|
104
|
-
...getChangeset(["author: @Andarist", "author: @mitchellhamilton"].join("\n"), mockData.commit),
|
|
105
|
-
)
|
|
106
|
-
expect(result).toBe(
|
|
107
|
-
"\n\n- [#1613](https://github.com/emotion-js/emotion/pull/1613) [\`a085003\`](https://github.com/emotion-js/emotion/commit/a085003) Thanks [@Andarist](https://github.com/Andarist), [@mitchellhamilton](https://github.com/mitchellhamilton)! - something\n",
|
|
108
|
-
)
|
|
109
|
-
})
|
package/src/index.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { ChangelogFunctions } from "@changesets/types"
|
|
2
|
-
import { getInfo, getInfoFromPullRequest } from "@changesets/get-github-info"
|
|
3
|
-
|
|
4
|
-
const changelogFunctions: ChangelogFunctions = {
|
|
5
|
-
getDependencyReleaseLine: async (changesets, dependenciesUpdated, options) => {
|
|
6
|
-
if (!options.repo) {
|
|
7
|
-
throw new Error(
|
|
8
|
-
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
|
|
9
|
-
)
|
|
10
|
-
}
|
|
11
|
-
if (dependenciesUpdated.length === 0) return ""
|
|
12
|
-
|
|
13
|
-
const changesetLink = `- Updated dependencies [${(
|
|
14
|
-
await Promise.all(
|
|
15
|
-
changesets.map(async (cs) => {
|
|
16
|
-
if (cs.commit) {
|
|
17
|
-
let { links } = await getInfo({
|
|
18
|
-
repo: options.repo,
|
|
19
|
-
commit: cs.commit,
|
|
20
|
-
})
|
|
21
|
-
return links.commit
|
|
22
|
-
}
|
|
23
|
-
}),
|
|
24
|
-
)
|
|
25
|
-
)
|
|
26
|
-
.filter((_) => _)
|
|
27
|
-
.join(", ")}]:`
|
|
28
|
-
|
|
29
|
-
const updatedDepenenciesList = dependenciesUpdated.map(
|
|
30
|
-
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
return [changesetLink, ...updatedDepenenciesList].join("\n")
|
|
34
|
-
},
|
|
35
|
-
getReleaseLine: async (changeset, type, options) => {
|
|
36
|
-
if (!options || !options.repo) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
'Please provide a repo to this changelog generator like this:\n"changelog": ["@changesets/changelog-github", { "repo": "org/repo" }]',
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let prFromSummary: number | undefined
|
|
43
|
-
let commitFromSummary: string | undefined
|
|
44
|
-
let usersFromSummary: string[] = []
|
|
45
|
-
|
|
46
|
-
const replacedChangelog = changeset.summary
|
|
47
|
-
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
|
|
48
|
-
let num = Number(pr)
|
|
49
|
-
if (!isNaN(num)) prFromSummary = num
|
|
50
|
-
return ""
|
|
51
|
-
})
|
|
52
|
-
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
|
|
53
|
-
commitFromSummary = commit
|
|
54
|
-
return ""
|
|
55
|
-
})
|
|
56
|
-
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
|
|
57
|
-
usersFromSummary.push(user)
|
|
58
|
-
return ""
|
|
59
|
-
})
|
|
60
|
-
.trim()
|
|
61
|
-
|
|
62
|
-
const [firstLine, ...futureLines] = replacedChangelog.split("\n").map((l) => l.trimRight())
|
|
63
|
-
|
|
64
|
-
const links = await (async () => {
|
|
65
|
-
if (prFromSummary !== undefined) {
|
|
66
|
-
let { links } = await getInfoFromPullRequest({
|
|
67
|
-
repo: options.repo,
|
|
68
|
-
pull: prFromSummary,
|
|
69
|
-
})
|
|
70
|
-
if (commitFromSummary) {
|
|
71
|
-
const shortCommitId = commitFromSummary.slice(0, 7)
|
|
72
|
-
links = {
|
|
73
|
-
...links,
|
|
74
|
-
commit: `[\`${shortCommitId}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return links
|
|
78
|
-
}
|
|
79
|
-
const commitToFetchFrom = commitFromSummary || changeset.commit
|
|
80
|
-
if (commitToFetchFrom) {
|
|
81
|
-
let { links } = await getInfo({
|
|
82
|
-
repo: options.repo,
|
|
83
|
-
commit: commitToFetchFrom,
|
|
84
|
-
})
|
|
85
|
-
return links
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
commit: null,
|
|
89
|
-
pull: null,
|
|
90
|
-
user: null,
|
|
91
|
-
}
|
|
92
|
-
})()
|
|
93
|
-
|
|
94
|
-
const users =
|
|
95
|
-
usersFromSummary.length ?
|
|
96
|
-
usersFromSummary
|
|
97
|
-
.map((userFromSummary) => `[@${userFromSummary}](https://github.com/${userFromSummary})`)
|
|
98
|
-
.join(", ")
|
|
99
|
-
: links.user
|
|
100
|
-
|
|
101
|
-
const prefix = [
|
|
102
|
-
links.pull === null ? "" : ` ${links.pull}`,
|
|
103
|
-
links.commit === null ? "" : ` ${links.commit}`,
|
|
104
|
-
users === null ? "" : ` Thanks ${users}!`,
|
|
105
|
-
].join("")
|
|
106
|
-
|
|
107
|
-
return `\n\n-${prefix ? `${prefix} -` : ""} ${firstLine}\n${futureLines
|
|
108
|
-
.map((l) => ` ${l}`)
|
|
109
|
-
.join("\n")}`
|
|
110
|
-
},
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export default changelogFunctions
|
package/tsconfig.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Environment setup & latest features
|
|
4
|
-
"lib": ["ESNext"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "Preserve",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
|
|
11
|
-
// Bundler mode
|
|
12
|
-
"moduleResolution": "bundler",
|
|
13
|
-
"allowImportingTsExtensions": true,
|
|
14
|
-
"verbatimModuleSyntax": true,
|
|
15
|
-
"noEmit": true,
|
|
16
|
-
|
|
17
|
-
// Best practices
|
|
18
|
-
"strict": true,
|
|
19
|
-
"skipLibCheck": true,
|
|
20
|
-
"noFallthroughCasesInSwitch": true,
|
|
21
|
-
"noUncheckedIndexedAccess": true,
|
|
22
|
-
"noImplicitOverride": true,
|
|
23
|
-
|
|
24
|
-
// Some stricter flags (disabled by default)
|
|
25
|
-
"noUnusedLocals": false,
|
|
26
|
-
"noUnusedParameters": false,
|
|
27
|
-
"noPropertyAccessFromIndexSignature": false
|
|
28
|
-
}
|
|
29
|
-
}
|