@kors/generate-changelog 0.2.4 → 1.0.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/README.md
CHANGED
|
@@ -1,5 +1,95 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center">generate-changelog</h1>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
#### Supported Platforms
|
|
6
|
+
<img src="https://stefkors.com/api/platform/index.svg?os=terminal,web" />
|
|
7
|
+
|
|
8
|
+
Generate structured changelog JSON from git commit history. Works with local repos and remote GitHub repositories.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @kors/generate-changelog
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### CLI
|
|
2
19
|
|
|
3
20
|
```bash
|
|
4
|
-
|
|
5
|
-
|
|
21
|
+
# Generate from local repo and write to changelog.json
|
|
22
|
+
npx @kors/generate-changelog --write
|
|
23
|
+
|
|
24
|
+
# Generate from a remote GitHub repo
|
|
25
|
+
npx @kors/generate-changelog --owner="StefKors" --repo="generate-changelog"
|
|
26
|
+
|
|
27
|
+
# Remote repo with a GitHub token (private repos, or to avoid unauthenticated rate limits)
|
|
28
|
+
GITHUB_TOKEN=ghp_xxx npx @kors/generate-changelog --owner="StefKors" --repo="my-private-repo"
|
|
29
|
+
# or pass the token explicitly
|
|
30
|
+
npx @kors/generate-changelog --owner="StefKors" --repo="my-private-repo" --token="ghp_xxx"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Programmatic
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { generateChangelog } from "@kors/generate-changelog"
|
|
37
|
+
|
|
38
|
+
const changelog = await generateChangelog({ write: true })
|
|
39
|
+
// or from a remote repo (optional githubToken for private repos / rate limits)
|
|
40
|
+
const remote = await generateChangelog({
|
|
41
|
+
owner: "StefKors",
|
|
42
|
+
repo: "generate-changelog",
|
|
43
|
+
githubToken: process.env["GITHUB_TOKEN"],
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## CLI Options
|
|
48
|
+
|
|
49
|
+
| Flag | Short | Description |
|
|
50
|
+
|------|-------|-------------|
|
|
51
|
+
| `--write` | `-w` | Write output to `changelog.json` |
|
|
52
|
+
| `--owner` | `-o` | GitHub repo owner (use with `--repo`) |
|
|
53
|
+
| `--repo` | `-r` | GitHub repo name (use with `--owner`) |
|
|
54
|
+
| `--token` | `-t` | GitHub token (optional; also reads `GITHUB_TOKEN` or `GH_TOKEN` if unset) |
|
|
55
|
+
| `--version` | | Print current version |
|
|
56
|
+
| `--help` | | Print help message |
|
|
57
|
+
|
|
58
|
+
## Output Format
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"releases": {
|
|
63
|
+
"1.2.0": [
|
|
64
|
+
{ "type": "Added", "message": "New feature description" },
|
|
65
|
+
{ "type": "Fixed", "message": "Bug fix description" }
|
|
66
|
+
],
|
|
67
|
+
"1.1.0": [
|
|
68
|
+
{ "type": "Improved", "message": "Performance improvement" }
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Change types are auto-detected from commit messages: **Added**, **Fixed**, **Improved**, **Removed**.
|
|
75
|
+
|
|
76
|
+
## GitHub authentication
|
|
77
|
+
|
|
78
|
+
When using `--owner` and `--repo`, the GitHub REST API is called without a token by default. That works for public repositories but is subject to [lower rate limits](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api). For **private** repositories, or to use authenticated rate limits, provide a token in either of these ways:
|
|
79
|
+
|
|
80
|
+
- **Environment variable:** set `GITHUB_TOKEN` (or `GH_TOKEN`) before running the CLI. The CLI reads `GITHUB_TOKEN` automatically.
|
|
81
|
+
- **CLI flag:** `--token` / `-t` overrides the environment when both are set.
|
|
82
|
+
|
|
83
|
+
Create a token under GitHub → Settings → Developer settings → Personal access tokens. The token needs read access to repository contents (for private repos, use a classic token with `repo` scope, or a fine-grained token with Contents read access).
|
|
84
|
+
|
|
85
|
+
## Features
|
|
86
|
+
|
|
87
|
+
- Parses git tags to group commits by version
|
|
88
|
+
- Auto-classifies changes by type from commit messages
|
|
89
|
+
- Filters out merge commits and version bumps
|
|
90
|
+
- Supports local git repos and remote GitHub repos via Octokit
|
|
91
|
+
- Outputs structured JSON for use in release notes, changelogs, or UIs
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|
package/distribution/cli.js
CHANGED
|
@@ -9,6 +9,7 @@ const cli = meow(`
|
|
|
9
9
|
--write, -w Write output to changelog.json
|
|
10
10
|
--owner, -o Fetch commits from github owner (used with --repo)
|
|
11
11
|
--repo, -r Fetch commit from github repo (used with --owner)
|
|
12
|
+
--token, -t GitHub token (or set GITHUB_TOKEN in the environment)
|
|
12
13
|
--version Print current version
|
|
13
14
|
--help Print help message
|
|
14
15
|
|
|
@@ -17,7 +18,10 @@ const cli = meow(`
|
|
|
17
18
|
$ generate-changelog --write
|
|
18
19
|
|
|
19
20
|
Generate from remote repo:
|
|
20
|
-
$ generate-changelog --owner="StefKors" --repo="generate-changelog"
|
|
21
|
+
$ generate-changelog --owner="StefKors" --repo="generate-changelog"
|
|
22
|
+
|
|
23
|
+
With authentication (private repos or higher API rate limits):
|
|
24
|
+
$ generate-changelog --owner="StefKors" --repo="generate-changelog" --token="$GITHUB_TOKEN"
|
|
21
25
|
`, {
|
|
22
26
|
importMeta: import.meta,
|
|
23
27
|
flags: {
|
|
@@ -32,7 +36,16 @@ const cli = meow(`
|
|
|
32
36
|
repo: {
|
|
33
37
|
type: 'string',
|
|
34
38
|
shortFlag: 'r'
|
|
39
|
+
},
|
|
40
|
+
token: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
shortFlag: 't'
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
});
|
|
38
|
-
generateChangelog(
|
|
46
|
+
generateChangelog({
|
|
47
|
+
write: cli.flags.write,
|
|
48
|
+
owner: cli.flags.owner,
|
|
49
|
+
repo: cli.flags.repo,
|
|
50
|
+
githubToken: cli.flags.token ?? process.env['GITHUB_TOKEN'] ?? process.env['GH_TOKEN'],
|
|
51
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const fetchGitHubCommits: (owner: string, repo: string) => Promise<string[]>;
|
|
1
|
+
export declare const fetchGitHubCommits: (owner: string, repo: string, token?: string) => Promise<string[]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Octokit } from 'octokit';
|
|
2
|
-
export const fetchGitHubCommits = async (owner, repo) => {
|
|
3
|
-
const octokit = new Octokit({});
|
|
2
|
+
export const fetchGitHubCommits = async (owner, repo, token) => {
|
|
3
|
+
const octokit = new Octokit(token ? { auth: token } : {});
|
|
4
4
|
const data = await octokit.paginate('GET /repos/{owner}/{repo}/commits', {
|
|
5
5
|
owner: owner,
|
|
6
6
|
repo: repo,
|
|
@@ -13,6 +13,8 @@ export interface Options {
|
|
|
13
13
|
write?: boolean;
|
|
14
14
|
repo?: string;
|
|
15
15
|
owner?: string;
|
|
16
|
+
/** GitHub personal access token or fine-grained token (higher rate limits; required for private repos). */
|
|
17
|
+
githubToken?: string;
|
|
16
18
|
}
|
|
17
|
-
declare const generateChangelog: ({ write, owner, repo }: Options) => Promise<Changelog>;
|
|
19
|
+
declare const generateChangelog: ({ write, owner, repo, githubToken }: Options) => Promise<Changelog>;
|
|
18
20
|
export { generateChangelog };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import { getLocalCommits } from './getLocalCommits.js';
|
|
3
3
|
import { fetchGitHubCommits } from './fetchGitHubCommits.js';
|
|
4
|
-
const generateChangelog = async ({ write, owner, repo }) => {
|
|
4
|
+
const generateChangelog = async ({ write, owner, repo, githubToken }) => {
|
|
5
5
|
try {
|
|
6
6
|
let lines = [];
|
|
7
7
|
if (repo && owner) {
|
|
8
8
|
console.log("fetching from remote", owner, repo);
|
|
9
|
-
lines = await fetchGitHubCommits(owner, repo);
|
|
9
|
+
lines = await fetchGitHubCommits(owner, repo, githubToken);
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
12
|
console.log("reading local commits");
|