skuba 13.0.0-subpath-imports-20250730060533 → 13.0.0-subpath-imports-20251003052152

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 (266) hide show
  1. package/README.md +1 -2
  2. package/config/tsconfig.json +2 -1
  3. package/jest/moduleNameMapper.js +3 -11
  4. package/lib/cli/build/assets.js +4 -8
  5. package/lib/cli/build/assets.js.map +2 -2
  6. package/lib/cli/build/esbuild.d.ts +2 -1
  7. package/lib/cli/build/esbuild.js +5 -4
  8. package/lib/cli/build/esbuild.js.map +2 -2
  9. package/lib/cli/build/index.js +9 -5
  10. package/lib/cli/build/index.js.map +2 -2
  11. package/lib/cli/build/tsc.d.ts +9 -2
  12. package/lib/cli/build/tsc.js +76 -40
  13. package/lib/cli/build/tsc.js.map +3 -3
  14. package/lib/cli/configure/analyseDependencies.d.ts +2 -2
  15. package/lib/cli/configure/analyseDependencies.js.map +1 -1
  16. package/lib/cli/configure/analysis/package.d.ts +1 -1
  17. package/lib/cli/configure/analysis/package.js +1 -1
  18. package/lib/cli/configure/analysis/package.js.map +2 -2
  19. package/lib/cli/configure/ensureTemplateCompletion.d.ts +2 -2
  20. package/lib/cli/configure/ensureTemplateCompletion.js.map +1 -1
  21. package/lib/cli/configure/getEntryPoint.d.ts +2 -2
  22. package/lib/cli/configure/getEntryPoint.js.map +1 -1
  23. package/lib/cli/configure/getProjectType.d.ts +2 -2
  24. package/lib/cli/configure/getProjectType.js.map +1 -1
  25. package/lib/cli/configure/processing/configFile.d.ts +1 -1
  26. package/lib/cli/configure/processing/configFile.js +48 -6
  27. package/lib/cli/configure/processing/configFile.js.map +2 -2
  28. package/lib/cli/configure/processing/package.js +8 -2
  29. package/lib/cli/configure/processing/package.js.map +2 -2
  30. package/lib/cli/init/getConfig.js +1 -1
  31. package/lib/cli/init/getConfig.js.map +2 -2
  32. package/lib/cli/init/git.js +1 -1
  33. package/lib/cli/init/git.js.map +2 -2
  34. package/lib/cli/init/index.js +4 -4
  35. package/lib/cli/init/index.js.map +3 -3
  36. package/lib/cli/lint/annotate/buildkite/eslint.js +1 -1
  37. package/lib/cli/lint/annotate/buildkite/eslint.js.map +2 -2
  38. package/lib/cli/lint/annotate/buildkite/index.js +1 -1
  39. package/lib/cli/lint/annotate/buildkite/index.js.map +2 -2
  40. package/lib/cli/lint/annotate/buildkite/internal.js +1 -1
  41. package/lib/cli/lint/annotate/buildkite/internal.js.map +2 -2
  42. package/lib/cli/lint/annotate/buildkite/prettier.js +1 -1
  43. package/lib/cli/lint/annotate/buildkite/prettier.js.map +2 -2
  44. package/lib/cli/lint/annotate/buildkite/tsc.js +1 -1
  45. package/lib/cli/lint/annotate/buildkite/tsc.js.map +2 -2
  46. package/lib/cli/lint/annotate/github/eslint.d.ts +1 -1
  47. package/lib/cli/lint/annotate/github/eslint.js.map +2 -2
  48. package/lib/cli/lint/annotate/github/index.js +3 -4
  49. package/lib/cli/lint/annotate/github/index.js.map +2 -2
  50. package/lib/cli/lint/annotate/github/internal.d.ts +1 -1
  51. package/lib/cli/lint/annotate/github/internal.js.map +2 -2
  52. package/lib/cli/lint/annotate/github/prettier.d.ts +1 -1
  53. package/lib/cli/lint/annotate/github/prettier.js.map +2 -2
  54. package/lib/cli/lint/annotate/github/tsc.d.ts +1 -1
  55. package/lib/cli/lint/annotate/github/tsc.js.map +2 -2
  56. package/lib/cli/lint/autofix.d.ts +1 -1
  57. package/lib/cli/lint/autofix.js +3 -3
  58. package/lib/cli/lint/autofix.js.map +2 -2
  59. package/lib/cli/lint/internal.js +1 -1
  60. package/lib/cli/lint/internal.js.map +2 -2
  61. package/lib/cli/lint/internalLints/patchRenovateConfig.js +3 -3
  62. package/lib/cli/lint/internalLints/patchRenovateConfig.js.map +2 -2
  63. package/lib/cli/lint/internalLints/refreshConfigFiles.js +5 -3
  64. package/lib/cli/lint/internalLints/refreshConfigFiles.js.map +2 -2
  65. package/lib/cli/lint/internalLints/upgrade/index.d.ts +2 -2
  66. package/lib/cli/lint/internalLints/upgrade/index.js.map +1 -1
  67. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js +3 -3
  68. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js.map +2 -2
  69. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.d.ts +4 -0
  70. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js +162 -0
  71. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js.map +7 -0
  72. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/index.d.ts +2 -0
  73. package/lib/{api/buildkite → cli/lint/internalLints/upgrade/patches/12.1.1}/index.js +12 -9
  74. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/index.js.map +7 -0
  75. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/patchJestSnapshots.d.ts +3 -0
  76. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/patchJestSnapshots.js +105 -0
  77. package/lib/cli/lint/internalLints/upgrade/patches/12.1.1/patchJestSnapshots.js.map +7 -0
  78. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/index.d.ts +2 -0
  79. package/lib/{api/git/statusMatrix.js → cli/lint/internalLints/upgrade/patches/12.3.0/index.js} +18 -25
  80. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/index.js.map +7 -0
  81. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchApiTokenFromEnvironment.d.ts +3 -0
  82. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchApiTokenFromEnvironment.js +100 -0
  83. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchApiTokenFromEnvironment.js.map +7 -0
  84. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchDockerfileSyntaxDirective.d.ts +3 -0
  85. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchDockerfileSyntaxDirective.js +99 -0
  86. package/lib/cli/lint/internalLints/upgrade/patches/12.3.0/patchDockerfileSyntaxDirective.js.map +7 -0
  87. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/index.d.ts +2 -0
  88. package/lib/{api/buildkite/md.js → cli/lint/internalLints/upgrade/patches/12.4.0/index.js} +13 -11
  89. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/index.js.map +7 -0
  90. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/patchDockerfileCIVariable.d.ts +3 -0
  91. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/patchDockerfileCIVariable.js +101 -0
  92. package/lib/cli/lint/internalLints/upgrade/patches/12.4.0/patchDockerfileCIVariable.js.map +7 -0
  93. package/lib/cli/lint/internalLints/upgrade/patches/13.0.0/index.d.ts +2 -0
  94. package/lib/{api/net → cli/lint/internalLints/upgrade/patches/13.0.0}/index.js +12 -6
  95. package/lib/cli/lint/internalLints/upgrade/patches/13.0.0/index.js.map +7 -0
  96. package/lib/cli/lint/internalLints/upgrade/patches/13.0.0/rewriteSrcImports.d.ts +13 -0
  97. package/lib/cli/lint/internalLints/upgrade/patches/13.0.0/rewriteSrcImports.js +221 -0
  98. package/lib/cli/lint/internalLints/upgrade/patches/13.0.0/rewriteSrcImports.js.map +7 -0
  99. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/upgradeESLint.js +1 -1
  100. package/lib/cli/lint/internalLints/upgrade/patches/8.2.1/upgradeESLint.js.map +2 -2
  101. package/lib/cli/node/index.js +6 -0
  102. package/lib/cli/node/index.js.map +2 -2
  103. package/lib/cli/start/index.js +6 -0
  104. package/lib/cli/start/index.js.map +2 -2
  105. package/lib/cli/test/index.d.ts +1 -1
  106. package/lib/cli/test/index.js +18 -4
  107. package/lib/cli/test/index.js.map +2 -2
  108. package/lib/cli/test/reporters/github/annotations.d.ts +1 -1
  109. package/lib/cli/test/reporters/github/annotations.js.map +1 -1
  110. package/lib/cli/test/reporters/github/index.js +3 -4
  111. package/lib/cli/test/reporters/github/index.js.map +2 -2
  112. package/lib/index.d.ts +4 -4
  113. package/lib/index.js +4 -4
  114. package/lib/index.js.map +2 -2
  115. package/lib/utils/args.d.ts +2 -0
  116. package/lib/utils/args.js +5 -0
  117. package/lib/utils/args.js.map +2 -2
  118. package/lib/utils/dir.js +2 -2
  119. package/lib/utils/dir.js.map +3 -3
  120. package/lib/utils/manifest.d.ts +6 -2
  121. package/lib/utils/manifest.js +17 -8
  122. package/lib/utils/manifest.js.map +2 -2
  123. package/lib/utils/template.d.ts +1 -1
  124. package/package.json +19 -21
  125. package/template/base/_.prettierrc.js +1 -1
  126. package/template/base/_eslint.config.js +1 -1
  127. package/template/base/_pnpm-workspace.yaml +11 -0
  128. package/template/base/jest.config.ts +4 -0
  129. package/template/base/jest.setup.ts +1 -1
  130. package/template/express-rest-api/.buildkite/pipeline.yml +6 -0
  131. package/template/express-rest-api/.env +1 -1
  132. package/template/express-rest-api/.gantry/dev.yml +5 -1
  133. package/template/express-rest-api/.gantry/prod.yml +5 -1
  134. package/template/express-rest-api/Dockerfile +2 -2
  135. package/template/express-rest-api/Dockerfile.dev-deps +0 -2
  136. package/template/express-rest-api/README.md +5 -5
  137. package/template/express-rest-api/gantry.apply.yml +17 -1
  138. package/template/express-rest-api/package.json +11 -5
  139. package/template/express-rest-api/src/api/healthCheck.ts +2 -2
  140. package/template/express-rest-api/src/config.ts +7 -7
  141. package/template/express-rest-api/src/framework/logging.ts +11 -7
  142. package/template/express-rest-api/src/framework/metrics.ts +1 -1
  143. package/template/express-rest-api/src/listen.ts +6 -0
  144. package/template/express-rest-api/src/tracing.ts +56 -0
  145. package/template/greeter/Dockerfile +0 -2
  146. package/template/greeter/README.md +2 -2
  147. package/template/greeter/package.json +2 -2
  148. package/template/koa-rest-api/.buildkite/pipeline.yml +6 -0
  149. package/template/koa-rest-api/.env +1 -1
  150. package/template/koa-rest-api/.gantry/dev.yml +3 -3
  151. package/template/koa-rest-api/.gantry/prod.yml +3 -3
  152. package/template/koa-rest-api/Dockerfile +1 -1
  153. package/template/koa-rest-api/Dockerfile.dev-deps +0 -2
  154. package/template/koa-rest-api/README.md +6 -6
  155. package/template/koa-rest-api/gantry.apply.yml +15 -3
  156. package/template/koa-rest-api/package.json +10 -11
  157. package/template/koa-rest-api/src/api/healthCheck.ts +2 -2
  158. package/template/koa-rest-api/src/config.ts +7 -7
  159. package/template/koa-rest-api/src/framework/logging.ts +12 -8
  160. package/template/koa-rest-api/src/framework/metrics.ts +1 -1
  161. package/template/koa-rest-api/src/framework/server.test.ts +7 -8
  162. package/template/koa-rest-api/src/framework/server.ts +1 -4
  163. package/template/koa-rest-api/src/listen.ts +6 -0
  164. package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +6 -2
  165. package/template/lambda-sqs-worker-cdk/.env +1 -1
  166. package/template/lambda-sqs-worker-cdk/Dockerfile +0 -2
  167. package/template/lambda-sqs-worker-cdk/README.md +8 -8
  168. package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +54 -26
  169. package/template/lambda-sqs-worker-cdk/infra/appStack.test.ts +5 -22
  170. package/template/lambda-sqs-worker-cdk/infra/appStack.ts +16 -9
  171. package/template/lambda-sqs-worker-cdk/infra/config.ts +34 -20
  172. package/template/lambda-sqs-worker-cdk/infra/index.ts +1 -1
  173. package/template/lambda-sqs-worker-cdk/package.json +7 -9
  174. package/template/lambda-sqs-worker-cdk/src/app.test.ts +91 -51
  175. package/template/lambda-sqs-worker-cdk/src/app.ts +10 -9
  176. package/template/lambda-sqs-worker-cdk/src/config.ts +11 -16
  177. package/template/lambda-sqs-worker-cdk/src/framework/handler.test.ts +10 -5
  178. package/template/lambda-sqs-worker-cdk/src/framework/handler.ts +48 -24
  179. package/template/lambda-sqs-worker-cdk/src/framework/logging.ts +23 -11
  180. package/template/lambda-sqs-worker-cdk/src/framework/metrics.ts +1 -4
  181. package/template/lambda-sqs-worker-cdk/src/testing/handler.ts +4 -1
  182. package/template/oss-npm-package/.github/workflows/release.yml +7 -8
  183. package/template/oss-npm-package/.github/workflows/validate.yml +6 -6
  184. package/template/oss-npm-package/README.md +1 -1
  185. package/template/oss-npm-package/_package.json +0 -3
  186. package/template/oss-npm-package/skuba.template.js +1 -1
  187. package/lib/api/buildkite/annotate.d.ts +0 -28
  188. package/lib/api/buildkite/annotate.js +0 -62
  189. package/lib/api/buildkite/annotate.js.map +0 -7
  190. package/lib/api/buildkite/index.d.ts +0 -3
  191. package/lib/api/buildkite/index.js.map +0 -7
  192. package/lib/api/buildkite/md.d.ts +0 -6
  193. package/lib/api/buildkite/md.js.map +0 -7
  194. package/lib/api/git/commit.d.ts +0 -15
  195. package/lib/api/git/commit.js +0 -52
  196. package/lib/api/git/commit.js.map +0 -7
  197. package/lib/api/git/commitAllChanges.d.ts +0 -19
  198. package/lib/api/git/commitAllChanges.js +0 -83
  199. package/lib/api/git/commitAllChanges.js.map +0 -7
  200. package/lib/api/git/currentBranch.d.ts +0 -10
  201. package/lib/api/git/currentBranch.js +0 -59
  202. package/lib/api/git/currentBranch.js.map +0 -7
  203. package/lib/api/git/findRoot.d.ts +0 -9
  204. package/lib/api/git/findRoot.js +0 -52
  205. package/lib/api/git/findRoot.js.map +0 -7
  206. package/lib/api/git/getChangedFiles.d.ts +0 -20
  207. package/lib/api/git/getChangedFiles.js +0 -81
  208. package/lib/api/git/getChangedFiles.js.map +0 -7
  209. package/lib/api/git/index.d.ts +0 -12
  210. package/lib/api/git/index.js +0 -61
  211. package/lib/api/git/index.js.map +0 -7
  212. package/lib/api/git/isFileGitIgnored.d.ts +0 -4
  213. package/lib/api/git/isFileGitIgnored.js +0 -49
  214. package/lib/api/git/isFileGitIgnored.js.map +0 -7
  215. package/lib/api/git/log.d.ts +0 -19
  216. package/lib/api/git/log.js +0 -71
  217. package/lib/api/git/log.js.map +0 -7
  218. package/lib/api/git/pull.d.ts +0 -35
  219. package/lib/api/git/pull.js +0 -69
  220. package/lib/api/git/pull.js.map +0 -7
  221. package/lib/api/git/push.d.ts +0 -52
  222. package/lib/api/git/push.js +0 -70
  223. package/lib/api/git/push.js.map +0 -7
  224. package/lib/api/git/remote.d.ts +0 -20
  225. package/lib/api/git/remote.js +0 -73
  226. package/lib/api/git/remote.js.map +0 -7
  227. package/lib/api/git/reset.d.ts +0 -12
  228. package/lib/api/git/reset.js +0 -62
  229. package/lib/api/git/reset.js.map +0 -7
  230. package/lib/api/git/statusMatrix.d.ts +0 -7
  231. package/lib/api/git/statusMatrix.js.map +0 -7
  232. package/lib/api/github/checkRun.d.ts +0 -44
  233. package/lib/api/github/checkRun.js +0 -81
  234. package/lib/api/github/checkRun.js.map +0 -7
  235. package/lib/api/github/environment.d.ts +0 -17
  236. package/lib/api/github/environment.js +0 -48
  237. package/lib/api/github/environment.js.map +0 -7
  238. package/lib/api/github/index.d.ts +0 -7
  239. package/lib/api/github/index.js +0 -48
  240. package/lib/api/github/index.js.map +0 -7
  241. package/lib/api/github/issueComment.d.ts +0 -61
  242. package/lib/api/github/issueComment.js +0 -99
  243. package/lib/api/github/issueComment.js.map +0 -7
  244. package/lib/api/github/octokit.d.ts +0 -6
  245. package/lib/api/github/octokit.js +0 -42
  246. package/lib/api/github/octokit.js.map +0 -7
  247. package/lib/api/github/pullRequest.d.ts +0 -21
  248. package/lib/api/github/pullRequest.js +0 -69
  249. package/lib/api/github/pullRequest.js.map +0 -7
  250. package/lib/api/github/push.d.ts +0 -85
  251. package/lib/api/github/push.js +0 -166
  252. package/lib/api/github/push.js.map +0 -7
  253. package/lib/api/net/compose.d.ts +0 -4
  254. package/lib/api/net/compose.js +0 -51
  255. package/lib/api/net/compose.js.map +0 -7
  256. package/lib/api/net/index.d.ts +0 -1
  257. package/lib/api/net/index.js.map +0 -7
  258. package/lib/api/net/socket.d.ts +0 -5
  259. package/lib/api/net/socket.js +0 -68
  260. package/lib/api/net/socket.js.map +0 -7
  261. package/lib/api/net/waitFor.d.ts +0 -22
  262. package/lib/api/net/waitFor.js +0 -40
  263. package/lib/api/net/waitFor.js.map +0 -7
  264. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/rewriteSrcImports.d.ts +0 -6
  265. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/rewriteSrcImports.js +0 -104
  266. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/rewriteSrcImports.js.map +0 -7
@@ -1,44 +0,0 @@
1
- import type { Endpoints } from '@octokit/types';
2
- type Output = NonNullable<Endpoints['PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}']['parameters']['output']>;
3
- export type Annotation = NonNullable<Output['annotations']>[number];
4
- /**
5
- * {@link https://docs.github.com/en/rest/reference/checks#create-a-check-run}
6
- */
7
- interface CreateCheckRunParameters {
8
- /**
9
- * Adds information from your analysis to specific lines of code.
10
- * Annotations are visible on GitHub in the **Checks** and **Files changed**
11
- * tab of the pull request.
12
- */
13
- annotations: Annotation[];
14
- /**
15
- * The final conclusion of the check.
16
- */
17
- conclusion: 'failure' | 'success';
18
- /**
19
- * The name of the check. For example, "code-coverage".
20
- */
21
- name: string;
22
- /**
23
- * The summary of the check run. This parameter supports Markdown.
24
- */
25
- summary: string;
26
- /**
27
- * The details of the check run. This parameter supports Markdown.
28
- */
29
- text?: string;
30
- /**
31
- * The title of the check run.
32
- */
33
- title: string;
34
- }
35
- /**
36
- * Asynchronously creates a GitHub check run with annotations.
37
- *
38
- * The first 50 `annotations` are written in full to GitHub.
39
- *
40
- * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with the `checks:write` permission
41
- * must be present on the environment.
42
- */
43
- export declare const createCheckRun: ({ annotations, conclusion, name, summary, text, title, }: CreateCheckRunParameters) => Promise<void>;
44
- export {};
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var checkRun_exports = {};
30
- __export(checkRun_exports, {
31
- createCheckRun: () => createCheckRun
32
- });
33
- module.exports = __toCommonJS(checkRun_exports);
34
- var import_logging = require("../../utils/logging.js");
35
- var Git = __toESM(require("../git/index.js"));
36
- var import_environment = require("./environment.js");
37
- var import_octokit = require("./octokit.js");
38
- const GITHUB_MAX_ANNOTATIONS = 50;
39
- const suffixTitle = (title, inputAnnotations) => {
40
- const addedAnnotations = inputAnnotations > GITHUB_MAX_ANNOTATIONS ? GITHUB_MAX_ANNOTATIONS : inputAnnotations;
41
- return `${title} (${(0, import_logging.pluralise)(addedAnnotations, "annotation")} added)`;
42
- };
43
- const createEnrichedSummary = (summary, inputAnnotations) => [
44
- summary,
45
- ...inputAnnotations > GITHUB_MAX_ANNOTATIONS ? [
46
- `${inputAnnotations} annotations were provided, but only the first ${GITHUB_MAX_ANNOTATIONS} are visible in GitHub.`
47
- ] : []
48
- ].join("\n\n");
49
- const createCheckRun = async ({
50
- annotations,
51
- conclusion,
52
- name,
53
- summary,
54
- text,
55
- title
56
- }) => {
57
- const dir = process.cwd();
58
- const [commitId, { owner, repo }] = await Promise.all([
59
- Git.getHeadCommitId({ dir }),
60
- Git.getOwnerAndRepo({ dir })
61
- ]);
62
- const client = await (0, import_octokit.createRestClient)({ auth: (0, import_environment.apiTokenFromEnvironment)() });
63
- await client.checks.create({
64
- conclusion,
65
- head_sha: commitId,
66
- name,
67
- output: {
68
- annotations: annotations.slice(0, GITHUB_MAX_ANNOTATIONS),
69
- summary: createEnrichedSummary(summary, annotations.length),
70
- text,
71
- title: suffixTitle(title, annotations.length)
72
- },
73
- owner,
74
- repo
75
- });
76
- };
77
- // Annotate the CommonJS export names for ESM import in node:
78
- 0 && (module.exports = {
79
- createCheckRun
80
- });
81
- //# sourceMappingURL=checkRun.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/api/github/checkRun.ts"],
4
- "sourcesContent": ["import type { Endpoints } from '@octokit/types';\n\nimport { pluralise } from '../../utils/logging.js';\nimport * as Git from '../git/index.js';\n\nimport { apiTokenFromEnvironment } from './environment.js';\nimport { createRestClient } from './octokit.js';\n\ntype Output = NonNullable<\n Endpoints['PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}']['parameters']['output']\n>;\n\nexport type Annotation = NonNullable<Output['annotations']>[number];\n\nconst GITHUB_MAX_ANNOTATIONS = 50;\n\n/**\n * Suffixes the title with the number of annotations added, e.g.\n *\n * ```text\n * Build #12 failed (24 annotations added)\n * ```\n */\nconst suffixTitle = (title: string, inputAnnotations: number): string => {\n const addedAnnotations =\n inputAnnotations > GITHUB_MAX_ANNOTATIONS\n ? GITHUB_MAX_ANNOTATIONS\n : inputAnnotations;\n\n return `${title} (${pluralise(addedAnnotations, 'annotation')} added)`;\n};\n\n/**\n * Enriches the summary with more context about the check run.\n */\nconst createEnrichedSummary = (\n summary: string,\n inputAnnotations: number,\n): string =>\n [\n summary,\n ...(inputAnnotations > GITHUB_MAX_ANNOTATIONS\n ? [\n `${inputAnnotations} annotations were provided, but only the first ${GITHUB_MAX_ANNOTATIONS} are visible in GitHub.`,\n ]\n : []),\n ].join('\\n\\n');\n\n/**\n * {@link https://docs.github.com/en/rest/reference/checks#create-a-check-run}\n */\ninterface CreateCheckRunParameters {\n /**\n * Adds information from your analysis to specific lines of code.\n * Annotations are visible on GitHub in the **Checks** and **Files changed**\n * tab of the pull request.\n */\n annotations: Annotation[];\n\n /**\n * The final conclusion of the check.\n */\n conclusion: 'failure' | 'success';\n\n /**\n * The name of the check. For example, \"code-coverage\".\n */\n name: string;\n\n /**\n * The summary of the check run. This parameter supports Markdown.\n */\n summary: string;\n\n /**\n * The details of the check run. This parameter supports Markdown.\n */\n text?: string;\n\n /**\n * The title of the check run.\n */\n title: string;\n}\n\n/**\n * Asynchronously creates a GitHub check run with annotations.\n *\n * The first 50 `annotations` are written in full to GitHub.\n *\n * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with the `checks:write` permission\n * must be present on the environment.\n */\nexport const createCheckRun = async ({\n annotations,\n conclusion,\n name,\n summary,\n text,\n title,\n}: CreateCheckRunParameters): Promise<void> => {\n const dir = process.cwd();\n\n const [commitId, { owner, repo }] = await Promise.all([\n Git.getHeadCommitId({ dir }),\n Git.getOwnerAndRepo({ dir }),\n ]);\n\n const client = await createRestClient({ auth: apiTokenFromEnvironment() });\n\n await client.checks.create({\n conclusion,\n head_sha: commitId,\n name,\n output: {\n annotations: annotations.slice(0, GITHUB_MAX_ANNOTATIONS),\n summary: createEnrichedSummary(summary, annotations.length),\n text,\n title: suffixTitle(title, annotations.length),\n },\n owner,\n repo,\n });\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA0B;AAC1B,UAAqB;AAErB,yBAAwC;AACxC,qBAAiC;AAQjC,MAAM,yBAAyB;AAS/B,MAAM,cAAc,CAAC,OAAe,qBAAqC;AACvE,QAAM,mBACJ,mBAAmB,yBACf,yBACA;AAEN,SAAO,GAAG,KAAK,SAAK,0BAAU,kBAAkB,YAAY,CAAC;AAC/D;AAKA,MAAM,wBAAwB,CAC5B,SACA,qBAEA;AAAA,EACE;AAAA,EACA,GAAI,mBAAmB,yBACnB;AAAA,IACE,GAAG,gBAAgB,kDAAkD,sBAAsB;AAAA,EAC7F,IACA,CAAC;AACP,EAAE,KAAK,MAAM;AA+CR,MAAM,iBAAiB,OAAO;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA+C;AAC7C,QAAM,MAAM,QAAQ,IAAI;AAExB,QAAM,CAAC,UAAU,EAAE,OAAO,KAAK,CAAC,IAAI,MAAM,QAAQ,IAAI;AAAA,IACpD,IAAI,gBAAgB,EAAE,IAAI,CAAC;AAAA,IAC3B,IAAI,gBAAgB,EAAE,IAAI,CAAC;AAAA,EAC7B,CAAC;AAED,QAAM,SAAS,UAAM,iCAAiB,EAAE,UAAM,4CAAwB,EAAE,CAAC;AAEzE,QAAM,OAAO,OAAO,OAAO;AAAA,IACzB;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,MACN,aAAa,YAAY,MAAM,GAAG,sBAAsB;AAAA,MACxD,SAAS,sBAAsB,SAAS,YAAY,MAAM;AAAA,MAC1D;AAAA,MACA,OAAO,YAAY,OAAO,YAAY,MAAM;AAAA,IAC9C;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
6
- "names": []
7
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Returns the name of the build as seen in GitHub status checks.
3
- *
4
- * This is driven off of environment variables and falls back to `Build`.
5
- */
6
- export declare const buildNameFromEnvironment: (env?: NodeJS.ProcessEnv) => string;
7
- /**
8
- * Whether GitHub API interactions should be enabled.
9
- *
10
- * This checks environment variables to see if the code is executing in a CI
11
- * environment and has access to a GitHub API token.
12
- */
13
- export declare const enabledFromEnvironment: (env?: NodeJS.ProcessEnv) => boolean;
14
- /**
15
- * Tries to return a GitHub API token from the environment.
16
- */
17
- export declare const apiTokenFromEnvironment: (env?: NodeJS.ProcessEnv) => string | undefined;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var environment_exports = {};
20
- __export(environment_exports, {
21
- apiTokenFromEnvironment: () => apiTokenFromEnvironment,
22
- buildNameFromEnvironment: () => buildNameFromEnvironment,
23
- enabledFromEnvironment: () => enabledFromEnvironment
24
- });
25
- module.exports = __toCommonJS(environment_exports);
26
- var import_env = require("../../utils/env.js");
27
- const buildNameFromEnvironment = (env = process.env) => {
28
- if (env.BUILDKITE_BUILD_NUMBER) {
29
- return `Build #${env.BUILDKITE_BUILD_NUMBER}`;
30
- }
31
- if (env.GITHUB_RUN_NUMBER) {
32
- return `${env.GITHUB_WORKFLOW ?? "Build"} #${env.GITHUB_RUN_NUMBER}`;
33
- }
34
- return "Build";
35
- };
36
- const enabledFromEnvironment = (env = process.env) => (
37
- // Running in a CI environment.
38
- (0, import_env.isCiEnv)(env) && // Has an API token at the ready.
39
- Boolean(apiTokenFromEnvironment(env))
40
- );
41
- const apiTokenFromEnvironment = (env = process.env) => env.GITHUB_API_TOKEN ?? env.GITHUB_TOKEN;
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
44
- apiTokenFromEnvironment,
45
- buildNameFromEnvironment,
46
- enabledFromEnvironment
47
- });
48
- //# sourceMappingURL=environment.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/api/github/environment.ts"],
4
- "sourcesContent": ["import { isCiEnv } from '../../utils/env.js';\n\n/**\n * Returns the name of the build as seen in GitHub status checks.\n *\n * This is driven off of environment variables and falls back to `Build`.\n */\nexport const buildNameFromEnvironment = (env = process.env): string => {\n if (env.BUILDKITE_BUILD_NUMBER) {\n return `Build #${env.BUILDKITE_BUILD_NUMBER}`;\n }\n\n if (env.GITHUB_RUN_NUMBER) {\n return `${env.GITHUB_WORKFLOW ?? 'Build'} #${env.GITHUB_RUN_NUMBER}`;\n }\n\n return 'Build';\n};\n\n/**\n * Whether GitHub API interactions should be enabled.\n *\n * This checks environment variables to see if the code is executing in a CI\n * environment and has access to a GitHub API token.\n */\nexport const enabledFromEnvironment = (env = process.env): boolean =>\n // Running in a CI environment.\n isCiEnv(env) &&\n // Has an API token at the ready.\n Boolean(apiTokenFromEnvironment(env));\n\n/**\n * Tries to return a GitHub API token from the environment.\n */\nexport const apiTokenFromEnvironment = (\n env = process.env,\n): string | undefined => env.GITHUB_API_TOKEN ?? env.GITHUB_TOKEN;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAwB;AAOjB,MAAM,2BAA2B,CAAC,MAAM,QAAQ,QAAgB;AACrE,MAAI,IAAI,wBAAwB;AAC9B,WAAO,UAAU,IAAI,sBAAsB;AAAA,EAC7C;AAEA,MAAI,IAAI,mBAAmB;AACzB,WAAO,GAAG,IAAI,mBAAmB,OAAO,KAAK,IAAI,iBAAiB;AAAA,EACpE;AAEA,SAAO;AACT;AAQO,MAAM,yBAAyB,CAAC,MAAM,QAAQ;AAAA;AAAA,MAEnD,oBAAQ,GAAG;AAAA,EAEX,QAAQ,wBAAwB,GAAG,CAAC;AAAA;AAK/B,MAAM,0BAA0B,CACrC,MAAM,QAAQ,QACS,IAAI,oBAAoB,IAAI;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- export type { Annotation } from './checkRun.js';
2
- export { buildNameFromEnvironment } from './environment.js';
3
- export { createCheckRun } from './checkRun.js';
4
- export { enabledFromEnvironment } from './environment.js';
5
- export { getPullRequestNumber } from './pullRequest.js';
6
- export { putIssueComment } from './issueComment.js';
7
- export { readFileChanges, uploadAllFileChanges, uploadFileChanges, } from './push.js';
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var github_exports = {};
20
- __export(github_exports, {
21
- buildNameFromEnvironment: () => import_environment.buildNameFromEnvironment,
22
- createCheckRun: () => import_checkRun.createCheckRun,
23
- enabledFromEnvironment: () => import_environment2.enabledFromEnvironment,
24
- getPullRequestNumber: () => import_pullRequest.getPullRequestNumber,
25
- putIssueComment: () => import_issueComment.putIssueComment,
26
- readFileChanges: () => import_push.readFileChanges,
27
- uploadAllFileChanges: () => import_push.uploadAllFileChanges,
28
- uploadFileChanges: () => import_push.uploadFileChanges
29
- });
30
- module.exports = __toCommonJS(github_exports);
31
- var import_environment = require("./environment.js");
32
- var import_checkRun = require("./checkRun.js");
33
- var import_environment2 = require("./environment.js");
34
- var import_pullRequest = require("./pullRequest.js");
35
- var import_issueComment = require("./issueComment.js");
36
- var import_push = require("./push.js");
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {
39
- buildNameFromEnvironment,
40
- createCheckRun,
41
- enabledFromEnvironment,
42
- getPullRequestNumber,
43
- putIssueComment,
44
- readFileChanges,
45
- uploadAllFileChanges,
46
- uploadFileChanges
47
- });
48
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/api/github/index.ts"],
4
- "sourcesContent": ["export type { Annotation } from './checkRun.js';\nexport { buildNameFromEnvironment } from './environment.js';\nexport { createCheckRun } from './checkRun.js';\nexport { enabledFromEnvironment } from './environment.js';\nexport { getPullRequestNumber } from './pullRequest.js';\nexport { putIssueComment } from './issueComment.js';\nexport {\n readFileChanges,\n uploadAllFileChanges,\n uploadFileChanges,\n} from './push.js';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAAyC;AACzC,sBAA+B;AAC/B,IAAAA,sBAAuC;AACvC,yBAAqC;AACrC,0BAAgC;AAChC,kBAIO;",
6
- "names": ["import_environment"]
7
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * https://docs.github.com/en/rest/reference/issues#create-an-issue-comment
3
- */
4
- interface PutIssueCommentParameters {
5
- /**
6
- * The body of the issue comment.
7
- *
8
- * An explicit `null` value will remove the comment, if `internalId` is provided.
9
- */
10
- body: string | null;
11
- /**
12
- * An internal identifier for the issue comment.
13
- *
14
- * This can be used to scope a given `put` to a particular comment, preventing
15
- * it from clobbering other comments from the same bot or user.
16
- *
17
- * The identifier is embedded as hidden content in the comment body.
18
- */
19
- internalId?: string;
20
- env?: Record<string, string | undefined>;
21
- /**
22
- * The number that identifies the GitHub issue.
23
- *
24
- * If this is not provided, the number will be inferred from the GitHub Repos
25
- * API by finding the latest pull request associated with the head commit.
26
- *
27
- * https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit
28
- */
29
- issueNumber?: number;
30
- /**
31
- * The ID of authenticated bot or user that is putting the issue comment.
32
- *
33
- * This drives our `put` behaviour, which tries to locate and edit an existing
34
- * comment before creating a new one. If this is not provided, the ID will be
35
- * inferred from the GitHub Users API.
36
- *
37
- * https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
38
- *
39
- * If you're at SEEK and using BuildAgency's GitHub API integration, you may
40
- * use `'seek-build-agency'` as an optimisation to skip the user lookup.
41
- *
42
- * https://api.github.com/users/buildagencygitapitoken[bot]
43
- */
44
- userId?: number | 'seek-build-agency';
45
- }
46
- interface IssueComment {
47
- id: number;
48
- }
49
- /**
50
- * Asynchronously creates or updates a GitHub issue comment.
51
- *
52
- * This emulates `put` behaviour by overwriting the first existing comment by
53
- * the same author on the issue, enabling use cases like a persistent bot
54
- * comment at the top of the pull request that reflects the current status of a
55
- * CI check.
56
- *
57
- * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with write permissions must be present
58
- * on the environment.
59
- */
60
- export declare const putIssueComment: (params: PutIssueCommentParameters) => Promise<IssueComment | null>;
61
- export {};
@@ -1,99 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var issueComment_exports = {};
30
- __export(issueComment_exports, {
31
- putIssueComment: () => putIssueComment
32
- });
33
- module.exports = __toCommonJS(issueComment_exports);
34
- var Git = __toESM(require("../git/index.js"));
35
- var import_environment = require("./environment.js");
36
- var import_octokit = require("./octokit.js");
37
- var import_pullRequest = require("./pullRequest.js");
38
- const getUserId = async (client) => {
39
- const { data } = await client.users.getAuthenticated();
40
- return data.id;
41
- };
42
- const putIssueComment = async (params) => {
43
- if (params.body === null && !params.internalId) {
44
- throw new Error("Cannot remove comment without an internalId");
45
- }
46
- const env = params.env ?? process.env;
47
- const dir = process.cwd();
48
- const { owner, repo } = await Git.getOwnerAndRepo({ dir });
49
- const client = await (0, import_octokit.createRestClient)({ auth: (0, import_environment.apiTokenFromEnvironment)() });
50
- const issueNumber = params.issueNumber ?? await (0, import_pullRequest.getPullRequestNumber)({ client, env });
51
- if (!issueNumber) {
52
- throw new Error("Failed to infer an issue number");
53
- }
54
- const comments = await client.issues.listComments({
55
- issue_number: issueNumber,
56
- owner,
57
- repo
58
- });
59
- const userId = params.userId === "seek-build-agency" ? (
60
- // https://api.github.com/users/buildagencygitapitoken[bot]
61
- 87109344
62
- ) : params.userId ?? await getUserId(client);
63
- const commentId = comments.data.find(
64
- (comment) => comment.user?.id === userId && (params.internalId ? comment.body?.endsWith(`
65
-
66
- <!-- ${params.internalId} -->`) : true)
67
- )?.id;
68
- if (params.body === null) {
69
- if (commentId) {
70
- await client.issues.deleteComment({
71
- comment_id: commentId,
72
- owner,
73
- repo
74
- });
75
- }
76
- return null;
77
- }
78
- const body = params.internalId ? [params.body.trim(), `<!-- ${params.internalId} -->`].join("\n\n") : params.body.trim();
79
- const response = await (commentId ? client.issues.updateComment({
80
- body,
81
- comment_id: commentId,
82
- issue_number: issueNumber,
83
- owner,
84
- repo
85
- }) : client.issues.createComment({
86
- body,
87
- issue_number: issueNumber,
88
- owner,
89
- repo
90
- }));
91
- return {
92
- id: response.data.id
93
- };
94
- };
95
- // Annotate the CommonJS export names for ESM import in node:
96
- 0 && (module.exports = {
97
- putIssueComment
98
- });
99
- //# sourceMappingURL=issueComment.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/api/github/issueComment.ts"],
4
- "sourcesContent": ["import type { Octokit } from '@octokit/rest';\n\nimport * as Git from '../git/index.js';\n\nimport { apiTokenFromEnvironment } from './environment.js';\nimport { createRestClient } from './octokit.js';\nimport { getPullRequestNumber } from './pullRequest.js';\n\nconst getUserId = async (client: Octokit): Promise<number> => {\n const { data } = await client.users.getAuthenticated();\n\n return data.id;\n};\n\n/**\n * https://docs.github.com/en/rest/reference/issues#create-an-issue-comment\n */\ninterface PutIssueCommentParameters {\n /**\n * The body of the issue comment.\n *\n * An explicit `null` value will remove the comment, if `internalId` is provided.\n */\n body: string | null;\n\n /**\n * An internal identifier for the issue comment.\n *\n * This can be used to scope a given `put` to a particular comment, preventing\n * it from clobbering other comments from the same bot or user.\n *\n * The identifier is embedded as hidden content in the comment body.\n */\n internalId?: string;\n\n env?: Record<string, string | undefined>;\n\n /**\n * The number that identifies the GitHub issue.\n *\n * If this is not provided, the number will be inferred from the GitHub Repos\n * API by finding the latest pull request associated with the head commit.\n *\n * https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit\n */\n issueNumber?: number;\n\n /**\n * The ID of authenticated bot or user that is putting the issue comment.\n *\n * This drives our `put` behaviour, which tries to locate and edit an existing\n * comment before creating a new one. If this is not provided, the ID will be\n * inferred from the GitHub Users API.\n *\n * https://docs.github.com/en/rest/reference/users#get-the-authenticated-user\n *\n * If you're at SEEK and using BuildAgency's GitHub API integration, you may\n * use `'seek-build-agency'` as an optimisation to skip the user lookup.\n *\n * https://api.github.com/users/buildagencygitapitoken[bot]\n */\n userId?: number | 'seek-build-agency';\n}\n\ninterface IssueComment {\n id: number;\n}\n\n/**\n * Asynchronously creates or updates a GitHub issue comment.\n *\n * This emulates `put` behaviour by overwriting the first existing comment by\n * the same author on the issue, enabling use cases like a persistent bot\n * comment at the top of the pull request that reflects the current status of a\n * CI check.\n *\n * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with write permissions must be present\n * on the environment.\n */\nexport const putIssueComment = async (\n params: PutIssueCommentParameters,\n): Promise<IssueComment | null> => {\n if (params.body === null && !params.internalId) {\n // It's dangerous to just delete the first comment, as it may not be\n // from the current flow.\n throw new Error('Cannot remove comment without an internalId');\n }\n\n const env = params.env ?? process.env;\n\n const dir = process.cwd();\n\n const { owner, repo } = await Git.getOwnerAndRepo({ dir });\n\n const client = await createRestClient({ auth: apiTokenFromEnvironment() });\n\n const issueNumber =\n params.issueNumber ?? (await getPullRequestNumber({ client, env }));\n\n if (!issueNumber) {\n throw new Error('Failed to infer an issue number');\n }\n\n const comments = await client.issues.listComments({\n issue_number: issueNumber,\n owner,\n repo,\n });\n\n const userId: number =\n params.userId === 'seek-build-agency'\n ? // https://api.github.com/users/buildagencygitapitoken[bot]\n 87109344\n : (params.userId ?? (await getUserId(client)));\n\n const commentId = comments.data.find(\n (comment) =>\n comment.user?.id === userId &&\n (params.internalId\n ? comment.body?.endsWith(`\\n\\n<!-- ${params.internalId} -->`)\n : true),\n )?.id;\n\n if (params.body === null) {\n if (commentId) {\n await client.issues.deleteComment({\n comment_id: commentId,\n owner,\n repo,\n });\n }\n\n return null;\n }\n\n const body = params.internalId\n ? [params.body.trim(), `<!-- ${params.internalId} -->`].join('\\n\\n')\n : params.body.trim();\n\n const response = await (commentId\n ? client.issues.updateComment({\n body,\n comment_id: commentId,\n issue_number: issueNumber,\n owner,\n repo,\n })\n : client.issues.createComment({\n body,\n issue_number: issueNumber,\n owner,\n repo,\n }));\n\n return {\n id: response.data.id,\n };\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,UAAqB;AAErB,yBAAwC;AACxC,qBAAiC;AACjC,yBAAqC;AAErC,MAAM,YAAY,OAAO,WAAqC;AAC5D,QAAM,EAAE,KAAK,IAAI,MAAM,OAAO,MAAM,iBAAiB;AAErD,SAAO,KAAK;AACd;AAmEO,MAAM,kBAAkB,OAC7B,WACiC;AACjC,MAAI,OAAO,SAAS,QAAQ,CAAC,OAAO,YAAY;AAG9C,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AAEA,QAAM,MAAM,OAAO,OAAO,QAAQ;AAElC,QAAM,MAAM,QAAQ,IAAI;AAExB,QAAM,EAAE,OAAO,KAAK,IAAI,MAAM,IAAI,gBAAgB,EAAE,IAAI,CAAC;AAEzD,QAAM,SAAS,UAAM,iCAAiB,EAAE,UAAM,4CAAwB,EAAE,CAAC;AAEzE,QAAM,cACJ,OAAO,eAAgB,UAAM,yCAAqB,EAAE,QAAQ,IAAI,CAAC;AAEnE,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,WAAW,MAAM,OAAO,OAAO,aAAa;AAAA,IAChD,cAAc;AAAA,IACd;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,SACJ,OAAO,WAAW;AAAA;AAAA,IAEd;AAAA,MACC,OAAO,UAAW,MAAM,UAAU,MAAM;AAE/C,QAAM,YAAY,SAAS,KAAK;AAAA,IAC9B,CAAC,YACC,QAAQ,MAAM,OAAO,WACpB,OAAO,aACJ,QAAQ,MAAM,SAAS;AAAA;AAAA,OAAY,OAAO,UAAU,MAAM,IAC1D;AAAA,EACR,GAAG;AAEH,MAAI,OAAO,SAAS,MAAM;AACxB,QAAI,WAAW;AACb,YAAM,OAAO,OAAO,cAAc;AAAA,QAChC,YAAY;AAAA,QACZ;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,OAAO,aAChB,CAAC,OAAO,KAAK,KAAK,GAAG,QAAQ,OAAO,UAAU,MAAM,EAAE,KAAK,MAAM,IACjE,OAAO,KAAK,KAAK;AAErB,QAAM,WAAW,OAAO,YACpB,OAAO,OAAO,cAAc;AAAA,IAC1B;AAAA,IACA,YAAY;AAAA,IACZ,cAAc;AAAA,IACd;AAAA,IACA;AAAA,EACF,CAAC,IACD,OAAO,OAAO,cAAc;AAAA,IAC1B;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA;AAAA,EACF,CAAC;AAEL,SAAO;AAAA,IACL,IAAI,SAAS,KAAK;AAAA,EACpB;AACF;",
6
- "names": []
7
- }
@@ -1,6 +0,0 @@
1
- import type { Octokit } from '@octokit/rest';
2
- import type { RequestParameters } from '@octokit/types';
3
- export declare const createRestClient: (options: {
4
- auth: unknown;
5
- }) => Promise<Octokit>;
6
- export declare const graphql: <ResponseData>(query: string, parameters?: RequestParameters) => Promise<ResponseData>;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var octokit_exports = {};
30
- __export(octokit_exports, {
31
- createRestClient: () => createRestClient,
32
- graphql: () => graphql
33
- });
34
- module.exports = __toCommonJS(octokit_exports);
35
- const createRestClient = async (options) => new (await import("@octokit/rest")).Octokit(options);
36
- const graphql = async (query, parameters) => (await import("@octokit/graphql")).graphql(query, parameters);
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {
39
- createRestClient,
40
- graphql
41
- });
42
- //# sourceMappingURL=octokit.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/api/github/octokit.ts"],
4
- "sourcesContent": ["import type { Octokit } from '@octokit/rest';\nimport type { RequestParameters } from '@octokit/types';\n\nexport const createRestClient = async (options: {\n auth: unknown;\n}): Promise<Octokit> => new (await import('@octokit/rest')).Octokit(options);\n\nexport const graphql = async <ResponseData>(\n query: string,\n parameters?: RequestParameters,\n) =>\n (await import('@octokit/graphql')).graphql<ResponseData>(query, parameters);\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,mBAAmB,OAAO,YAEf,KAAK,MAAM,OAAO,eAAe,GAAG,QAAQ,OAAO;AAEpE,MAAM,UAAU,OACrB,OACA,gBAEC,MAAM,OAAO,kBAAkB,GAAG,QAAsB,OAAO,UAAU;",
6
- "names": []
7
- }
@@ -1,21 +0,0 @@
1
- import type { Octokit } from '@octokit/rest' with { 'resolution-mode': 'import' };
2
- interface GetPullRequestParameters {
3
- /**
4
- * A preconstructed Octokit client to interact with GitHub's APIs.
5
- *
6
- * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with write permissions must be
7
- * present on the environment if this is not provided.
8
- */
9
- client?: Octokit;
10
- env?: Record<string, string | undefined>;
11
- }
12
- /**
13
- * Gets the number of the current pull request.
14
- *
15
- * This tries to extract the pull request from common CI environment variables,
16
- * and falls back to querying the GitHub Repos API for the latest pull request
17
- * associated with the head commit. An error is thrown if there are no
18
- * associated pull requests, or if they are all closed or locked.
19
- */
20
- export declare const getPullRequestNumber: (params?: GetPullRequestParameters) => Promise<number>;
21
- export {};
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var pullRequest_exports = {};
30
- __export(pullRequest_exports, {
31
- getPullRequestNumber: () => getPullRequestNumber
32
- });
33
- module.exports = __toCommonJS(pullRequest_exports);
34
- var Git = __toESM(require("../git/index.js"));
35
- var import_environment = require("./environment.js");
36
- var import_octokit = require("./octokit.js");
37
- const getPullRequestNumber = async (params = {}) => {
38
- const env = params.env ?? process.env;
39
- const dir = process.cwd();
40
- const number = Number(
41
- env.BUILDKITE_PULL_REQUEST ?? env.GITHUB_REF?.replace(/^refs\/pull\/(\d+).*$/, "$1")
42
- );
43
- if (Number.isSafeInteger(number)) {
44
- return number;
45
- }
46
- const client = params.client ?? await (0, import_octokit.createRestClient)({ auth: (0, import_environment.apiTokenFromEnvironment)() });
47
- const [commitId, { owner, repo }] = await Promise.all([
48
- Git.getHeadCommitId({ dir, env }),
49
- Git.getOwnerAndRepo({ dir })
50
- ]);
51
- const response = await client.repos.listPullRequestsAssociatedWithCommit({
52
- commit_sha: commitId,
53
- owner,
54
- repo
55
- });
56
- const data = response.data.filter((pr) => pr.state === "open" && !pr.locked).sort((a, b) => b.updated_at.localeCompare(a.updated_at));
57
- const pullRequestData = data[0];
58
- if (!pullRequestData) {
59
- throw new Error(
60
- `Commit ${commitId} is not associated with an open GitHub pull request`
61
- );
62
- }
63
- return pullRequestData.number;
64
- };
65
- // Annotate the CommonJS export names for ESM import in node:
66
- 0 && (module.exports = {
67
- getPullRequestNumber
68
- });
69
- //# sourceMappingURL=pullRequest.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/api/github/pullRequest.ts"],
4
- "sourcesContent": ["import type { Octokit } from '@octokit/rest' with { 'resolution-mode': 'import' };\n\nimport * as Git from '../git/index.js';\n\nimport { apiTokenFromEnvironment } from './environment.js';\nimport { createRestClient } from './octokit.js';\n\ninterface GetPullRequestParameters {\n /**\n * A preconstructed Octokit client to interact with GitHub's APIs.\n *\n * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with write permissions must be\n * present on the environment if this is not provided.\n */\n client?: Octokit;\n\n env?: Record<string, string | undefined>;\n}\n\n/**\n * Gets the number of the current pull request.\n *\n * This tries to extract the pull request from common CI environment variables,\n * and falls back to querying the GitHub Repos API for the latest pull request\n * associated with the head commit. An error is thrown if there are no\n * associated pull requests, or if they are all closed or locked.\n */\nexport const getPullRequestNumber = async (\n params: GetPullRequestParameters = {},\n): Promise<number> => {\n const env = params.env ?? process.env;\n\n const dir = process.cwd();\n\n const number = Number(\n env.BUILDKITE_PULL_REQUEST ??\n env.GITHUB_REF?.replace(/^refs\\/pull\\/(\\d+).*$/, '$1'),\n );\n\n if (Number.isSafeInteger(number)) {\n return number;\n }\n\n const client =\n params.client ??\n (await createRestClient({ auth: apiTokenFromEnvironment() }));\n\n const [commitId, { owner, repo }] = await Promise.all([\n Git.getHeadCommitId({ dir, env }),\n Git.getOwnerAndRepo({ dir }),\n ]);\n\n const response = await client.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: commitId,\n owner,\n repo,\n });\n\n const data = response.data\n .filter((pr) => pr.state === 'open' && !pr.locked)\n .sort((a, b) => b.updated_at.localeCompare(a.updated_at));\n\n const pullRequestData = data[0];\n if (!pullRequestData) {\n throw new Error(\n `Commit ${commitId} is not associated with an open GitHub pull request`,\n );\n }\n\n return pullRequestData.number;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,UAAqB;AAErB,yBAAwC;AACxC,qBAAiC;AAsB1B,MAAM,uBAAuB,OAClC,SAAmC,CAAC,MAChB;AACpB,QAAM,MAAM,OAAO,OAAO,QAAQ;AAElC,QAAM,MAAM,QAAQ,IAAI;AAExB,QAAM,SAAS;AAAA,IACb,IAAI,0BACF,IAAI,YAAY,QAAQ,yBAAyB,IAAI;AAAA,EACzD;AAEA,MAAI,OAAO,cAAc,MAAM,GAAG;AAChC,WAAO;AAAA,EACT;AAEA,QAAM,SACJ,OAAO,UACN,UAAM,iCAAiB,EAAE,UAAM,4CAAwB,EAAE,CAAC;AAE7D,QAAM,CAAC,UAAU,EAAE,OAAO,KAAK,CAAC,IAAI,MAAM,QAAQ,IAAI;AAAA,IACpD,IAAI,gBAAgB,EAAE,KAAK,IAAI,CAAC;AAAA,IAChC,IAAI,gBAAgB,EAAE,IAAI,CAAC;AAAA,EAC7B,CAAC;AAED,QAAM,WAAW,MAAM,OAAO,MAAM,qCAAqC;AAAA,IACvE,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,OAAO,SAAS,KACnB,OAAO,CAAC,OAAO,GAAG,UAAU,UAAU,CAAC,GAAG,MAAM,EAChD,KAAK,CAAC,GAAG,MAAM,EAAE,WAAW,cAAc,EAAE,UAAU,CAAC;AAE1D,QAAM,kBAAkB,KAAK,CAAC;AAC9B,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI;AAAA,MACR,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAEA,SAAO,gBAAgB;AACzB;",
6
- "names": []
7
- }