tegami 1.2.3 → 1.2.5

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.
@@ -1,9 +1,8 @@
1
- import { a as formatPackageVersion } from "../semver-DrtaCCZK.js";
2
- import { t as changelogFilename } from "../generate-Cgl2G5ea.js";
1
+ import { t as changelogFilename } from "../generate-Cip5o2xy.js";
3
2
  import { n as execFailure, o as cached, r as fetchFailure, s as isCI } from "../error-CAsrGb6e.js";
4
- import { a as createDraft, l as readChangelogEntries } from "../publish-BEYIILK5.js";
3
+ import { a as createDraft, l as readChangelogEntries } from "../publish-CQifflae.js";
5
4
  import { git } from "./git.js";
6
- import { n as onVersionRequest, t as formatPreview } from "../version-request-C89RO85i.js";
5
+ import { i as versionRequestPlugin, n as formatPreview, r as resolveFileCommit, t as createAutoRelease } from "../version-request-CLEmlVnL.js";
7
6
  import { readFile, writeFile } from "node:fs/promises";
8
7
  import { basename, join, relative, resolve } from "node:path";
9
8
  import { x } from "tinyexec";
@@ -35,9 +34,9 @@ async function releaseExistsByTag(repo, tag, token) {
35
34
  if (!response.ok) throw await fetchFailure(`Failed to get GitHub release for ${tag}`, response);
36
35
  return true;
37
36
  }
38
- async function createRelease(repo, options) {
39
- const { owner, repo: name } = parseGitHubRepo(repo);
40
- const response = await githubRequest(`/repos/${owner}/${name}/releases`, options.token, {
37
+ async function createRelease(options) {
38
+ const { owner, repo } = parseGitHubRepo(options.repo);
39
+ const response = await githubRequest(`/repos/${owner}/${repo}/releases`, options.token, {
41
40
  method: "POST",
42
41
  headers: { "Content-Type": "application/json" },
43
42
  body: JSON.stringify({
@@ -309,201 +308,112 @@ function parsePositiveInt(value, option) {
309
308
  /** Create GitHub releases for successfully published packages after the whole plan succeeds. */
310
309
  function github(options = {}) {
311
310
  const { release: releaseOptions = true } = options;
312
- let renderer;
313
- function getRenderer(context) {
314
- return renderer ??= createChangelogRenderer(context);
315
- }
316
- const versionRequests = onVersionRequest({
317
- name: "github",
318
- options: options.versionPr,
319
- canCreate(context) {
320
- const { repo, token } = context.github ?? {};
321
- return Boolean(repo && token);
322
- },
323
- async upsert(context, request, update) {
324
- const { repo, token } = context.github;
325
- const openPr = await findOpenPullRequest(repo, request.head, token);
326
- if (openPr === void 0) await createPullRequest(repo, {
327
- title: request.title,
328
- body: request.body,
329
- head: request.head,
330
- base: request.base,
331
- token
332
- });
333
- else if (update) await updatePullRequest(repo, openPr, {
334
- title: request.title,
335
- body: request.body,
336
- token
337
- });
338
- }
339
- });
340
- const plugin = {
341
- ...versionRequests,
342
- name: "github",
343
- init() {
344
- this.github = {
345
- repo: options.repo ?? process.env.GITHUB_REPOSITORY,
346
- token: options.token ?? process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN
347
- };
348
- },
349
- async resolvePlanStatus({ plan }) {
350
- if (versionRequests.resolvePlanStatus.call(this, { plan }) === "pending") return "pending";
351
- const { repo, token } = this.github;
352
- if (!repo || !token || releaseOptions === false) return;
353
- const requiredTags = /* @__PURE__ */ new Set();
354
- for (const pkg of plan.packages.values()) if (pkg.preflight.shouldPublish && pkg.git?.tag) requiredTags.add(pkg.git.tag);
355
- return Array.from(requiredTags, async (tag) => {
356
- if (!await releaseExistsByTag(repo, tag, token)) return "pending";
357
- });
358
- },
359
- async afterPublishAll({ plan }) {
360
- const { repo, token } = this.github;
361
- if (!repo || !token || releaseOptions === false) return;
362
- const { eager = false, create, createGrouped } = releaseOptions === true ? {} : releaseOptions;
363
- const groups = /* @__PURE__ */ new Map();
364
- for (const [id, { preflight, publishResult, git }] of plan.packages) {
365
- if (!eager && publishResult.type === "failed") return;
366
- const tag = git?.tag;
367
- if (!tag || !preflight.shouldPublish) continue;
368
- const pkg = this.graph.get(id);
369
- const group = groups.get(tag);
370
- if (group) group.push(pkg);
371
- else groups.set(tag, [pkg]);
372
- }
373
- await Promise.all(Array.from(groups, async ([tag, packages]) => {
374
- for (const member of packages) if (plan.packages.get(member.id).publishResult.type === "failed") return;
375
- if (await releaseExistsByTag(repo, tag, token)) return;
376
- let release;
377
- if (packages.length > 1) {
378
- const overrides = await createGrouped?.call(this, {
379
- tag,
380
- packages,
381
- plan
382
- }) ?? {};
383
- release = {
384
- title: overrides.title ?? tag,
385
- notes: overrides.notes ?? await defaultGroupedNotes(getRenderer(this), plan, packages),
386
- prerelease: overrides.prerelease ?? packages.some((pkg) => pkg.version && semver.prerelease(pkg.version))
387
- };
388
- } else {
389
- const pkg = packages[0];
390
- const overrides = await create?.call(this, {
391
- tag,
392
- pkg,
393
- plan
394
- }) ?? {};
395
- const packagePlan = plan.packages.get(pkg.id);
396
- release = {
397
- title: overrides.title ?? formatPackageVersion(pkg.name, pkg.version, packagePlan?.npm?.distTag),
398
- notes: overrides.notes ?? await defaultNotes(getRenderer(this), pkg, packagePlan),
399
- prerelease: overrides.prerelease ?? (pkg.version !== void 0 && semver.prerelease(pkg.version) !== null)
400
- };
311
+ let autoRelease;
312
+ return [
313
+ git(options),
314
+ {
315
+ name: "github",
316
+ init() {
317
+ const { repo, token } = this.github = {
318
+ repo: options.repo ?? process.env.GITHUB_REPOSITORY,
319
+ token: options.token ?? process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN
320
+ };
321
+ if (repo && token && releaseOptions !== false) {
322
+ const { eager = false, create, createGrouped } = releaseOptions === true ? {} : releaseOptions;
323
+ const resolveEntryMeta = cached((entry) => entry.id, async (entry) => {
324
+ const commit = await resolveFileCommit(this, entry.filename);
325
+ if (!commit) return {
326
+ commit,
327
+ pullRequests: []
328
+ };
329
+ return {
330
+ commit,
331
+ pullRequests: await listPullRequestsForCommit(repo, commit, token).catch(() => [])
332
+ };
333
+ });
334
+ autoRelease = createAutoRelease({
335
+ eager,
336
+ override: create,
337
+ overrideGroup: createGrouped,
338
+ async formatChangelog(entry) {
339
+ const meta = await resolveEntryMeta(entry);
340
+ const lines = [];
341
+ const commitSuffix = meta.commit ? ` ([${meta.commit.slice(0, 7)}](https://github.com/${repo}/commit/${meta.commit}))` : "";
342
+ for (const section of entry.sections) {
343
+ lines.push(`### ${section.title}${commitSuffix}`, "");
344
+ if (section.content) lines.push(section.content, "");
345
+ }
346
+ if (meta.pullRequests.length > 0) {
347
+ lines.push("<details>", "<summary>Pull request & contributors</summary>", "");
348
+ for (const pr of meta.pullRequests) {
349
+ let line = `- [#${pr.number} ${pr.title}](https://github.com/${repo}/pull/${pr.number})`;
350
+ if (pr.user) line += ` by @${pr.user.login}`;
351
+ lines.push(line);
352
+ }
353
+ lines.push("", "</details>");
354
+ }
355
+ return lines.join("\n").trim();
356
+ },
357
+ create({ input, packages, tag }) {
358
+ return createRelease({
359
+ ...input,
360
+ repo,
361
+ tag,
362
+ token,
363
+ prerelease: input.prerelease ?? packages.some((pkg) => pkg.version && semver.prerelease(pkg.version))
364
+ });
365
+ },
366
+ releaseExistsByTag(tag) {
367
+ return releaseExistsByTag(repo, tag, token);
368
+ }
369
+ });
401
370
  }
402
- await createRelease(repo, {
403
- tag,
404
- title: release.title,
405
- notes: release.notes,
406
- prerelease: release.prerelease,
371
+ },
372
+ async resolvePlanStatus({ plan }) {
373
+ if (await autoRelease?.hasPending.call(this, plan)) return "pending";
374
+ },
375
+ async afterPublishAll({ plan }) {
376
+ await autoRelease?.create.call(this, plan);
377
+ },
378
+ async initCli(cli) {
379
+ registerPrCli(cli);
380
+ if (!isCI()) return;
381
+ const { repo, token } = this.github ?? {};
382
+ if (!token || !repo) return;
383
+ const result = await x("git", [
384
+ "remote",
385
+ "set-url",
386
+ "origin",
387
+ `https://x-access-token:${token}@github.com/${repo}.git`
388
+ ], { nodeOptions: { cwd: this.cwd } });
389
+ if (result.exitCode !== 0) throw execFailure("Failed to configure git remote for GitHub Actions.", result);
390
+ }
391
+ },
392
+ versionRequestPlugin({
393
+ name: "github",
394
+ options: options.versionPr,
395
+ canCreate(context) {
396
+ const { repo, token } = context.github ?? {};
397
+ return Boolean(repo && token);
398
+ },
399
+ async upsert(context, request, update) {
400
+ const { repo, token } = context.github;
401
+ const openPr = await findOpenPullRequest(repo, request.head, token);
402
+ if (openPr === void 0) await createPullRequest(repo, {
403
+ title: request.title,
404
+ body: request.body,
405
+ head: request.head,
406
+ base: request.base,
407
407
  token
408
408
  });
409
- }));
410
- },
411
- async initCli(cli) {
412
- registerPrCli(cli);
413
- if (!isCI()) return;
414
- const { repo, token } = this.github ?? {};
415
- if (!token || !repo) return;
416
- const result = await x("git", [
417
- "remote",
418
- "set-url",
419
- "origin",
420
- `https://x-access-token:${token}@github.com/${repo}.git`
421
- ], { nodeOptions: { cwd: this.cwd } });
422
- if (result.exitCode !== 0) throw execFailure("Failed to configure git remote for GitHub Actions.", result);
423
- }
424
- };
425
- return [git(options), plugin];
426
- }
427
- function createChangelogRenderer(context) {
428
- const { repo, token } = context.github;
429
- const resolveFileCommit = cached((filename) => filename, async (filename) => {
430
- const result = await x("git", [
431
- "log",
432
- "--diff-filter=A",
433
- "-1",
434
- "--format=%H",
435
- "--",
436
- relative(context.cwd, join(context.changelogDir, filename))
437
- ], { nodeOptions: { cwd: context.cwd } });
438
- if (result.exitCode !== 0) return;
439
- return result.stdout.trim() || void 0;
440
- });
441
- const resolveEntryMeta = cached((entry) => entry.id, async (entry) => {
442
- const commit = await resolveFileCommit(entry.filename);
443
- if (!commit || !repo) return {
444
- commit,
445
- pullRequests: []
446
- };
447
- return {
448
- commit,
449
- pullRequests: await listPullRequestsForCommit(repo, commit, token).catch(() => [])
450
- };
451
- });
452
- function formatEntryDetails(meta) {
453
- if (meta.pullRequests.length === 0) return;
454
- const lines = [];
455
- for (const pr of meta.pullRequests) {
456
- let line = repo ? `- [#${pr.number} ${pr.title}](https://github.com/${repo}/pull/${pr.number})` : `- #${pr.number} ${pr.title}`;
457
- if (pr.user) line += ` by @${pr.user.login}`;
458
- lines.push(line);
459
- }
460
- return [
461
- "<details>",
462
- "<summary>Pull request & contributors</summary>",
463
- "",
464
- ...lines,
465
- "",
466
- "</details>"
467
- ].join("\n");
468
- }
469
- return async (entry) => {
470
- const meta = await resolveEntryMeta(entry);
471
- let commitSuffix = "";
472
- if (meta.commit) {
473
- const short = meta.commit.slice(0, 7);
474
- const link = repo ? `[${short}](https://github.com/${repo}/commit/${meta.commit})` : `\`${short}\``;
475
- commitSuffix += ` (${link})`;
476
- }
477
- const lines = [];
478
- for (const section of entry.sections) {
479
- lines.push(`### ${section.title}${commitSuffix}`, "");
480
- if (section.content) lines.push(section.content, "");
481
- }
482
- const details = formatEntryDetails(meta);
483
- if (details) lines.push(details);
484
- return lines.join("\n").trim();
485
- };
486
- }
487
- async function defaultNotes(renderer, pkg, packagePlan) {
488
- if (packagePlan && packagePlan.changelogs.length > 0) return (await Promise.all(packagePlan.changelogs.map(renderer))).join("\n\n");
489
- return `Published ${formatPackageVersion(pkg.name, pkg.version, packagePlan?.npm?.distTag)}.`;
490
- }
491
- async function defaultGroupedNotes(renderer, plan, packages) {
492
- const changelogs = /* @__PURE__ */ new Map();
493
- for (const pkg of packages) {
494
- const packagePlan = plan.packages.get(pkg.id);
495
- if (!packagePlan) continue;
496
- for (const entry of packagePlan.changelogs) changelogs.set(entry.id, entry);
497
- }
498
- const sections = [packages.map((pkg) => {
499
- const packagePlan = plan.packages.get(pkg.id);
500
- return `- ${formatPackageVersion(pkg.name, pkg.version, packagePlan?.npm?.distTag)}`;
501
- }).join("\n")];
502
- if (changelogs.size > 0) {
503
- const notes = await Promise.all(Array.from(changelogs.values(), renderer));
504
- sections.push("", notes.join("\n\n"));
505
- }
506
- return sections.join("\n");
409
+ else if (update) await updatePullRequest(repo, openPr, {
410
+ title: request.title,
411
+ body: request.body,
412
+ token
413
+ });
414
+ }
415
+ })
416
+ ];
507
417
  }
508
418
  //#endregion
509
419
  export { github };
@@ -1,13 +1,12 @@
1
- import { j as WorkspacePackage, s as TegamiPlugin, t as Awaitable, x as TegamiContext, y as PublishPlan } from "../types-Kj7Nxbjz.js";
1
+ import { j as WorkspacePackage, s as TegamiPlugin, t as Awaitable, v as PublishPlan, x as TegamiContext } from "../types-Cn0Au3Kk.js";
2
2
  import { GitPluginOptions } from "./git.js";
3
- import { t as VersionRequestOptions } from "../version-request-C5vtakPE.js";
4
-
3
+ import { t as VersionRequestOptions } from "../version-request-DHxFYvna.js";
5
4
  //#region src/plugins/gitlab.d.ts
6
5
  interface GitlabRelease {
7
6
  /** Release title */
8
- title?: string;
7
+ title: string;
9
8
  /** Release notes */
10
- notes?: string;
9
+ notes: string;
11
10
  }
12
11
  /** Options for creating GitLab releases after a successful publish. */
13
12
  interface GitLabPluginOptions extends GitPluginOptions {
@@ -30,17 +29,19 @@ interface GitLabPluginOptions extends GitPluginOptions {
30
29
  *
31
30
  * @default false
32
31
  */
33
- eager?: boolean; /** Override release details for a single package. */
32
+ eager?: boolean;
33
+ /** Override release details for a single package. */
34
34
  create?: (this: TegamiContext, opts: {
35
35
  tag: string;
36
36
  pkg: WorkspacePackage;
37
37
  plan: PublishPlan;
38
- }) => Awaitable<GitlabRelease>; /** Override release details when multiple packages share a git tag. */
38
+ }) => Awaitable<Partial<GitlabRelease>>;
39
+ /** Override release details when multiple packages share a git tag. */
39
40
  createGrouped?: (this: TegamiContext, opts: {
40
41
  tag: string;
41
42
  packages: WorkspacePackage[];
42
43
  plan: PublishPlan;
43
- }) => Awaitable<GitlabRelease>;
44
+ }) => Awaitable<Partial<GitlabRelease>>;
44
45
  };
45
46
  /**
46
47
  * (CLI only) Open a version merge request after versioning.