skuba 3.16.2 → 3.17.0-beta.4

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 (137) hide show
  1. package/jest/moduleNameMapper.js +75 -0
  2. package/jest/moduleNameMapper.test.ts +75 -0
  3. package/jest/transform.js +19 -0
  4. package/jest-preset.js +7 -24
  5. package/lib/api/git/commit.d.ts +15 -0
  6. package/lib/api/git/commit.js +31 -0
  7. package/lib/api/git/commit.js.map +1 -0
  8. package/lib/api/git/commitAllChanges.d.ts +12 -0
  9. package/lib/api/git/commitAllChanges.js +36 -0
  10. package/lib/api/git/commitAllChanges.js.map +1 -0
  11. package/lib/api/git/getChangedFiles.d.ts +14 -0
  12. package/lib/api/git/getChangedFiles.js +41 -0
  13. package/lib/api/git/getChangedFiles.js.map +1 -0
  14. package/lib/api/git/index.d.ts +7 -0
  15. package/lib/api/git/index.js +18 -0
  16. package/lib/api/git/index.js.map +1 -0
  17. package/lib/api/git/log.d.ts +12 -0
  18. package/lib/api/git/log.js +37 -0
  19. package/lib/api/git/log.js.map +1 -0
  20. package/lib/api/git/push.d.ts +43 -0
  21. package/lib/api/git/push.js +46 -0
  22. package/lib/api/git/push.js.map +1 -0
  23. package/lib/api/git/remote.d.ts +18 -0
  24. package/lib/api/git/remote.js +57 -0
  25. package/lib/api/git/remote.js.map +1 -0
  26. package/lib/api/git/reset.d.ts +12 -0
  27. package/lib/api/git/reset.js +39 -0
  28. package/lib/api/git/reset.js.map +1 -0
  29. package/lib/api/git/statusMatrix.d.ts +7 -0
  30. package/lib/api/git/statusMatrix.js +14 -0
  31. package/lib/api/git/statusMatrix.js.map +1 -0
  32. package/lib/api/github/checkRun.d.ts +27 -5
  33. package/lib/api/github/checkRun.js +29 -49
  34. package/lib/api/github/checkRun.js.map +1 -1
  35. package/lib/api/github/environment.d.ts +19 -0
  36. package/lib/api/github/environment.js +23 -2
  37. package/lib/api/github/environment.js.map +1 -1
  38. package/lib/api/github/index.d.ts +4 -0
  39. package/lib/api/github/index.js +9 -1
  40. package/lib/api/github/index.js.map +1 -1
  41. package/lib/api/github/issueComment.d.ts +59 -0
  42. package/lib/api/github/issueComment.js +96 -0
  43. package/lib/api/github/issueComment.js.map +1 -0
  44. package/lib/api/github/pullRequest.d.ts +21 -0
  45. package/lib/api/github/pullRequest.js +70 -0
  46. package/lib/api/github/pullRequest.js.map +1 -0
  47. package/lib/api/jest/index.d.ts +2 -2
  48. package/lib/api/jest/index.js.map +1 -1
  49. package/lib/api/net/waitFor.d.ts +1 -1
  50. package/lib/api/net/waitFor.js.map +1 -1
  51. package/lib/cli/adapter/eslint.d.ts +2 -2
  52. package/lib/cli/adapter/eslint.js.map +1 -1
  53. package/lib/cli/adapter/prettier.d.ts +1 -1
  54. package/lib/cli/adapter/prettier.js.map +1 -1
  55. package/lib/cli/configure/analyseConfiguration.d.ts +1 -1
  56. package/lib/cli/configure/analyseDependencies.d.ts +2 -2
  57. package/lib/cli/configure/analyseDependencies.js.map +1 -1
  58. package/lib/cli/configure/analysis/package.d.ts +1 -1
  59. package/lib/cli/configure/analysis/project.d.ts +1 -1
  60. package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.d.ts +1 -1
  61. package/lib/cli/configure/dependencies/seekKoala.d.ts +1 -1
  62. package/lib/cli/configure/dependencies/skuba.d.ts +1 -1
  63. package/lib/cli/configure/dependencies/skubaDeps.d.ts +1 -1
  64. package/lib/cli/configure/dependencies/skubaDive.d.ts +1 -1
  65. package/lib/cli/configure/ensureTemplateCompletion.d.ts +2 -2
  66. package/lib/cli/configure/ensureTemplateCompletion.js.map +1 -1
  67. package/lib/cli/configure/getEntryPoint.d.ts +3 -3
  68. package/lib/cli/configure/getProjectType.d.ts +2 -2
  69. package/lib/cli/configure/modules/eslint.d.ts +1 -1
  70. package/lib/cli/configure/modules/ignore.d.ts +1 -1
  71. package/lib/cli/configure/modules/index.d.ts +1 -1
  72. package/lib/cli/configure/modules/jest.d.ts +1 -1
  73. package/lib/cli/configure/modules/nodemon.d.ts +1 -1
  74. package/lib/cli/configure/modules/package.d.ts +1 -1
  75. package/lib/cli/configure/modules/prettier.d.ts +1 -1
  76. package/lib/cli/configure/modules/renovate.d.ts +1 -1
  77. package/lib/cli/configure/modules/serverless.d.ts +1 -1
  78. package/lib/cli/configure/modules/skubaDive.d.ts +1 -1
  79. package/lib/cli/configure/modules/tsconfig.d.ts +1 -1
  80. package/lib/cli/configure/modules/tslint.d.ts +1 -1
  81. package/lib/cli/configure/processing/deleteFiles.d.ts +1 -1
  82. package/lib/cli/configure/processing/loadFiles.d.ts +1 -1
  83. package/lib/cli/configure/processing/package.d.ts +1 -1
  84. package/lib/cli/configure/processing/typescript.js +1 -1
  85. package/lib/cli/configure/processing/typescript.js.map +1 -1
  86. package/lib/cli/configure/types.d.ts +1 -1
  87. package/lib/cli/init/getConfig.d.ts +2 -2
  88. package/lib/cli/init/getConfig.js.map +1 -1
  89. package/lib/cli/init/git.js +22 -8
  90. package/lib/cli/init/git.js.map +1 -1
  91. package/lib/cli/init/writePackageJson.d.ts +1 -1
  92. package/lib/cli/lint/annotate/buildkite/eslint.d.ts +1 -1
  93. package/lib/cli/lint/annotate/buildkite/index.d.ts +3 -3
  94. package/lib/cli/lint/annotate/buildkite/prettier.d.ts +1 -1
  95. package/lib/cli/lint/annotate/buildkite/tsc.d.ts +1 -1
  96. package/lib/cli/lint/annotate/github/eslint.d.ts +2 -2
  97. package/lib/cli/lint/annotate/github/index.d.ts +3 -3
  98. package/lib/cli/lint/annotate/github/index.js +1 -2
  99. package/lib/cli/lint/annotate/github/index.js.map +1 -1
  100. package/lib/cli/lint/annotate/github/prettier.d.ts +2 -2
  101. package/lib/cli/lint/annotate/github/tsc.d.ts +2 -2
  102. package/lib/cli/lint/annotate/index.d.ts +3 -3
  103. package/lib/cli/lint/eslint.d.ts +1 -1
  104. package/lib/cli/lint/eslint.js.map +1 -1
  105. package/lib/cli/lint/prettier.d.ts +1 -1
  106. package/lib/cli/lint/prettier.js.map +1 -1
  107. package/lib/cli/node.js +1 -1
  108. package/lib/cli/node.js.map +1 -1
  109. package/lib/cli/start.js +1 -1
  110. package/lib/cli/start.js.map +1 -1
  111. package/lib/cli/{test.d.ts → test/index.d.ts} +0 -0
  112. package/lib/cli/{test.js → test/index.js} +4 -4
  113. package/lib/cli/test/index.js.map +1 -0
  114. package/lib/cli/test/reporters/github/annotations.d.ts +9 -0
  115. package/lib/cli/test/reporters/github/annotations.js +86 -0
  116. package/lib/cli/test/reporters/github/annotations.js.map +1 -0
  117. package/lib/cli/test/reporters/github/index.d.ts +5 -0
  118. package/lib/cli/test/reporters/github/index.js +69 -0
  119. package/lib/cli/test/reporters/github/index.js.map +1 -0
  120. package/lib/index.d.ts +2 -1
  121. package/lib/index.js +3 -2
  122. package/lib/index.js.map +1 -1
  123. package/lib/utils/args.d.ts +1 -1
  124. package/lib/utils/exec.d.ts +2 -1
  125. package/lib/utils/exec.js.map +1 -1
  126. package/lib/utils/manifest.d.ts +2 -1
  127. package/lib/utils/manifest.js.map +1 -1
  128. package/package.json +10 -7
  129. package/template/express-rest-api/.buildkite/pipeline.yml +2 -0
  130. package/template/greeter/.buildkite/pipeline.yml +2 -0
  131. package/template/koa-rest-api/.buildkite/pipeline.yml +2 -0
  132. package/template/lambda-sqs-worker/.buildkite/pipeline.yml +3 -1
  133. package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +3 -1
  134. package/lib/cli/test.js.map +0 -1
  135. package/lib/register.d.ts +0 -20
  136. package/lib/register.js +0 -44
  137. package/lib/register.js.map +0 -1
@@ -0,0 +1,75 @@
1
+ const path = require('path');
2
+
3
+ const { pathsToModuleNameMapper } = require('ts-jest/utils');
4
+ const {
5
+ sys,
6
+ findConfigFile,
7
+ readConfigFile,
8
+ parseJsonConfigFileContent,
9
+ } = require('typescript');
10
+
11
+ /**
12
+ * Set a default `src` module alias for backward compatibility.
13
+ *
14
+ * TODO: drop this default in skuba v4.
15
+ */
16
+ const DEFAULT_PATHS = { src: ['src'], 'src/*': ['src/*'] };
17
+
18
+ /**
19
+ * @returns {unknown}
20
+ */
21
+ const getConfigFromDisk = () => {
22
+ const filename =
23
+ findConfigFile('.', sys.fileExists.bind(this), tsconfigName) ||
24
+ 'tsconfig.json';
25
+
26
+ return readConfigFile(filename, sys.readFile.bind(this)).config;
27
+ };
28
+
29
+ module.exports.createModuleNameMapper = (getConfig = getConfigFromDisk) => {
30
+ try {
31
+ const json = getConfig();
32
+
33
+ const parsedConfig = parseJsonConfigFileContent(json, sys, '.');
34
+
35
+ const paths = Object.fromEntries(
36
+ Object.entries(parsedConfig.options.paths ?? DEFAULT_PATHS).flatMap(
37
+ ([key, values]) => [
38
+ [
39
+ key.replace(/\/$/, ''),
40
+ values.map((value) => value.replace(/\/$/, '')),
41
+ ],
42
+ ...(key.endsWith('/*')
43
+ ? [
44
+ [
45
+ key.replace(/\/\*$/, ''),
46
+ values.map((value) => value.replace(/\/\*$/, '')),
47
+ ],
48
+ ]
49
+ : [
50
+ [
51
+ path.join(key, '*'),
52
+ values.map((value) => path.join(value, '*')),
53
+ ],
54
+ ]),
55
+ ],
56
+ ),
57
+ );
58
+
59
+ const prefix = path.join('<rootDir>', parsedConfig.options.baseUrl || '.');
60
+
61
+ const moduleNameMapper = pathsToModuleNameMapper(paths, { prefix });
62
+
63
+ return Object.fromEntries(
64
+ Object.entries(moduleNameMapper).map(([key, values]) => [
65
+ key,
66
+ Array.isArray(values)
67
+ ? values.map((value) => path.normalize(value))
68
+ : path.normalize(values),
69
+ ]),
70
+ );
71
+ } catch {
72
+ // Bail out here to support zero-config mode.
73
+ return pathsToModuleNameMapper(DEFAULT_PATHS, { prefix: '<rootDir>' });
74
+ }
75
+ };
@@ -0,0 +1,75 @@
1
+ import { createModuleNameMapper } from './moduleNameMapper';
2
+
3
+ describe('moduleNameMapper', () => {
4
+ const act = (paths?: unknown, baseUrl?: string) =>
5
+ createModuleNameMapper(() => ({
6
+ compilerOptions: {
7
+ baseUrl,
8
+ paths,
9
+ },
10
+ }));
11
+
12
+ it('expands wildcard paths', () =>
13
+ expect(act({ 'src/*': ['src/*'], 'lib/wip/*': ['lib/wip/*'] }))
14
+ .toMatchInlineSnapshot(`
15
+ Object {
16
+ "^lib/wip$": "<rootDir>/lib/wip",
17
+ "^lib/wip/(.*)$": "<rootDir>/lib/wip/$1",
18
+ "^src$": "<rootDir>/src",
19
+ "^src/(.*)$": "<rootDir>/src/$1",
20
+ }
21
+ `));
22
+
23
+ it('expands non-wildcard paths', () =>
24
+ expect(act({ cli: ['cli'], 'src/': ['src/'] })).toMatchInlineSnapshot(`
25
+ Object {
26
+ "^cli$": "<rootDir>/cli",
27
+ "^cli/(.*)$": "<rootDir>/cli/$1",
28
+ "^src$": "<rootDir>/src",
29
+ "^src/(.*)$": "<rootDir>/src/$1",
30
+ }
31
+ `));
32
+
33
+ it('expands duplicate asymmetric paths', () =>
34
+ expect(
35
+ act({
36
+ jquery: ['node_modules/jquery/dist/jquery'],
37
+ 'jquery/*': ['node_modules/jquery/dist/jquery/*'],
38
+ }),
39
+ ).toMatchInlineSnapshot(`
40
+ Object {
41
+ "^jquery$": "<rootDir>/node_modules/jquery/dist/jquery",
42
+ "^jquery/(.*)$": "<rootDir>/node_modules/jquery/dist/jquery/$1",
43
+ }
44
+ `));
45
+
46
+ it('respects a base URL', () =>
47
+ expect(act({ cli: ['../cli'], 'app/*': ['app/*'] }, 'src'))
48
+ .toMatchInlineSnapshot(`
49
+ Object {
50
+ "^app$": "<rootDir>/src/app",
51
+ "^app/(.*)$": "<rootDir>/src/app/$1",
52
+ "^cli$": "<rootDir>/cli",
53
+ "^cli/(.*)$": "<rootDir>/cli/$1",
54
+ }
55
+ `));
56
+
57
+ it('respects no paths', () =>
58
+ expect(act({})).toMatchInlineSnapshot(`Object {}`));
59
+
60
+ it('falls back on undefined paths', () =>
61
+ expect(act(undefined)).toMatchInlineSnapshot(`
62
+ Object {
63
+ "^src$": "<rootDir>/src",
64
+ "^src/(.*)$": "<rootDir>/src/$1",
65
+ }
66
+ `));
67
+
68
+ it('falls back on invalid config', () =>
69
+ expect(act('INVALID')).toMatchInlineSnapshot(`
70
+ Object {
71
+ "^src$": "<rootDir>/src",
72
+ "^src/(.*)$": "<rootDir>/src/$1",
73
+ }
74
+ `));
75
+ });
@@ -0,0 +1,19 @@
1
+ const { defaults } = require('ts-jest/presets');
2
+
3
+ const TS_JEST_NAME = 'ts-jest';
4
+
5
+ /**
6
+ * Resolved path of the `ts-jest` preset.
7
+ *
8
+ * This allows Jest to resolve the preset even if it is installed to a nested
9
+ * `./node_modules/skuba/node_modules/ts-jest` directory.
10
+ */
11
+ const TS_JEST_PATH = require.resolve(TS_JEST_NAME);
12
+
13
+ // Rewrite `ts-jest` transformations using our resolved `TS_JEST_PATH`.
14
+ module.exports.transform = Object.fromEntries(
15
+ Object.entries(defaults.transform).map(([key, value]) => [
16
+ key,
17
+ value === TS_JEST_NAME ? TS_JEST_PATH : value,
18
+ ]),
19
+ );
package/jest-preset.js CHANGED
@@ -1,28 +1,14 @@
1
- const { defaults: tsJestDefaults } = require('ts-jest/presets');
1
+ const { defaults } = require('ts-jest/presets');
2
2
 
3
- const TS_JEST_NAME = 'ts-jest';
4
-
5
- /**
6
- * Resolved path of the `ts-jest` preset.
7
- *
8
- * This allows Jest to resolve the preset even if it is installed to a nested
9
- * `./node_modules/skuba/node_modules/ts-jest` directory.
10
- */
11
- const TS_JEST_PATH = require.resolve(TS_JEST_NAME);
12
-
13
- // Rewrite `ts-jest` transformations using our resolved `TS_JEST_PATH`.
14
- const tsJestTransform = Object.fromEntries(
15
- Object.entries(tsJestDefaults.transform).map(([key, value]) => [
16
- key,
17
- value === TS_JEST_NAME ? TS_JEST_PATH : value,
18
- ]),
19
- );
3
+ const { createModuleNameMapper } = require('./jest/moduleNameMapper');
4
+ const { transform } = require('./jest/transform');
20
5
 
21
6
  /** @type {import('@jest/types').Config.InitialOptions} */
22
7
  module.exports = {
23
- ...tsJestDefaults,
8
+ ...defaults,
24
9
 
25
- transform: tsJestTransform,
10
+ moduleNameMapper: createModuleNameMapper(),
11
+ transform,
26
12
 
27
13
  collectCoverageFrom: [
28
14
  '**/*.ts',
@@ -35,13 +21,10 @@ module.exports = {
35
21
  '!<rootDir>/jest.*.ts',
36
22
  ],
37
23
  coverageDirectory: 'coverage',
38
- moduleNameMapper: {
39
- '^src$': '<rootDir>/src',
40
- '^src/(.+)$': '<rootDir>/src/$1',
41
- },
42
24
  testEnvironment: 'node',
43
25
  testPathIgnorePatterns: [
44
26
  '/node_modules.*/',
45
27
  '<rootDir>/(coverage|dist|lib|tmp).*/',
46
28
  ],
29
+ reporters: ['default', require.resolve('./lib/cli/test/reporters/github')],
47
30
  };
@@ -0,0 +1,15 @@
1
+ export interface Identity {
2
+ email?: string;
3
+ name?: string;
4
+ }
5
+ interface CommitParameters {
6
+ author?: Identity;
7
+ committer?: Identity;
8
+ dir: string;
9
+ message: string;
10
+ }
11
+ /**
12
+ * Writes a commit to the local Git repository.
13
+ */
14
+ export declare const commit: ({ author, committer, dir, message, }: CommitParameters) => Promise<string>;
15
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.commit = void 0;
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const isomorphic_git_1 = __importDefault(require("isomorphic-git"));
18
+ /**
19
+ * Writes a commit to the local Git repository.
20
+ */
21
+ const commit = ({ author = { name: 'skuba' }, committer = { name: 'skuba' }, dir, message, }) => __awaiter(void 0, void 0, void 0, function* () {
22
+ return isomorphic_git_1.default.commit({
23
+ author,
24
+ committer,
25
+ dir,
26
+ fs: fs_extra_1.default,
27
+ message,
28
+ });
29
+ });
30
+ exports.commit = commit;
31
+ //# sourceMappingURL=commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.js","sourceRoot":"","sources":["../../../src/api/git/commit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,oEAAiC;AAcjC;;GAEG;AACI,MAAM,MAAM,GAAG,CAAO,EAC3B,MAAM,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAC1B,SAAS,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAC7B,GAAG,EACH,OAAO,GACU,EAAmB,EAAE;IACtC,OAAA,wBAAG,CAAC,MAAM,CAAC;QACT,MAAM;QACN,SAAS;QACT,GAAG;QACH,EAAE,EAAF,kBAAE;QACF,OAAO;KACR,CAAC,CAAA;EAAA,CAAC;AAZQ,QAAA,MAAM,UAYd"}
@@ -0,0 +1,12 @@
1
+ import type { Identity } from './commit';
2
+ interface CommitAllParameters {
3
+ dir: string;
4
+ message: string;
5
+ author?: Identity;
6
+ committer?: Identity;
7
+ }
8
+ /**
9
+ * Stages all changes and writes a commit to the local Git repository.
10
+ */
11
+ export declare const commitAllChanges: ({ dir, message, author, committer, }: CommitAllParameters) => Promise<void>;
12
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.commitAllChanges = void 0;
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const isomorphic_git_1 = __importDefault(require("isomorphic-git"));
18
+ const commit_1 = require("./commit");
19
+ const getChangedFiles_1 = require("./getChangedFiles");
20
+ /**
21
+ * Stages all changes and writes a commit to the local Git repository.
22
+ */
23
+ const commitAllChanges = ({ dir, message, author, committer, }) => __awaiter(void 0, void 0, void 0, function* () {
24
+ const changedFiles = yield (0, getChangedFiles_1.getChangedFiles)({ dir });
25
+ yield Promise.all(changedFiles.map((file) => file.state === 'deleted'
26
+ ? isomorphic_git_1.default.remove({ fs: fs_extra_1.default, dir, filepath: file.path })
27
+ : isomorphic_git_1.default.add({ fs: fs_extra_1.default, dir, filepath: file.path })));
28
+ yield (0, commit_1.commit)({
29
+ dir,
30
+ message,
31
+ author,
32
+ committer,
33
+ });
34
+ });
35
+ exports.commitAllChanges = commitAllChanges;
36
+ //# sourceMappingURL=commitAllChanges.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commitAllChanges.js","sourceRoot":"","sources":["../../../src/api/git/commitAllChanges.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,oEAAiC;AAEjC,qCAAkC;AAElC,uDAAoD;AASpD;;GAEG;AACI,MAAM,gBAAgB,GAAG,CAAO,EACrC,GAAG,EACH,OAAO,EACP,MAAM,EACN,SAAS,GACW,EAAiB,EAAE;IACvC,MAAM,YAAY,GAAG,MAAM,IAAA,iCAAe,EAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACpD,MAAM,OAAO,CAAC,GAAG,CACf,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACxB,IAAI,CAAC,KAAK,KAAK,SAAS;QACtB,CAAC,CAAC,wBAAG,CAAC,MAAM,CAAC,EAAE,EAAE,EAAF,kBAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QAC9C,CAAC,CAAC,wBAAG,CAAC,GAAG,CAAC,EAAE,EAAE,EAAF,kBAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAC9C,CACF,CAAC;IAEF,MAAM,IAAA,eAAM,EAAC;QACX,GAAG;QACH,OAAO;QACP,MAAM;QACN,SAAS;KACV,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AArBW,QAAA,gBAAgB,oBAqB3B"}
@@ -0,0 +1,14 @@
1
+ declare type ChangedFileState = 'added' | 'modified' | 'deleted';
2
+ export interface ChangedFile {
3
+ path: string;
4
+ state: ChangedFileState;
5
+ }
6
+ interface ChangedFilesParameters {
7
+ dir: string;
8
+ }
9
+ /**
10
+ * Returns all the files which have been added, modified or deleted in the
11
+ * working directory of the local Git repository since the last commit.
12
+ */
13
+ export declare const getChangedFiles: ({ dir, }: ChangedFilesParameters) => Promise<ChangedFile[]>;
14
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getChangedFiles = void 0;
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const isomorphic_git_1 = __importDefault(require("isomorphic-git"));
18
+ const statusMatrix_1 = require("./statusMatrix");
19
+ const mapState = (row) => {
20
+ if (row[statusMatrix_1.HEAD] === statusMatrix_1.ABSENT) {
21
+ return 'added';
22
+ }
23
+ if (row[statusMatrix_1.WORKDIR] === statusMatrix_1.MODIFIED) {
24
+ return 'modified';
25
+ }
26
+ return 'deleted';
27
+ };
28
+ /**
29
+ * Returns all the files which have been added, modified or deleted in the
30
+ * working directory of the local Git repository since the last commit.
31
+ */
32
+ const getChangedFiles = ({ dir, }) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const allFiles = yield isomorphic_git_1.default.statusMatrix({ fs: fs_extra_1.default, dir });
34
+ return allFiles
35
+ .filter((row) => row[statusMatrix_1.HEAD] !== statusMatrix_1.UNMODIFIED ||
36
+ row[statusMatrix_1.WORKDIR] !== statusMatrix_1.UNMODIFIED ||
37
+ row[statusMatrix_1.STAGE] !== statusMatrix_1.UNMODIFIED)
38
+ .map((row) => ({ path: row[statusMatrix_1.FILEPATH], state: mapState(row) }));
39
+ });
40
+ exports.getChangedFiles = getChangedFiles;
41
+ //# sourceMappingURL=getChangedFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getChangedFiles.js","sourceRoot":"","sources":["../../../src/api/git/getChangedFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,oEAAiC;AAEjC,iDAQwB;AAWxB,MAAM,QAAQ,GAAG,CACf,GAA8C,EAC5B,EAAE;IACpB,IAAI,GAAG,CAAC,mBAAI,CAAC,KAAK,qBAAM,EAAE;QACxB,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,GAAG,CAAC,sBAAO,CAAC,KAAK,uBAAQ,EAAE;QAC7B,OAAO,UAAU,CAAC;KACnB;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAO,EACpC,GAAG,GACoB,EAA0B,EAAE;IACnD,MAAM,QAAQ,GAAG,MAAM,wBAAG,CAAC,YAAY,CAAC,EAAE,EAAE,EAAF,kBAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACrD,OAAO,QAAQ;SACZ,MAAM,CACL,CAAC,GAAG,EAAE,EAAE,CACN,GAAG,CAAC,mBAAI,CAAC,KAAK,yBAAU;QACxB,GAAG,CAAC,sBAAO,CAAC,KAAK,yBAAU;QAC3B,GAAG,CAAC,oBAAK,CAAC,KAAK,yBAAU,CAC5B;SACA,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,uBAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACnE,CAAC,CAAA,CAAC;AAZW,QAAA,eAAe,mBAY1B"}
@@ -0,0 +1,7 @@
1
+ export { commit } from './commit';
2
+ export { commitAllChanges } from './commitAllChanges';
3
+ export { getChangedFiles } from './getChangedFiles';
4
+ export { getHeadCommitId } from './log';
5
+ export { getOwnerAndRepo } from './remote';
6
+ export { push } from './push';
7
+ export { reset } from './reset';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reset = exports.push = exports.getOwnerAndRepo = exports.getHeadCommitId = exports.getChangedFiles = exports.commitAllChanges = exports.commit = void 0;
4
+ var commit_1 = require("./commit");
5
+ Object.defineProperty(exports, "commit", { enumerable: true, get: function () { return commit_1.commit; } });
6
+ var commitAllChanges_1 = require("./commitAllChanges");
7
+ Object.defineProperty(exports, "commitAllChanges", { enumerable: true, get: function () { return commitAllChanges_1.commitAllChanges; } });
8
+ var getChangedFiles_1 = require("./getChangedFiles");
9
+ Object.defineProperty(exports, "getChangedFiles", { enumerable: true, get: function () { return getChangedFiles_1.getChangedFiles; } });
10
+ var log_1 = require("./log");
11
+ Object.defineProperty(exports, "getHeadCommitId", { enumerable: true, get: function () { return log_1.getHeadCommitId; } });
12
+ var remote_1 = require("./remote");
13
+ Object.defineProperty(exports, "getOwnerAndRepo", { enumerable: true, get: function () { return remote_1.getOwnerAndRepo; } });
14
+ var push_1 = require("./push");
15
+ Object.defineProperty(exports, "push", { enumerable: true, get: function () { return push_1.push; } });
16
+ var reset_1 = require("./reset");
17
+ Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return reset_1.reset; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/git/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AACf,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,6BAAwC;AAA/B,sGAAA,eAAe,OAAA;AACxB,mCAA2C;AAAlC,yGAAA,eAAe,OAAA;AACxB,+BAA8B;AAArB,4FAAA,IAAI,OAAA;AACb,iCAAgC;AAAvB,8FAAA,KAAK,OAAA"}
@@ -0,0 +1,12 @@
1
+ interface GetHeadCommitIdParameters {
2
+ dir: string;
3
+ env?: Record<string, string | undefined>;
4
+ }
5
+ /**
6
+ * Gets the object ID of the head commit.
7
+ *
8
+ * This tries to extract the commit ID from common CI environment variables,
9
+ * and falls back to the local Git repository log.
10
+ */
11
+ export declare const getHeadCommitId: ({ dir, env, }: GetHeadCommitIdParameters) => Promise<string>;
12
+ export {};
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getHeadCommitId = void 0;
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const isomorphic_git_1 = __importDefault(require("isomorphic-git"));
18
+ /**
19
+ * Gets the object ID of the head commit.
20
+ *
21
+ * This tries to extract the commit ID from common CI environment variables,
22
+ * and falls back to the local Git repository log.
23
+ */
24
+ const getHeadCommitId = ({ dir, env = process.env, }) => __awaiter(void 0, void 0, void 0, function* () {
25
+ var _a;
26
+ const oidFromEnv = (_a = env.BUILDKITE_COMMIT) !== null && _a !== void 0 ? _a : env.GITHUB_SHA;
27
+ if (oidFromEnv) {
28
+ return oidFromEnv;
29
+ }
30
+ const [headCommit] = yield isomorphic_git_1.default.log({ depth: 1, dir, fs: fs_extra_1.default });
31
+ if (!headCommit) {
32
+ throw new Error('Git log does not contain any commits');
33
+ }
34
+ return headCommit.oid;
35
+ });
36
+ exports.getHeadCommitId = getHeadCommitId;
37
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/api/git/log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,oEAAiC;AAOjC;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAO,EACpC,GAAG,EACH,GAAG,GAAG,OAAO,CAAC,GAAG,GACS,EAAmB,EAAE;;IAC/C,MAAM,UAAU,GAAG,MAAA,GAAG,CAAC,gBAAgB,mCAAI,GAAG,CAAC,UAAU,CAAC;IAE1D,IAAI,UAAU,EAAE;QACd,OAAO,UAAU,CAAC;KACnB;IAED,MAAM,CAAC,UAAU,CAAC,GAAG,MAAM,wBAAG,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAF,kBAAE,EAAE,CAAC,CAAC;IAE1D,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;KACzD;IAED,OAAO,UAAU,CAAC,GAAG,CAAC;AACxB,CAAC,CAAA,CAAC;AAjBW,QAAA,eAAe,mBAiB1B"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Use a GitHub app token to auth the Git push.
3
+ *
4
+ * This defaults to the `GITHUB_API_TOKEN` and `GITHUB_TOKEN` environment
5
+ * variables if `token` is not provided.
6
+ */
7
+ interface GitHubAppAuth {
8
+ type: 'gitHubApp';
9
+ token?: string;
10
+ }
11
+ interface PushParameters {
12
+ /**
13
+ * The auth mechanism for the push.
14
+ *
15
+ * Currently, only GitHub app tokens are supported.
16
+ */
17
+ auth: GitHubAppAuth;
18
+ dir: string;
19
+ /**
20
+ * The reference to push to the remote.
21
+ *
22
+ * This may be a commit, branch or tag in the local repository.
23
+ */
24
+ ref: string;
25
+ remote?: string;
26
+ /**
27
+ * The destination branch or tag on the remote.
28
+ *
29
+ * This defaults to `ref`.
30
+ */
31
+ remoteRef?: string;
32
+ /**
33
+ * Forcefully override any conflicts.
34
+ *
35
+ * This defaults to `false`.
36
+ */
37
+ force?: boolean;
38
+ }
39
+ /**
40
+ * Pushes the specified `ref` from the local Git repository to a remote.
41
+ */
42
+ export declare const push: ({ auth, dir, ref, remote, remoteRef, force, }: PushParameters) => Promise<import("isomorphic-git").PushResult>;
43
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.push = void 0;
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const isomorphic_git_1 = __importDefault(require("isomorphic-git"));
18
+ const node_1 = __importDefault(require("isomorphic-git/http/node"));
19
+ const environment_1 = require("../github/environment");
20
+ const remote_1 = require("./remote");
21
+ /**
22
+ * Pushes the specified `ref` from the local Git repository to a remote.
23
+ */
24
+ const push = ({ auth, dir, ref, remote, remoteRef, force, }) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const { owner, repo } = yield (0, remote_1.getOwnerAndRepo)({ dir });
26
+ const url = `https://github.com/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`;
27
+ return isomorphic_git_1.default.push({
28
+ onAuth: () => {
29
+ var _a;
30
+ return ({
31
+ username: 'x-access-token',
32
+ password: (_a = auth.token) !== null && _a !== void 0 ? _a : (0, environment_1.apiTokenFromEnvironment)(),
33
+ });
34
+ },
35
+ dir,
36
+ fs: fs_extra_1.default,
37
+ http: node_1.default,
38
+ ref,
39
+ remote,
40
+ remoteRef,
41
+ url,
42
+ force,
43
+ });
44
+ });
45
+ exports.push = push;
46
+ //# sourceMappingURL=push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push.js","sourceRoot":"","sources":["../../../src/api/git/push.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,oEAAiC;AACjC,oEAA4C;AAE5C,uDAAgE;AAEhE,qCAA2C;AA+C3C;;GAEG;AACI,MAAM,IAAI,GAAG,CAAO,EACzB,IAAI,EACJ,GAAG,EACH,GAAG,EACH,MAAM,EACN,SAAS,EACT,KAAK,GACU,EAAE,EAAE;IACnB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,wBAAe,EAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAEvD,MAAM,GAAG,GAAG,sBAAsB,kBAAkB,CAClD,KAAK,CACN,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;IAEhC,OAAO,wBAAG,CAAC,IAAI,CAAC;QACd,MAAM,EAAE,GAAG,EAAE;;YAAC,OAAA,CAAC;gBACb,QAAQ,EAAE,gBAAgB;gBAC1B,QAAQ,EAAE,MAAA,IAAI,CAAC,KAAK,mCAAI,IAAA,qCAAuB,GAAE;aAClD,CAAC,CAAA;SAAA;QACF,GAAG;QACH,EAAE,EAAF,kBAAE;QACF,IAAI,EAAJ,cAAI;QACJ,GAAG;QACH,MAAM;QACN,SAAS;QACT,GAAG;QACH,KAAK;KACN,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AA5BW,QAAA,IAAI,QA4Bf"}
@@ -0,0 +1,18 @@
1
+ interface GetOwnerAndRepoParameters {
2
+ dir: string;
3
+ }
4
+ /**
5
+ * Extracts the owner and repository names from local Git remotes.
6
+ *
7
+ * Currently, only GitHub repository URLs are supported:
8
+ *
9
+ * ```console
10
+ * git@github.com:seek-oss/skuba.git
11
+ * https://github.com/seek-oss/skuba.git
12
+ * ```
13
+ */
14
+ export declare const getOwnerAndRepo: ({ dir, }: GetOwnerAndRepoParameters) => Promise<{
15
+ owner: string;
16
+ repo: string;
17
+ }>;
18
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getOwnerAndRepo = void 0;
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const isomorphic_git_1 = __importDefault(require("isomorphic-git"));
18
+ /**
19
+ * Matches the owner and repository names in a GitHub repository URL.
20
+ *
21
+ * For example, given the following input strings:
22
+ *
23
+ * ```console
24
+ * git@github.com:seek-oss/skuba.git
25
+ * https://github.com/seek-oss/skuba.git
26
+ * ```
27
+ *
28
+ * This pattern will produce the following matches:
29
+ *
30
+ * 1. seek-oss
31
+ * 2. skuba
32
+ */
33
+ const ownerRepoRegex = /github.com(?::|\/)(.+)\/(.+).git$/;
34
+ /**
35
+ * Extracts the owner and repository names from local Git remotes.
36
+ *
37
+ * Currently, only GitHub repository URLs are supported:
38
+ *
39
+ * ```console
40
+ * git@github.com:seek-oss/skuba.git
41
+ * https://github.com/seek-oss/skuba.git
42
+ * ```
43
+ */
44
+ const getOwnerAndRepo = ({ dir, }) => __awaiter(void 0, void 0, void 0, function* () {
45
+ const remotes = yield isomorphic_git_1.default.listRemotes({ dir, fs: fs_extra_1.default });
46
+ for (const { url } of remotes) {
47
+ const match = ownerRepoRegex.exec(url);
48
+ const owner = match === null || match === void 0 ? void 0 : match[1];
49
+ const repo = match === null || match === void 0 ? void 0 : match[2];
50
+ if (owner && repo) {
51
+ return { owner, repo };
52
+ }
53
+ }
54
+ throw new Error('Could not find a GitHub remote');
55
+ });
56
+ exports.getOwnerAndRepo = getOwnerAndRepo;
57
+ //# sourceMappingURL=remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["../../../src/api/git/remote.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,oEAAiC;AAEjC;;;;;;;;;;;;;;GAcG;AACH,MAAM,cAAc,GAAG,mCAAmC,CAAC;AAM3D;;;;;;;;;GASG;AACI,MAAM,eAAe,GAAG,CAAO,EACpC,GAAG,GACuB,EAA4C,EAAE;IACxE,MAAM,OAAO,GAAG,MAAM,wBAAG,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE,EAAF,kBAAE,EAAE,CAAC,CAAC;IAEnD,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,OAAO,EAAE;QAC7B,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEvC,MAAM,KAAK,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,CAAC,CAAC,CAAC;QACzB,MAAM,IAAI,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,CAAC,CAAC,CAAC;QAExB,IAAI,KAAK,IAAI,IAAI,EAAE;YACjB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SACxB;KACF;IAED,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;AACpD,CAAC,CAAA,CAAC;AAjBW,QAAA,eAAe,mBAiB1B"}