@mui/internal-code-infra 0.1.1-canary.39 → 0.1.1-canary.40
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.
|
@@ -11,6 +11,10 @@ export type PullRequest = {
|
|
|
11
11
|
login: string;
|
|
12
12
|
type: string;
|
|
13
13
|
} | null;
|
|
14
|
+
assignees?: {
|
|
15
|
+
login: string;
|
|
16
|
+
type: string;
|
|
17
|
+
}[] | null;
|
|
14
18
|
author_association: string;
|
|
15
19
|
labels: {
|
|
16
20
|
name?: string;
|
|
@@ -23,14 +27,16 @@ export type PullRequest = {
|
|
|
23
27
|
* @param {string} options.previousSha
|
|
24
28
|
* @param {string} options.releaseSha
|
|
25
29
|
* @param {boolean} options.includeDirectCommits
|
|
30
|
+
* @param {string[]} [options.excludeBots] - Bots whose changes are left out, as `app/<slug>` or login
|
|
26
31
|
* @param {AbortController} options.controller - Aborted when a request fails
|
|
27
32
|
* @returns {Promise<ChangelogChange[]>}
|
|
28
33
|
*/
|
|
29
|
-
export declare function fetchChangelogChanges({ octokit, repository, previousSha, releaseSha, includeDirectCommits, controller, }: {
|
|
34
|
+
export declare function fetchChangelogChanges({ octokit, repository, previousSha, releaseSha, includeDirectCommits, excludeBots, controller, }: {
|
|
30
35
|
octokit: Octokit;
|
|
31
36
|
repository: GitHubRepository;
|
|
32
37
|
previousSha: string;
|
|
33
38
|
releaseSha: string;
|
|
34
39
|
includeDirectCommits: boolean;
|
|
40
|
+
excludeBots?: string[];
|
|
35
41
|
controller: AbortController;
|
|
36
42
|
}): Promise<ChangelogChange[]>;
|
|
@@ -410,6 +410,10 @@ export interface ChangelogAuthor {
|
|
|
410
410
|
*/
|
|
411
411
|
name: string | null;
|
|
412
412
|
association: 'team' | 'community' | 'first-timer';
|
|
413
|
+
/**
|
|
414
|
+
* Whether it is a bot that works on its own. Not for Copilot, which works for a person.
|
|
415
|
+
*/
|
|
416
|
+
isBot: boolean;
|
|
413
417
|
}
|
|
414
418
|
/**
|
|
415
419
|
* A merged pull request, or a commit that landed without one.
|
|
@@ -438,6 +442,11 @@ export interface ChangelogChange {
|
|
|
438
442
|
number: number;
|
|
439
443
|
title: string;
|
|
440
444
|
body: string;
|
|
445
|
+
/**
|
|
446
|
+
* Not necessarily the author of the change: a cherry-pick can be opened by a bot, and Copilot
|
|
447
|
+
* works for a person. `null` when the GitHub account was deleted.
|
|
448
|
+
*/
|
|
449
|
+
openedBy: ChangelogAuthor | null;
|
|
441
450
|
} | null;
|
|
442
451
|
/**
|
|
443
452
|
* `null` when the GitHub account was deleted.
|
|
@@ -526,6 +535,13 @@ export interface FetchChangelogDataOptions {
|
|
|
526
535
|
* @default false
|
|
527
536
|
*/
|
|
528
537
|
includeDirectCommits?: boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Bots whose changes are left out, as `app/<slug>` like in GitHub search, or as their login, such
|
|
540
|
+
* as `renovate[bot]`. A change is left out when its author or the opener of its pull request is
|
|
541
|
+
* one of them. Pass `[]` to keep all.
|
|
542
|
+
* @default ['app/renovate', 'app/code-infra-renovate']
|
|
543
|
+
*/
|
|
544
|
+
excludeBots?: string[];
|
|
529
545
|
/**
|
|
530
546
|
* GitHub client. Defaults to one authenticated as the developer running it.
|
|
531
547
|
*/
|
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.40",
|
|
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": "cbde0adb5cb3e77e9f33ad1c8cbdabd97cd372fc",
|
|
203
203
|
"scripts": {
|
|
204
204
|
"build": "tsc -p tsconfig.build.json",
|
|
205
205
|
"typescript": "tsc -noEmit",
|
|
@@ -18,6 +18,7 @@ import { getRateLimitRetryTime } from '../utils/github.mjs';
|
|
|
18
18
|
* @property {string} title
|
|
19
19
|
* @property {string | null} body
|
|
20
20
|
* @property {{ login: string, type: string } | null} user
|
|
21
|
+
* @property {{ login: string, type: string }[] | null} [assignees]
|
|
21
22
|
* @property {string} author_association
|
|
22
23
|
* @property {{ name?: string }[]} labels
|
|
23
24
|
*/
|
|
@@ -36,6 +37,7 @@ const ASSOCIATIONS = {
|
|
|
36
37
|
|
|
37
38
|
const BREAKING_CHANGE_LABELS = ['breaking', 'breaking change'];
|
|
38
39
|
const CHERRY_PICK_LABEL = 'cherry-pick';
|
|
40
|
+
const COPILOT = 'Copilot';
|
|
39
41
|
const PULL_REFERENCE =
|
|
40
42
|
/(?:https:\/\/github\.com\/(?<urlOwner>[\w.-]+)\/(?<urlRepo>[\w.-]+)\/pull\/|(?:(?<owner>[\w.-]+)\/(?<repo>[\w.-]+))?#)(?<number>\d+)/;
|
|
41
43
|
// Unnamed, so that the pattern can be repeated.
|
|
@@ -68,6 +70,15 @@ function getCherryPickReferences(pull, repository) {
|
|
|
68
70
|
);
|
|
69
71
|
}
|
|
70
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Copilot works for a person, so what it does isn't the routine work of other bots.
|
|
75
|
+
*
|
|
76
|
+
* @param {{ login?: string, type?: string } | null} [account]
|
|
77
|
+
*/
|
|
78
|
+
function isBotAccount(account) {
|
|
79
|
+
return account?.type === 'Bot' && account.login !== COPILOT;
|
|
80
|
+
}
|
|
81
|
+
|
|
71
82
|
/**
|
|
72
83
|
* @param {any} error
|
|
73
84
|
*/
|
|
@@ -179,7 +190,27 @@ function createAuthorResolver({ octokit, repository, signal }) {
|
|
|
179
190
|
: // The association with another repository says nothing about this one.
|
|
180
191
|
await getMembership(login);
|
|
181
192
|
}
|
|
182
|
-
return { login, name: null, association };
|
|
193
|
+
return { login, name: null, association, isBot: isBotAccount(pull.user) };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The opener, or the person who asked Copilot for the pull request.
|
|
198
|
+
*
|
|
199
|
+
* @param {PullRequest} pull
|
|
200
|
+
* @param {GitHubRepository} pullRepository
|
|
201
|
+
* @returns {Promise<ChangelogAuthor | null>}
|
|
202
|
+
*/
|
|
203
|
+
async function getCredit(pull, pullRepository) {
|
|
204
|
+
if (pull.user?.login === COPILOT) {
|
|
205
|
+
// It assigns itself and whoever asked for the pull request.
|
|
206
|
+
const people = (pull.assignees ?? []).filter((assignee) => assignee.type !== 'Bot');
|
|
207
|
+
if (people.length === 1) {
|
|
208
|
+
const { login } = people[0];
|
|
209
|
+
// The association of the pull request is the one of Copilot.
|
|
210
|
+
return { login, name: null, association: await getMembership(login), isBot: false };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return getOpener(pull, pullRepository);
|
|
183
214
|
}
|
|
184
215
|
|
|
185
216
|
/**
|
|
@@ -190,9 +221,9 @@ function createAuthorResolver({ octokit, repository, signal }) {
|
|
|
190
221
|
* `null` when the pull request is a cherry-pick by a bot of which the original author is unknown
|
|
191
222
|
*/
|
|
192
223
|
async function resolve(pull, pullRepository, chain = []) {
|
|
193
|
-
const isBot = pull.user
|
|
224
|
+
const isBot = isBotAccount(pull.user);
|
|
194
225
|
const opener = async () => ({
|
|
195
|
-
author: await
|
|
226
|
+
author: await getCredit(pull, pullRepository),
|
|
196
227
|
isBot,
|
|
197
228
|
references: [],
|
|
198
229
|
});
|
|
@@ -227,19 +258,26 @@ function createAuthorResolver({ octokit, repository, signal }) {
|
|
|
227
258
|
return {
|
|
228
259
|
/**
|
|
229
260
|
* @param {PullRequest} pull
|
|
230
|
-
* @returns {Promise<{ author: ChangelogAuthor | null, references: string[] }>}
|
|
261
|
+
* @returns {Promise<{ author: ChangelogAuthor | null, openedBy: ChangelogAuthor | null, references: string[] }>}
|
|
231
262
|
*/
|
|
232
263
|
async fromPullRequest(pull) {
|
|
264
|
+
const openedBy = await getOpener(pull, repository);
|
|
233
265
|
const resolved = await resolve(pull, repository);
|
|
234
|
-
if (resolved) {
|
|
235
|
-
|
|
266
|
+
if (!resolved) {
|
|
267
|
+
console.warn(
|
|
268
|
+
`#${pull.number} is a cherry-pick, but its original author can't be determined. ` +
|
|
269
|
+
`${openedBy?.login} is credited instead.`,
|
|
270
|
+
);
|
|
271
|
+
return { author: openedBy, openedBy, references: [] };
|
|
236
272
|
}
|
|
237
|
-
const author
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
273
|
+
const { author, references } = resolved;
|
|
274
|
+
if (author?.login === COPILOT) {
|
|
275
|
+
console.warn(
|
|
276
|
+
`#${pull.number} is by ${COPILOT}, but who it worked for can't be determined. ` +
|
|
277
|
+
`${COPILOT} is credited instead.`,
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return { author, openedBy, references };
|
|
243
281
|
},
|
|
244
282
|
/**
|
|
245
283
|
* @param {Commit} commit
|
|
@@ -254,6 +292,7 @@ function createAuthorResolver({ octokit, repository, signal }) {
|
|
|
254
292
|
login === null || commit.author?.type === 'Bot'
|
|
255
293
|
? 'community'
|
|
256
294
|
: await getMembership(login),
|
|
295
|
+
isBot: isBotAccount(commit.author),
|
|
257
296
|
};
|
|
258
297
|
},
|
|
259
298
|
};
|
|
@@ -282,6 +321,7 @@ function stripTrailingReferences(title, references, stripCredits) {
|
|
|
282
321
|
* @param {string} options.previousSha
|
|
283
322
|
* @param {string} options.releaseSha
|
|
284
323
|
* @param {boolean} options.includeDirectCommits
|
|
324
|
+
* @param {string[]} [options.excludeBots] - Bots whose changes are left out, as `app/<slug>` or login
|
|
285
325
|
* @param {AbortController} options.controller - Aborted when a request fails
|
|
286
326
|
* @returns {Promise<ChangelogChange[]>}
|
|
287
327
|
*/
|
|
@@ -291,9 +331,16 @@ export async function fetchChangelogChanges({
|
|
|
291
331
|
previousSha,
|
|
292
332
|
releaseSha,
|
|
293
333
|
includeDirectCommits,
|
|
334
|
+
excludeBots = ['app/renovate', 'app/code-infra-renovate'],
|
|
294
335
|
controller,
|
|
295
336
|
}) {
|
|
296
337
|
const { signal } = controller;
|
|
338
|
+
const excluded = new Set(
|
|
339
|
+
excludeBots.map((bot) => (bot.startsWith('app/') ? `${bot.slice('app/'.length)}[bot]` : bot)),
|
|
340
|
+
);
|
|
341
|
+
const isExcludedAccount = (
|
|
342
|
+
/** @type {{ login?: string, type?: string } | null | undefined} */ account,
|
|
343
|
+
) => account?.type === 'Bot' && excluded.has(account.login ?? '');
|
|
297
344
|
const location = { ...repository, request: { signal } };
|
|
298
345
|
const authors = createAuthorResolver({ octokit, repository, signal });
|
|
299
346
|
|
|
@@ -368,7 +415,13 @@ export async function fetchChangelogChanges({
|
|
|
368
415
|
|
|
369
416
|
const pull = await findPullRequest(sha, subject);
|
|
370
417
|
if (pull) {
|
|
371
|
-
|
|
418
|
+
if (isExcludedAccount(pull.user)) {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
const { author, openedBy, references } = await authors.fromPullRequest(pull);
|
|
422
|
+
if (author?.isBot && excluded.has(author.login ?? '')) {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
372
425
|
const ownReference = `#${pull.number}`;
|
|
373
426
|
const title = subject.endsWith(`(${ownReference})`) ? subject : pull.title;
|
|
374
427
|
const isCreditedCherryPick = references.length > 0;
|
|
@@ -379,14 +432,19 @@ export async function fetchChangelogChanges({
|
|
|
379
432
|
url: pull.html_url,
|
|
380
433
|
labels: pull.labels.map((label) => label.name),
|
|
381
434
|
isBreakingChange: pull.labels.some((label) => BREAKING_CHANGE_LABELS.includes(label.name)),
|
|
382
|
-
pullRequest: {
|
|
435
|
+
pullRequest: {
|
|
436
|
+
number: pull.number,
|
|
437
|
+
title: pull.title,
|
|
438
|
+
body: pull.body ?? '',
|
|
439
|
+
openedBy,
|
|
440
|
+
},
|
|
383
441
|
author,
|
|
384
442
|
createdAt: pull.created_at,
|
|
385
443
|
mergedAt: pull.merged_at,
|
|
386
444
|
};
|
|
387
445
|
}
|
|
388
446
|
|
|
389
|
-
if (!includeDirectCommits) {
|
|
447
|
+
if (!includeDirectCommits || isExcludedAccount(commit.author)) {
|
|
390
448
|
return null;
|
|
391
449
|
}
|
|
392
450
|
return {
|
package/src/changelog/types.ts
CHANGED
|
@@ -463,6 +463,10 @@ export interface ChangelogAuthor {
|
|
|
463
463
|
*/
|
|
464
464
|
name: string | null;
|
|
465
465
|
association: 'team' | 'community' | 'first-timer';
|
|
466
|
+
/**
|
|
467
|
+
* Whether it is a bot that works on its own. Not for Copilot, which works for a person.
|
|
468
|
+
*/
|
|
469
|
+
isBot: boolean;
|
|
466
470
|
}
|
|
467
471
|
|
|
468
472
|
/**
|
|
@@ -488,7 +492,16 @@ export interface ChangelogChange {
|
|
|
488
492
|
* Whether the pull request has the `breaking` or the `breaking change` label.
|
|
489
493
|
*/
|
|
490
494
|
isBreakingChange: boolean;
|
|
491
|
-
pullRequest: {
|
|
495
|
+
pullRequest: {
|
|
496
|
+
number: number;
|
|
497
|
+
title: string;
|
|
498
|
+
body: string;
|
|
499
|
+
/**
|
|
500
|
+
* Not necessarily the author of the change: a cherry-pick can be opened by a bot, and Copilot
|
|
501
|
+
* works for a person. `null` when the GitHub account was deleted.
|
|
502
|
+
*/
|
|
503
|
+
openedBy: ChangelogAuthor | null;
|
|
504
|
+
} | null;
|
|
492
505
|
/**
|
|
493
506
|
* `null` when the GitHub account was deleted.
|
|
494
507
|
*/
|
|
@@ -579,6 +592,13 @@ export interface FetchChangelogDataOptions {
|
|
|
579
592
|
* @default false
|
|
580
593
|
*/
|
|
581
594
|
includeDirectCommits?: boolean;
|
|
595
|
+
/**
|
|
596
|
+
* Bots whose changes are left out, as `app/<slug>` like in GitHub search, or as their login, such
|
|
597
|
+
* as `renovate[bot]`. A change is left out when its author or the opener of its pull request is
|
|
598
|
+
* one of them. Pass `[]` to keep all.
|
|
599
|
+
* @default ['app/renovate', 'app/code-infra-renovate']
|
|
600
|
+
*/
|
|
601
|
+
excludeBots?: string[];
|
|
582
602
|
/**
|
|
583
603
|
* GitHub client. Defaults to one authenticated as the developer running it.
|
|
584
604
|
*/
|