skuba 3.15.3-beta.0 → 3.17.0-beta.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 (168) hide show
  1. package/jest-preset.js +1 -0
  2. package/lib/api/git/commit.d.ts +15 -0
  3. package/lib/api/git/commit.js +31 -0
  4. package/lib/api/git/commit.js.map +1 -0
  5. package/lib/api/git/commitAllChanges.d.ts +12 -0
  6. package/lib/api/git/commitAllChanges.js +36 -0
  7. package/lib/api/git/commitAllChanges.js.map +1 -0
  8. package/lib/api/git/getChangedFiles.d.ts +14 -0
  9. package/lib/api/git/getChangedFiles.js +41 -0
  10. package/lib/api/git/getChangedFiles.js.map +1 -0
  11. package/lib/api/git/index.d.ts +7 -0
  12. package/lib/api/git/index.js +18 -0
  13. package/lib/api/git/index.js.map +1 -0
  14. package/lib/api/git/log.d.ts +12 -0
  15. package/lib/api/git/log.js +37 -0
  16. package/lib/api/git/log.js.map +1 -0
  17. package/lib/api/git/push.d.ts +43 -0
  18. package/lib/api/git/push.js +46 -0
  19. package/lib/api/git/push.js.map +1 -0
  20. package/lib/api/git/remote.d.ts +18 -0
  21. package/lib/api/git/remote.js +57 -0
  22. package/lib/api/git/remote.js.map +1 -0
  23. package/lib/api/git/reset.d.ts +12 -0
  24. package/lib/api/git/reset.js +39 -0
  25. package/lib/api/git/reset.js.map +1 -0
  26. package/lib/api/git/statusMatrix.d.ts +7 -0
  27. package/lib/api/git/statusMatrix.js +14 -0
  28. package/lib/api/git/statusMatrix.js.map +1 -0
  29. package/lib/api/github/checkRun.d.ts +37 -4
  30. package/lib/api/github/checkRun.js +60 -59
  31. package/lib/api/github/checkRun.js.map +1 -1
  32. package/lib/api/github/environment.d.ts +22 -0
  33. package/lib/api/github/environment.js +42 -0
  34. package/lib/api/github/environment.js.map +1 -0
  35. package/lib/api/github/index.d.ts +2 -1
  36. package/lib/api/github/index.js +5 -2
  37. package/lib/api/github/index.js.map +1 -1
  38. package/lib/api/github/issueComment.d.ts +59 -0
  39. package/lib/api/github/issueComment.js +96 -0
  40. package/lib/api/github/issueComment.js.map +1 -0
  41. package/lib/api/github/pullRequest.d.ts +21 -0
  42. package/lib/api/github/pullRequest.js +70 -0
  43. package/lib/api/github/pullRequest.js.map +1 -0
  44. package/lib/api/jest/index.d.ts +2 -2
  45. package/lib/api/jest/index.js.map +1 -1
  46. package/lib/api/net/waitFor.d.ts +1 -1
  47. package/lib/api/net/waitFor.js.map +1 -1
  48. package/lib/cli/adapter/eslint.d.ts +2 -2
  49. package/lib/cli/adapter/eslint.js +3 -4
  50. package/lib/cli/adapter/eslint.js.map +1 -1
  51. package/lib/cli/adapter/prettier.d.ts +22 -1
  52. package/lib/cli/adapter/prettier.js +49 -17
  53. package/lib/cli/adapter/prettier.js.map +1 -1
  54. package/lib/cli/configure/analyseConfiguration.d.ts +1 -1
  55. package/lib/cli/configure/analyseDependencies.d.ts +2 -2
  56. package/lib/cli/configure/analyseDependencies.js.map +1 -1
  57. package/lib/cli/configure/analysis/package.d.ts +1 -1
  58. package/lib/cli/configure/analysis/project.d.ts +1 -1
  59. package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.d.ts +1 -1
  60. package/lib/cli/configure/dependencies/seekKoala.d.ts +1 -1
  61. package/lib/cli/configure/dependencies/skuba.d.ts +1 -1
  62. package/lib/cli/configure/dependencies/skubaDeps.d.ts +1 -1
  63. package/lib/cli/configure/dependencies/skubaDive.d.ts +1 -1
  64. package/lib/cli/configure/ensureTemplateCompletion.d.ts +2 -2
  65. package/lib/cli/configure/ensureTemplateCompletion.js.map +1 -1
  66. package/lib/cli/configure/getEntryPoint.d.ts +3 -3
  67. package/lib/cli/configure/getProjectType.d.ts +2 -2
  68. package/lib/cli/configure/modules/eslint.d.ts +1 -1
  69. package/lib/cli/configure/modules/ignore.d.ts +1 -1
  70. package/lib/cli/configure/modules/index.d.ts +1 -1
  71. package/lib/cli/configure/modules/jest.d.ts +1 -1
  72. package/lib/cli/configure/modules/nodemon.d.ts +1 -1
  73. package/lib/cli/configure/modules/package.d.ts +1 -1
  74. package/lib/cli/configure/modules/prettier.d.ts +1 -1
  75. package/lib/cli/configure/modules/renovate.d.ts +1 -1
  76. package/lib/cli/configure/modules/serverless.d.ts +1 -1
  77. package/lib/cli/configure/modules/skubaDive.d.ts +1 -1
  78. package/lib/cli/configure/modules/tsconfig.d.ts +1 -1
  79. package/lib/cli/configure/modules/tslint.d.ts +1 -1
  80. package/lib/cli/configure/processing/deleteFiles.d.ts +1 -1
  81. package/lib/cli/configure/processing/loadFiles.d.ts +1 -1
  82. package/lib/cli/configure/processing/package.d.ts +1 -1
  83. package/lib/cli/configure/processing/typescript.js +1 -1
  84. package/lib/cli/configure/processing/typescript.js.map +1 -1
  85. package/lib/cli/configure/refreshIgnoreFiles.d.ts +2 -0
  86. package/lib/cli/configure/refreshIgnoreFiles.js +55 -0
  87. package/lib/cli/configure/refreshIgnoreFiles.js.map +1 -0
  88. package/lib/cli/configure/types.d.ts +1 -1
  89. package/lib/cli/format.js +2 -0
  90. package/lib/cli/format.js.map +1 -1
  91. package/lib/cli/init/getConfig.d.ts +2 -2
  92. package/lib/cli/init/getConfig.js.map +1 -1
  93. package/lib/cli/init/git.js +22 -8
  94. package/lib/cli/init/git.js.map +1 -1
  95. package/lib/cli/init/writePackageJson.d.ts +1 -1
  96. package/lib/cli/lint/annotate/buildkite/eslint.d.ts +1 -1
  97. package/lib/cli/lint/annotate/buildkite/index.d.ts +3 -3
  98. package/lib/cli/lint/annotate/buildkite/prettier.d.ts +1 -1
  99. package/lib/cli/lint/annotate/buildkite/tsc.d.ts +1 -1
  100. package/lib/cli/lint/annotate/buildkite/tsc.js +0 -1
  101. package/lib/cli/lint/annotate/buildkite/tsc.js.map +1 -1
  102. package/lib/cli/lint/annotate/github/eslint.d.ts +2 -2
  103. package/lib/cli/lint/annotate/github/eslint.js +1 -1
  104. package/lib/cli/lint/annotate/github/eslint.js.map +1 -1
  105. package/lib/cli/lint/annotate/github/index.d.ts +4 -4
  106. package/lib/cli/lint/annotate/github/index.js +14 -7
  107. package/lib/cli/lint/annotate/github/index.js.map +1 -1
  108. package/lib/cli/lint/annotate/github/prettier.d.ts +2 -2
  109. package/lib/cli/lint/annotate/github/prettier.js +11 -8
  110. package/lib/cli/lint/annotate/github/prettier.js.map +1 -1
  111. package/lib/cli/lint/annotate/github/tsc.d.ts +2 -2
  112. package/lib/cli/lint/annotate/github/tsc.js +37 -34
  113. package/lib/cli/lint/annotate/github/tsc.js.map +1 -1
  114. package/lib/cli/lint/annotate/index.d.ts +4 -4
  115. package/lib/cli/lint/annotate/index.js +2 -2
  116. package/lib/cli/lint/annotate/index.js.map +1 -1
  117. package/lib/cli/lint/eslint.d.ts +1 -1
  118. package/lib/cli/lint/eslint.js.map +1 -1
  119. package/lib/cli/lint/external.js +13 -7
  120. package/lib/cli/lint/external.js.map +1 -1
  121. package/lib/cli/lint/index.js +2 -0
  122. package/lib/cli/lint/index.js.map +1 -1
  123. package/lib/cli/lint/prettier.d.ts +1 -1
  124. package/lib/cli/lint/prettier.js.map +1 -1
  125. package/lib/cli/node.js +1 -1
  126. package/lib/cli/node.js.map +1 -1
  127. package/lib/cli/start.js +1 -1
  128. package/lib/cli/start.js.map +1 -1
  129. package/lib/cli/{test.d.ts → test/index.d.ts} +0 -0
  130. package/lib/cli/{test.js → test/index.js} +4 -4
  131. package/lib/cli/test/index.js.map +1 -0
  132. package/lib/cli/test/reporters/github/annotations.d.ts +9 -0
  133. package/lib/cli/test/reporters/github/annotations.js +86 -0
  134. package/lib/cli/test/reporters/github/annotations.js.map +1 -0
  135. package/lib/cli/test/reporters/github/index.d.ts +5 -0
  136. package/lib/cli/test/reporters/github/index.js +69 -0
  137. package/lib/cli/test/reporters/github/index.js.map +1 -0
  138. package/lib/index.d.ts +2 -1
  139. package/lib/index.js +3 -2
  140. package/lib/index.js.map +1 -1
  141. package/lib/utils/args.d.ts +1 -1
  142. package/lib/utils/exec.d.ts +2 -1
  143. package/lib/utils/exec.js.map +1 -1
  144. package/lib/utils/logging.d.ts +1 -2
  145. package/lib/utils/logging.js +3 -2
  146. package/lib/utils/logging.js.map +1 -1
  147. package/lib/utils/manifest.d.ts +2 -1
  148. package/lib/utils/manifest.js.map +1 -1
  149. package/lib/utils/worker.d.ts +0 -1
  150. package/lib/wrapper/functionHandler.js +4 -1
  151. package/lib/wrapper/functionHandler.js.map +1 -1
  152. package/package.json +12 -9
  153. package/template/base/_.gitignore +1 -0
  154. package/template/express-rest-api/.buildkite/pipeline.yml +2 -0
  155. package/template/express-rest-api/docker-compose.yml +4 -2
  156. package/template/greeter/.buildkite/pipeline.yml +2 -0
  157. package/template/greeter/docker-compose.yml +4 -2
  158. package/template/koa-rest-api/.buildkite/pipeline.yml +2 -0
  159. package/template/koa-rest-api/docker-compose.yml +4 -2
  160. package/template/lambda-sqs-worker/.buildkite/pipeline.yml +3 -1
  161. package/template/lambda-sqs-worker/docker-compose.yml +3 -1
  162. package/template/lambda-sqs-worker/serverless.yml +1 -0
  163. package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +3 -1
  164. package/template/lambda-sqs-worker-cdk/docker-compose.yml +3 -1
  165. package/lib/cli/test.js.map +0 -1
  166. package/lib/register.d.ts +0 -20
  167. package/lib/register.js +0 -44
  168. package/lib/register.js.map +0 -1
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -9,82 +28,64 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
28
  });
10
29
  };
11
30
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createCheckRunFromBuildkite = void 0;
31
+ exports.createCheckRun = void 0;
13
32
  const rest_1 = require("@octokit/rest");
33
+ const logging_1 = require("../../utils/logging");
34
+ const Git = __importStar(require("../git"));
35
+ const environment_1 = require("./environment");
14
36
  const GITHUB_MAX_ANNOTATIONS = 50;
15
- const isGitHubAnnotationsEnabled = () => Boolean(process.env.BUILDKITE_BUILD_NUMBER &&
16
- process.env.BUILDKITE_COMMIT &&
17
- process.env.BUILDKITE_REPO &&
18
- process.env.GITHUB_API_TOKEN);
19
- // Pulls out the GitHub Owner + Repo String from repo urls eg.
20
- // git@github.com:seek-oss/skuba.git
21
- // https://github.com/seek-oss/skuba.git
22
- // Pulls out `seek-oss` as owner and `skuba` as repo
23
- const ownerRepoRegex = new RegExp(/github.com(?::|\/)(.*)\/(.*).git/);
24
- const getOwnerRepo = () => {
25
- const match = ownerRepoRegex.exec(process.env.BUILDKITE_REPO);
26
- const owner = match === null || match === void 0 ? void 0 : match[1];
27
- const repo = match === null || match === void 0 ? void 0 : match[2];
28
- if (!owner || !repo) {
29
- throw new Error('Could not extract GitHub owner/repo from BUILDKITE_REPO environment variable');
30
- }
31
- return {
32
- owner,
33
- repo,
34
- };
35
- };
36
37
  /**
37
- * Create a uniform title format for our check runs
38
- * @param conclusion - `failure` or `success`
39
- * @param annotationsLength - Number of annotations added
40
- * @returns Title eg. Build #12 failed (24 annotations added)
38
+ * Suffixes the title with the number of annotations added, e.g.
39
+ *
40
+ * ```text
41
+ * Build #12 failed (24 annotations added)
42
+ * ```
41
43
  */
42
- const createTitle = (conclusion, annotationsLength) => {
43
- const build = `Build #${process.env.BUILDKITE_BUILD_NUMBER}`;
44
- const numAnnotations = annotationsLength > GITHUB_MAX_ANNOTATIONS
44
+ const suffixTitle = (title, inputAnnotations) => {
45
+ const addedAnnotations = inputAnnotations > GITHUB_MAX_ANNOTATIONS
45
46
  ? GITHUB_MAX_ANNOTATIONS
46
- : annotationsLength;
47
- const status = conclusion === 'success' ? 'passed' : 'failed';
48
- const plural = numAnnotations === 1 ? '' : 's';
49
- return `${build} ${status} (${numAnnotations} annotation${plural} added)`;
47
+ : inputAnnotations;
48
+ return `${title} (${(0, logging_1.pluralise)(addedAnnotations, 'annotation')} added)`;
50
49
  };
51
50
  /**
52
- * Adds more context to the summary provided
53
- * @param summary - report summary
54
- * @param annotationsLength - Number of annotations added
55
- * @returns summary with extra metadata
51
+ * Enriches the summary with more context about the check run.
56
52
  */
57
- const createEnrichedSummary = (summary, annotationsLength) => [
53
+ const createEnrichedSummary = (summary, inputAnnotations) => [
58
54
  summary,
59
- ...(annotationsLength > GITHUB_MAX_ANNOTATIONS
55
+ ...(inputAnnotations > GITHUB_MAX_ANNOTATIONS
60
56
  ? [
61
- `There were ${annotationsLength} annotations created. However, the number of annotations displayed has been capped to ${GITHUB_MAX_ANNOTATIONS}`,
57
+ `${inputAnnotations} annotations were provided, but only the first ${GITHUB_MAX_ANNOTATIONS} are visible in GitHub.`,
62
58
  ]
63
59
  : []),
64
60
  ].join('\n\n');
65
- const createCheckRunFromBuildkite = ({ name, summary, annotations, conclusion, }) => __awaiter(void 0, void 0, void 0, function* () {
66
- if (!isGitHubAnnotationsEnabled()) {
67
- return;
68
- }
69
- const client = new rest_1.Octokit({
70
- auth: process.env.GITHUB_API_TOKEN,
71
- });
72
- const { owner, repo } = getOwnerRepo();
73
- const title = createTitle(conclusion, annotations.length);
74
- const enrichedSummary = createEnrichedSummary(summary, annotations.length);
75
- const checkRunName = `skuba/${name}`;
61
+ /**
62
+ * Asynchronously creates a GitHub check run with annotations.
63
+ *
64
+ * The first 50 `annotations` are written in full to GitHub.
65
+ *
66
+ * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with the `checks:write` permission
67
+ * must be present on the environment.
68
+ */
69
+ const createCheckRun = ({ annotations, conclusion, name, summary, text, title, }) => __awaiter(void 0, void 0, void 0, function* () {
70
+ const dir = process.cwd();
71
+ const [commitId, { owner, repo }] = yield Promise.all([
72
+ Git.getHeadCommitId({ dir }),
73
+ Git.getOwnerAndRepo({ dir }),
74
+ ]);
75
+ const client = new rest_1.Octokit({ auth: (0, environment_1.apiTokenFromEnvironment)() });
76
76
  yield client.checks.create({
77
- owner,
78
- repo,
79
- name: checkRunName,
77
+ conclusion,
78
+ head_sha: commitId,
79
+ name,
80
80
  output: {
81
- title,
82
- summary: enrichedSummary,
83
81
  annotations: annotations.slice(0, GITHUB_MAX_ANNOTATIONS),
82
+ summary: createEnrichedSummary(summary, annotations.length),
83
+ text,
84
+ title: suffixTitle(title, annotations.length),
84
85
  },
85
- head_sha: process.env.BUILDKITE_COMMIT,
86
- conclusion,
86
+ owner,
87
+ repo,
87
88
  });
88
89
  });
89
- exports.createCheckRunFromBuildkite = createCheckRunFromBuildkite;
90
+ exports.createCheckRun = createCheckRun;
90
91
  //# sourceMappingURL=checkRun.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkRun.js","sourceRoot":"","sources":["../../../src/api/github/checkRun.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAwC;AASxC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC,MAAM,0BAA0B,GAAG,GAAY,EAAE,CAC/C,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,sBAAsB;IAChC,OAAO,CAAC,GAAG,CAAC,gBAAgB;IAC5B,OAAO,CAAC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M,CAAC,MAAM,CAAC;QACzB,UAAU;QACV,QAAQ,EAAE,QAAQ;QAClB,IAAI;QACJ,MAAM,EAAE;YACN,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAsB,CAAC;YACzD,OAAO,EAAE,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC;YAC3D,IAAI;YACJ,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC;SAC9C;QACD,KAAK;QACL,IAAI;KACL,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AA9BW,QAAA,cAAc,kBA8BzB"}
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Returns the name of the build as seen in GitHub status checks.
4
+ *
5
+ * This is driven off of environment variables and falls back to `Build`.
6
+ */
7
+ export declare const buildNameFromEnvironment: (env?: NodeJS.ProcessEnv) => string;
8
+ /**
9
+ * Whether GitHub API interactions should be enabled.
10
+ *
11
+ * This checks environment variables to see if the code is executing in a CI
12
+ * environment and has access to a GitHub API token.
13
+ */
14
+ export declare const enabledFromEnvironment: (env?: NodeJS.ProcessEnv) => boolean;
15
+ /**
16
+ * Tries to return a GitHub API token from the environment.
17
+ */
18
+ export declare const apiTokenFromEnvironment: (env?: NodeJS.ProcessEnv) => string | undefined;
19
+ /**
20
+ * Tries to return a branch name from CI environment variables.
21
+ */
22
+ export declare const currentBranchFromEnvironment: (env?: NodeJS.ProcessEnv) => string | undefined;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.currentBranchFromEnvironment = exports.apiTokenFromEnvironment = exports.enabledFromEnvironment = exports.buildNameFromEnvironment = void 0;
4
+ /**
5
+ * Returns the name of the build as seen in GitHub status checks.
6
+ *
7
+ * This is driven off of environment variables and falls back to `Build`.
8
+ */
9
+ const buildNameFromEnvironment = (env = process.env) => {
10
+ var _a;
11
+ if (env.BUILDKITE_BUILD_NUMBER) {
12
+ return `Build #${env.BUILDKITE_BUILD_NUMBER}`;
13
+ }
14
+ if (env.GITHUB_RUN_NUMBER) {
15
+ return `${(_a = env.GITHUB_WORKFLOW) !== null && _a !== void 0 ? _a : 'Build'} #${env.GITHUB_RUN_NUMBER}`;
16
+ }
17
+ return 'Build';
18
+ };
19
+ exports.buildNameFromEnvironment = buildNameFromEnvironment;
20
+ /**
21
+ * Whether GitHub API interactions should be enabled.
22
+ *
23
+ * This checks environment variables to see if the code is executing in a CI
24
+ * environment and has access to a GitHub API token.
25
+ */
26
+ const enabledFromEnvironment = (env = process.env) =>
27
+ // Running in a CI environment.
28
+ Boolean(env.BUILDKITE || env.CI || env.GITHUB_ACTIONS) &&
29
+ // Has an API token at the ready.
30
+ Boolean((0, exports.apiTokenFromEnvironment)(env));
31
+ exports.enabledFromEnvironment = enabledFromEnvironment;
32
+ /**
33
+ * Tries to return a GitHub API token from the environment.
34
+ */
35
+ const apiTokenFromEnvironment = (env = process.env) => { var _a; return (_a = env.GITHUB_API_TOKEN) !== null && _a !== void 0 ? _a : env.GITHUB_TOKEN; };
36
+ exports.apiTokenFromEnvironment = apiTokenFromEnvironment;
37
+ /**
38
+ * Tries to return a branch name from CI environment variables.
39
+ */
40
+ const currentBranchFromEnvironment = (env = process.env) => { var _a; return (_a = env.BUILDKITE_BRANCH) !== null && _a !== void 0 ? _a : env.GITHUB_REF_NAME; };
41
+ exports.currentBranchFromEnvironment = currentBranchFromEnvironment;
42
+ //# sourceMappingURL=environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/api/github/environment.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAU,EAAE;;IACpE,IAAI,GAAG,CAAC,sBAAsB,EAAE;QAC9B,OAAO,UAAU,GAAG,CAAC,sBAAsB,EAAE,CAAC;KAC/C;IAED,IAAI,GAAG,CAAC,iBAAiB,EAAE;QACzB,OAAO,GAAG,MAAA,GAAG,CAAC,eAAe,mCAAI,OAAO,KAAK,GAAG,CAAC,iBAAiB,EAAE,CAAC;KACtE;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAVW,QAAA,wBAAwB,4BAUnC;AAEF;;;;;GAKG;AACI,MAAM,sBAAsB,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAW,EAAE;AACnE,+BAA+B;AAC/B,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,cAAc,CAAC;IACtD,iCAAiC;IACjC,OAAO,CAAC,IAAA,+BAAuB,EAAC,GAAG,CAAC,CAAC,CAAC;AAJ3B,QAAA,sBAAsB,0BAIK;AAExC;;GAEG;AACI,MAAM,uBAAuB,GAAG,CACrC,GAAG,GAAG,OAAO,CAAC,GAAG,EACG,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,gBAAgB,mCAAI,GAAG,CAAC,YAAY,CAAA,EAAA,CAAC;AAFrD,QAAA,uBAAuB,2BAE8B;AAElE;;GAEG;AACI,MAAM,4BAA4B,GAAG,CAC1C,GAAG,GAAG,OAAO,CAAC,GAAG,EACG,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,gBAAgB,mCAAI,GAAG,CAAC,eAAe,CAAA,EAAA,CAAC;AAFxD,QAAA,4BAA4B,gCAE4B"}
@@ -1,2 +1,3 @@
1
1
  export type { Annotation } from './checkRun';
2
- export { createCheckRunFromBuildkite } from './checkRun';
2
+ export { createCheckRun } from './checkRun';
3
+ export { buildNameFromEnvironment, enabledFromEnvironment, } from './environment';
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCheckRunFromBuildkite = void 0;
3
+ exports.enabledFromEnvironment = exports.buildNameFromEnvironment = exports.createCheckRun = void 0;
4
4
  var checkRun_1 = require("./checkRun");
5
- Object.defineProperty(exports, "createCheckRunFromBuildkite", { enumerable: true, get: function () { return checkRun_1.createCheckRunFromBuildkite; } });
5
+ Object.defineProperty(exports, "createCheckRun", { enumerable: true, get: function () { return checkRun_1.createCheckRun; } });
6
+ var environment_1 = require("./environment");
7
+ Object.defineProperty(exports, "buildNameFromEnvironment", { enumerable: true, get: function () { return environment_1.buildNameFromEnvironment; } });
8
+ Object.defineProperty(exports, "enabledFromEnvironment", { enumerable: true, get: function () { return environment_1.enabledFromEnvironment; } });
6
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/github/index.ts"],"names":[],"mappings":";;;AACA,uCAAyD;AAAhD,uHAAA,2BAA2B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/github/index.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAAnC,0GAAA,cAAc,OAAA;AACvB,6CAGuB;AAFrB,uHAAA,wBAAwB,OAAA;AACxB,qHAAA,sBAAsB,OAAA"}
@@ -0,0 +1,59 @@
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
+ body: string;
9
+ /**
10
+ * An internal identifier for the issue comment.
11
+ *
12
+ * This can be used to scope a given `put` to a particular comment, preventing
13
+ * it from clobbering other comments from the same bot or user.
14
+ *
15
+ * The identifier is embedded as hidden content in the comment body.
16
+ */
17
+ internalId?: string;
18
+ env?: Record<string, string | undefined>;
19
+ /**
20
+ * The number that identifies the GitHub issue.
21
+ *
22
+ * If this is not provided, the number will be inferred from the GitHub Repos
23
+ * API by finding the latest pull request associated with the head commit.
24
+ *
25
+ * https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit
26
+ */
27
+ issueNumber?: number;
28
+ /**
29
+ * The ID of authenticated bot or user that is putting the issue comment.
30
+ *
31
+ * This drives our `put` behaviour, which tries to locate and edit an existing
32
+ * comment before creating a new one. If this is not provided, the ID will be
33
+ * inferred from the GitHub Users API.
34
+ *
35
+ * https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
36
+ *
37
+ * If you're at SEEK and using BuildAgency's GitHub API integration, you may
38
+ * hardcode this to `87109344` as an optimisation to skip the user lookup.
39
+ *
40
+ * https://api.github.com/users/buildagencygitapitoken[bot]
41
+ */
42
+ userId?: number;
43
+ }
44
+ interface IssueComment {
45
+ id: number;
46
+ }
47
+ /**
48
+ * Asynchronously creates or updates a GitHub issue comment.
49
+ *
50
+ * This emulates `put` behaviour by overwriting the first existing comment by
51
+ * the same author on the issue, enabling use cases like a persistent bot
52
+ * comment at the top of the pull request that reflects the current status of a
53
+ * CI check.
54
+ *
55
+ * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with write permissions must be present
56
+ * on the environment.
57
+ */
58
+ export declare const putIssueComment: (params: PutIssueCommentParameters) => Promise<IssueComment>;
59
+ export {};
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.putIssueComment = void 0;
32
+ const rest_1 = require("@octokit/rest");
33
+ const Git = __importStar(require("../git"));
34
+ const environment_1 = require("./environment");
35
+ const pullRequest_1 = require("./pullRequest");
36
+ const getUserId = (client) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const { data } = yield client.users.getAuthenticated();
38
+ return data.id;
39
+ });
40
+ /**
41
+ * Asynchronously creates or updates a GitHub issue comment.
42
+ *
43
+ * This emulates `put` behaviour by overwriting the first existing comment by
44
+ * the same author on the issue, enabling use cases like a persistent bot
45
+ * comment at the top of the pull request that reflects the current status of a
46
+ * CI check.
47
+ *
48
+ * A `GITHUB_API_TOKEN` or `GITHUB_TOKEN` with write permissions must be present
49
+ * on the environment.
50
+ */
51
+ const putIssueComment = (params) => __awaiter(void 0, void 0, void 0, function* () {
52
+ var _a, _b, _c, _d;
53
+ const env = (_a = params.env) !== null && _a !== void 0 ? _a : process.env;
54
+ const dir = process.cwd();
55
+ const { owner, repo } = yield Git.getOwnerAndRepo({ dir });
56
+ const client = new rest_1.Octokit({ auth: (0, environment_1.apiTokenFromEnvironment)() });
57
+ const issueNumber = (_b = params.issueNumber) !== null && _b !== void 0 ? _b : (yield (0, pullRequest_1.getPullRequestNumber)({ client, env }));
58
+ if (!issueNumber) {
59
+ throw new Error('Failed to infer an issue number');
60
+ }
61
+ const comments = yield client.issues.listComments({
62
+ issue_number: issueNumber,
63
+ owner,
64
+ repo,
65
+ });
66
+ const userId = (_c = params.userId) !== null && _c !== void 0 ? _c : (yield getUserId(client));
67
+ const commentId = (_d = comments.data.find((comment) => {
68
+ var _a, _b;
69
+ return ((_a = comment.user) === null || _a === void 0 ? void 0 : _a.id) === userId &&
70
+ (params.internalId
71
+ ? (_b = comment.body) === null || _b === void 0 ? void 0 : _b.endsWith(`\n\n<!-- ${params.internalId} -->`)
72
+ : true);
73
+ })) === null || _d === void 0 ? void 0 : _d.id;
74
+ const body = params.internalId
75
+ ? [params.body.trim(), `<!-- ${params.internalId} -->`].join('\n\n')
76
+ : params.body.trim();
77
+ const response = yield (commentId
78
+ ? client.issues.updateComment({
79
+ body,
80
+ comment_id: commentId,
81
+ issue_number: issueNumber,
82
+ owner,
83
+ repo,
84
+ })
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
+ exports.putIssueComment = putIssueComment;
96
+ //# sourceMappingURL=issueComment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issueComment.js","sourceRoot":"","sources":["../../../src/api/github/issueComment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAwC;AAExC,4CAA8B;AAE9B,+CAAwD;AACxD,+CAAqD;AAErD,MAAM,SAAS,GAAG,CAAO,MAAe,EAAmB,EAAE;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;IAEvD,OAAO,IAAI,CAAC,EAAE,CAAC;AACjB,CAAC,CAAA,CAAC;AAsDF;;;;;;;;;;GAUG;AACI,MAAM,eAAe,GAAG,CAC7B,MAAiC,EACV,EAAE;;IACzB,MAAM,GAAG,GAAG,MAAA,MAAM,CAAC,GAAG,mCAAI,OAAO,CAAC,GAAG,CAAC;IAEtC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAE1B,MAAM,EAAE,KAAK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E,CAAC;IAEvB,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS;QAC/B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;YAC1B,IAAI;YACJ,UAAU,EAAE,SAAS;YACrB,YAAY,EAAE,WAAW;YACzB,KAAK;YACL,IAAI;SACL,CAAC;QACJ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;YAC1B,IAAI;YACJ,YAAY,EAAE,WAAW;YACzB,KAAK;YACL,IAAI;SACL,CAAC,CAAC,CAAC;IAER,OAAO;QACL,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE;KACrB,CAAC;AACJ,CAAC,CAAA,CAAC;AAxDW,QAAA,eAAe,mBAwD1B"}
@@ -0,0 +1,21 @@
1
+ import { Octokit } from '@octokit/rest';
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 {};
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.getPullRequestNumber = void 0;
32
+ const rest_1 = require("@octokit/rest");
33
+ const Git = __importStar(require("../git"));
34
+ const environment_1 = require("./environment");
35
+ /**
36
+ * Gets the number of the current pull request.
37
+ *
38
+ * This tries to extract the pull request from common CI environment variables,
39
+ * and falls back to querying the GitHub Repos API for the latest pull request
40
+ * associated with the head commit. An error is thrown if there are no
41
+ * associated pull requests, or if they are all closed or locked.
42
+ */
43
+ const getPullRequestNumber = (params = {}) => __awaiter(void 0, void 0, void 0, function* () {
44
+ var _a, _b, _c, _d;
45
+ const env = (_a = params.env) !== null && _a !== void 0 ? _a : process.env;
46
+ const dir = process.cwd();
47
+ const number = Number((_b = env.BUILDKITE_PULL_REQUEST) !== null && _b !== void 0 ? _b : (_c = env.GITHUB_REF) === null || _c === void 0 ? void 0 : _c.replace(/^refs\/pull\/(\d+).*$/, '$1'));
48
+ if (Number.isSafeInteger(number)) {
49
+ return number;
50
+ }
51
+ const client = (_d = params.client) !== null && _d !== void 0 ? _d : new rest_1.Octokit({ auth: (0, environment_1.apiTokenFromEnvironment)() });
52
+ const [commitId, { owner, repo }] = yield Promise.all([
53
+ Git.getHeadCommitId({ dir, env }),
54
+ Git.getOwnerAndRepo({ dir }),
55
+ ]);
56
+ const response = yield client.repos.listPullRequestsAssociatedWithCommit({
57
+ commit_sha: commitId,
58
+ owner,
59
+ repo,
60
+ });
61
+ const data = response.data
62
+ .filter((pr) => pr.state === 'open' && !pr.locked)
63
+ .sort((a, b) => b.updated_at.localeCompare(a.updated_at));
64
+ if (!data.length) {
65
+ throw new Error(`Commit ${commitId} is not associated with an open GitHub pull request`);
66
+ }
67
+ return data[0].number;
68
+ });
69
+ exports.getPullRequestNumber = getPullRequestNumber;
70
+ //# sourceMappingURL=pullRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pullRequest.js","sourceRoot":"","sources":["../../../src/api/github/pullRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAwC;AAExC,4CAA8B;AAE9B,+CAAwD;AAcxD;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAAG,CAClC,SAAmC,EAAE,EACpB,EAAE;;IACnB,MAAM,GAAG,GAAG,MAAA,MAAM,CAAC,GAAG,mCAAI,OAAO,CAAC,GAAG,CAAC;IAEtC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAE1B,MAAM,MAAM,GAAG,MAAM,CACnB,MAAA,GAAG,CAAC,sBAAsB,mCACxB,MAAA,GAAG,CAAC,UAAU,0CAAE,OAAO,CAAC,uBAAuB,EAAE,IAAI,CAAC,CACzD,CAAC;IAEF,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE;QAChC,OAAO,MAAM,CAAC;KACf;IAED,MAAM,MAAM,GACV,MAAA,MAAM,CAAC,MAAM,mCAAI,IAAI,cAAO,CAAC,EAAE,IAAI,EAAE,IAAA,qCAAuB,GAAE,EAAE,CAAC,CAAC;IAEpE,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACpD,GAAG,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACjC,GAAG,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,CAAC;KAC7B,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC;QACvE,UAAU,EAAE,QAAQ;QACpB,KAAK;QACL,IAAI;KACL,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI;SACvB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,KAAK,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;SACjD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IAE5D,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;QAChB,MAAM,IAAI,KAAK,CACb,UAAU,QAAQ,qDAAqD,CACxE,CAAC;KACH;IAED,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACxB,CAAC,CAAA,CAAC;AAzCW,QAAA,oBAAoB,wBAyC/B"}
@@ -1,5 +1,5 @@
1
- import { Config } from '@jest/types';
2
- declare type Props = Pick<Config.InitialOptions, 'collectCoverage' | 'collectCoverageFrom' | 'collectCoverageOnlyFrom' | 'coveragePathIgnorePatterns' | 'coverageThreshold' | 'globals' | 'globalSetup' | 'globalTeardown' | 'setupFiles' | 'setupFilesAfterEnv' | 'snapshotSerializers' | 'testEnvironment' | 'testPathIgnorePatterns' | 'testTimeout' | 'watchPathIgnorePatterns'>;
1
+ import type { Config } from '@jest/types';
2
+ declare type Props = Pick<Config.InitialOptions, 'collectCoverage' | 'collectCoverageFrom' | 'collectCoverageOnlyFrom' | 'coveragePathIgnorePatterns' | 'coverageThreshold' | 'displayName' | 'globals' | 'globalSetup' | 'globalTeardown' | 'projects' | 'setupFiles' | 'setupFilesAfterEnv' | 'snapshotSerializers' | 'testEnvironment' | 'testPathIgnorePatterns' | 'testTimeout' | 'watchPathIgnorePatterns'>;
3
3
  /**
4
4
  * Merge additional Jest options into the **skuba** preset.
5
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/jest/index.ts"],"names":[],"mappings":";;;;;;AAEA,uEAA8C;AAC9C,kEAAiE;AAqBjE;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,KAAY,EAAyB,EAAE,CACjE,IAAA,iBAAQ,EAAC,qBAAU,EAAE,KAAK,CAAC,CAAC;AADjB,QAAA,WAAW,eACM"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/jest/index.ts"],"names":[],"mappings":";;;;;;AAEA,uEAA8C;AAC9C,kEAAiE;AAuBjE;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,KAAY,EAAyB,EAAE,CACjE,IAAA,iBAAQ,EAAC,qBAAU,EAAE,KAAK,CAAC,CAAC;AADjB,QAAA,WAAW,eACM"}
@@ -1,4 +1,4 @@
1
- import { SocketAddress } from './socket';
1
+ import type { SocketAddress } from './socket';
2
2
  /**
3
3
  * Wait for a resource to start listening on a socket address.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"waitFor.js","sourceRoot":"","sources":["../../../src/api/net/waitFor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAkD;AAClD,qCAAqD;AAErD;;;;;GAKG;AACI,MAAM,OAAO,GAAG,CAAO,EAC5B,IAAI,GAAG,WAAW,EAClB,IAAI,EACJ,cAAc,GAAG,KAAK,EACtB,OAAO,GAAG,KAAM,GAkBjB,EAA0B,EAAE;IAC3B,MAAM,eAAe,GAAG,cAAc;QACpC,CAAC,CAAC,MAAM,IAAA,+BAAqB,EAAC,IAAI,EAAE,IAAI,CAAC;QACzC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAEnB,MAAM,IAAA,mBAAU,EAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEtE,OAAO,eAAe,CAAC;AACzB,CAAC,CAAA,CAAC;AA9BW,QAAA,OAAO,WA8BlB"}
1
+ {"version":3,"file":"waitFor.js","sourceRoot":"","sources":["../../../src/api/net/waitFor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAkD;AAElD,qCAAsC;AAEtC;;;;;GAKG;AACI,MAAM,OAAO,GAAG,CAAO,EAC5B,IAAI,GAAG,WAAW,EAClB,IAAI,EACJ,cAAc,GAAG,KAAK,EACtB,OAAO,GAAG,KAAM,GAkBjB,EAA0B,EAAE;IAC3B,MAAM,eAAe,GAAG,cAAc;QACpC,CAAC,CAAC,MAAM,IAAA,+BAAqB,EAAC,IAAI,EAAE,IAAI,CAAC;QACzC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAEnB,MAAM,IAAA,mBAAU,EAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEtE,OAAO,eAAe,CAAC;AACzB,CAAC,CAAA,CAAC;AA9BW,QAAA,OAAO,WA8BlB"}
@@ -1,5 +1,5 @@
1
- import { Linter } from 'eslint';
2
- import { Logger } from '../../utils/logging';
1
+ import type { Linter } from 'eslint';
2
+ import type { Logger } from '../../utils/logging';
3
3
  export interface ESLintResult {
4
4
  messages: Linter.LintMessage[];
5
5
  filePath: string;
@@ -16,6 +16,7 @@ exports.runESLint = void 0;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
18
  const eslint_1 = require("eslint");
19
+ const logging_1 = require("../../utils/logging");
19
20
  const symbolForResult = (result) => {
20
21
  if (result.errorCount) {
21
22
  return chalk_1.default.red('○');
@@ -25,9 +26,7 @@ const symbolForResult = (result) => {
25
26
  const runESLint = (mode, logger) => __awaiter(void 0, void 0, void 0, function* () {
26
27
  logger.debug('Initialising ESLint...');
27
28
  const engine = new eslint_1.ESLint({
28
- // TODO: enable this once we have a less overzealous `skuba configure` that
29
- // everyone can apply to update their `.gitignore` files.
30
- // cache: true,
29
+ cache: true,
31
30
  extensions: ['js', 'ts', 'tsx'],
32
31
  fix: mode === 'format',
33
32
  reportUnusedDisableDirectives: 'error',
@@ -40,7 +39,7 @@ const runESLint = (mode, logger) => __awaiter(void 0, void 0, void 0, function*
40
39
  engine.lintFiles('.'),
41
40
  ]);
42
41
  const end = process.hrtime.bigint();
43
- logger.plain(`Processed ${logger.pluralise(results.length, 'file')} in ${logger.timing(start, end)}.`);
42
+ logger.plain(`Processed ${(0, logging_1.pluralise)(results.length, 'file')} in ${logger.timing(start, end)}.`);
44
43
  const errors = [];
45
44
  const warnings = [];
46
45
  for (const result of results) {
@@ -1 +1 @@
1
- {"version":3,"file":"eslint.js","sourceRoot":"","sources":["../../../src/cli/adapter/eslint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gDAAwB;AAExB,kDAA0B;AAC1B,mCAAwC;AAIxC,MAAM,eAAe,GAAG,CAAC,MAAyB,EAAE,EAAE;IACpD,IAAI,MAAM,CAAC,UAAU,EAAE;QACrB,OAAO,eAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KACvB;IAED,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,eAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,eAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACpE,CAAC,CAAC;AAcK,MAAM,SAAS,GAAG,CACvB,IAAuB,EACvB,MAAc,EACS,EAAE;IACzB,MAAM,CAAC,KAAK,CAAC,wBAA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AED,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC;KACrD;IAED,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC;IAE/B,MAAM,eAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAElC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEzC,IAAI,MAAM,EAAE;QACV,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;KACtB;IAED,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC,CAAA,CAAC;AAlEW,QAAA,SAAS,aAkEpB"}
@@ -1,4 +1,25 @@
1
- import { Logger } from '../../utils/logging';
1
+ import type { Logger } from '../../utils/logging';
2
+ /**
3
+ * Infers a parser for the specified filepath.
4
+ *
5
+ * This is a cut-down version of Prettier's built-in function of the same name;
6
+ * ours operates purely on the `filepath` string and does not perform file I/O.
7
+ * Prettier's internal `getInterpreter` function can open a file to read the
8
+ * shebang, and its file descriptor usage can throw warnings on worker threads:
9
+ *
10
+ * ```console
11
+ * Warning: File descriptor 123 closed but not opened in unmanaged mode
12
+ * at Object.closeSync (node:fs:530:11)
13
+ * at Object.closeSync (node_modules/graceful-fs/graceful-fs.js:74:20)
14
+ * ...
15
+ * ```
16
+ *
17
+ * References:
18
+ *
19
+ * - https://github.com/prettier/prettier/blob/2.4.1/src/main/options.js#L167
20
+ * - seek-oss/skuba#659
21
+ */
22
+ export declare const inferParser: (filepath: string) => string | undefined;
2
23
  interface Result {
3
24
  count: number;
4
25
  errored: Array<{