@mui/internal-code-infra 0.1.1-canary.37 → 0.1.1-canary.38
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/build/changelog/changelogChanges.d.mts +36 -0
- package/build/changelog/changelogTags.d.mts +15 -0
- package/build/changelog/fetchChangelogData.d.mts +16 -0
- package/build/changelog/index.d.mts +13 -0
- package/build/changelog/octokit.d.mts +7 -0
- package/build/changelog/types.d.ts +137 -0
- package/package.json +2 -2
- package/src/changelog/changelogChanges.mjs +418 -0
- package/src/changelog/changelogTags.mjs +34 -0
- package/src/changelog/fetchChangelogData.mjs +171 -0
- package/src/changelog/fetchChangelogs.mjs +3 -30
- package/src/changelog/index.mjs +9 -0
- package/src/changelog/octokit.mjs +35 -0
- package/src/changelog/types.ts +142 -0
- package/build/brokenLinksChecker/__fixtures__/no-signal-forwarding.d.mts +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type Octokit = import('@octokit/rest').Octokit;
|
|
2
|
+
export type GitHubRepository = import('./types.ts').GitHubRepository;
|
|
3
|
+
export type ChangelogAuthor = import('./types.ts').ChangelogAuthor;
|
|
4
|
+
export type ChangelogChange = import('./types.ts').ChangelogChange;
|
|
5
|
+
export type Commit = Awaited<ReturnType<Octokit['repos']['compareCommitsWithBasehead']>>['data']['commits'][number];
|
|
6
|
+
export type PullRequest = {
|
|
7
|
+
number: number;
|
|
8
|
+
title: string;
|
|
9
|
+
body: string | null;
|
|
10
|
+
user: {
|
|
11
|
+
login: string;
|
|
12
|
+
type: string;
|
|
13
|
+
} | null;
|
|
14
|
+
author_association: string;
|
|
15
|
+
labels: {
|
|
16
|
+
name?: string;
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* @param {Object} options
|
|
21
|
+
* @param {Octokit} options.octokit
|
|
22
|
+
* @param {GitHubRepository} options.repository
|
|
23
|
+
* @param {string} options.previousSha
|
|
24
|
+
* @param {string} options.releaseSha
|
|
25
|
+
* @param {boolean} options.includeDirectCommits
|
|
26
|
+
* @param {AbortController} options.controller - Aborted when a request fails
|
|
27
|
+
* @returns {Promise<ChangelogChange[]>}
|
|
28
|
+
*/
|
|
29
|
+
export declare function fetchChangelogChanges({ octokit, repository, previousSha, releaseSha, includeDirectCommits, controller, }: {
|
|
30
|
+
octokit: Octokit;
|
|
31
|
+
repository: GitHubRepository;
|
|
32
|
+
previousSha: string;
|
|
33
|
+
releaseSha: string;
|
|
34
|
+
includeDirectCommits: boolean;
|
|
35
|
+
controller: AbortController;
|
|
36
|
+
}): Promise<ChangelogChange[]>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The closest version tag behind a commit. Tags on the commit itself are the release being made, not
|
|
3
|
+
* the one before it.
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {string} options.cwd
|
|
7
|
+
* @param {string | null} options.remote - Remote to fetch the tags and the commit from
|
|
8
|
+
* @param {string} options.sha
|
|
9
|
+
* @returns {Promise<string>}
|
|
10
|
+
*/
|
|
11
|
+
export declare function findPreviousVersionTag({ cwd, remote, sha }: {
|
|
12
|
+
cwd: string;
|
|
13
|
+
remote: string | null;
|
|
14
|
+
sha: string;
|
|
15
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type FetchChangelogDataOptions = import('./types.ts').FetchChangelogDataOptions;
|
|
2
|
+
export type GitHubRepository = import('./types.ts').GitHubRepository;
|
|
3
|
+
export type ChangelogData = import('./types.ts').ChangelogData;
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
|
|
6
|
+
* @typedef {import('./types.ts').GitHubRepository} GitHubRepository
|
|
7
|
+
* @typedef {import('./types.ts').ChangelogData} ChangelogData
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Collects what happened in a release: its changes and its packages. Run inside a checkout of the
|
|
11
|
+
* repository, every option is optional.
|
|
12
|
+
*
|
|
13
|
+
* @param {FetchChangelogDataOptions} [options]
|
|
14
|
+
* @returns {Promise<ChangelogData>}
|
|
15
|
+
*/
|
|
16
|
+
export declare function fetchChangelogData(options?: FetchChangelogDataOptions): Promise<ChangelogData>;
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Changelog generation utilities.
|
|
3
3
|
*/
|
|
4
|
+
export type FetchChangelogDataOptions = import('./types.ts').FetchChangelogDataOptions;
|
|
5
|
+
export type ChangelogData = import('./types.ts').ChangelogData;
|
|
6
|
+
export type ChangelogChange = import('./types.ts').ChangelogChange;
|
|
7
|
+
export type ChangelogAuthor = import('./types.ts').ChangelogAuthor;
|
|
8
|
+
export type ChangelogPackage = import('./types.ts').ChangelogPackage;
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
|
|
11
|
+
* @typedef {import('./types.ts').ChangelogData} ChangelogData
|
|
12
|
+
* @typedef {import('./types.ts').ChangelogChange} ChangelogChange
|
|
13
|
+
* @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
|
|
14
|
+
* @typedef {import('./types.ts').ChangelogPackage} ChangelogPackage
|
|
15
|
+
*/
|
|
4
16
|
export { generateChangelog } from './generateChangelog.mjs';
|
|
5
17
|
export * from './loadChangelogConfig.mjs';
|
|
6
18
|
export * from './fetchChangelogs.mjs';
|
|
19
|
+
export { fetchChangelogData } from './fetchChangelogData.mjs';
|
|
7
20
|
export { findLatestTaggedVersion } from '../utils/git.mjs';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/rest';
|
|
2
|
+
import type { RepoInfo } from '../utils/git.mjs';
|
|
1
3
|
/**
|
|
2
4
|
* Commit details fetched from GitHub including PR information and labels.
|
|
3
5
|
*/
|
|
@@ -390,3 +392,138 @@ export interface GenerateChangelogResult {
|
|
|
390
392
|
all: string[];
|
|
391
393
|
};
|
|
392
394
|
}
|
|
395
|
+
export type GitHubRepository = Pick<RepoInfo, 'owner' | 'repo'>;
|
|
396
|
+
export interface ReleaseRef {
|
|
397
|
+
/**
|
|
398
|
+
* The ref as given. A local `HEAD` is replaced by its SHA.
|
|
399
|
+
*/
|
|
400
|
+
ref: string;
|
|
401
|
+
sha: string;
|
|
402
|
+
}
|
|
403
|
+
export interface ChangelogAuthor {
|
|
404
|
+
/**
|
|
405
|
+
* `null` for a commit author without a linked GitHub account.
|
|
406
|
+
*/
|
|
407
|
+
login: string | null;
|
|
408
|
+
/**
|
|
409
|
+
* Git author name. Only known for direct commits.
|
|
410
|
+
*/
|
|
411
|
+
name: string | null;
|
|
412
|
+
association: 'team' | 'community' | 'first-timer';
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* A merged pull request, or a commit that landed without one.
|
|
416
|
+
*/
|
|
417
|
+
export interface ChangelogChange {
|
|
418
|
+
/**
|
|
419
|
+
* Subject of the commit, without the references that the other fields already carry: the pull
|
|
420
|
+
* request it belongs to and, for a cherry-pick, the original pull request and its author.
|
|
421
|
+
*/
|
|
422
|
+
title: string;
|
|
423
|
+
/**
|
|
424
|
+
* Full commit message.
|
|
425
|
+
*/
|
|
426
|
+
message: string;
|
|
427
|
+
sha: string;
|
|
428
|
+
/**
|
|
429
|
+
* Page of the pull request, or of the commit when there is none.
|
|
430
|
+
*/
|
|
431
|
+
url: string;
|
|
432
|
+
labels: string[];
|
|
433
|
+
pullRequest: {
|
|
434
|
+
number: number;
|
|
435
|
+
title: string;
|
|
436
|
+
body: string;
|
|
437
|
+
} | null;
|
|
438
|
+
/**
|
|
439
|
+
* `null` when the GitHub account was deleted.
|
|
440
|
+
*/
|
|
441
|
+
author: ChangelogAuthor | null;
|
|
442
|
+
/**
|
|
443
|
+
* When the pull request was opened, or the commit authored. ISO 8601.
|
|
444
|
+
*/
|
|
445
|
+
createdAt: string | null;
|
|
446
|
+
/**
|
|
447
|
+
* When the pull request was merged, or the commit committed. ISO 8601.
|
|
448
|
+
*/
|
|
449
|
+
mergedAt: string | null;
|
|
450
|
+
}
|
|
451
|
+
export interface ChangelogPackage {
|
|
452
|
+
name: string;
|
|
453
|
+
version: string | null;
|
|
454
|
+
/**
|
|
455
|
+
* Whether the package can't be published: marked as private, or without a version.
|
|
456
|
+
*/
|
|
457
|
+
private: boolean;
|
|
458
|
+
/**
|
|
459
|
+
* Directory relative to the workspace root, with `/` separators. `.` for the root package.
|
|
460
|
+
*/
|
|
461
|
+
path: string;
|
|
462
|
+
/**
|
|
463
|
+
* Whether the version differs from the previous release. `true` for a new package, `null` when the
|
|
464
|
+
* previous release isn't available locally.
|
|
465
|
+
*/
|
|
466
|
+
changed: boolean | null;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* What happened in a release, as JSON-serializable data.
|
|
470
|
+
*/
|
|
471
|
+
export interface ChangelogData {
|
|
472
|
+
repository: GitHubRepository;
|
|
473
|
+
previous: ReleaseRef;
|
|
474
|
+
release: ReleaseRef;
|
|
475
|
+
version: string;
|
|
476
|
+
/**
|
|
477
|
+
* ISO 8601.
|
|
478
|
+
*/
|
|
479
|
+
date: string;
|
|
480
|
+
/**
|
|
481
|
+
* Oldest first.
|
|
482
|
+
*/
|
|
483
|
+
changes: ChangelogChange[];
|
|
484
|
+
/**
|
|
485
|
+
* Named packages in the working tree, sorted by path. Without a workspace, only the root package.
|
|
486
|
+
*/
|
|
487
|
+
packages: ChangelogPackage[];
|
|
488
|
+
}
|
|
489
|
+
export interface FetchChangelogDataOptions {
|
|
490
|
+
/**
|
|
491
|
+
* A directory of the released workspace.
|
|
492
|
+
* @default process.cwd()
|
|
493
|
+
*/
|
|
494
|
+
cwd?: string;
|
|
495
|
+
/**
|
|
496
|
+
* Repository name. Defaults to the one the checkout's remote points at.
|
|
497
|
+
*/
|
|
498
|
+
repo?: string;
|
|
499
|
+
/**
|
|
500
|
+
* @default 'mui'
|
|
501
|
+
*/
|
|
502
|
+
org?: string;
|
|
503
|
+
/**
|
|
504
|
+
* Ref of the previous release. Defaults to the closest version tag before `release`.
|
|
505
|
+
*/
|
|
506
|
+
lastRelease?: string;
|
|
507
|
+
/**
|
|
508
|
+
* Ref of the release.
|
|
509
|
+
* @default 'HEAD'
|
|
510
|
+
*/
|
|
511
|
+
release?: string;
|
|
512
|
+
/**
|
|
513
|
+
* Defaults to the version `release` is a tag of, else the version of the root package.
|
|
514
|
+
*/
|
|
515
|
+
version?: string;
|
|
516
|
+
/**
|
|
517
|
+
* Defaults to the commit date when `release` is a version tag, else now.
|
|
518
|
+
*/
|
|
519
|
+
date?: Date | string;
|
|
520
|
+
/**
|
|
521
|
+
* Include commits that landed without a pull request.
|
|
522
|
+
* @default false
|
|
523
|
+
*/
|
|
524
|
+
includeDirectCommits?: boolean;
|
|
525
|
+
/**
|
|
526
|
+
* GitHub client. Defaults to one authenticated as the developer running it.
|
|
527
|
+
*/
|
|
528
|
+
octokit?: Octokit;
|
|
529
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-code-infra",
|
|
3
|
-
"version": "0.1.1-canary.
|
|
3
|
+
"version": "0.1.1-canary.38",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Infra scripts and configs to be used across MUI repos.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -199,7 +199,7 @@
|
|
|
199
199
|
"publishConfig": {
|
|
200
200
|
"access": "public"
|
|
201
201
|
},
|
|
202
|
-
"gitSha": "
|
|
202
|
+
"gitSha": "e44688894ae822e6f958f1b7f0ce29cab20210a8",
|
|
203
203
|
"scripts": {
|
|
204
204
|
"build": "tsc -p tsconfig.build.json",
|
|
205
205
|
"typescript": "tsc -noEmit",
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { mapAsync } from 'es-toolkit/array';
|
|
2
|
+
|
|
3
|
+
import { getRateLimitRetryTime } from '../utils/github.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('@octokit/rest').Octokit} Octokit
|
|
7
|
+
* @typedef {import('./types.ts').GitHubRepository} GitHubRepository
|
|
8
|
+
* @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
|
|
9
|
+
* @typedef {import('./types.ts').ChangelogChange} ChangelogChange
|
|
10
|
+
* @typedef {Awaited<ReturnType<Octokit['repos']['compareCommitsWithBasehead']>>['data']['commits'][number]} Commit
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* What is needed from a pull request. Listing and getting one return different supersets of this.
|
|
15
|
+
*
|
|
16
|
+
* @typedef {Object} PullRequest
|
|
17
|
+
* @property {number} number
|
|
18
|
+
* @property {string} title
|
|
19
|
+
* @property {string | null} body
|
|
20
|
+
* @property {{ login: string, type: string } | null} user
|
|
21
|
+
* @property {string} author_association
|
|
22
|
+
* @property {{ name?: string }[]} labels
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** @type {Record<string, ChangelogAuthor['association']>} */
|
|
26
|
+
const ASSOCIATIONS = {
|
|
27
|
+
OWNER: 'team',
|
|
28
|
+
MEMBER: 'team',
|
|
29
|
+
COLLABORATOR: 'community',
|
|
30
|
+
CONTRIBUTOR: 'community',
|
|
31
|
+
FIRST_TIMER: 'first-timer',
|
|
32
|
+
FIRST_TIME_CONTRIBUTOR: 'first-timer',
|
|
33
|
+
MANNEQUIN: 'first-timer',
|
|
34
|
+
NONE: 'first-timer',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const CHERRY_PICK_LABEL = 'cherry-pick';
|
|
38
|
+
const PULL_REFERENCE =
|
|
39
|
+
/(?:https:\/\/github\.com\/(?<urlOwner>[\w.-]+)\/(?<urlRepo>[\w.-]+)\/pull\/|(?:(?<owner>[\w.-]+)\/(?<repo>[\w.-]+))?#)(?<number>\d+)/;
|
|
40
|
+
// Unnamed, so that the pattern can be repeated.
|
|
41
|
+
const ANY_PULL_REFERENCE = PULL_REFERENCE.source.replaceAll(/\(\?<\w+>/g, '(?:');
|
|
42
|
+
// Anchored to the start of a line: changelogs quoted in dependency bumps mention cherry-picks too.
|
|
43
|
+
const CHERRY_PICK_LINE = new RegExp(
|
|
44
|
+
`^cherry[- ]pick(?:ed|s)?(?: of| from)?:? (${ANY_PULL_REFERENCE}(?:(?:,? and |, ?| )${ANY_PULL_REFERENCE})*)`,
|
|
45
|
+
'gim',
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {PullRequest} pull
|
|
50
|
+
* @param {GitHubRepository} repository - Where the pull request is
|
|
51
|
+
* @returns {(GitHubRepository & { number: number, text: string })[]}
|
|
52
|
+
*/
|
|
53
|
+
function getCherryPickReferences(pull, repository) {
|
|
54
|
+
return [...(pull.body ?? '').matchAll(CHERRY_PICK_LINE)].flatMap(([, references]) =>
|
|
55
|
+
[...references.matchAll(new RegExp(PULL_REFERENCE, 'g'))].map(({ groups = {} }) => {
|
|
56
|
+
const owner = groups.urlOwner ?? groups.owner ?? repository.owner;
|
|
57
|
+
const repo = groups.urlRepo ?? groups.repo ?? repository.repo;
|
|
58
|
+
const isSameRepository = owner === repository.owner && repo === repository.repo;
|
|
59
|
+
return {
|
|
60
|
+
owner,
|
|
61
|
+
repo,
|
|
62
|
+
number: Number(groups.number),
|
|
63
|
+
// As written in a title, also when the body has a link.
|
|
64
|
+
text: isSameRepository ? `#${groups.number}` : `${owner}/${repo}#${groups.number}`,
|
|
65
|
+
};
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {any} error
|
|
72
|
+
*/
|
|
73
|
+
function isForbidden(error) {
|
|
74
|
+
return error.status === 403 && getRateLimitRetryTime(error) === null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @template {string} Key
|
|
79
|
+
* @template Value
|
|
80
|
+
* @param {(key: Key) => Promise<Value>} load
|
|
81
|
+
* @returns {(key: Key) => Promise<Value>}
|
|
82
|
+
*/
|
|
83
|
+
function memoize(load) {
|
|
84
|
+
/** @type {Map<Key, Promise<Value>>} */
|
|
85
|
+
const cache = new Map();
|
|
86
|
+
return (key) => {
|
|
87
|
+
const cached = cache.get(key) ?? load(key);
|
|
88
|
+
cache.set(key, cached);
|
|
89
|
+
return cached;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {Object} options
|
|
95
|
+
* @param {Octokit} options.octokit
|
|
96
|
+
* @param {GitHubRepository} options.repository
|
|
97
|
+
* @param {AbortSignal} options.signal
|
|
98
|
+
*/
|
|
99
|
+
function createAuthorResolver({ octokit, repository, signal }) {
|
|
100
|
+
let hasWarnedAboutMembership = false;
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} login
|
|
103
|
+
*/
|
|
104
|
+
function creditUnchecked(login) {
|
|
105
|
+
if (!hasWarnedAboutMembership) {
|
|
106
|
+
hasWarnedAboutMembership = true;
|
|
107
|
+
console.warn(
|
|
108
|
+
`The token can't read the private members of ${repository.owner}. ` +
|
|
109
|
+
`Authors that can't be checked, such as ${login}, are credited as community.`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
return /** @type {const} */ ('community');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const getMembership = memoize(
|
|
116
|
+
/**
|
|
117
|
+
* @param {string} login
|
|
118
|
+
* @returns {Promise<ChangelogAuthor['association']>}
|
|
119
|
+
*/
|
|
120
|
+
async (login) => {
|
|
121
|
+
try {
|
|
122
|
+
await octokit.orgs.checkMembershipForUser({
|
|
123
|
+
org: repository.owner,
|
|
124
|
+
username: login,
|
|
125
|
+
request: { signal },
|
|
126
|
+
});
|
|
127
|
+
return 'team';
|
|
128
|
+
} catch (/** @type {any} */ error) {
|
|
129
|
+
if (isForbidden(error)) {
|
|
130
|
+
return creditUnchecked(login);
|
|
131
|
+
}
|
|
132
|
+
if (error.status === 404) {
|
|
133
|
+
// GitHub redirects outsiders to the public members, which don't tell about private ones.
|
|
134
|
+
return error.response?.url.includes('/public_members/')
|
|
135
|
+
? creditUnchecked(login)
|
|
136
|
+
: 'community';
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const getOriginal = memoize(async (/** @type {string} */ key) => {
|
|
144
|
+
const [owner, repo, number] = key.split('/');
|
|
145
|
+
try {
|
|
146
|
+
const { data } = await octokit.pulls.get({
|
|
147
|
+
owner,
|
|
148
|
+
repo,
|
|
149
|
+
pull_number: Number(number),
|
|
150
|
+
request: { signal },
|
|
151
|
+
});
|
|
152
|
+
return /** @type {PullRequest} */ (data);
|
|
153
|
+
} catch (/** @type {any} */ error) {
|
|
154
|
+
if (error.status === 404 || isForbidden(error)) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {PullRequest} pull
|
|
163
|
+
* @param {GitHubRepository} pullRepository
|
|
164
|
+
* @returns {Promise<ChangelogAuthor | null>}
|
|
165
|
+
*/
|
|
166
|
+
async function getOpener(pull, pullRepository) {
|
|
167
|
+
if (!pull.user) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
const { login, type } = pull.user;
|
|
171
|
+
const isSameRepository =
|
|
172
|
+
pullRepository.owner === repository.owner && pullRepository.repo === repository.repo;
|
|
173
|
+
/** @type {ChangelogAuthor['association']} */
|
|
174
|
+
let association = 'community';
|
|
175
|
+
if (type !== 'Bot') {
|
|
176
|
+
association = isSameRepository
|
|
177
|
+
? (ASSOCIATIONS[pull.author_association] ?? 'community')
|
|
178
|
+
: // The association with another repository says nothing about this one.
|
|
179
|
+
await getMembership(login);
|
|
180
|
+
}
|
|
181
|
+
return { login, name: null, association };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @param {PullRequest} pull
|
|
186
|
+
* @param {GitHubRepository} pullRepository
|
|
187
|
+
* @param {string[]} chain - Cherry-picks that led to this pull request
|
|
188
|
+
* @returns {Promise<{ author: ChangelogAuthor | null, isBot: boolean, references: string[] } | null>}
|
|
189
|
+
* `null` when the pull request is a cherry-pick by a bot of which the original author is unknown
|
|
190
|
+
*/
|
|
191
|
+
async function resolve(pull, pullRepository, chain = []) {
|
|
192
|
+
const isBot = pull.user?.type === 'Bot';
|
|
193
|
+
const opener = async () => ({
|
|
194
|
+
author: await getOpener(pull, pullRepository),
|
|
195
|
+
isBot,
|
|
196
|
+
references: [],
|
|
197
|
+
});
|
|
198
|
+
const references = getCherryPickReferences(pull, pullRepository);
|
|
199
|
+
if (references.length === 0) {
|
|
200
|
+
const isLabeled = pull.labels.some((label) => label.name === CHERRY_PICK_LABEL);
|
|
201
|
+
return isBot && isLabeled ? null : opener();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const originals = await Promise.all(
|
|
205
|
+
references.map(async (reference) => {
|
|
206
|
+
const key = `${reference.owner}/${reference.repo}/${reference.number}`;
|
|
207
|
+
const original = chain.includes(key) ? null : await getOriginal(key);
|
|
208
|
+
return original && resolve(original, reference, [...chain, key]);
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
const author = originals[0]?.author;
|
|
212
|
+
if (author && originals.every((original) => original?.author?.login === author.login)) {
|
|
213
|
+
// A person who cherry-picks the work of a bot is the better credit.
|
|
214
|
+
const isBotAuthor = originals.some((original) => original?.isBot);
|
|
215
|
+
if (isBot || !isBotAuthor) {
|
|
216
|
+
return {
|
|
217
|
+
author,
|
|
218
|
+
isBot: isBotAuthor,
|
|
219
|
+
references: references.map((reference) => reference.text),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return isBot ? null : opener();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
/**
|
|
228
|
+
* @param {PullRequest} pull
|
|
229
|
+
* @returns {Promise<{ author: ChangelogAuthor | null, references: string[] }>}
|
|
230
|
+
*/
|
|
231
|
+
async fromPullRequest(pull) {
|
|
232
|
+
const resolved = await resolve(pull, repository);
|
|
233
|
+
if (resolved) {
|
|
234
|
+
return resolved;
|
|
235
|
+
}
|
|
236
|
+
const author = await getOpener(pull, repository);
|
|
237
|
+
console.warn(
|
|
238
|
+
`#${pull.number} is a cherry-pick, but its original author can't be determined. ` +
|
|
239
|
+
`${author?.login} is credited instead.`,
|
|
240
|
+
);
|
|
241
|
+
return { author, references: [] };
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* @param {Commit} commit
|
|
245
|
+
* @returns {Promise<ChangelogAuthor>}
|
|
246
|
+
*/
|
|
247
|
+
async fromCommit(commit) {
|
|
248
|
+
const login = commit.author?.login ?? null;
|
|
249
|
+
return {
|
|
250
|
+
login,
|
|
251
|
+
name: commit.commit.author?.name ?? null,
|
|
252
|
+
association:
|
|
253
|
+
login === null || commit.author?.type === 'Bot'
|
|
254
|
+
? 'community'
|
|
255
|
+
: await getMembership(login),
|
|
256
|
+
};
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Strips trailing `(#1)` references, and `(@login)` credits when asked to.
|
|
263
|
+
*
|
|
264
|
+
* @param {string} title
|
|
265
|
+
* @param {string[]} references
|
|
266
|
+
* @param {boolean} stripCredits
|
|
267
|
+
* @returns {string}
|
|
268
|
+
*/
|
|
269
|
+
function stripTrailingReferences(title, references, stripCredits) {
|
|
270
|
+
const [, rest, reference] = /^(.*?)\s*\(([^()]+)\)$/.exec(title) ?? [];
|
|
271
|
+
// The credit can name a login that has since been renamed.
|
|
272
|
+
return references.includes(reference) || (stripCredits && /^@[\w-]+$/.test(reference))
|
|
273
|
+
? stripTrailingReferences(rest, references, stripCredits)
|
|
274
|
+
: title;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @param {Object} options
|
|
279
|
+
* @param {Octokit} options.octokit
|
|
280
|
+
* @param {GitHubRepository} options.repository
|
|
281
|
+
* @param {string} options.previousSha
|
|
282
|
+
* @param {string} options.releaseSha
|
|
283
|
+
* @param {boolean} options.includeDirectCommits
|
|
284
|
+
* @param {AbortController} options.controller - Aborted when a request fails
|
|
285
|
+
* @returns {Promise<ChangelogChange[]>}
|
|
286
|
+
*/
|
|
287
|
+
export async function fetchChangelogChanges({
|
|
288
|
+
octokit,
|
|
289
|
+
repository,
|
|
290
|
+
previousSha,
|
|
291
|
+
releaseSha,
|
|
292
|
+
includeDirectCommits,
|
|
293
|
+
controller,
|
|
294
|
+
}) {
|
|
295
|
+
const { signal } = controller;
|
|
296
|
+
const location = { ...repository, request: { signal } };
|
|
297
|
+
const authors = createAuthorResolver({ octokit, repository, signal });
|
|
298
|
+
|
|
299
|
+
async function listCommits() {
|
|
300
|
+
/** @type {Commit[]} */
|
|
301
|
+
const commits = [];
|
|
302
|
+
let total = 0;
|
|
303
|
+
const pages = octokit.paginate.iterator(
|
|
304
|
+
octokit.repos.compareCommitsWithBasehead.endpoint.merge({
|
|
305
|
+
...location,
|
|
306
|
+
basehead: `${previousSha}...${releaseSha}`,
|
|
307
|
+
per_page: 100,
|
|
308
|
+
}),
|
|
309
|
+
);
|
|
310
|
+
for await (const { data } of /** @type {AsyncIterable<any>} */ (pages)) {
|
|
311
|
+
commits.push(...data.commits);
|
|
312
|
+
total = data.total_commits;
|
|
313
|
+
}
|
|
314
|
+
if (commits.length !== total) {
|
|
315
|
+
throw new Error(`GitHub listed ${commits.length} of the ${total} commits in the release.`);
|
|
316
|
+
}
|
|
317
|
+
return commits;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Asks GitHub rather than trusting the message, where a reference to an issue or to another pull
|
|
322
|
+
* request looks the same as the pull request the commit was merged from.
|
|
323
|
+
*
|
|
324
|
+
* @param {string} sha
|
|
325
|
+
* @param {string} subject
|
|
326
|
+
*/
|
|
327
|
+
async function findPullRequest(sha, subject) {
|
|
328
|
+
const isMergedAsCommit = (
|
|
329
|
+
/** @type {{ merged_at: string | null, merge_commit_sha: string | null }} */ pull,
|
|
330
|
+
) => pull.merged_at !== null && pull.merge_commit_sha === sha;
|
|
331
|
+
|
|
332
|
+
const pulls = await octokit.paginate(octokit.repos.listPullRequestsAssociatedWithCommit, {
|
|
333
|
+
...location,
|
|
334
|
+
commit_sha: sha,
|
|
335
|
+
per_page: 100,
|
|
336
|
+
});
|
|
337
|
+
// On maintenance branches, GitHub also lists pull requests that merely contain the commit.
|
|
338
|
+
const listed = pulls.find(isMergedAsCommit);
|
|
339
|
+
if (listed) {
|
|
340
|
+
return listed;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// GitHub lists nothing for some commits, such as mui/mui-x@227a2fee.
|
|
344
|
+
const reference = /\(#(\d+)\)$/.exec(subject);
|
|
345
|
+
if (!reference) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
const { data } = await octokit.pulls.get({ ...location, pull_number: Number(reference[1]) });
|
|
350
|
+
return isMergedAsCommit(data) ? data : null;
|
|
351
|
+
} catch (/** @type {any} */ error) {
|
|
352
|
+
if (error.status === 404) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* @param {Commit} commit
|
|
361
|
+
* @returns {Promise<ChangelogChange | null>}
|
|
362
|
+
*/
|
|
363
|
+
async function toChange(commit) {
|
|
364
|
+
const { sha } = commit;
|
|
365
|
+
const { message } = commit.commit;
|
|
366
|
+
const subject = message.split('\n', 1)[0].trim();
|
|
367
|
+
|
|
368
|
+
const pull = await findPullRequest(sha, subject);
|
|
369
|
+
if (pull) {
|
|
370
|
+
const { author, references } = await authors.fromPullRequest(pull);
|
|
371
|
+
const ownReference = `#${pull.number}`;
|
|
372
|
+
const title = subject.endsWith(`(${ownReference})`) ? subject : pull.title;
|
|
373
|
+
const isCreditedCherryPick = references.length > 0;
|
|
374
|
+
return {
|
|
375
|
+
title: stripTrailingReferences(title, [ownReference, ...references], isCreditedCherryPick),
|
|
376
|
+
message,
|
|
377
|
+
sha,
|
|
378
|
+
url: pull.html_url,
|
|
379
|
+
labels: pull.labels.map((label) => label.name),
|
|
380
|
+
pullRequest: { number: pull.number, title: pull.title, body: pull.body ?? '' },
|
|
381
|
+
author,
|
|
382
|
+
createdAt: pull.created_at,
|
|
383
|
+
mergedAt: pull.merged_at,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (!includeDirectCommits) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
title: subject,
|
|
392
|
+
message,
|
|
393
|
+
sha,
|
|
394
|
+
url: commit.html_url,
|
|
395
|
+
labels: [],
|
|
396
|
+
pullRequest: null,
|
|
397
|
+
author: await authors.fromCommit(commit),
|
|
398
|
+
createdAt: commit.commit.author?.date ?? null,
|
|
399
|
+
mergedAt: commit.commit.committer?.date ?? null,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const changes = await mapAsync(
|
|
404
|
+
await listCommits(),
|
|
405
|
+
async (commit) => {
|
|
406
|
+
signal.throwIfAborted();
|
|
407
|
+
try {
|
|
408
|
+
return await toChange(commit);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
// Immediately, or the next queued commit still gets to make its request.
|
|
411
|
+
controller.abort(error);
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
{ concurrency: 10 },
|
|
416
|
+
);
|
|
417
|
+
return changes.filter((change) => change !== null);
|
|
418
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { $ } from 'execa';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The closest version tag behind a commit. Tags on the commit itself are the release being made, not
|
|
5
|
+
* the one before it.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} options
|
|
8
|
+
* @param {string} options.cwd
|
|
9
|
+
* @param {string | null} options.remote - Remote to fetch the tags and the commit from
|
|
10
|
+
* @param {string} options.sha
|
|
11
|
+
* @returns {Promise<string>}
|
|
12
|
+
*/
|
|
13
|
+
export async function findPreviousVersionTag({ cwd, remote, sha }) {
|
|
14
|
+
const $$ = $({ cwd });
|
|
15
|
+
if (remote) {
|
|
16
|
+
// --force to update any existing tags that may have changed to avoid the clobering error.
|
|
17
|
+
const { exitCode } = await $$({ reject: false })`git cat-file -e ${sha}^{commit}`;
|
|
18
|
+
const missing = exitCode === 0 ? [] : [sha];
|
|
19
|
+
await $$`git fetch --tags --force ${remote} ${missing}`;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const { stdout: ownTags } = await $$`git tag --points-at ${sha}`;
|
|
23
|
+
const excludes = ownTags.split('\n').flatMap((tag) => (tag ? ['--exclude', tag] : []));
|
|
24
|
+
const { stdout } =
|
|
25
|
+
await $$`git describe --tags --abbrev=0 --match ${'v[0-9]*'} ${excludes} ${sha}`;
|
|
26
|
+
return stdout.trim();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`No version tag found behind ${sha}. A shallow clone is the usual cause: fetch the full ` +
|
|
30
|
+
'history, or pass the `lastRelease` ref.',
|
|
31
|
+
{ cause: error },
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
|
4
|
+
import { mapAsync } from 'es-toolkit/array';
|
|
5
|
+
import { $ } from 'execa';
|
|
6
|
+
import * as semver from 'semver';
|
|
7
|
+
|
|
8
|
+
import { getCurrentGitSha, getRepositoryInfo } from '../utils/git.mjs';
|
|
9
|
+
import { getWorkspacePackages } from '../utils/pnpm.mjs';
|
|
10
|
+
import { createOctokit } from './octokit.mjs';
|
|
11
|
+
import { fetchChangelogChanges } from './changelogChanges.mjs';
|
|
12
|
+
import { findPreviousVersionTag } from './changelogTags.mjs';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
|
|
16
|
+
* @typedef {import('./types.ts').GitHubRepository} GitHubRepository
|
|
17
|
+
* @typedef {import('./types.ts').ChangelogData} ChangelogData
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Collects what happened in a release: its changes and its packages. Run inside a checkout of the
|
|
22
|
+
* repository, every option is optional.
|
|
23
|
+
*
|
|
24
|
+
* @param {FetchChangelogDataOptions} [options]
|
|
25
|
+
* @returns {Promise<ChangelogData>}
|
|
26
|
+
*/
|
|
27
|
+
export async function fetchChangelogData(options = {}) {
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
try {
|
|
30
|
+
return await collectData(options, controller);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
// Cancels what is still in flight. The first failure is the reason, not the cancellations
|
|
33
|
+
// that follow from it.
|
|
34
|
+
controller.abort(error);
|
|
35
|
+
throw controller.signal.reason;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {FetchChangelogDataOptions} options
|
|
41
|
+
* @param {AbortController} controller
|
|
42
|
+
* @returns {Promise<ChangelogData>}
|
|
43
|
+
*/
|
|
44
|
+
async function collectData(options, controller) {
|
|
45
|
+
const cwd = await fs.realpath(options.cwd ?? process.cwd());
|
|
46
|
+
const octokit = options.octokit ?? createOctokit();
|
|
47
|
+
const { signal } = controller;
|
|
48
|
+
|
|
49
|
+
const { repository, remote } = await resolveRepository(cwd, options);
|
|
50
|
+
const isLocalHead = (options.release ?? 'HEAD') === 'HEAD';
|
|
51
|
+
const releaseRef = isLocalHead
|
|
52
|
+
? await getCurrentGitSha(cwd)
|
|
53
|
+
: /** @type {string} */ (options.release);
|
|
54
|
+
const releaseCommit = await getCommit(octokit, repository, releaseRef, signal).catch((error) => {
|
|
55
|
+
if (isLocalHead && error.status === 422) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`HEAD (${releaseRef}) is not on GitHub in ${repository.owner}/${repository.repo}. ` +
|
|
58
|
+
'Push it, or pass a `release` ref that is already pushed.',
|
|
59
|
+
{ cause: error },
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
});
|
|
64
|
+
const releaseSha = releaseCommit.sha;
|
|
65
|
+
|
|
66
|
+
const previousRef =
|
|
67
|
+
options.lastRelease ?? (await findPreviousVersionTag({ cwd, remote, sha: releaseSha }));
|
|
68
|
+
const previousSha = (await getCommit(octokit, repository, previousRef, signal)).sha;
|
|
69
|
+
|
|
70
|
+
const changes = await fetchChangelogChanges({
|
|
71
|
+
octokit,
|
|
72
|
+
repository,
|
|
73
|
+
previousSha,
|
|
74
|
+
releaseSha,
|
|
75
|
+
includeDirectCommits: options.includeDirectCommits ?? false,
|
|
76
|
+
controller,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const packages = await readPackages(cwd, previousSha);
|
|
80
|
+
const taggedVersion = isLocalHead ? null : semver.valid(releaseRef);
|
|
81
|
+
const version =
|
|
82
|
+
options.version ?? taggedVersion ?? packages.find((pkg) => pkg.path === '.')?.version;
|
|
83
|
+
if (!version) {
|
|
84
|
+
throw new Error('The root package.json has no version. Pass the `version` of the release.');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const date =
|
|
88
|
+
options.date ?? (taggedVersion && releaseCommit.commit.committer?.date) ?? new Date();
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
repository,
|
|
92
|
+
previous: { ref: previousRef, sha: previousSha },
|
|
93
|
+
release: { ref: releaseRef, sha: releaseSha },
|
|
94
|
+
version,
|
|
95
|
+
date: new Date(date).toISOString(),
|
|
96
|
+
changes,
|
|
97
|
+
packages: packages.flatMap(({ name, ...pkg }) => (name === null ? [] : [{ name, ...pkg }])),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The packages as they are in the working tree, named or not, sorted by path.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} cwd
|
|
105
|
+
* @param {string} previousSha
|
|
106
|
+
*/
|
|
107
|
+
async function readPackages(cwd, previousSha) {
|
|
108
|
+
const workspaceDir = await findWorkspaceDir(cwd);
|
|
109
|
+
const root = workspaceDir ?? cwd;
|
|
110
|
+
const packages = await getWorkspacePackages({ cwd: root });
|
|
111
|
+
const $$ = $({ cwd: root, reject: false });
|
|
112
|
+
const { exitCode } = await $$`git cat-file -e ${previousSha}^{commit}`;
|
|
113
|
+
|
|
114
|
+
const described = await mapAsync(
|
|
115
|
+
// Without a workspace, pnpm lists the packages of all subdirectories.
|
|
116
|
+
packages.filter((pkg) => workspaceDir || pkg.path === root),
|
|
117
|
+
async (pkg) => {
|
|
118
|
+
const directory = path.relative(root, pkg.path).split(path.sep).join('/') || '.';
|
|
119
|
+
const version = pkg.version ?? null;
|
|
120
|
+
let changed = null;
|
|
121
|
+
if (exitCode === 0) {
|
|
122
|
+
const previous =
|
|
123
|
+
await $$`git show ${previousSha}:./${path.posix.join(directory, 'package.json')}`;
|
|
124
|
+
changed =
|
|
125
|
+
previous.exitCode !== 0 || (JSON.parse(previous.stdout).version ?? null) !== version;
|
|
126
|
+
}
|
|
127
|
+
return { name: pkg.name ?? null, version, private: pkg.isPrivate, path: directory, changed };
|
|
128
|
+
},
|
|
129
|
+
{ concurrency: 10 },
|
|
130
|
+
);
|
|
131
|
+
return described.sort((a, b) => (a.path < b.path ? -1 : 1));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The repository, and the remote of the checkout that points at it, if any.
|
|
136
|
+
*
|
|
137
|
+
* @param {string} cwd
|
|
138
|
+
* @param {FetchChangelogDataOptions} options
|
|
139
|
+
* @returns {Promise<{ repository: GitHubRepository, remote: string | null }>}
|
|
140
|
+
*/
|
|
141
|
+
async function resolveRepository(cwd, options) {
|
|
142
|
+
const info = await getRepositoryInfo(cwd).catch((error) => {
|
|
143
|
+
if (options.repo) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
throw error;
|
|
147
|
+
});
|
|
148
|
+
const owner = options.org ?? 'mui';
|
|
149
|
+
const repo = options.repo ?? /** @type {NonNullable<typeof info>} */ (info).repo;
|
|
150
|
+
const isCheckout = info?.owner === owner && info.repo === repo;
|
|
151
|
+
return { repository: { owner, repo }, remote: isCheckout ? info.remoteName : null };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Resolving refs up front keeps a moving branch from shifting the range while it is paginated.
|
|
156
|
+
*
|
|
157
|
+
* @param {import('@octokit/rest').Octokit} octokit
|
|
158
|
+
* @param {GitHubRepository} repository
|
|
159
|
+
* @param {string} ref
|
|
160
|
+
* @param {AbortSignal} signal
|
|
161
|
+
*/
|
|
162
|
+
async function getCommit(octokit, repository, ref, signal) {
|
|
163
|
+
const { data } = await octokit.repos.getCommit({
|
|
164
|
+
...repository,
|
|
165
|
+
ref,
|
|
166
|
+
// Limits the file list, which can be large and isn't needed.
|
|
167
|
+
per_page: 1,
|
|
168
|
+
request: { signal },
|
|
169
|
+
});
|
|
170
|
+
return data;
|
|
171
|
+
}
|
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import { retry } from '@octokit/plugin-retry';
|
|
2
|
-
import { throttling } from '@octokit/plugin-throttling';
|
|
3
|
-
import { Octokit } from '@octokit/rest';
|
|
4
1
|
import { mapAsync } from 'es-toolkit/array';
|
|
5
2
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
const ThrottledOctokit = Octokit.plugin(throttling, retry);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Waits out short rate limits. Longer ones fail with the original error.
|
|
12
|
-
*
|
|
13
|
-
* @param {number} retryAfter - Seconds until the request may be retried
|
|
14
|
-
* @param {unknown} options
|
|
15
|
-
* @param {unknown} octokit
|
|
16
|
-
* @param {number} retryCount
|
|
17
|
-
* @returns {boolean}
|
|
18
|
-
*/
|
|
19
|
-
function shouldRetryRateLimit(retryAfter, options, octokit, retryCount) {
|
|
20
|
-
return retryAfter <= 60 && retryCount < 3;
|
|
21
|
-
}
|
|
3
|
+
import { createOctokit } from './octokit.mjs';
|
|
22
4
|
|
|
23
5
|
/**
|
|
24
6
|
* @typedef {import('@octokit/rest').Octokit} OctokitType
|
|
@@ -45,16 +27,7 @@ function shouldRetryRateLimit(retryAfter, options, octokit, retryCount) {
|
|
|
45
27
|
* @returns {Promise<FetchedCommitDetails[]>}
|
|
46
28
|
*/
|
|
47
29
|
export async function fetchCommitsBetweenRefs(opts) {
|
|
48
|
-
const octokit =
|
|
49
|
-
'octokit' in opts && opts.octokit
|
|
50
|
-
? opts.octokit
|
|
51
|
-
: new ThrottledOctokit({
|
|
52
|
-
authStrategy: persistentAuthStrategy,
|
|
53
|
-
throttle: {
|
|
54
|
-
onRateLimit: shouldRetryRateLimit,
|
|
55
|
-
onSecondaryRateLimit: shouldRetryRateLimit,
|
|
56
|
-
},
|
|
57
|
-
});
|
|
30
|
+
const octokit = 'octokit' in opts && opts.octokit ? opts.octokit : createOctokit();
|
|
58
31
|
|
|
59
32
|
return fetchCommitsRest({
|
|
60
33
|
octokit,
|
|
@@ -77,7 +50,7 @@ export async function fetchCommitsBetweenRefs(opts) {
|
|
|
77
50
|
*/
|
|
78
51
|
async function fetchCommitsRest({ octokit, repo, lastRelease, release, org = 'mui', onProgress }) {
|
|
79
52
|
/**
|
|
80
|
-
* @typedef {Awaited<ReturnType<
|
|
53
|
+
* @typedef {Awaited<ReturnType<OctokitType['repos']['compareCommits']>>['data']['commits']} Commits
|
|
81
54
|
*/
|
|
82
55
|
/**
|
|
83
56
|
* @type {Commits}
|
package/src/changelog/index.mjs
CHANGED
|
@@ -2,9 +2,18 @@
|
|
|
2
2
|
* Changelog generation utilities.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('./types.ts').FetchChangelogDataOptions} FetchChangelogDataOptions
|
|
7
|
+
* @typedef {import('./types.ts').ChangelogData} ChangelogData
|
|
8
|
+
* @typedef {import('./types.ts').ChangelogChange} ChangelogChange
|
|
9
|
+
* @typedef {import('./types.ts').ChangelogAuthor} ChangelogAuthor
|
|
10
|
+
* @typedef {import('./types.ts').ChangelogPackage} ChangelogPackage
|
|
11
|
+
*/
|
|
12
|
+
|
|
5
13
|
export { generateChangelog } from './generateChangelog.mjs';
|
|
6
14
|
export * from './loadChangelogConfig.mjs';
|
|
7
15
|
export * from './fetchChangelogs.mjs';
|
|
16
|
+
export { fetchChangelogData } from './fetchChangelogData.mjs';
|
|
8
17
|
// Moved to the git utilities, where the rest of the local git plumbing lives. Re-exported because
|
|
9
18
|
// `@mui/internal-code-infra/changelog` is a published entry point and this was part of it.
|
|
10
19
|
export { findLatestTaggedVersion } from '../utils/git.mjs';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { retry } from '@octokit/plugin-retry';
|
|
2
|
+
import { throttling } from '@octokit/plugin-throttling';
|
|
3
|
+
import { Octokit } from '@octokit/rest';
|
|
4
|
+
|
|
5
|
+
import { persistentAuthStrategy } from '../utils/github.mjs';
|
|
6
|
+
|
|
7
|
+
const ThrottledOctokit = Octokit.plugin(throttling, retry);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Waits out short rate limits. Longer ones fail with the original error.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} retryAfter - Seconds until the request may be retried
|
|
13
|
+
* @param {unknown} options
|
|
14
|
+
* @param {unknown} octokit
|
|
15
|
+
* @param {number} retryCount
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
function shouldRetryRateLimit(retryAfter, options, octokit, retryCount) {
|
|
19
|
+
return retryAfter <= 60 && retryCount < 3;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A client that authenticates as the developer running it.
|
|
24
|
+
*
|
|
25
|
+
* @returns {Octokit}
|
|
26
|
+
*/
|
|
27
|
+
export function createOctokit() {
|
|
28
|
+
return new ThrottledOctokit({
|
|
29
|
+
authStrategy: persistentAuthStrategy,
|
|
30
|
+
throttle: {
|
|
31
|
+
onRateLimit: shouldRetryRateLimit,
|
|
32
|
+
onSecondaryRateLimit: shouldRetryRateLimit,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
package/src/changelog/types.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/rest';
|
|
2
|
+
// eslint-disable-next-line import/extensions
|
|
3
|
+
import type { RepoInfo } from '../utils/git.mjs';
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Commit details fetched from GitHub including PR information and labels.
|
|
3
7
|
*/
|
|
@@ -438,3 +442,141 @@ export interface GenerateChangelogResult {
|
|
|
438
442
|
all: string[];
|
|
439
443
|
};
|
|
440
444
|
}
|
|
445
|
+
|
|
446
|
+
export type GitHubRepository = Pick<RepoInfo, 'owner' | 'repo'>;
|
|
447
|
+
|
|
448
|
+
export interface ReleaseRef {
|
|
449
|
+
/**
|
|
450
|
+
* The ref as given. A local `HEAD` is replaced by its SHA.
|
|
451
|
+
*/
|
|
452
|
+
ref: string;
|
|
453
|
+
sha: string;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export interface ChangelogAuthor {
|
|
457
|
+
/**
|
|
458
|
+
* `null` for a commit author without a linked GitHub account.
|
|
459
|
+
*/
|
|
460
|
+
login: string | null;
|
|
461
|
+
/**
|
|
462
|
+
* Git author name. Only known for direct commits.
|
|
463
|
+
*/
|
|
464
|
+
name: string | null;
|
|
465
|
+
association: 'team' | 'community' | 'first-timer';
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* A merged pull request, or a commit that landed without one.
|
|
470
|
+
*/
|
|
471
|
+
export interface ChangelogChange {
|
|
472
|
+
/**
|
|
473
|
+
* Subject of the commit, without the references that the other fields already carry: the pull
|
|
474
|
+
* request it belongs to and, for a cherry-pick, the original pull request and its author.
|
|
475
|
+
*/
|
|
476
|
+
title: string;
|
|
477
|
+
/**
|
|
478
|
+
* Full commit message.
|
|
479
|
+
*/
|
|
480
|
+
message: string;
|
|
481
|
+
sha: string;
|
|
482
|
+
/**
|
|
483
|
+
* Page of the pull request, or of the commit when there is none.
|
|
484
|
+
*/
|
|
485
|
+
url: string;
|
|
486
|
+
labels: string[];
|
|
487
|
+
pullRequest: { number: number; title: string; body: string } | null;
|
|
488
|
+
/**
|
|
489
|
+
* `null` when the GitHub account was deleted.
|
|
490
|
+
*/
|
|
491
|
+
author: ChangelogAuthor | null;
|
|
492
|
+
/**
|
|
493
|
+
* When the pull request was opened, or the commit authored. ISO 8601.
|
|
494
|
+
*/
|
|
495
|
+
createdAt: string | null;
|
|
496
|
+
/**
|
|
497
|
+
* When the pull request was merged, or the commit committed. ISO 8601.
|
|
498
|
+
*/
|
|
499
|
+
mergedAt: string | null;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export interface ChangelogPackage {
|
|
503
|
+
name: string;
|
|
504
|
+
version: string | null;
|
|
505
|
+
/**
|
|
506
|
+
* Whether the package can't be published: marked as private, or without a version.
|
|
507
|
+
*/
|
|
508
|
+
private: boolean;
|
|
509
|
+
/**
|
|
510
|
+
* Directory relative to the workspace root, with `/` separators. `.` for the root package.
|
|
511
|
+
*/
|
|
512
|
+
path: string;
|
|
513
|
+
/**
|
|
514
|
+
* Whether the version differs from the previous release. `true` for a new package, `null` when the
|
|
515
|
+
* previous release isn't available locally.
|
|
516
|
+
*/
|
|
517
|
+
changed: boolean | null;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* What happened in a release, as JSON-serializable data.
|
|
522
|
+
*/
|
|
523
|
+
export interface ChangelogData {
|
|
524
|
+
repository: GitHubRepository;
|
|
525
|
+
previous: ReleaseRef;
|
|
526
|
+
release: ReleaseRef;
|
|
527
|
+
version: string;
|
|
528
|
+
/**
|
|
529
|
+
* ISO 8601.
|
|
530
|
+
*/
|
|
531
|
+
date: string;
|
|
532
|
+
/**
|
|
533
|
+
* Oldest first.
|
|
534
|
+
*/
|
|
535
|
+
changes: ChangelogChange[];
|
|
536
|
+
/**
|
|
537
|
+
* Named packages in the working tree, sorted by path. Without a workspace, only the root package.
|
|
538
|
+
*/
|
|
539
|
+
packages: ChangelogPackage[];
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export interface FetchChangelogDataOptions {
|
|
543
|
+
/**
|
|
544
|
+
* A directory of the released workspace.
|
|
545
|
+
* @default process.cwd()
|
|
546
|
+
*/
|
|
547
|
+
cwd?: string;
|
|
548
|
+
/**
|
|
549
|
+
* Repository name. Defaults to the one the checkout's remote points at.
|
|
550
|
+
*/
|
|
551
|
+
repo?: string;
|
|
552
|
+
/**
|
|
553
|
+
* @default 'mui'
|
|
554
|
+
*/
|
|
555
|
+
org?: string;
|
|
556
|
+
/**
|
|
557
|
+
* Ref of the previous release. Defaults to the closest version tag before `release`.
|
|
558
|
+
*/
|
|
559
|
+
lastRelease?: string;
|
|
560
|
+
/**
|
|
561
|
+
* Ref of the release.
|
|
562
|
+
* @default 'HEAD'
|
|
563
|
+
*/
|
|
564
|
+
release?: string;
|
|
565
|
+
/**
|
|
566
|
+
* Defaults to the version `release` is a tag of, else the version of the root package.
|
|
567
|
+
*/
|
|
568
|
+
version?: string;
|
|
569
|
+
/**
|
|
570
|
+
* Defaults to the commit date when `release` is a version tag, else now.
|
|
571
|
+
*/
|
|
572
|
+
date?: Date | string;
|
|
573
|
+
/**
|
|
574
|
+
* Include commits that landed without a pull request.
|
|
575
|
+
* @default false
|
|
576
|
+
*/
|
|
577
|
+
includeDirectCommits?: boolean;
|
|
578
|
+
/**
|
|
579
|
+
* GitHub client. Defaults to one authenticated as the developer running it.
|
|
580
|
+
*/
|
|
581
|
+
octokit?: Octokit;
|
|
582
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|