@release-change/github 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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/close-issue.d.ts +8 -0
  4. package/dist/close-issue.d.ts.map +1 -0
  5. package/dist/close-issue.js +63 -0
  6. package/dist/close-issue.js.map +1 -0
  7. package/dist/create-pull-request.d.ts +8 -0
  8. package/dist/create-pull-request.d.ts.map +1 -0
  9. package/dist/create-pull-request.js +96 -0
  10. package/dist/create-pull-request.js.map +1 -0
  11. package/dist/find-npm-tag-from-git-tag.d.ts +9 -0
  12. package/dist/find-npm-tag-from-git-tag.d.ts.map +1 -0
  13. package/dist/find-npm-tag-from-git-tag.js +11 -0
  14. package/dist/find-npm-tag-from-git-tag.js.map +1 -0
  15. package/dist/get-associated-pull-requests.d.ts +11 -0
  16. package/dist/get-associated-pull-requests.d.ts.map +1 -0
  17. package/dist/get-associated-pull-requests.js +81 -0
  18. package/dist/get-associated-pull-requests.js.map +1 -0
  19. package/dist/get-issues.d.ts +10 -0
  20. package/dist/get-issues.d.ts.map +1 -0
  21. package/dist/get-issues.js +33 -0
  22. package/dist/get-issues.js.map +1 -0
  23. package/dist/get-related-pull-requests-and-issues.d.ts +10 -0
  24. package/dist/get-related-pull-requests-and-issues.d.ts.map +1 -0
  25. package/dist/get-related-pull-requests-and-issues.js +77 -0
  26. package/dist/get-related-pull-requests-and-issues.js.map +1 -0
  27. package/dist/get-repository-related-entry-point.d.ts +7 -0
  28. package/dist/get-repository-related-entry-point.d.ts.map +1 -0
  29. package/dist/get-repository-related-entry-point.js +23 -0
  30. package/dist/get-repository-related-entry-point.js.map +1 -0
  31. package/dist/github.types.d.ts +16 -0
  32. package/dist/github.types.d.ts.map +1 -0
  33. package/dist/github.types.js +2 -0
  34. package/dist/github.types.js.map +1 -0
  35. package/dist/index.d.ts +9 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +8 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/is-auto-merge-allowed.d.ts +3 -0
  40. package/dist/is-auto-merge-allowed.d.ts.map +1 -0
  41. package/dist/is-auto-merge-allowed.js +52 -0
  42. package/dist/is-auto-merge-allowed.js.map +1 -0
  43. package/dist/linkify-release-info.d.ts +8 -0
  44. package/dist/linkify-release-info.d.ts.map +1 -0
  45. package/dist/linkify-release-info.js +10 -0
  46. package/dist/linkify-release-info.js.map +1 -0
  47. package/dist/merge-references-by-number.d.ts +10 -0
  48. package/dist/merge-references-by-number.d.ts.map +1 -0
  49. package/dist/merge-references-by-number.js +32 -0
  50. package/dist/merge-references-by-number.js.map +1 -0
  51. package/dist/post-fail-comment.d.ts +8 -0
  52. package/dist/post-fail-comment.d.ts.map +1 -0
  53. package/dist/post-fail-comment.js +100 -0
  54. package/dist/post-fail-comment.js.map +1 -0
  55. package/dist/post-success-comment.d.ts +8 -0
  56. package/dist/post-success-comment.d.ts.map +1 -0
  57. package/dist/post-success-comment.js +115 -0
  58. package/dist/post-success-comment.js.map +1 -0
  59. package/dist/tag-pull-request-and-issue.d.ts +3 -0
  60. package/dist/tag-pull-request-and-issue.d.ts.map +1 -0
  61. package/dist/tag-pull-request-and-issue.js +87 -0
  62. package/dist/tag-pull-request-and-issue.js.map +1 -0
  63. package/package.json +40 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Victor Brito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @release-change/github
2
+
3
+ Functions used internally in release-change to publish a GitHub release and comment on released pull requests and issues
4
+
5
+ ![License: MIT](https://img.shields.io/github/license/release-change/release-change)
6
+ [![ESM-only package](https://img.shields.io/badge/package-ESM--only-ffe536)](https://nodejs.org/api/esm.html)
7
+ [![Conventional Commits 1.0.0](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
8
+ [![Formatted with Biome](https://img.shields.io/badge/Formatted_with-Biome-60a5fa?style=flat&logo=biome)](https://biomejs.dev/)
9
+ ![NPM latest version](https://img.shields.io/npm/v/%40release-change%2Fgithub/latest)
10
+ ![Node support](https://img.shields.io/node/v/%40release-change%2Fgithub)
11
+ ![Build status](https://img.shields.io/github/actions/workflow/status/release-change/release-change/run-tests.yml)
12
+
13
+ ## Copyright & licence
14
+
15
+ © 2025-present Victor Brito — Released under the [MIT licence](./LICENSE).
@@ -0,0 +1,8 @@
1
+ import type { Context } from "@release-change/shared";
2
+ /**
3
+ * Closes an issue.
4
+ * @param number - The number of the issue to close.
5
+ * @param context - The context where the CLI is running.
6
+ */
7
+ export declare const closeIssue: (number: number, context: Context) => Promise<void>;
8
+ //# sourceMappingURL=close-issue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"close-issue.d.ts","sourceRoot":"","sources":["../src/close-issue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAWtD;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAU,QAAQ,MAAM,EAAE,SAAS,OAAO,KAAG,OAAO,CAAC,IAAI,CAsD/E,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { inspect } from "node:util";
2
+ import { getIssueAndPullRequestToken } from "@release-change/ci";
3
+ import { setLogger } from "@release-change/logger";
4
+ import { formatDetailedError } from "@release-change/shared";
5
+ import { getRepositoryRelatedEntryPoint } from "./get-repository-related-entry-point.js";
6
+ /**
7
+ * Closes an issue.
8
+ * @param number - The number of the issue to close.
9
+ * @param context - The context where the CLI is running.
10
+ */
11
+ export const closeIssue = async (number, context) => {
12
+ const { env, config: { debug, repositoryUrl } } = context;
13
+ const logger = setLogger(debug);
14
+ logger.setScope("github");
15
+ const issuePullRequestToken = getIssueAndPullRequestToken(env);
16
+ const repositoryEntryPoint = getRepositoryRelatedEntryPoint(repositoryUrl);
17
+ const uri = `${repositoryEntryPoint}/issues/${number}`;
18
+ const requestBody = {
19
+ state: "closed",
20
+ state_reason: "completed"
21
+ };
22
+ const issueClosingResponse = await fetch(uri, {
23
+ method: "PATCH",
24
+ headers: {
25
+ Accept: "application/vnd.github+json",
26
+ Authorization: `Bearer ${issuePullRequestToken}`,
27
+ "Content-Type": "application/json",
28
+ "X-GitHub-Api-Version": "2022-11-28"
29
+ },
30
+ body: JSON.stringify(requestBody)
31
+ });
32
+ const { headers, status, statusText } = issueClosingResponse;
33
+ const issueClosingResponseData = issueClosingResponse.json();
34
+ if (debug) {
35
+ logger.setDebugScope("github:close-issue");
36
+ logger.logDebug(`API entry point: ${uri}`);
37
+ logger.logDebug(`Request body: ${inspect(requestBody, { depth: Number.POSITIVE_INFINITY })}`);
38
+ logger.logDebug(`Response status: ${status}`);
39
+ logger.logDebug(`Response status text: ${statusText}`);
40
+ logger.logDebug(`Response headers: ${inspect(headers, { depth: Number.POSITIVE_INFINITY })}`);
41
+ logger.logDebug(`Response JSON: ${inspect(await issueClosingResponseData, { depth: Number.POSITIVE_INFINITY })}`);
42
+ }
43
+ if (status === 200)
44
+ logger.logSuccess(`Closed issue #${number} successfully.`);
45
+ else if (status === 404) {
46
+ logger.logWarn(`The resource requested for issue #${number} has not been found.`);
47
+ }
48
+ else {
49
+ const responseError = await issueClosingResponseData;
50
+ const { message, documentation_url: documentationUrl } = responseError;
51
+ const documentationReference = documentationUrl ? ` See ${documentationUrl}.` : "";
52
+ logger.logError(`Failed to close issue #${number}.`);
53
+ process.exitCode = status;
54
+ throw formatDetailedError({
55
+ title: "Failed to close the issue",
56
+ message: `${message}${documentationReference}`,
57
+ details: {
58
+ output: `status: ${status}`
59
+ }
60
+ });
61
+ }
62
+ };
63
+ //# sourceMappingURL=close-issue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"close-issue.js","sourceRoot":"","sources":["../src/close-issue.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAEzF;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,MAAc,EAAE,OAAgB,EAAiB,EAAE;IAClF,MAAM,EACJ,GAAG,EACH,MAAM,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,EACjC,GAAG,OAAO,CAAC;IACZ,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC1B,MAAM,qBAAqB,GAAG,2BAA2B,CAAC,GAAG,CAAC,CAAC;IAC/D,M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,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,EAAE,CACjG,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,KAAK,GAAG;QAAE,MAAM,CAAC,UAAU,CAAC,iBAAiB,MAAM,gBAAgB,CAAC,CAAC;SAC1E,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACxB,MAAM,CAAC,OAAO,CAAC,qCAAqC,MAAM,sBAAsB,CAAC,CAAC;IACpF,CAAC;SAAM,CAAC;QACN,MAAM,aAAa,GAAwB,MAAM,wBAAwB,CAAC;QAC1E,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,GAAG,aAAa,CAAC;QACvE,MAAM,sBAAsB,GAAG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,gBAAgB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACnF,MAAM,CAAC,QAAQ,CAAC,0BAA0B,MAAM,GAAG,CAAC,CAAC;QACrD,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC1B,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,2BAA2B;YAClC,OAAO,EAAE,GAAG,OAAO,GAAG,sBAAsB,EAAE;YAC9C,OAAO,EAAE;gBACP,MAAM,EAAE,WAAW,MAAM,EAAE;aAC5B;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Context } from "@release-change/shared";
2
+ /**
3
+ * Creates a pull request.
4
+ * @param headBranch - The name of the branch to create the pull request from.
5
+ * @param context - The context where the CLI is running.
6
+ */
7
+ export declare const createPullRequest: (headBranch: string, context: Context) => Promise<void>;
8
+ //# sourceMappingURL=create-pull-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-pull-request.d.ts","sourceRoot":"","sources":["../src/create-pull-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAYtD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,YAAY,MAAM,EAAE,SAAS,OAAO,KAAG,OAAO,CAAC,IAAI,CAwF1F,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { inspect } from "node:util";
2
+ import { getIssueAndPullRequestToken } from "@release-change/ci";
3
+ import { setLogger } from "@release-change/logger";
4
+ import { formatDetailedError } from "@release-change/shared";
5
+ import { getRepositoryRelatedEntryPoint } from "./get-repository-related-entry-point.js";
6
+ import { isAutoMergeAllowed } from "./is-auto-merge-allowed.js";
7
+ /**
8
+ * Creates a pull request.
9
+ * @param headBranch - The name of the branch to create the pull request from.
10
+ * @param context - The context where the CLI is running.
11
+ */
12
+ export const createPullRequest = async (headBranch, context) => {
13
+ const { env, config: { debug, repositoryUrl, isMonorepo }, branch, nextRelease } = context;
14
+ if (branch && headBranch) {
15
+ const logger = setLogger(debug);
16
+ logger.setScope("github");
17
+ const issuePullRequestToken = getIssueAndPullRequestToken(env);
18
+ const repositoryEntryPoint = getRepositoryRelatedEntryPoint(repositoryUrl);
19
+ const uri = `${repositoryEntryPoint}/pulls`;
20
+ const packageNumber = isMonorepo ? "packages" : "package";
21
+ const releasesBody = nextRelease?.length
22
+ ? `\n#### Releases\n\n${nextRelease.map(release => `- ${release.gitTag}`).join("\n")}\n`
23
+ : "";
24
+ const autoMergeBody = (await isAutoMergeAllowed(repositoryEntryPoint, context))
25
+ ? "The auto-merge is enabled."
26
+ : "The auto-merge is disabled. Please merge this pull request manually.";
27
+ const commentBody = `This pull request was automatically created.
28
+
29
+ ${autoMergeBody}
30
+ ${releasesBody}`;
31
+ const requestBody = {
32
+ title: `chore: release version ${packageNumber} [skip ci]`,
33
+ head: headBranch,
34
+ base: branch,
35
+ body: commentBody
36
+ };
37
+ const pullRequestCreationResponse = await fetch(uri, {
38
+ method: "POST",
39
+ headers: {
40
+ Accept: "application/vnd.github+json",
41
+ Authorization: `Bearer ${issuePullRequestToken}`,
42
+ "Content-Type": "application/json",
43
+ "X-GitHub-Api-Version": "2022-11-28"
44
+ },
45
+ body: JSON.stringify(requestBody)
46
+ });
47
+ const { headers, status, statusText } = pullRequestCreationResponse;
48
+ const pullRequestCreationResponseData = pullRequestCreationResponse.json();
49
+ if (debug) {
50
+ logger.setDebugScope("github:create-pull-request");
51
+ logger.logDebug(`API entry point: ${uri}`);
52
+ logger.logDebug(`Request body: ${inspect(requestBody, { depth: Number.POSITIVE_INFINITY })}`);
53
+ logger.logDebug(`Response status: ${status}`);
54
+ logger.logDebug(`Response status text: ${statusText}`);
55
+ logger.logDebug(`Response headers: ${inspect(headers, { depth: Number.POSITIVE_INFINITY })}`);
56
+ logger.logDebug(`Response JSON: ${inspect(await pullRequestCreationResponseData, { depth: Number.POSITIVE_INFINITY })}`);
57
+ }
58
+ if (status === 201)
59
+ logger.logSuccess("Created the pull request successfully.");
60
+ else {
61
+ const responseError = await pullRequestCreationResponseData;
62
+ const { message, documentation_url: documentationUrl } = responseError;
63
+ const documentationReference = documentationUrl ? ` See ${documentationUrl}.` : "";
64
+ logger.logError("Failed to create the pull request.");
65
+ process.exitCode = status;
66
+ throw formatDetailedError({
67
+ title: "Failed to create the pull request",
68
+ message: `${message}${documentationReference}`,
69
+ details: {
70
+ output: `status: ${status}`,
71
+ command: `POST ${uri}`
72
+ }
73
+ });
74
+ }
75
+ }
76
+ else {
77
+ process.exitCode = 1;
78
+ throw formatDetailedError({
79
+ title: "Failed to create the pull request",
80
+ message: branch
81
+ ? "The head branch must not be empty."
82
+ : headBranch
83
+ ? "The target branch is not defined."
84
+ : "Both the target branch and the head branch must be defined.",
85
+ details: {
86
+ output: branch
87
+ ? `branch: ${branch}, headBranch: `
88
+ : headBranch
89
+ ? `branch: undefined, headBranch: ${headBranch}`
90
+ : "branch: undefined, headBranch: ",
91
+ command: "POST /repos/:owner/:repo/pulls"
92
+ }
93
+ });
94
+ }
95
+ };
96
+ //# sourceMappingURL=create-pull-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-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CAAC,UAAU;wBACV,CAAC,CAAC,kCAAkC,UAAU,EAAE;wBAChD,CAAC,CAAC,iCAAiC;gBACvC,OAAO,EAAE,gCAAgC;aAC1C;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { NextRelease } from "@release-change/shared";
2
+ /**
3
+ * Find the NPM tag from a Git tag.
4
+ * @param gitTag - The Git tag to use.
5
+ * @param nextRelease - The next release data where to find the NPM tag for the given Git tag.
6
+ * @return The NPM tag if the Git tag is included in next release data and the NPM tag is defined, `undefined` if the NPM tag is not defined, `null` otherwise.
7
+ */
8
+ export declare const findNpmTagFromGitTag: (gitTag: string, nextRelease: NextRelease) => string | undefined | null;
9
+ //# sourceMappingURL=find-npm-tag-from-git-tag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-npm-tag-from-git-tag.d.ts","sourceRoot":"","sources":["../src/find-npm-tag-from-git-tag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,MAAM,EACd,aAAa,WAAW,KACvB,MAAM,GAAG,SAAS,GAAG,IAKvB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Find the NPM tag from a Git tag.
3
+ * @param gitTag - The Git tag to use.
4
+ * @param nextRelease - The next release data where to find the NPM tag for the given Git tag.
5
+ * @return The NPM tag if the Git tag is included in next release data and the NPM tag is defined, `undefined` if the NPM tag is not defined, `null` otherwise.
6
+ */
7
+ export const findNpmTagFromGitTag = (gitTag, nextRelease) => {
8
+ const packageNextRelease = nextRelease.find(packageNextRelease => packageNextRelease.gitTag === gitTag);
9
+ return packageNextRelease ? packageNextRelease.npmTag : null;
10
+ };
11
+ //# sourceMappingURL=find-npm-tag-from-git-tag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-npm-tag-from-git-tag.js","sourceRoot":"","sources":["../src/find-npm-tag-from-git-tag.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,WAAwB,EACG,EAAE;IAC7B,MAAM,kBAAkB,GAAG,WAAW,CAAC,IAAI,CACzC,kBAAkB,CAAC,EAAE,CAAC,kBAAkB,CAAC,MAAM,KAAK,MAAM,CAC3D,CAAC;IACF,OAAO,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/D,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Context } from "@release-change/shared";
2
+ import type { AssociatedPullRequest } from "./github.types.js";
3
+ /**
4
+ * Gets the pull requests associated with a given commit.
5
+ * @param uri - The URI to request.
6
+ * @param gitTags - The git tags associated with the commit.
7
+ * @param context - The context where the CLI is running.
8
+ * @return An array of associated pull requests.
9
+ */
10
+ export declare const getAssociatedPullRequests: (uri: string, gitTags: string[], context: Context) => Promise<AssociatedPullRequest[]>;
11
+ //# sourceMappingURL=get-associated-pull-requests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-associated-pull-requests.d.ts","sourceRoot":"","sources":["../src/get-associated-pull-requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EACV,qBAAqB,EAGtB,MAAM,mBAAmB,CAAC;AAQ3B;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACpC,KAAK,MAAM,EACX,SAAS,MAAM,EAAE,EACjB,SAAS,OAAO,KACf,OAAO,CAAC,qBAAqB,EAAE,CA2EjC,CAAC"}
@@ -0,0 +1,81 @@
1
+ import { inspect } from "node:util";
2
+ import { getReleaseToken } from "@release-change/ci";
3
+ import { setLogger } from "@release-change/logger";
4
+ import { formatDetailedError } from "@release-change/shared";
5
+ /**
6
+ * Gets the pull requests associated with a given commit.
7
+ * @param uri - The URI to request.
8
+ * @param gitTags - The git tags associated with the commit.
9
+ * @param context - The context where the CLI is running.
10
+ * @return An array of associated pull requests.
11
+ */
12
+ export const getAssociatedPullRequests = async (uri, gitTags, context) => {
13
+ const { env, config: { debug } } = context;
14
+ const logger = setLogger(debug);
15
+ const releaseToken = getReleaseToken(env);
16
+ const associatedPullRequest = [];
17
+ const pullRequestResponse = await fetch(uri, {
18
+ headers: {
19
+ Accept: "application/vnd.github+json",
20
+ Authorization: `Bearer ${releaseToken}`,
21
+ "X-GitHub-Api-Version": "2022-11-28"
22
+ }
23
+ });
24
+ const { headers, status, statusText } = pullRequestResponse;
25
+ const pullRequestResponseData = pullRequestResponse.json();
26
+ if (debug) {
27
+ logger.setDebugScope("github:get-associated-pull-requests");
28
+ logger.logDebug(`API entry point: ${uri}`);
29
+ logger.logDebug(`Response status: ${status}`);
30
+ logger.logDebug(`Response status text: ${statusText}`);
31
+ logger.logDebug(`Response headers: ${inspect(headers, { depth: Number.POSITIVE_INFINITY })}`);
32
+ logger.logDebug(`Response JSON: ${inspect(await pullRequestResponseData, { depth: Number.POSITIVE_INFINITY })}`);
33
+ }
34
+ if (status === 200) {
35
+ const pullRequests = await pullRequestResponseData;
36
+ for (const pullRequest of pullRequests) {
37
+ const { number, title, body } = pullRequest;
38
+ associatedPullRequest.push({
39
+ title,
40
+ body,
41
+ reference: { number, isPullRequest: true, gitTags }
42
+ });
43
+ }
44
+ if (debug) {
45
+ logger.logDebug(`Associated pull requests: ${inspect(associatedPullRequest, { depth: Number.POSITIVE_INFINITY })}`);
46
+ }
47
+ return associatedPullRequest;
48
+ }
49
+ if (status === 404) {
50
+ process.exitCode = 404;
51
+ throw formatDetailedError({
52
+ title: "Failed to get the associated pull requests",
53
+ message: `Failed to fetch URI ${uri}.`,
54
+ details: {
55
+ output: `status: ${status}`
56
+ }
57
+ });
58
+ }
59
+ const responseError = await pullRequestResponseData;
60
+ const { message, documentation_url: documentationUrl } = responseError;
61
+ const documentationReference = documentationUrl ? ` See ${documentationUrl}.` : "";
62
+ if (status === 403 || status === 409 || status === 429) {
63
+ process.exitCode = status;
64
+ throw formatDetailedError({
65
+ title: "Failed to get the associated pull requests",
66
+ message: `${message}${documentationReference}`,
67
+ details: {
68
+ output: `status: ${status}`
69
+ }
70
+ });
71
+ }
72
+ process.exitCode = status;
73
+ throw formatDetailedError({
74
+ title: "Failed to get the associated pull requests",
75
+ message,
76
+ details: {
77
+ output: `status: ${status}`
78
+ }
79
+ });
80
+ };
81
+ //# sourceMappingURL=get-associated-pull-requests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-associated-pull-requests.js","sourceRoot":"","sources":["../src/get-associated-pull-requests.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAC5C,GAAW,EACX,OAAiB,EACjB,OAAgB,EACkB,EAAE;IACpC,MAAM,EACJ,GAAG,EACH,MAAM,EAAE,EAAE,KAAK,EAAE,EAClB,GAAG,OAAO,CAAC;IACZ,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,qBAAqB,GAA4B,EAAE,CAAC;IAC1D,MAAM,mBAAmB,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC3C,OAAO,EAAE;YACP,MAAM,EAAE,6BAA6B;YACrC,aAAa,EAAE,UAAU,YAAY,EAAE;YACvC,sBAAsB,EAAE,YAAY;SACrC;KACF,CAAC,CAAC;IACH,MAAM,EAAE,OAAO,EAAE,MAAM,EAA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AC;IACD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACnB,OAAO,CAAC,QAAQ,GAAG,GAAG,CAAC;QACvB,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,4CAA4C;YACnD,OAAO,EAAE,uBAAuB,GAAG,GAAG;YACtC,OAAO,EAAE;gBACP,MAAM,EAAE,WAAW,MAAM,EAAE;aAC5B;SACF,CAAC,CAAC;IACL,CAAC;IACD,MAAM,aAAa,GAAwB,MAAM,uBAAuB,CAAC;IACzE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,GAAG,aAAa,CAAC;IACvE,MAAM,sBAAsB,GAAG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,gBAAgB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACnF,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;QACvD,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC1B,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,4CAA4C;YACnD,OAAO,EAAE,GAAG,OAAO,GAAG,sBAAsB,EAAE;YAC9C,OAAO,EAAE;gBACP,MAAM,EAAE,WAAW,MAAM,EAAE;aAC5B;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC;IAC1B,MAAM,mBAAmB,CAAC;QACxB,KAAK,EAAE,4CAA4C;QACnD,OAAO;QACP,OAAO,EAAE;YACP,MAAM,EAAE,WAAW,MAAM,EAAE;SAC5B;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Commit, Reference } from "@release-change/shared";
2
+ /**
3
+ * Gets the issues mentioned by a commit or a pull request body.
4
+ * @param contents - The contents to parse.
5
+ * @param gitTags - The git tags associated with the commit or pull request.
6
+ * @param [debug] - Whether the CLI is running in debug mode or not.
7
+ * @return An array of unique objects with the issue number and the `isPullRequest` property set to `false`.
8
+ */
9
+ export declare const getIssues: (contents: Partial<Commit>, gitTags: string[], debug?: boolean) => Reference[];
10
+ //# sourceMappingURL=get-issues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-issues.d.ts","sourceRoot":"","sources":["../src/get-issues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAShE;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GACpB,UAAU,OAAO,CAAC,MAAM,CAAC,EACzB,SAAS,MAAM,EAAE,EACjB,eAAa,KACZ,SAAS,EAoBX,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { inspect } from "node:util";
2
+ import { ISSUE_ID } from "@release-change/commit-analyser";
3
+ import { setLogger } from "@release-change/logger";
4
+ import { mergeReferencesByNumber } from "./merge-references-by-number.js";
5
+ /**
6
+ * Gets the issues mentioned by a commit or a pull request body.
7
+ * @param contents - The contents to parse.
8
+ * @param gitTags - The git tags associated with the commit or pull request.
9
+ * @param [debug] - Whether the CLI is running in debug mode or not.
10
+ * @return An array of unique objects with the issue number and the `isPullRequest` property set to `false`.
11
+ */
12
+ export const getIssues = (contents, gitTags, debug = false) => {
13
+ const logger = setLogger(debug);
14
+ logger.setScope("github");
15
+ const issues = [];
16
+ const { message, body, footer } = contents;
17
+ const content = [message ?? "", ...(body ?? ""), ...(footer ?? "")].join(" ");
18
+ const matches = content.matchAll(ISSUE_ID);
19
+ for (const match of matches) {
20
+ const issue = {
21
+ number: Number(match.groups?.issueId ?? ""),
22
+ isPullRequest: false,
23
+ gitTags
24
+ };
25
+ issues.push(issue);
26
+ if (debug) {
27
+ logger.setDebugScope("github:get-issues");
28
+ logger.logDebug(`Associated issue: ${inspect(issue, { depth: Number.POSITIVE_INFINITY })}`);
29
+ }
30
+ }
31
+ return mergeReferencesByNumber(issues);
32
+ };
33
+ //# sourceMappingURL=get-issues.js.map
@@ -0,0 +1 @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AC,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9F,CAAC;IACH,CAAC;IACD,OAAO,uBAAuB,CAAC,MAAM,CAAC,CAAC;AACzC,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Commit, Context } from "@release-change/shared";
2
+ /**
3
+ * Gets pull requests and issues related to the commits which are part of the release.
4
+ *
5
+ * First, the pull requests associated with each commit are retrieved. Then, the issues mentioned in the commit message, body and footer are retrieved. Finally, those mentioned in the pull request titles and bodies are retrieved.
6
+ * @param commits - The commits to parse.
7
+ * @param context - The context where the CLI is running.
8
+ */
9
+ export declare const getRelatedPullRequestsAndIssues: (commits: Commit[], context: Context) => Promise<void>;
10
+ //# sourceMappingURL=get-related-pull-requests-and-issues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-related-pull-requests-and-issues.d.ts","sourceRoot":"","sources":["../src/get-related-pull-requests-and-issues.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAa,MAAM,wBAAwB,CAAC;AAczE;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,GAC1C,SAAS,MAAM,EAAE,EACjB,SAAS,OAAO,KACf,OAAO,CAAC,IAAI,CAmFd,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { inspect } from "node:util";
2
+ import { getGitTags } from "@release-change/commit-analyser";
3
+ import { addErrorToContext, checkErrorType, setLogger } from "@release-change/logger";
4
+ import { agreeInNumber } from "@release-change/shared";
5
+ import { getAssociatedPullRequests } from "./get-associated-pull-requests.js";
6
+ import { getIssues } from "./get-issues.js";
7
+ import { getRepositoryRelatedEntryPoint } from "./get-repository-related-entry-point.js";
8
+ import { mergeReferencesByNumber } from "./merge-references-by-number.js";
9
+ /**
10
+ * Gets pull requests and issues related to the commits which are part of the release.
11
+ *
12
+ * First, the pull requests associated with each commit are retrieved. Then, the issues mentioned in the commit message, body and footer are retrieved. Finally, those mentioned in the pull request titles and bodies are retrieved.
13
+ * @param commits - The commits to parse.
14
+ * @param context - The context where the CLI is running.
15
+ */
16
+ export const getRelatedPullRequestsAndIssues = async (commits, context) => {
17
+ const { config, nextRelease } = context;
18
+ const { debug, repositoryUrl } = config;
19
+ const logger = setLogger(debug);
20
+ logger.setScope("github");
21
+ try {
22
+ const repositoryEntryPoint = getRepositoryRelatedEntryPoint(repositoryUrl);
23
+ if (commits.length && nextRelease) {
24
+ logger.logInfo("Searching for related pull requests and issues…");
25
+ const references = [];
26
+ const relatedPullRequests = [];
27
+ const commitsWithSha = commits.filter(commit => typeof commit.sha === "string" &&
28
+ !commit.message.match(/^chore: (@[^@]+)?v\d+\.\d+\.\d+$/i) &&
29
+ !commit.message.startsWith("chore: release version package"));
30
+ if (commitsWithSha.length) {
31
+ const pullRequestReferences = [];
32
+ for (const commitWithSha of commitsWithSha) {
33
+ const associatedPullRequests = await getAssociatedPullRequests(`${repositoryEntryPoint}/commits/${commitWithSha.sha}/pulls`, getGitTags(commitWithSha, context), context);
34
+ relatedPullRequests.push(...associatedPullRequests);
35
+ pullRequestReferences.push(...associatedPullRequests.map(associatedPullRequest => associatedPullRequest.reference));
36
+ }
37
+ references.push(...mergeReferencesByNumber(pullRequestReferences));
38
+ }
39
+ const pullRequestNumberSet = new Set(relatedPullRequests.map(pullRequestReference => pullRequestReference.reference.number));
40
+ const issueReferences = [];
41
+ for (const commit of commits) {
42
+ const issues = getIssues(commit, getGitTags(commit, context), debug).filter(issue => !pullRequestNumberSet.has(issue.number));
43
+ issueReferences.push(...issues);
44
+ }
45
+ const pullRequestTitlesAndBodies = relatedPullRequests.flatMap(pullRequestReference => getIssues({
46
+ message: pullRequestReference.title,
47
+ body: pullRequestReference.body?.split(/\n{2,}/) ?? [""]
48
+ }, pullRequestReference.reference.gitTags, debug).filter(issue => !pullRequestNumberSet.has(issue.number)));
49
+ issueReferences.push(...pullRequestTitlesAndBodies);
50
+ references.push(...mergeReferencesByNumber(issueReferences));
51
+ context.references = references;
52
+ const totalPullRequestReferences = context.references.filter(reference => reference.isPullRequest).length;
53
+ const totalIssueReferences = context.references.filter(reference => !reference.isPullRequest).length;
54
+ const totalPullRequestReferencesMessage = `${totalPullRequestReferences || "No"} pull ${agreeInNumber(totalPullRequestReferences, ["request", "requests"])}`;
55
+ const totalIssueReferencesMessage = `${totalIssueReferences || "no"} ${agreeInNumber(totalIssueReferences, ["issue", "issues"])}`;
56
+ logger.logInfo(!totalPullRequestReferences && !totalIssueReferences
57
+ ? "No pull requests nor issues found."
58
+ : `${totalPullRequestReferencesMessage} and ${totalIssueReferencesMessage} found.`);
59
+ }
60
+ else {
61
+ context.references = [];
62
+ logger.logInfo("No pull requests nor issues found.");
63
+ }
64
+ if (debug) {
65
+ logger.setDebugScope("github:get-related-pull-requests-and-issues");
66
+ logger.logDebug("context.references:");
67
+ logger.logDebug(inspect(context.references, { depth: Number.POSITIVE_INFINITY }));
68
+ }
69
+ }
70
+ catch (error) {
71
+ logger.logError("Failed to get related pull requests and issues.");
72
+ logger.logError(checkErrorType(error));
73
+ addErrorToContext(error, context);
74
+ process.exit(process.exitCode ?? 1);
75
+ }
76
+ };
77
+ //# sourceMappingURL=get-related-pull-requests-and-issues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-related-pull-requests-and-issues.js","sourceRoot":"","sources":["../src/get-related-pull-requests-and-issues.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OA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AC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,QAAQ,CAAC,iDAAiD,CAAC,CAAC;QACnE,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;QACvC,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the repository-related entry point for REST API calls.
3
+ * @param repositoryUrl - The repository URL.
4
+ * @return The entry point to use to call the REST API.
5
+ */
6
+ export declare const getRepositoryRelatedEntryPoint: (repositoryUrl: string) => string;
7
+ //# sourceMappingURL=get-repository-related-entry-point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-repository-related-entry-point.d.ts","sourceRoot":"","sources":["../src/get-repository-related-entry-point.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,GAAI,eAAe,MAAM,KAAG,MAetE,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { formatDetailedError, parsePathname } from "@release-change/shared";
2
+ /**
3
+ * Gets the repository-related entry point for REST API calls.
4
+ * @param repositoryUrl - The repository URL.
5
+ * @return The entry point to use to call the REST API.
6
+ */
7
+ export const getRepositoryRelatedEntryPoint = (repositoryUrl) => {
8
+ const { pathname } = new URL(repositoryUrl);
9
+ const pathnameGroups = parsePathname(pathname);
10
+ if (!pathnameGroups) {
11
+ process.exitCode = 1;
12
+ throw formatDetailedError({
13
+ title: "Failed to get the repository-related entry point",
14
+ message: "Malformed repository URL: no owner or repository found",
15
+ details: {
16
+ output: `repositoryUrl: ${repositoryUrl}`
17
+ }
18
+ });
19
+ }
20
+ const { owner, repository } = pathnameGroups;
21
+ return `https://api.github.com/repos/${owner}/${repository}`;
22
+ };
23
+ //# sourceMappingURL=get-repository-related-entry-point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-repository-related-entry-point.js","sourceRoot":"","sources":["../src/get-repository-related-entry-point.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,aAAqB,EAAU,EAAE;IAC9E,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,kDAAkD;YACzD,OAAO,EAAE,wDAAwD;YACjE,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB,aAAa,EAAE;aAC1C;SACF,CAAC,CAAC;IACL,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,cAAc,CAAC;IAC7C,OAAO,gCAAgC,KAAK,IAAI,UAAU,EAAE,CAAC;AAC/D,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Reference } from "@release-change/shared";
2
+ export type GitHubResponseError = {
3
+ message: string;
4
+ documentation_url?: string;
5
+ };
6
+ export type PullRequestAssociatedWithCommit = {
7
+ number: number;
8
+ title: string;
9
+ body: string | null;
10
+ };
11
+ export type AssociatedPullRequest = {
12
+ title: string;
13
+ body: string | null;
14
+ reference: Reference;
15
+ };
16
+ //# sourceMappingURL=github.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.types.d.ts","sourceRoot":"","sources":["../src/github.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AACF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=github.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.types.js","sourceRoot":"","sources":["../src/github.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export type { GitHubResponseError } from "./github.types.js";
2
+ export { closeIssue } from "./close-issue.js";
3
+ export { createPullRequest } from "./create-pull-request.js";
4
+ export { getRelatedPullRequestsAndIssues } from "./get-related-pull-requests-and-issues.js";
5
+ export { getRepositoryRelatedEntryPoint } from "./get-repository-related-entry-point.js";
6
+ export { postFailComment } from "./post-fail-comment.js";
7
+ export { postSuccessComment } from "./post-success-comment.js";
8
+ export { tagPullRequestAndIssue } from "./tag-pull-request-and-issue.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,2CAA2C,CAAC;AAC5F,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC"}