@lbdudc/linea-git 0.0.0-stage → 0.1.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.
Files changed (152) hide show
  1. package/README.md +47 -2
  2. package/dist/access.d.ts +18 -0
  3. package/dist/access.js +18 -0
  4. package/dist/access.js.map +1 -0
  5. package/dist/auth.d.ts +11 -0
  6. package/dist/auth.js +16 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/changelog/generate.d.ts +18 -0
  9. package/dist/changelog/generate.js +166 -0
  10. package/dist/changelog/generate.js.map +1 -0
  11. package/dist/changelog/index.d.ts +5 -0
  12. package/dist/changelog/index.js +3 -0
  13. package/dist/changelog/index.js.map +1 -0
  14. package/dist/changelog/parse.d.ts +43 -0
  15. package/dist/changelog/parse.js +91 -0
  16. package/dist/changelog/parse.js.map +1 -0
  17. package/dist/changelog/types.d.ts +85 -0
  18. package/dist/changelog/types.js +2 -0
  19. package/dist/changelog/types.js.map +1 -0
  20. package/dist/checkout/credential.d.ts +14 -0
  21. package/dist/checkout/credential.js +29 -0
  22. package/dist/checkout/credential.js.map +1 -0
  23. package/dist/checkout/git.d.ts +78 -0
  24. package/dist/checkout/git.js +191 -0
  25. package/dist/checkout/git.js.map +1 -0
  26. package/dist/checkout/index.d.ts +3 -0
  27. package/dist/checkout/index.js +4 -0
  28. package/dist/checkout/index.js.map +1 -0
  29. package/dist/checkout/sync.d.ts +156 -0
  30. package/dist/checkout/sync.js +211 -0
  31. package/dist/checkout/sync.js.map +1 -0
  32. package/dist/closing.d.ts +1 -0
  33. package/dist/closing.js +14 -0
  34. package/dist/closing.js.map +1 -0
  35. package/dist/config.d.ts +53 -0
  36. package/dist/config.js +40 -0
  37. package/dist/config.js.map +1 -0
  38. package/dist/deletion.d.ts +19 -0
  39. package/dist/deletion.js +27 -0
  40. package/dist/deletion.js.map +1 -0
  41. package/dist/errors.d.ts +26 -0
  42. package/dist/errors.js +47 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/factory.d.ts +20 -0
  45. package/dist/factory.js +46 -0
  46. package/dist/factory.js.map +1 -0
  47. package/dist/github/client.d.ts +44 -0
  48. package/dist/github/client.js +145 -0
  49. package/dist/github/client.js.map +1 -0
  50. package/dist/github/config.d.ts +24 -0
  51. package/dist/github/config.js +11 -0
  52. package/dist/github/config.js.map +1 -0
  53. package/dist/github/provider.d.ts +510 -0
  54. package/dist/github/provider.js +1009 -0
  55. package/dist/github/provider.js.map +1 -0
  56. package/dist/gitlab/client.d.ts +50 -0
  57. package/dist/gitlab/client.js +228 -0
  58. package/dist/gitlab/client.js.map +1 -0
  59. package/dist/gitlab/provider.d.ts +487 -0
  60. package/dist/gitlab/provider.js +719 -0
  61. package/dist/gitlab/provider.js.map +1 -0
  62. package/dist/host.d.ts +27 -0
  63. package/dist/host.js +45 -0
  64. package/dist/host.js.map +1 -0
  65. package/dist/index.d.ts +46 -0
  66. package/dist/index.js +31 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/local/diff.d.ts +3 -0
  69. package/dist/local/diff.js +43 -0
  70. package/dist/local/diff.js.map +1 -0
  71. package/dist/local/git.d.ts +24 -0
  72. package/dist/local/git.js +51 -0
  73. package/dist/local/git.js.map +1 -0
  74. package/dist/local/health.d.ts +36 -0
  75. package/dist/local/health.js +57 -0
  76. package/dist/local/health.js.map +1 -0
  77. package/dist/local/hooks.d.ts +2 -0
  78. package/dist/local/hooks.js +44 -0
  79. package/dist/local/hooks.js.map +1 -0
  80. package/dist/local/http.d.ts +35 -0
  81. package/dist/local/http.js +160 -0
  82. package/dist/local/http.js.map +1 -0
  83. package/dist/local/provider.d.ts +571 -0
  84. package/dist/local/provider.js +1237 -0
  85. package/dist/local/provider.js.map +1 -0
  86. package/dist/local/store.d.ts +136 -0
  87. package/dist/local/store.js +171 -0
  88. package/dist/local/store.js.map +1 -0
  89. package/dist/packages/github-source.d.ts +69 -0
  90. package/dist/packages/github-source.js +133 -0
  91. package/dist/packages/github-source.js.map +1 -0
  92. package/dist/packages/gitlab-source.d.ts +59 -0
  93. package/dist/packages/gitlab-source.js +214 -0
  94. package/dist/packages/gitlab-source.js.map +1 -0
  95. package/dist/packages/index.d.ts +30 -0
  96. package/dist/packages/index.js +45 -0
  97. package/dist/packages/index.js.map +1 -0
  98. package/dist/packages/provider-source.d.ts +34 -0
  99. package/dist/packages/provider-source.js +57 -0
  100. package/dist/packages/provider-source.js.map +1 -0
  101. package/dist/packages/repository-files.d.ts +12 -0
  102. package/dist/packages/repository-files.js +16 -0
  103. package/dist/packages/repository-files.js.map +1 -0
  104. package/dist/provider.d.ts +888 -0
  105. package/dist/provider.js +29 -0
  106. package/dist/provider.js.map +1 -0
  107. package/dist/read-cache.d.ts +5 -0
  108. package/dist/read-cache.js +101 -0
  109. package/dist/read-cache.js.map +1 -0
  110. package/dist/registry/catalog.d.ts +55 -0
  111. package/dist/registry/catalog.js +143 -0
  112. package/dist/registry/catalog.js.map +1 -0
  113. package/dist/registry/kinds.d.ts +21 -0
  114. package/dist/registry/kinds.js +43 -0
  115. package/dist/registry/kinds.js.map +1 -0
  116. package/dist/registry/packages.d.ts +165 -0
  117. package/dist/registry/packages.js +290 -0
  118. package/dist/registry/packages.js.map +1 -0
  119. package/dist/registry/publish.d.ts +35 -0
  120. package/dist/registry/publish.js +155 -0
  121. package/dist/registry/publish.js.map +1 -0
  122. package/dist/registry/release.d.ts +63 -0
  123. package/dist/registry/release.js +79 -0
  124. package/dist/registry/release.js.map +1 -0
  125. package/dist/restoration.d.ts +14 -0
  126. package/dist/restoration.js +33 -0
  127. package/dist/restoration.js.map +1 -0
  128. package/dist/templates.d.ts +8 -0
  129. package/dist/templates.js +39 -0
  130. package/dist/templates.js.map +1 -0
  131. package/dist/testing/contract.d.ts +43 -0
  132. package/dist/testing/contract.js +713 -0
  133. package/dist/testing/contract.js.map +1 -0
  134. package/dist/testing/diff.d.ts +1 -0
  135. package/dist/testing/diff.js +65 -0
  136. package/dist/testing/diff.js.map +1 -0
  137. package/dist/testing/git-http.d.ts +12 -0
  138. package/dist/testing/git-http.js +308 -0
  139. package/dist/testing/git-http.js.map +1 -0
  140. package/dist/testing/github-double.d.ts +151 -0
  141. package/dist/testing/github-double.js +1129 -0
  142. package/dist/testing/github-double.js.map +1 -0
  143. package/dist/testing/gitlab-double.d.ts +161 -0
  144. package/dist/testing/gitlab-double.js +1554 -0
  145. package/dist/testing/gitlab-double.js.map +1 -0
  146. package/dist/testing/index.d.ts +7 -0
  147. package/dist/testing/index.js +8 -0
  148. package/dist/testing/index.js.map +1 -0
  149. package/dist/version.d.ts +2 -0
  150. package/dist/version.js +12 -0
  151. package/dist/version.js.map +1 -0
  152. package/package.json +66 -4
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # Temporary Holding Version
1
+ # @lbdudc/linea-git
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The git host of LINEA, **GitLab or GitHub**, behind one interface. The LINEA server and the LINEA CLI both use it, so what a deployment
4
+ can do on one host it can do on the other, and a package can be published from a terminal exactly as the server publishes it.
5
+
6
+ ```
7
+ linea-core offline: SPLs, feature models, modules, metamodels, derivation (no network, by design)
8
+ linea-git the network: repositories, files, commits, pull/merge requests, the registry of packages
9
+ server, CLI use both
10
+ ```
11
+
12
+ ## What is in it
13
+
14
+ | | |
15
+ |---|---|
16
+ | `GitProvider` | the contract: ~45 methods (namespaces, repositories, files, commits, branches, tags, change requests, pipelines, webhooks, identity) in neutral words and shapes |
17
+ | `GitLabProvider`, `GitHubProvider` | the contract on each host. A provider is also a unit of work: `rollback()` undoes what it created |
18
+ | `createGitProvider(config)`, `gitConfigFromEnv(env)` | the host a deployment is on, from `GIT_PROVIDER` and the usual settings (the server reads its environment, the CLI its own) |
19
+ | `createPackageSource(config, …)`, `GitLabPackageSource`, `GitHubPackageSource` | where linea-core reads modules and metamodels from: `gitlab:group/project`, `github:owner/repo`, mixed in one SPL, limited by `trustedNamespaces` |
20
+ | `listPackages`, `createPackage`, `getPackage`, `savePackageFile`, `publishPackage` | the registry of modules and metamodels: repositories with the topic `linea-module` / `linea-metamodel`, versions are `vX.Y.Z` tags |. Publishing (also `publishFolder`, which throws on a version already tagged) validates the version (semver, higher than the last tag), tags it, creates the release with the changelog and warns when the version does not match the commits; `getPackageChangelog` / `listPackageChangelogs` give the changelog per version for the catalog
21
+ | `publishFolder` | publishes the `modules/` and `metamodels/` of a folder to a host (GitLab: under a group; GitHub: siblings of an owner) |
22
+ | `generateChangelog({ provider, token, id, from?, to })` | release notes from the commits alone (Conventional Commits): `{ markdown, sections, commits, mergeRequests, issues }`. `from` defaults to the previous `vX.Y.Z` tag; `#N` / `!N` are resolved to issues and merge requests; version bumps, merges and LINEA's own generation/sync commits are left out. Caps: with no previous tag only the last page of commits a host gives (100) is read, a range stops at 1000 commits, and GitHub's compare returns at most 250; `truncated` is set when the generator knows it was cut (not for a host that cuts on its own). At most 200 references are resolved |
23
+ | `buildAuthorizeUrl` | where to send a browser to log in on the host |
24
+ | `@lbdudc/linea-git/testing` | the two hosts **in memory** (`startGitlabDouble`, `startGithubDouble`): REST-compatible, with real git behind them |
25
+ | `@lbdudc/linea-git/contract` | `describeGitProviderContract`: what any provider has to do. A new host is done when it passes |
26
+
27
+ How a line (a GitLab group with a subgroup per product) is represented on GitHub, which has no groups inside groups, is in
28
+ [`linea/docs/git-provider.md`](../linea/docs/git-provider.md).
29
+
30
+ ## Use
31
+
32
+ ```ts
33
+ import { createGitProvider, publishFolder, listPackages } from '@lbdudc/linea-git'
34
+
35
+ const provider = createGitProvider({ provider: 'github', github: {} }) // or { provider: 'gitlab', gitlab: { url } }
36
+ await publishFolder({ provider, token, dir: './workspace', root: 'my-org' })
37
+ const modules = await listPackages({ provider, token, kind: 'module' })
38
+ ```
39
+
40
+ ## Develop
41
+
42
+ ```bash
43
+ npm install && npm test # the contract on both hosts, the registry, publishing, package sources, configuration
44
+ npm run build # dist/, which is what the server and the CLI load
45
+ ```
46
+
47
+ `gitlab-commando` (the undoable GitLab session) is a dependency. A consumer that spies on it in its own tests (the server does) has to
48
+ resolve it to its own copy: `resolve.dedupe: ['gitlab-commando']` in vitest.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * How much a person may do in a repository, as numbers that grow with it. They are GitLab's own access levels (the other hosts map
3
+ * what they have onto them), so a level read from any host compares with these.
4
+ */
5
+ export declare const ACCESS: {
6
+ /** Sees the repository exists. */
7
+ readonly MINIMAL: 5;
8
+ readonly GUEST: 10;
9
+ /** Reads the code. */
10
+ readonly REPORTER: 20;
11
+ /** Pushes to branches. */
12
+ readonly DEVELOPER: 30;
13
+ /** Merges, and manages the repository's settings. */
14
+ readonly MAINTAINER: 40;
15
+ /** Deletes it. */
16
+ readonly OWNER: 50;
17
+ };
18
+ export type AccessLevel = (typeof ACCESS)[keyof typeof ACCESS];
package/dist/access.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * How much a person may do in a repository, as numbers that grow with it. They are GitLab's own access levels (the other hosts map
3
+ * what they have onto them), so a level read from any host compares with these.
4
+ */
5
+ export const ACCESS = {
6
+ /** Sees the repository exists. */
7
+ MINIMAL: 5,
8
+ GUEST: 10,
9
+ /** Reads the code. */
10
+ REPORTER: 20,
11
+ /** Pushes to branches. */
12
+ DEVELOPER: 30,
13
+ /** Merges, and manages the repository's settings. */
14
+ MAINTAINER: 40,
15
+ /** Deletes it. */
16
+ OWNER: 50
17
+ };
18
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.js","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,kCAAkC;IAClC,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,EAAE;IACT,sBAAsB;IACtB,QAAQ,EAAE,EAAE;IACZ,0BAA0B;IAC1B,SAAS,EAAE,EAAE;IACb,qDAAqD;IACrD,UAAU,EAAE,EAAE;IACd,kBAAkB;IAClB,KAAK,EAAE,EAAE;CACD,CAAA","sourcesContent":["/**\n * How much a person may do in a repository, as numbers that grow with it. They are GitLab's own access levels (the other hosts map\n * what they have onto them), so a level read from any host compares with these.\n */\nexport const ACCESS = {\n /** Sees the repository exists. */\n MINIMAL: 5,\n GUEST: 10,\n /** Reads the code. */\n REPORTER: 20,\n /** Pushes to branches. */\n DEVELOPER: 30,\n /** Merges, and manages the repository's settings. */\n MAINTAINER: 40,\n /** Deletes it. */\n OWNER: 50\n} as const\n\nexport type AccessLevel = (typeof ACCESS)[keyof typeof ACCESS]\n"]}
package/dist/auth.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { AuthConfig } from './provider.js';
2
+ /**
3
+ * Where to send a browser to log the user in on the host (the OAuth "authorize" page). The server's `/api/users/config` says which host
4
+ * it is on and how (`AuthConfig`); a client that builds the address itself (the CLI, with a loopback redirect) uses this.
5
+ */
6
+ export declare const buildAuthorizeUrl: ({ auth, redirectUri, state, scope }: {
7
+ auth: Pick<AuthConfig, "authorizeUrl" | "clientId" | "scope">;
8
+ redirectUri: string;
9
+ state?: string;
10
+ scope?: string;
11
+ }) => string;
package/dist/auth.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Where to send a browser to log the user in on the host (the OAuth "authorize" page). The server's `/api/users/config` says which host
3
+ * it is on and how (`AuthConfig`); a client that builds the address itself (the CLI, with a loopback redirect) uses this.
4
+ */
5
+ export const buildAuthorizeUrl = ({ auth, redirectUri, state, scope }) => {
6
+ const params = new URLSearchParams({
7
+ client_id: auth.clientId ?? '',
8
+ redirect_uri: redirectUri,
9
+ response_type: 'code',
10
+ scope: scope ?? auth.scope
11
+ });
12
+ if (state)
13
+ params.set('state', state);
14
+ return `${auth.authorizeUrl}?${params.toString()}`;
15
+ };
16
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAA0H,EAAU,EAAE;IACvM,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;QACjC,SAAS,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE;QAC9B,YAAY,EAAE,WAAW;QACzB,aAAa,EAAE,MAAM;QACrB,KAAK,EAAE,KAAK,IAAI,IAAI,CAAC,KAAK;KAC3B,CAAC,CAAA;IACF,IAAI,KAAK;QAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IACrC,OAAO,GAAG,IAAI,CAAC,YAAY,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAA;AACpD,CAAC,CAAA","sourcesContent":["import type { AuthConfig } from './provider.js'\n\n/**\n * Where to send a browser to log the user in on the host (the OAuth \"authorize\" page). The server's `/api/users/config` says which host\n * it is on and how (`AuthConfig`); a client that builds the address itself (the CLI, with a loopback redirect) uses this.\n */\nexport const buildAuthorizeUrl = ({ auth, redirectUri, state, scope }: { auth: Pick<AuthConfig, 'authorizeUrl' | 'clientId' | 'scope'>, redirectUri: string, state?: string, scope?: string }): string => {\n const params = new URLSearchParams({\n client_id: auth.clientId ?? '',\n redirect_uri: redirectUri,\n response_type: 'code',\n scope: scope ?? auth.scope\n })\n if (state) params.set('state', state)\n return `${auth.authorizeUrl}?${params.toString()}`\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import type { ChangelogLocale } from './parse.js';
2
+ import type { Changelog, ChangelogOptions, ChangelogSection } from './types.js';
3
+ /** The greatest `vX.Y.Z` tag lower than `to` (any, when `to` is not itself a version), or `null`. */
4
+ export declare const previousTag: (tags: {
5
+ name: string;
6
+ }[], to: string) => string | null;
7
+ export declare const renderMarkdown: ({ title, from, sections, truncated, locale }: {
8
+ title: string;
9
+ from: string | null;
10
+ sections: ChangelogSection[];
11
+ truncated?: boolean;
12
+ locale?: ChangelogLocale;
13
+ }) => string;
14
+ /**
15
+ * The release notes of a range, from the commits alone: `from` (exclusive) to `to`. Pure over what the provider answers (`listTags`,
16
+ * `compare` or `getCommits`, `getIssue`, `getMergeRequest`), so the same input gives the same changelog.
17
+ */
18
+ export declare const generateChangelog: (options: ChangelogOptions) => Promise<Changelog>;
@@ -0,0 +1,166 @@
1
+ import semver from 'semver';
2
+ import { DEFAULT_IGNORED, ISSUE_REF, MR_REF, SECTION_ORDER, CHANGELOG_TEXT, capMessage, isMerge, mergedRequestsOf, parseMessage, referencesIn, sectionOf } from './parse.js';
3
+ const VERSION_TAG = /^v?(\d+\.\d+\.\d+)$/;
4
+ /** Most a host gives in one page of commits: what a range with no previous tag reads. */
5
+ const FIRST_PAGE = 100;
6
+ /** Most commits read from a range, and most references resolved against the host (each is a call with the user's token). */
7
+ const MAX_COMMITS = 1000;
8
+ const MAX_RESOLVED = 200;
9
+ const CONCURRENCY = 5;
10
+ /** The greatest `vX.Y.Z` tag lower than `to` (any, when `to` is not itself a version), or `null`. */
11
+ export const previousTag = (tags, to) => {
12
+ // `to` may be a prerelease (`v1.2.0-rc.1`): it comes before `1.2.0`, so tags are compared with it as semver does
13
+ const limit = semver.valid(to.replace(/^v/, '')) ?? undefined;
14
+ const versions = tags
15
+ .map((tag) => ({ name: tag.name, version: VERSION_TAG.exec(tag.name)?.[1] }))
16
+ .filter((tag) => Boolean(tag.version) && (!limit || semver.lt(tag.version, limit)))
17
+ .sort((a, b) => semver.rcompare(a.version, b.version) || a.name.localeCompare(b.name));
18
+ return versions[0]?.name ?? null;
19
+ };
20
+ const statusOf = (error) => error.status;
21
+ const resolveReference = async ({ provider, token, id, kind, number }) => {
22
+ const missing = { kind, number, title: '', webUrl: '', resolved: false };
23
+ const tryRead = async (read) => {
24
+ try {
25
+ const found = await read();
26
+ return { kind, number, title: found.title, webUrl: found.webUrl, resolved: true };
27
+ }
28
+ catch (error) {
29
+ // only "it is not there" (or not for us) is an unresolved reference; a host that fails is a failure
30
+ if (statusOf(error) === 404 || statusOf(error) === 403)
31
+ return null;
32
+ throw error;
33
+ }
34
+ };
35
+ if (kind === 'mergeRequest')
36
+ return await tryRead(() => provider.getMergeRequest({ token, id, number })) ?? missing;
37
+ const issue = await tryRead(() => provider.getIssue({ token, id, number }));
38
+ if (issue)
39
+ return issue;
40
+ // only on GitHub does `#N` also name a pull request; elsewhere an unknown issue stays unresolved rather than link to an unrelated `!N`
41
+ if (provider.kind !== 'github')
42
+ return missing;
43
+ const mr = await tryRead(() => provider.getMergeRequest({ token, id, number }));
44
+ return mr ? { ...mr, kind: 'mergeRequest' } : missing;
45
+ };
46
+ /** Only a web address goes into a link, with what would end it early encoded. */
47
+ const safeUrl = (url) => (/^https?:\/\//i.test(url) ? url.replace(/[()\s]/g, (char) => encodeURIComponent(char).replace(/[()]/g, (paren) => (paren === '(' ? '%28' : '%29'))) : '');
48
+ const link = (text, url) => (safeUrl(url) ? `[${text}](${safeUrl(url)})` : text);
49
+ /** Text of a commit is data from whoever can push: its markdown and HTML are made plain, so it cannot add links, images or sections. */
50
+ const plain = (text) => text.replace(/[\\`*_[\]<>|]/g, (char) => `\\${char}`).replace(/\s+/g, ' ').trim();
51
+ const referenceMarkdown = (reference) => link(`${reference.kind === 'issue' ? '#' : '!'}${reference.number}`, reference.webUrl);
52
+ /** The description with the `#N` and `!N` it mentions turned into links (when they were resolved). */
53
+ const linked = (description, references) => {
54
+ // a `#N` can have turned out to be a merge request: it is looked for by number, the kind it was written with first
55
+ const urlOf = (kind, number) => (references.find((r) => r.kind === kind && r.number === number) ?? references.find((r) => r.number === number))?.webUrl ?? '';
56
+ return plain(description)
57
+ .replace(MR_REF, (match, number) => link(match, urlOf('mergeRequest', Number(number))))
58
+ .replace(ISSUE_REF, (match, number) => link(match, urlOf('issue', Number(number))));
59
+ };
60
+ const entryMarkdown = (entry, section) => {
61
+ const scope = entry.scope ? `**${plain(entry.scope)}:** ` : '';
62
+ const note = entry.breakingNote && entry.breakingNote !== entry.description ? ` — ${plain(entry.breakingNote)}` : '';
63
+ const inText = new Set(referencesIn(entry.description).map((reference) => `${reference.kind}:${reference.number}`));
64
+ const tail = [link(plain(entry.shortId), entry.webUrl), ...entry.references.filter((reference) => !inText.has(`${reference.kind}:${reference.number}`)).map(referenceMarkdown)].join(', ');
65
+ // a hidden type that was asked for keeps its name, so «Otros» says what each line is
66
+ const prefix = section === 'other' && entry.type ? `${entry.type}: ` : '';
67
+ return `- ${scope}${prefix}${linked(entry.description, entry.references)}${note} (${tail})`;
68
+ };
69
+ export const renderMarkdown = ({ title, from, sections, truncated = false, locale = 'en' }) => {
70
+ const text = CHANGELOG_TEXT[locale] ?? CHANGELOG_TEXT.en;
71
+ const lines = [`## ${plain(title)}`, ''];
72
+ if (from)
73
+ lines.push(`${text.since} \`${from.replace(/[`\s]+/g, ' ')}\`.`, '');
74
+ if (truncated)
75
+ lines.push(`> ${text.truncated}`, '');
76
+ if (sections.length === 0)
77
+ lines.push(`_${text.none}_`, '');
78
+ for (const section of sections) {
79
+ lines.push(`### ${section.title}`, '', ...section.entries.map((entry) => entryMarkdown(entry, section.id)), '');
80
+ }
81
+ return `${lines.join('\n').trimEnd()}\n`;
82
+ };
83
+ const byReference = (a, b) => a.number - b.number;
84
+ /**
85
+ * The release notes of a range, from the commits alone: `from` (exclusive) to `to`. Pure over what the provider answers (`listTags`,
86
+ * `compare` or `getCommits`, `getIssue`, `getMergeRequest`), so the same input gives the same changelog.
87
+ */
88
+ export const generateChangelog = async (options) => {
89
+ const { provider, token, id, to, include = [], ignore = [], ignoreDefaults = true } = options;
90
+ // a ref that starts with `-` would be read as an option by git
91
+ for (const ref of [to, options.from])
92
+ if (typeof ref === 'string' && (ref === '' || ref.startsWith('-')))
93
+ throw Object.assign(new Error(`Not a valid ref: "${ref}"`), { status: 400 });
94
+ const from = options.from === undefined
95
+ ? previousTag(await provider.listTags({ token, id }), to)
96
+ : options.from;
97
+ const read = from
98
+ ? (await provider.compare({ token, id, from, to })).commits
99
+ : await provider.getCommits({ token, id, ref: to, perPage: FIRST_PAGE });
100
+ // a host answers one page of the whole history when there is no `from`; and a range is not read without end
101
+ const truncated = (!from && read.length >= FIRST_PAGE) || read.length > MAX_COMMITS;
102
+ // the same history in the same order on every host (they answer oldest first or newest first)
103
+ // timestamps come with different offsets on different hosts, and a bad one counts as the oldest
104
+ const time = (value) => Date.parse(value) || 0;
105
+ const raw = [...read].sort((a, b) => time(b.createdAt) - time(a.createdAt) || a.shortId.localeCompare(b.shortId)).slice(0, MAX_COMMITS);
106
+ let path;
107
+ const repositoryPath = async () => path ??= (await provider.getRepository({ token, id })).path;
108
+ const patterns = [...(ignoreDefaults ? DEFAULT_IGNORED : []), ...ignore];
109
+ const kept = [];
110
+ const mentioned = [];
111
+ for (const commit of raw) {
112
+ const message = capMessage(commit.message ?? commit.title);
113
+ const references = referencesIn(message);
114
+ if (isMerge(commit.title)) {
115
+ // GitLab names the merge request of a merge as `See merge request group/project!7`, with this repository's path
116
+ const own = /^See merge request /m.test(message) ? await repositoryPath() : '';
117
+ mentioned.push(...references, ...mergedRequestsOf(message, own).map((number) => ({ kind: 'mergeRequest', number })));
118
+ continue;
119
+ }
120
+ if (patterns.some((pattern) => pattern.test(commit.title)))
121
+ continue;
122
+ const parsed = parseMessage(commit.title, message);
123
+ const section = sectionOf(parsed, include);
124
+ if (!section)
125
+ continue;
126
+ kept.push({
127
+ shortId: commit.shortId, title: commit.title, webUrl: commit.webUrl ?? '', authorName: commit.authorName, createdAt: commit.createdAt,
128
+ ...parsed, references, section
129
+ });
130
+ }
131
+ const wanted = new Map();
132
+ for (const reference of [...kept.flatMap((commit) => commit.references), ...mentioned])
133
+ wanted.set(`${reference.kind}:${reference.number}`, reference);
134
+ const resolved = new Map();
135
+ const ordered = [...wanted.values()].sort((a, b) => a.kind.localeCompare(b.kind) || a.number - b.number);
136
+ // the first ones resolve, in a few calls at a time; the rest stay plain text
137
+ for (const reference of ordered.slice(MAX_RESOLVED))
138
+ resolved.set(`${reference.kind}:${reference.number}`, { ...reference, title: '', webUrl: '', resolved: false });
139
+ const toResolve = ordered.slice(0, MAX_RESOLVED);
140
+ for (let start = 0; start < toResolve.length; start += CONCURRENCY) {
141
+ await Promise.all(toResolve.slice(start, start + CONCURRENCY).map(async (reference) => {
142
+ resolved.set(`${reference.kind}:${reference.number}`, await resolveReference({ provider, token, id, ...reference }));
143
+ }));
144
+ }
145
+ // `#N` that turned out to be a merge request counts as one
146
+ const all = [...resolved.values()];
147
+ const sections = [];
148
+ for (const sectionId of SECTION_ORDER) {
149
+ const entries = kept.filter((commit) => commit.section === sectionId).map((commit) => ({
150
+ shortId: commit.shortId, webUrl: commit.webUrl, type: commit.type, scope: commit.scope, description: commit.description,
151
+ breaking: commit.breaking, breakingNote: commit.breakingNote,
152
+ references: commit.references.map((reference) => resolved.get(`${reference.kind}:${reference.number}`))
153
+ }));
154
+ if (entries.length > 0)
155
+ sections.push({ id: sectionId, title: (CHANGELOG_TEXT[options.locale ?? 'en'] ?? CHANGELOG_TEXT.en).sections[sectionId], entries });
156
+ }
157
+ return {
158
+ from, to, truncated,
159
+ markdown: renderMarkdown({ title: options.title ?? to, from, sections, truncated, locale: options.locale }),
160
+ sections,
161
+ commits: kept,
162
+ mergeRequests: all.filter((reference) => reference.kind === 'mergeRequest').sort(byReference),
163
+ issues: all.filter((reference) => reference.kind === 'issue').sort(byReference)
164
+ };
165
+ };
166
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/changelog/generate.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAG3B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAG5K,MAAM,WAAW,GAAG,qBAAqB,CAAA;AACzC,yFA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,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY;YAC5D,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,MAAM,EAAE,CAAuB,CAAC;SAC9H,CAAC,CAAC,CAAA;QACH,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IAC7J,CAAC;IAED,OAAO;QACL,IAAI,EAAE,EAAE,EAAE,SAAS;QACnB,QAAQ,EAAE,cAAc,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QAC3G,QAAQ;QACR,OAAO,EAAE,IAAI;QACb,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;QAC7F,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;KAChF,CAAA;AACH,CAAC,CAAA","sourcesContent":["import semver from 'semver'\nimport type { CommitSummary, GitProvider, Id } from '../provider.js'\nimport type { ChangelogLocale } from './parse.js'\nimport { DEFAULT_IGNORED, ISSUE_REF, MR_REF, SECTION_ORDER, CHANGELOG_TEXT, capMessage, isMerge, mergedRequestsOf, parseMessage, referencesIn, sectionOf } from './parse.js'\nimport type { Changelog, ChangelogCommit, ChangelogEntry, ChangelogOptions, ChangelogReference, ChangelogSection } from './types.js'\n\nconst VERSION_TAG = /^v?(\\d+\\.\\d+\\.\\d+)$/\n/** Most a host gives in one page of commits: what a range with no previous tag reads. */\nconst FIRST_PAGE = 100\n/** Most commits read from a range, and most references resolved against the host (each is a call with the user's token). */\nconst MAX_COMMITS = 1000\nconst MAX_RESOLVED = 200\nconst CONCURRENCY = 5\n\n/** The greatest `vX.Y.Z` tag lower than `to` (any, when `to` is not itself a version), or `null`. */\nexport const previousTag = (tags: { name: string }[], to: string): string | null => {\n // `to` may be a prerelease (`v1.2.0-rc.1`): it comes before `1.2.0`, so tags are compared with it as semver does\n const limit = semver.valid(to.replace(/^v/, '')) ?? undefined\n const versions = tags\n .map((tag) => ({ name: tag.name, version: VERSION_TAG.exec(tag.name)?.[1] }))\n .filter((tag): tag is { name: string, version: string } => Boolean(tag.version) && (!limit || semver.lt(tag.version as string, limit)))\n .sort((a, b) => semver.rcompare(a.version, b.version) || a.name.localeCompare(b.name))\n return versions[0]?.name ?? null\n}\n\nconst statusOf = (error: unknown): number | undefined => (error as { status?: number }).status\n\nconst resolveReference = async ({ provider, token, id, kind, number }: { provider: GitProvider, token: string, id: Id, kind: 'issue' | 'mergeRequest', number: number }): Promise<ChangelogReference> => {\n const missing: ChangelogReference = { kind, number, title: '', webUrl: '', resolved: false }\n const tryRead = async (read: () => Promise<{ title: string, webUrl: string }>): Promise<ChangelogReference | null> => {\n try {\n const found = await read()\n return { kind, number, title: found.title, webUrl: found.webUrl, resolved: true }\n } catch (error) {\n // only \"it is not there\" (or not for us) is an unresolved reference; a host that fails is a failure\n if (statusOf(error) === 404 || statusOf(error) === 403) return null\n throw error\n }\n }\n if (kind === 'mergeRequest') return await tryRead(() => provider.getMergeRequest({ token, id, number })) ?? missing\n const issue = await tryRead(() => provider.getIssue({ token, id, number }))\n if (issue) return issue\n // only on GitHub does `#N` also name a pull request; elsewhere an unknown issue stays unresolved rather than link to an unrelated `!N`\n if (provider.kind !== 'github') return missing\n const mr = await tryRead(() => provider.getMergeRequest({ token, id, number }))\n return mr ? { ...mr, kind: 'mergeRequest' } : missing\n}\n\n/** Only a web address goes into a link, with what would end it early encoded. */\nconst safeUrl = (url: string): string => (/^https?:\\/\\//i.test(url) ? url.replace(/[()\\s]/g, (char) => encodeURIComponent(char).replace(/[()]/g, (paren) => (paren === '(' ? '%28' : '%29'))) : '')\n\nconst link = (text: string, url: string): string => (safeUrl(url) ? `[${text}](${safeUrl(url)})` : text)\n\n/** Text of a commit is data from whoever can push: its markdown and HTML are made plain, so it cannot add links, images or sections. */\nconst plain = (text: string): string => text.replace(/[\\\\`*_[\\]<>|]/g, (char) => `\\\\${char}`).replace(/\\s+/g, ' ').trim()\n\nconst referenceMarkdown = (reference: ChangelogReference): string => link(`${reference.kind === 'issue' ? '#' : '!'}${reference.number}`, reference.webUrl)\n\n/** The description with the `#N` and `!N` it mentions turned into links (when they were resolved). */\nconst linked = (description: string, references: ChangelogReference[]): string => {\n // a `#N` can have turned out to be a merge request: it is looked for by number, the kind it was written with first\n const urlOf = (kind: ChangelogReference['kind'], number: number): string =>\n (references.find((r) => r.kind === kind && r.number === number) ?? references.find((r) => r.number === number))?.webUrl ?? ''\n return plain(description)\n .replace(MR_REF, (match, number: string) => link(match, urlOf('mergeRequest', Number(number))))\n .replace(ISSUE_REF, (match, number: string) => link(match, urlOf('issue', Number(number))))\n}\n\nconst entryMarkdown = (entry: ChangelogEntry, section: ChangelogSection['id']): string => {\n const scope = entry.scope ? `**${plain(entry.scope)}:** ` : ''\n const note = entry.breakingNote && entry.breakingNote !== entry.description ? ` — ${plain(entry.breakingNote)}` : ''\n const inText = new Set(referencesIn(entry.description).map((reference) => `${reference.kind}:${reference.number}`))\n const tail = [link(plain(entry.shortId), entry.webUrl), ...entry.references.filter((reference) => !inText.has(`${reference.kind}:${reference.number}`)).map(referenceMarkdown)].join(', ')\n // a hidden type that was asked for keeps its name, so «Otros» says what each line is\n const prefix = section === 'other' && entry.type ? `${entry.type}: ` : ''\n return `- ${scope}${prefix}${linked(entry.description, entry.references)}${note} (${tail})`\n}\n\nexport const renderMarkdown = ({ title, from, sections, truncated = false, locale = 'en' }: { title: string, from: string | null, sections: ChangelogSection[], truncated?: boolean, locale?: ChangelogLocale }): string => {\n const text = CHANGELOG_TEXT[locale] ?? CHANGELOG_TEXT.en\n const lines = [`## ${plain(title)}`, '']\n if (from) lines.push(`${text.since} \\`${from.replace(/[`\\s]+/g, ' ')}\\`.`, '')\n if (truncated) lines.push(`> ${text.truncated}`, '')\n if (sections.length === 0) lines.push(`_${text.none}_`, '')\n for (const section of sections) {\n lines.push(`### ${section.title}`, '', ...section.entries.map((entry) => entryMarkdown(entry, section.id)), '')\n }\n return `${lines.join('\\n').trimEnd()}\\n`\n}\n\nconst byReference = (a: ChangelogReference, b: ChangelogReference): number => a.number - b.number\n\n/**\n * The release notes of a range, from the commits alone: `from` (exclusive) to `to`. Pure over what the provider answers (`listTags`,\n * `compare` or `getCommits`, `getIssue`, `getMergeRequest`), so the same input gives the same changelog.\n */\nexport const generateChangelog = async (options: ChangelogOptions): Promise<Changelog> => {\n const { provider, token, id, to, include = [], ignore = [], ignoreDefaults = true } = options\n // a ref that starts with `-` would be read as an option by git\n for (const ref of [to, options.from]) if (typeof ref === 'string' && (ref === '' || ref.startsWith('-'))) throw Object.assign(new Error(`Not a valid ref: \"${ref}\"`), { status: 400 })\n const from = options.from === undefined\n ? previousTag(await provider.listTags({ token, id }), to)\n : options.from\n const read: CommitSummary[] = from\n ? (await provider.compare({ token, id, from, to })).commits\n : await provider.getCommits({ token, id, ref: to, perPage: FIRST_PAGE })\n // a host answers one page of the whole history when there is no `from`; and a range is not read without end\n const truncated = (!from && read.length >= FIRST_PAGE) || read.length > MAX_COMMITS\n // the same history in the same order on every host (they answer oldest first or newest first)\n // timestamps come with different offsets on different hosts, and a bad one counts as the oldest\n const time = (value: string): number => Date.parse(value) || 0\n const raw = [...read].sort((a, b) => time(b.createdAt) - time(a.createdAt) || a.shortId.localeCompare(b.shortId)).slice(0, MAX_COMMITS)\n\n let path: string | undefined\n const repositoryPath = async (): Promise<string> => path ??= (await provider.getRepository({ token, id })).path\n const patterns = [...(ignoreDefaults ? DEFAULT_IGNORED : []), ...ignore]\n const kept: ChangelogCommit[] = []\n const mentioned: ChangelogCommit['references'] = []\n for (const commit of raw) {\n const message = capMessage(commit.message ?? commit.title)\n const references = referencesIn(message)\n if (isMerge(commit.title)) {\n // GitLab names the merge request of a merge as `See merge request group/project!7`, with this repository's path\n const own = /^See merge request /m.test(message) ? await repositoryPath() : ''\n mentioned.push(...references, ...mergedRequestsOf(message, own).map((number) => ({ kind: 'mergeRequest' as const, number })))\n continue\n }\n if (patterns.some((pattern) => pattern.test(commit.title))) continue\n const parsed = parseMessage(commit.title, message)\n const section = sectionOf(parsed, include)\n if (!section) continue\n kept.push({\n shortId: commit.shortId, title: commit.title, webUrl: commit.webUrl ?? '', authorName: commit.authorName, createdAt: commit.createdAt,\n ...parsed, references, section\n })\n }\n\n const wanted = new Map<string, ChangelogCommit['references'][number]>()\n for (const reference of [...kept.flatMap((commit) => commit.references), ...mentioned]) wanted.set(`${reference.kind}:${reference.number}`, reference)\n const resolved = new Map<string, ChangelogReference>()\n const ordered = [...wanted.values()].sort((a, b) => a.kind.localeCompare(b.kind) || a.number - b.number)\n // the first ones resolve, in a few calls at a time; the rest stay plain text\n for (const reference of ordered.slice(MAX_RESOLVED)) resolved.set(`${reference.kind}:${reference.number}`, { ...reference, title: '', webUrl: '', resolved: false })\n const toResolve = ordered.slice(0, MAX_RESOLVED)\n for (let start = 0; start < toResolve.length; start += CONCURRENCY) {\n await Promise.all(toResolve.slice(start, start + CONCURRENCY).map(async (reference) => {\n resolved.set(`${reference.kind}:${reference.number}`, await resolveReference({ provider, token, id, ...reference }))\n }))\n }\n // `#N` that turned out to be a merge request counts as one\n const all = [...resolved.values()]\n\n const sections: ChangelogSection[] = []\n for (const sectionId of SECTION_ORDER) {\n const entries = kept.filter((commit) => commit.section === sectionId).map((commit): ChangelogEntry => ({\n shortId: commit.shortId, webUrl: commit.webUrl, type: commit.type, scope: commit.scope, description: commit.description,\n breaking: commit.breaking, breakingNote: commit.breakingNote,\n references: commit.references.map((reference) => resolved.get(`${reference.kind}:${reference.number}`) as ChangelogReference)\n }))\n if (entries.length > 0) sections.push({ id: sectionId, title: (CHANGELOG_TEXT[options.locale ?? 'en'] ?? CHANGELOG_TEXT.en).sections[sectionId], entries })\n }\n\n return {\n from, to, truncated,\n markdown: renderMarkdown({ title: options.title ?? to, from, sections, truncated, locale: options.locale }),\n sections,\n commits: kept,\n mergeRequests: all.filter((reference) => reference.kind === 'mergeRequest').sort(byReference),\n issues: all.filter((reference) => reference.kind === 'issue').sort(byReference)\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export { generateChangelog, previousTag, renderMarkdown } from './generate.js';
2
+ export type { ChangelogLocale } from './parse.js';
3
+ export { DEFAULT_IGNORED, HIDDEN_TYPES, SECTION_ORDER, SECTION_TITLES, CHANGELOG_TEXT, CHANGELOG_LOCALES, parseMessage, referencesIn } from './parse.js';
4
+ export type { ParsedMessage } from './parse.js';
5
+ export type { Changelog, ChangelogCommit, ChangelogEntry, ChangelogOptions, ChangelogReference, ChangelogSection, CommitType, SectionId } from './types.js';
@@ -0,0 +1,3 @@
1
+ export { generateChangelog, previousTag, renderMarkdown } from './generate.js';
2
+ export { DEFAULT_IGNORED, HIDDEN_TYPES, SECTION_ORDER, SECTION_TITLES, CHANGELOG_TEXT, CHANGELOG_LOCALES, parseMessage, referencesIn } from './parse.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/changelog/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9E,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA","sourcesContent":["export { generateChangelog, previousTag, renderMarkdown } from './generate.js'\nexport type { ChangelogLocale } from './parse.js'\nexport { DEFAULT_IGNORED, HIDDEN_TYPES, SECTION_ORDER, SECTION_TITLES, CHANGELOG_TEXT, CHANGELOG_LOCALES, parseMessage, referencesIn } from './parse.js'\nexport type { ParsedMessage } from './parse.js'\nexport type {\n Changelog, ChangelogCommit, ChangelogEntry, ChangelogOptions, ChangelogReference, ChangelogSection, CommitType, SectionId\n} from './types.js'\n"]}
@@ -0,0 +1,43 @@
1
+ import type { ChangelogCommit, SectionId } from './types.js';
2
+ /** `#N`, N from 1; a `group/project#N` of another repository is not matched. */
3
+ export declare const ISSUE_REF: RegExp;
4
+ /** `!N`, N from 1; no prefix is allowed (a `group/project!N` is of another repository), which also keeps the match linear. */
5
+ export declare const MR_REF: RegExp;
6
+ /** Most of a message that is read, and most references taken from one commit: a message is data from whoever can push. */
7
+ export declare const MAX_MESSAGE = 10000;
8
+ /** Types that are left out of a changelog unless they are asked for. */
9
+ export declare const HIDDEN_TYPES: readonly string[];
10
+ /** The languages the notes of a release can be written in. */
11
+ export type ChangelogLocale = 'en' | 'es' | 'gl';
12
+ export declare const CHANGELOG_LOCALES: readonly ChangelogLocale[];
13
+ /** The words of a changelog, by language (English is the default: a release is read by whoever opens the repository). */
14
+ export declare const CHANGELOG_TEXT: Record<ChangelogLocale, {
15
+ since: string;
16
+ truncated: string;
17
+ none: string;
18
+ sections: Record<SectionId, string>;
19
+ }>;
20
+ /** The titles of the sections in English. */
21
+ export declare const SECTION_TITLES: Record<SectionId, string>;
22
+ export declare const SECTION_ORDER: readonly SectionId[];
23
+ /** Default commits that are not changes of the product: version bumps and what LINEA itself writes (generations, syncs). */
24
+ export declare const DEFAULT_IGNORED: readonly RegExp[];
25
+ export declare const isMerge: (title: string) => boolean;
26
+ /** What is read of a long message: its start and its end, where a `BREAKING CHANGE:` footer is. */
27
+ export declare const capMessage: (message: string) => string;
28
+ /**
29
+ * The merge requests a merge commit names the way GitLab writes them, `See merge request group/project!7`: the ones of `repositoryPath`
30
+ * (those of another project are not this repository's). Bounded, line by line.
31
+ */
32
+ export declare const mergedRequestsOf: (message: string, repositoryPath: string) => number[];
33
+ export declare const referencesIn: (text: string) => ChangelogCommit["references"];
34
+ export interface ParsedMessage {
35
+ type: string | null;
36
+ scope: string | null;
37
+ description: string;
38
+ breaking: boolean;
39
+ breakingNote: string | null;
40
+ }
41
+ /** Reads a commit message as a Conventional Commit. One that does not follow the convention keeps its title as the description. */
42
+ export declare const parseMessage: (title: string, message?: string) => ParsedMessage;
43
+ export declare const sectionOf: (parsed: ParsedMessage, include: readonly string[]) => SectionId | null;
@@ -0,0 +1,91 @@
1
+ const HEADER = /^(\w+)(?:\(([^)\r\n]*)\))?(!)?:\s+(\S.*)$/;
2
+ const BREAKING_FOOTER = /^BREAKING[ -]CHANGE:[ \t]*(.*(?:\n(?![A-Za-z-]+(?:: | #)).+)*)/m;
3
+ /** `#N`, N from 1; a `group/project#N` of another repository is not matched. */
4
+ export const ISSUE_REF = /(?<![\w&/])#([1-9]\d*)\b/g;
5
+ /** `!N`, N from 1; no prefix is allowed (a `group/project!N` is of another repository), which also keeps the match linear. */
6
+ export const MR_REF = /(?<![\w/&])!([1-9]\d*)\b/g;
7
+ /** Most of a message that is read, and most references taken from one commit: a message is data from whoever can push. */
8
+ export const MAX_MESSAGE = 10_000;
9
+ const MAX_REFERENCES = 50;
10
+ /** Types that are left out of a changelog unless they are asked for. */
11
+ export const HIDDEN_TYPES = ['chore', 'ci', 'test', 'docs'];
12
+ const SECTION_OF_TYPE = { feat: 'features', fix: 'fixes', perf: 'performance' };
13
+ export const CHANGELOG_LOCALES = ['en', 'es', 'gl'];
14
+ /** The words of a changelog, by language (English is the default: a release is read by whoever opens the repository). */
15
+ export const CHANGELOG_TEXT = {
16
+ en: {
17
+ since: 'Changes since', truncated: 'Incomplete history: only the most recent commits were read.', none: 'No changes.',
18
+ sections: { breaking: 'Breaking changes', features: 'Features', fixes: 'Fixes', performance: 'Performance', other: 'Other changes' }
19
+ },
20
+ es: {
21
+ since: 'Cambios desde', truncated: 'Historial incompleto: solo se han leído los commits más recientes.', none: 'Sin cambios.',
22
+ sections: { breaking: 'Cambios incompatibles', features: 'Novedades', fixes: 'Correcciones', performance: 'Rendimiento', other: 'Otros cambios' }
23
+ },
24
+ gl: {
25
+ since: 'Cambios desde', truncated: 'Historial incompleto: só se leron os commits máis recentes.', none: 'Sen cambios.',
26
+ sections: { breaking: 'Cambios incompatibles', features: 'Novidades', fixes: 'Correccións', performance: 'Rendemento', other: 'Outros cambios' }
27
+ }
28
+ };
29
+ /** The titles of the sections in English. */
30
+ export const SECTION_TITLES = CHANGELOG_TEXT.en.sections;
31
+ export const SECTION_ORDER = ['breaking', 'features', 'fixes', 'performance', 'other'];
32
+ /** Default commits that are not changes of the product: version bumps and what LINEA itself writes (generations, syncs). */
33
+ export const DEFAULT_IGNORED = [
34
+ // `chore(release): 1.2.3`, `chore: release v1.2.3 [skip ci]`, `build: bump version to 1.2.3`
35
+ /^(chore|build)(\([^)]*\))?!?:\s*((release|bump( version)?( to)?|version)\s+)?v?\d+\.\d+\.\d+\s*(\[[^\]]*\])?$/i,
36
+ // `Release 1.2.3`, `Bump version to 1.2.3`
37
+ /^(release|bump( version)?( to)?)\s+v?\d+\.\d+\.\d+\s*(\[[^\]]*\])?$/i,
38
+ /^v?\d+\.\d+\.\d+([-+][\w.]+)?$/,
39
+ // what LINEA writes itself
40
+ /^\[?linea(-bot)?\]?(\([^)]*\))?[:!\]]/i
41
+ ];
42
+ const MERGE = /^Merge (branch|pull request|remote-tracking branch|tag|commit)\b/i;
43
+ export const isMerge = (title) => MERGE.test(title);
44
+ /** What is read of a long message: its start and its end, where a `BREAKING CHANGE:` footer is. */
45
+ export const capMessage = (message) => message.length <= MAX_MESSAGE ? message : `${message.slice(0, MAX_MESSAGE / 2)}\n${message.slice(-MAX_MESSAGE / 2)}`;
46
+ /**
47
+ * The merge requests a merge commit names the way GitLab writes them, `See merge request group/project!7`: the ones of `repositoryPath`
48
+ * (those of another project are not this repository's). Bounded, line by line.
49
+ */
50
+ export const mergedRequestsOf = (message, repositoryPath) => {
51
+ const found = new Set();
52
+ for (const match of capMessage(message).matchAll(/^See merge request ([\w./-]{1,200})!([1-9]\d*)[ \t]*$/gm)) {
53
+ if (match[1].toLowerCase() === repositoryPath.toLowerCase())
54
+ found.add(Number(match[2]));
55
+ }
56
+ return [...found].sort((a, b) => a - b);
57
+ };
58
+ export const referencesIn = (text) => {
59
+ text = text.slice(0, MAX_MESSAGE);
60
+ const found = new Map();
61
+ for (const match of text.matchAll(MR_REF))
62
+ found.set(`m${match[1]}`, { kind: 'mergeRequest', number: Number(match[1]) });
63
+ for (const match of text.matchAll(ISSUE_REF))
64
+ found.set(`i${match[1]}`, { kind: 'issue', number: Number(match[1]) });
65
+ return [...found.values()].slice(0, MAX_REFERENCES).sort((a, b) => (a.kind === b.kind ? a.number - b.number : a.kind === 'issue' ? -1 : 1));
66
+ };
67
+ /** Reads a commit message as a Conventional Commit. One that does not follow the convention keeps its title as the description. */
68
+ export const parseMessage = (title, message) => {
69
+ const full = (message ?? title).replace(/\r\n/g, '\n');
70
+ const header = HEADER.exec(title.trim());
71
+ const body = full.slice(full.startsWith(title) ? title.length : full.indexOf('\n') >= 0 ? full.indexOf('\n') : full.length);
72
+ const note = BREAKING_FOOTER.exec(body)?.[1]?.trim() || null;
73
+ const hasFooter = BREAKING_FOOTER.test(body);
74
+ if (!header)
75
+ return { type: null, scope: null, description: title.trim(), breaking: hasFooter, breakingNote: note };
76
+ return {
77
+ type: header[1].toLowerCase(),
78
+ scope: header[2]?.trim() || null,
79
+ description: header[4].trim(),
80
+ breaking: header[3] === '!' || hasFooter,
81
+ breakingNote: note
82
+ };
83
+ };
84
+ export const sectionOf = (parsed, include) => {
85
+ if (parsed.breaking)
86
+ return 'breaking';
87
+ if (parsed.type && HIDDEN_TYPES.includes(parsed.type) && !include.includes(parsed.type))
88
+ return null;
89
+ return (parsed.type && SECTION_OF_TYPE[parsed.type]) || 'other';
90
+ };
91
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/changelog/parse.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAG,2CAA2C,CAAA;AAC1D,MAAM,eAAe,GAAG,iEAAiE,CAAA;AACzF,gFAAgF;AAChF,MAAM,CAAC,MAAM,SAAS,GAAG,2BAA2B,CAAA;AACpD,8HAA8H;AAC9H,MAAM,CAAC,MAAM,MAAM,GAAG,2BAA2B,CAAA;AAEjD,0HAA0H;AAC1H,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAA;AACjC,MAAM,cAAc,GAAG,EAAE,CAAA;AAEzB,wEAAwE;AACxE,MAAM,CAAC,MAAM,YAAY,GAAsB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAE9E,MAAM,eAAe,GAA8B,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;AAI1G,MAAM,CAAC,MAAM,iBAAiB,GAA+B,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AAE/E,yHAAyH;AACzH,MAAM,CAAC,MAAM,cAAc,GAAqH;IAC9I,EAAE,EAAE;QACF,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,6DAA6D,EAAE,IAAI,EAAE,aAAa;QACrH,QAAQ,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE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C,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5C,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,CAAA;IACnH,OAAO;QACL,IAAI,EAAG,MAAM,CAAC,CAAC,CAAY,CAAC,WAAW,EAAE;QACzC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI;QAChC,WAAW,EAAG,MAAM,CAAC,CAAC,CAAY,CAAC,IAAI,EAAE;QACzC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,SAAS;QACxC,YAAY,EAAE,IAAI;KACnB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAqB,EAAE,OAA0B,EAAoB,EAAE;IAC/F,IAAI,MAAM,CAAC,QAAQ;QAAE,OAAO,UAAU,CAAA;IACtC,IAAI,MAAM,CAAC,IAAI,IAAI,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IACpG,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,OAAO,CAAA;AACjE,CAAC,CAAA","sourcesContent":["import type { ChangelogCommit, SectionId } from './types.js'\n\nconst HEADER = /^(\\w+)(?:\\(([^)\\r\\n]*)\\))?(!)?:\\s+(\\S.*)$/\nconst BREAKING_FOOTER = /^BREAKING[ -]CHANGE:[ \\t]*(.*(?:\\n(?![A-Za-z-]+(?:: | #)).+)*)/m\n/** `#N`, N from 1; a `group/project#N` of another repository is not matched. */\nexport const ISSUE_REF = /(?<![\\w&/])#([1-9]\\d*)\\b/g\n/** `!N`, N from 1; no prefix is allowed (a `group/project!N` is of another repository), which also keeps the match linear. */\nexport const MR_REF = /(?<![\\w/&])!([1-9]\\d*)\\b/g\n\n/** Most of a message that is read, and most references taken from one commit: a message is data from whoever can push. */\nexport const MAX_MESSAGE = 10_000\nconst MAX_REFERENCES = 50\n\n/** Types that are left out of a changelog unless they are asked for. */\nexport const HIDDEN_TYPES: readonly string[] = ['chore', 'ci', 'test', 'docs']\n\nconst SECTION_OF_TYPE: Record<string, SectionId> = { feat: 'features', fix: 'fixes', perf: 'performance' }\n\n/** The languages the notes of a release can be written in. */\nexport type ChangelogLocale = 'en' | 'es' | 'gl'\nexport const CHANGELOG_LOCALES: readonly ChangelogLocale[] = ['en', 'es', 'gl']\n\n/** The words of a changelog, by language (English is the default: a release is read by whoever opens the repository). */\nexport const CHANGELOG_TEXT: Record<ChangelogLocale, { since: string, truncated: string, none: string, sections: Record<SectionId, string> }> = {\n en: {\n since: 'Changes since', truncated: 'Incomplete history: only the most recent commits were read.', none: 'No changes.',\n sections: { breaking: 'Breaking changes', features: 'Features', fixes: 'Fixes', performance: 'Performance', other: 'Other changes' }\n },\n es: {\n since: 'Cambios desde', truncated: 'Historial incompleto: solo se han leído los commits más recientes.', none: 'Sin cambios.',\n sections: { breaking: 'Cambios incompatibles', features: 'Novedades', fixes: 'Correcciones', performance: 'Rendimiento', other: 'Otros cambios' }\n },\n gl: {\n since: 'Cambios desde', truncated: 'Historial incompleto: só se leron os commits máis recentes.', none: 'Sen cambios.',\n sections: { breaking: 'Cambios incompatibles', features: 'Novidades', fixes: 'Correccións', performance: 'Rendemento', other: 'Outros cambios' }\n }\n}\n\n/** The titles of the sections in English. */\nexport const SECTION_TITLES: Record<SectionId, string> = CHANGELOG_TEXT.en.sections\n\nexport const SECTION_ORDER: readonly SectionId[] = ['breaking', 'features', 'fixes', 'performance', 'other']\n\n/** Default commits that are not changes of the product: version bumps and what LINEA itself writes (generations, syncs). */\nexport const DEFAULT_IGNORED: readonly RegExp[] = [\n // `chore(release): 1.2.3`, `chore: release v1.2.3 [skip ci]`, `build: bump version to 1.2.3`\n /^(chore|build)(\\([^)]*\\))?!?:\\s*((release|bump( version)?( to)?|version)\\s+)?v?\\d+\\.\\d+\\.\\d+\\s*(\\[[^\\]]*\\])?$/i,\n // `Release 1.2.3`, `Bump version to 1.2.3`\n /^(release|bump( version)?( to)?)\\s+v?\\d+\\.\\d+\\.\\d+\\s*(\\[[^\\]]*\\])?$/i,\n /^v?\\d+\\.\\d+\\.\\d+([-+][\\w.]+)?$/,\n // what LINEA writes itself\n /^\\[?linea(-bot)?\\]?(\\([^)]*\\))?[:!\\]]/i\n]\n\nconst MERGE = /^Merge (branch|pull request|remote-tracking branch|tag|commit)\\b/i\n\nexport const isMerge = (title: string): boolean => MERGE.test(title)\n\n/** What is read of a long message: its start and its end, where a `BREAKING CHANGE:` footer is. */\nexport const capMessage = (message: string): string =>\n message.length <= MAX_MESSAGE ? message : `${message.slice(0, MAX_MESSAGE / 2)}\\n${message.slice(-MAX_MESSAGE / 2)}`\n\n/**\n * The merge requests a merge commit names the way GitLab writes them, `See merge request group/project!7`: the ones of `repositoryPath`\n * (those of another project are not this repository's). Bounded, line by line.\n */\nexport const mergedRequestsOf = (message: string, repositoryPath: string): number[] => {\n const found = new Set<number>()\n for (const match of capMessage(message).matchAll(/^See merge request ([\\w./-]{1,200})!([1-9]\\d*)[ \\t]*$/gm)) {\n if ((match[1] as string).toLowerCase() === repositoryPath.toLowerCase()) found.add(Number(match[2]))\n }\n return [...found].sort((a, b) => a - b)\n}\n\nexport const referencesIn = (text: string): ChangelogCommit['references'] => {\n text = text.slice(0, MAX_MESSAGE)\n const found = new Map<string, ChangelogCommit['references'][number]>()\n for (const match of text.matchAll(MR_REF)) found.set(`m${match[1]}`, { kind: 'mergeRequest', number: Number(match[1]) })\n for (const match of text.matchAll(ISSUE_REF)) found.set(`i${match[1]}`, { kind: 'issue', number: Number(match[1]) })\n return [...found.values()].slice(0, MAX_REFERENCES).sort((a, b) => (a.kind === b.kind ? a.number - b.number : a.kind === 'issue' ? -1 : 1))\n}\n\nexport interface ParsedMessage {\n type: string | null\n scope: string | null\n description: string\n breaking: boolean\n breakingNote: string | null\n}\n\n/** Reads a commit message as a Conventional Commit. One that does not follow the convention keeps its title as the description. */\nexport const parseMessage = (title: string, message?: string): ParsedMessage => {\n const full = (message ?? title).replace(/\\r\\n/g, '\\n')\n const header = HEADER.exec(title.trim())\n const body = full.slice(full.startsWith(title) ? title.length : full.indexOf('\\n') >= 0 ? full.indexOf('\\n') : full.length)\n const note = BREAKING_FOOTER.exec(body)?.[1]?.trim() || null\n const hasFooter = BREAKING_FOOTER.test(body)\n if (!header) return { type: null, scope: null, description: title.trim(), breaking: hasFooter, breakingNote: note }\n return {\n type: (header[1] as string).toLowerCase(),\n scope: header[2]?.trim() || null,\n description: (header[4] as string).trim(),\n breaking: header[3] === '!' || hasFooter,\n breakingNote: note\n }\n}\n\nexport const sectionOf = (parsed: ParsedMessage, include: readonly string[]): SectionId | null => {\n if (parsed.breaking) return 'breaking'\n if (parsed.type && HIDDEN_TYPES.includes(parsed.type) && !include.includes(parsed.type)) return null\n return (parsed.type && SECTION_OF_TYPE[parsed.type]) || 'other'\n}\n"]}