@datadog/datadog-ci 2.40.3 → 2.41.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 (252) hide show
  1. package/README.md +1 -0
  2. package/dist/commands/deployment/cli.js +2 -1
  3. package/dist/commands/deployment/cli.js.map +1 -1
  4. package/dist/commands/deployment/correlate.d.ts +18 -0
  5. package/dist/commands/deployment/correlate.js +154 -0
  6. package/dist/commands/deployment/correlate.js.map +1 -0
  7. package/dist/commands/dsyms/utils.js +2 -4
  8. package/dist/commands/dsyms/utils.js.map +1 -1
  9. package/dist/helpers/git/get-git-data.d.ts +2 -0
  10. package/dist/helpers/git/get-git-data.js +11 -1
  11. package/dist/helpers/git/get-git-data.js.map +1 -1
  12. package/package.json +3 -2
  13. package/dist/__tests__/cli.test.d.ts +0 -1
  14. package/dist/__tests__/cli.test.js +0 -41
  15. package/dist/__tests__/cli.test.js.map +0 -1
  16. package/dist/commands/cloud-run/__tests__/fixtures.d.ts +0 -2
  17. package/dist/commands/cloud-run/__tests__/fixtures.js +0 -12
  18. package/dist/commands/cloud-run/__tests__/fixtures.js.map +0 -1
  19. package/dist/commands/cloud-run/__tests__/flare.test.d.ts +0 -1
  20. package/dist/commands/cloud-run/__tests__/flare.test.js +0 -557
  21. package/dist/commands/cloud-run/__tests__/flare.test.js.map +0 -1
  22. package/dist/commands/deployment/__tests__/mark.test.d.ts +0 -1
  23. package/dist/commands/deployment/__tests__/mark.test.js +0 -47
  24. package/dist/commands/deployment/__tests__/mark.test.js.map +0 -1
  25. package/dist/commands/dora/__tests__/deployment.test.d.ts +0 -1
  26. package/dist/commands/dora/__tests__/deployment.test.js +0 -201
  27. package/dist/commands/dora/__tests__/deployment.test.js.map +0 -1
  28. package/dist/commands/dsyms/__tests__/upload.test.d.ts +0 -1
  29. package/dist/commands/dsyms/__tests__/upload.test.js +0 -346
  30. package/dist/commands/dsyms/__tests__/upload.test.js.map +0 -1
  31. package/dist/commands/dsyms/__tests__/utils.test.d.ts +0 -1
  32. package/dist/commands/dsyms/__tests__/utils.test.js +0 -103
  33. package/dist/commands/dsyms/__tests__/utils.test.js.map +0 -1
  34. package/dist/commands/elf-symbols/__tests__/elf.test.d.ts +0 -1
  35. package/dist/commands/elf-symbols/__tests__/elf.test.js +0 -813
  36. package/dist/commands/elf-symbols/__tests__/elf.test.js.map +0 -1
  37. package/dist/commands/elf-symbols/__tests__/upload.test.d.ts +0 -1
  38. package/dist/commands/elf-symbols/__tests__/upload.test.js +0 -249
  39. package/dist/commands/elf-symbols/__tests__/upload.test.js.map +0 -1
  40. package/dist/commands/flutter-symbols/__tests__/upload.test.d.ts +0 -1
  41. package/dist/commands/flutter-symbols/__tests__/upload.test.js +0 -617
  42. package/dist/commands/flutter-symbols/__tests__/upload.test.js.map +0 -1
  43. package/dist/commands/gate/__tests__/evaluate.test.d.ts +0 -1
  44. package/dist/commands/gate/__tests__/evaluate.test.js +0 -398
  45. package/dist/commands/gate/__tests__/evaluate.test.js.map +0 -1
  46. package/dist/commands/gate/__tests__/scope.test.d.ts +0 -1
  47. package/dist/commands/gate/__tests__/scope.test.js +0 -29
  48. package/dist/commands/gate/__tests__/scope.test.js.map +0 -1
  49. package/dist/commands/git-metadata/__tests__/git.test.d.ts +0 -1
  50. package/dist/commands/git-metadata/__tests__/git.test.js +0 -132
  51. package/dist/commands/git-metadata/__tests__/git.test.js.map +0 -1
  52. package/dist/commands/git-metadata/__tests__/gitdb.test.d.ts +0 -1
  53. package/dist/commands/git-metadata/__tests__/gitdb.test.js +0 -1386
  54. package/dist/commands/git-metadata/__tests__/gitdb.test.js.map +0 -1
  55. package/dist/commands/git-metadata/__tests__/library.test.d.ts +0 -1
  56. package/dist/commands/git-metadata/__tests__/library.test.js +0 -118
  57. package/dist/commands/git-metadata/__tests__/library.test.js.map +0 -1
  58. package/dist/commands/git-metadata/__tests__/upload.test.d.ts +0 -1
  59. package/dist/commands/git-metadata/__tests__/upload.test.js +0 -52
  60. package/dist/commands/git-metadata/__tests__/upload.test.js.map +0 -1
  61. package/dist/commands/junit/__tests__/id.test.d.ts +0 -1
  62. package/dist/commands/junit/__tests__/id.test.js +0 -24
  63. package/dist/commands/junit/__tests__/id.test.js.map +0 -1
  64. package/dist/commands/junit/__tests__/upload.test.d.ts +0 -1
  65. package/dist/commands/junit/__tests__/upload.test.js +0 -495
  66. package/dist/commands/junit/__tests__/upload.test.js.map +0 -1
  67. package/dist/commands/lambda/__tests__/fixtures.d.ts +0 -51
  68. package/dist/commands/lambda/__tests__/fixtures.js +0 -146
  69. package/dist/commands/lambda/__tests__/fixtures.js.map +0 -1
  70. package/dist/commands/lambda/__tests__/flare.test.d.ts +0 -1
  71. package/dist/commands/lambda/__tests__/flare.test.js +0 -730
  72. package/dist/commands/lambda/__tests__/flare.test.js.map +0 -1
  73. package/dist/commands/lambda/__tests__/functions/commons.test.d.ts +0 -1
  74. package/dist/commands/lambda/__tests__/functions/commons.test.js +0 -791
  75. package/dist/commands/lambda/__tests__/functions/commons.test.js.map +0 -1
  76. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.d.ts +0 -1
  77. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js +0 -386
  78. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js.map +0 -1
  79. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.d.ts +0 -1
  80. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js +0 -721
  81. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js.map +0 -1
  82. package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +0 -1
  83. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +0 -513
  84. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js.map +0 -1
  85. package/dist/commands/lambda/__tests__/functions/versionChecker.test.d.ts +0 -1
  86. package/dist/commands/lambda/__tests__/functions/versionChecker.test.js +0 -33
  87. package/dist/commands/lambda/__tests__/functions/versionChecker.test.js.map +0 -1
  88. package/dist/commands/lambda/__tests__/instrument.test.d.ts +0 -1
  89. package/dist/commands/lambda/__tests__/instrument.test.js +0 -1511
  90. package/dist/commands/lambda/__tests__/instrument.test.js.map +0 -1
  91. package/dist/commands/lambda/__tests__/loggroup.test.d.ts +0 -1
  92. package/dist/commands/lambda/__tests__/loggroup.test.js +0 -340
  93. package/dist/commands/lambda/__tests__/loggroup.test.js.map +0 -1
  94. package/dist/commands/lambda/__tests__/prompt.test.d.ts +0 -1
  95. package/dist/commands/lambda/__tests__/prompt.test.js +0 -206
  96. package/dist/commands/lambda/__tests__/prompt.test.js.map +0 -1
  97. package/dist/commands/lambda/__tests__/tags.test.d.ts +0 -1
  98. package/dist/commands/lambda/__tests__/tags.test.js +0 -305
  99. package/dist/commands/lambda/__tests__/tags.test.js.map +0 -1
  100. package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +0 -1
  101. package/dist/commands/lambda/__tests__/uninstrument.test.js +0 -722
  102. package/dist/commands/lambda/__tests__/uninstrument.test.js.map +0 -1
  103. package/dist/commands/measure/__tests__/measure.test.d.ts +0 -1
  104. package/dist/commands/measure/__tests__/measure.test.js +0 -110
  105. package/dist/commands/measure/__tests__/measure.test.js.map +0 -1
  106. package/dist/commands/react-native/__tests__/codepush.test.d.ts +0 -1
  107. package/dist/commands/react-native/__tests__/codepush.test.js +0 -161
  108. package/dist/commands/react-native/__tests__/codepush.test.js.map +0 -1
  109. package/dist/commands/react-native/__tests__/interfaces.test.d.ts +0 -1
  110. package/dist/commands/react-native/__tests__/interfaces.test.js +0 -33
  111. package/dist/commands/react-native/__tests__/interfaces.test.js.map +0 -1
  112. package/dist/commands/react-native/__tests__/upload.test.d.ts +0 -1
  113. package/dist/commands/react-native/__tests__/upload.test.js +0 -238
  114. package/dist/commands/react-native/__tests__/upload.test.js.map +0 -1
  115. package/dist/commands/react-native/__tests__/utils.test.d.ts +0 -1
  116. package/dist/commands/react-native/__tests__/utils.test.js +0 -27
  117. package/dist/commands/react-native/__tests__/utils.test.js.map +0 -1
  118. package/dist/commands/react-native/__tests__/xcode.test.d.ts +0 -1
  119. package/dist/commands/react-native/__tests__/xcode.test.js +0 -465
  120. package/dist/commands/react-native/__tests__/xcode.test.js.map +0 -1
  121. package/dist/commands/sarif/__tests__/upload.test.d.ts +0 -1
  122. package/dist/commands/sarif/__tests__/upload.test.js +0 -228
  123. package/dist/commands/sarif/__tests__/upload.test.js.map +0 -1
  124. package/dist/commands/sbom/__tests__/payload.test.d.ts +0 -1
  125. package/dist/commands/sbom/__tests__/payload.test.js +0 -262
  126. package/dist/commands/sbom/__tests__/payload.test.js.map +0 -1
  127. package/dist/commands/sbom/__tests__/validation.test.d.ts +0 -1
  128. package/dist/commands/sbom/__tests__/validation.test.js +0 -41
  129. package/dist/commands/sbom/__tests__/validation.test.js.map +0 -1
  130. package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +0 -1
  131. package/dist/commands/sourcemaps/__tests__/upload.test.js +0 -270
  132. package/dist/commands/sourcemaps/__tests__/upload.test.js.map +0 -1
  133. package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +0 -1
  134. package/dist/commands/sourcemaps/__tests__/utils.test.js +0 -31
  135. package/dist/commands/sourcemaps/__tests__/utils.test.js.map +0 -1
  136. package/dist/commands/stepfunctions/__tests__/awsCommands.test.d.ts +0 -1
  137. package/dist/commands/stepfunctions/__tests__/awsCommands.test.js +0 -192
  138. package/dist/commands/stepfunctions/__tests__/awsCommands.test.js.map +0 -1
  139. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.d.ts +0 -6
  140. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.js +0 -45
  141. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.js.map +0 -1
  142. package/dist/commands/stepfunctions/__tests__/fixtures/cli.d.ts +0 -5
  143. package/dist/commands/stepfunctions/__tests__/fixtures/cli.js +0 -19
  144. package/dist/commands/stepfunctions/__tests__/fixtures/cli.js.map +0 -1
  145. package/dist/commands/stepfunctions/__tests__/helpers.test.d.ts +0 -1
  146. package/dist/commands/stepfunctions/__tests__/helpers.test.js +0 -205
  147. package/dist/commands/stepfunctions/__tests__/helpers.test.js.map +0 -1
  148. package/dist/commands/stepfunctions/__tests__/instrument.test.d.ts +0 -1
  149. package/dist/commands/stepfunctions/__tests__/instrument.test.js +0 -431
  150. package/dist/commands/stepfunctions/__tests__/instrument.test.js.map +0 -1
  151. package/dist/commands/stepfunctions/__tests__/uninstrument.test.d.ts +0 -1
  152. package/dist/commands/stepfunctions/__tests__/uninstrument.test.js +0 -166
  153. package/dist/commands/stepfunctions/__tests__/uninstrument.test.js.map +0 -1
  154. package/dist/commands/synthetics/__tests__/api.test.d.ts +0 -1
  155. package/dist/commands/synthetics/__tests__/api.test.js +0 -422
  156. package/dist/commands/synthetics/__tests__/api.test.js.map +0 -1
  157. package/dist/commands/synthetics/__tests__/cli.test.d.ts +0 -1
  158. package/dist/commands/synthetics/__tests__/cli.test.js +0 -1325
  159. package/dist/commands/synthetics/__tests__/cli.test.js.map +0 -1
  160. package/dist/commands/synthetics/__tests__/fixtures.d.ts +0 -149
  161. package/dist/commands/synthetics/__tests__/fixtures.js +0 -507
  162. package/dist/commands/synthetics/__tests__/fixtures.js.map +0 -1
  163. package/dist/commands/synthetics/__tests__/mobile.test.d.ts +0 -1
  164. package/dist/commands/synthetics/__tests__/mobile.test.js +0 -376
  165. package/dist/commands/synthetics/__tests__/mobile.test.js.map +0 -1
  166. package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +0 -1
  167. package/dist/commands/synthetics/__tests__/reporters/default.test.js +0 -354
  168. package/dist/commands/synthetics/__tests__/reporters/default.test.js.map +0 -1
  169. package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +0 -1
  170. package/dist/commands/synthetics/__tests__/reporters/junit.test.js +0 -353
  171. package/dist/commands/synthetics/__tests__/reporters/junit.test.js.map +0 -1
  172. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.d.ts +0 -1
  173. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.js +0 -232
  174. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.js.map +0 -1
  175. package/dist/commands/synthetics/__tests__/run-tests-lib.test.d.ts +0 -1
  176. package/dist/commands/synthetics/__tests__/run-tests-lib.test.js +0 -735
  177. package/dist/commands/synthetics/__tests__/run-tests-lib.test.js.map +0 -1
  178. package/dist/commands/synthetics/__tests__/test.test.d.ts +0 -1
  179. package/dist/commands/synthetics/__tests__/test.test.js +0 -33
  180. package/dist/commands/synthetics/__tests__/test.test.js.map +0 -1
  181. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.d.ts +0 -1
  182. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js +0 -21
  183. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js.map +0 -1
  184. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.d.ts +0 -1
  185. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js +0 -80
  186. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js.map +0 -1
  187. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.d.ts +0 -1
  188. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js +0 -109
  189. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js.map +0 -1
  190. package/dist/commands/synthetics/__tests__/utils/internal.test.d.ts +0 -1
  191. package/dist/commands/synthetics/__tests__/utils/internal.test.js +0 -186
  192. package/dist/commands/synthetics/__tests__/utils/internal.test.js.map +0 -1
  193. package/dist/commands/synthetics/__tests__/utils/public.test.d.ts +0 -1
  194. package/dist/commands/synthetics/__tests__/utils/public.test.js +0 -1526
  195. package/dist/commands/synthetics/__tests__/utils/public.test.js.map +0 -1
  196. package/dist/commands/tag/__tests__/tag.test.d.ts +0 -1
  197. package/dist/commands/tag/__tests__/tag.test.js +0 -75
  198. package/dist/commands/tag/__tests__/tag.test.js.map +0 -1
  199. package/dist/commands/trace/__tests__/trace.test.d.ts +0 -1
  200. package/dist/commands/trace/__tests__/trace.test.js +0 -145
  201. package/dist/commands/trace/__tests__/trace.test.js.map +0 -1
  202. package/dist/commands/unity-symbols/__tests__/upload.test.d.ts +0 -1
  203. package/dist/commands/unity-symbols/__tests__/upload.test.js +0 -369
  204. package/dist/commands/unity-symbols/__tests__/upload.test.js.map +0 -1
  205. package/dist/helpers/__tests__/app.test.d.ts +0 -1
  206. package/dist/helpers/__tests__/app.test.js +0 -31
  207. package/dist/helpers/__tests__/app.test.js.map +0 -1
  208. package/dist/helpers/__tests__/ci.test.d.ts +0 -1
  209. package/dist/helpers/__tests__/ci.test.js +0 -252
  210. package/dist/helpers/__tests__/ci.test.js.map +0 -1
  211. package/dist/helpers/__tests__/fixtures.d.ts +0 -33
  212. package/dist/helpers/__tests__/fixtures.js +0 -71
  213. package/dist/helpers/__tests__/fixtures.js.map +0 -1
  214. package/dist/helpers/__tests__/flare.test.d.ts +0 -1
  215. package/dist/helpers/__tests__/flare.test.js +0 -226
  216. package/dist/helpers/__tests__/flare.test.js.map +0 -1
  217. package/dist/helpers/__tests__/fs.test.d.ts +0 -1
  218. package/dist/helpers/__tests__/fs.test.js +0 -189
  219. package/dist/helpers/__tests__/fs.test.js.map +0 -1
  220. package/dist/helpers/__tests__/plist.test.d.ts +0 -1
  221. package/dist/helpers/__tests__/plist.test.js +0 -43
  222. package/dist/helpers/__tests__/plist.test.js.map +0 -1
  223. package/dist/helpers/__tests__/prompt.test.d.ts +0 -1
  224. package/dist/helpers/__tests__/prompt.test.js +0 -71
  225. package/dist/helpers/__tests__/prompt.test.js.map +0 -1
  226. package/dist/helpers/__tests__/retry.test.d.ts +0 -1
  227. package/dist/helpers/__tests__/retry.test.js +0 -99
  228. package/dist/helpers/__tests__/retry.test.js.map +0 -1
  229. package/dist/helpers/__tests__/tags.test.d.ts +0 -1
  230. package/dist/helpers/__tests__/tags.test.js +0 -71
  231. package/dist/helpers/__tests__/tags.test.js.map +0 -1
  232. package/dist/helpers/__tests__/upload.test.d.ts +0 -1
  233. package/dist/helpers/__tests__/upload.test.js +0 -231
  234. package/dist/helpers/__tests__/upload.test.js.map +0 -1
  235. package/dist/helpers/__tests__/user-provided-git.test.d.ts +0 -1
  236. package/dist/helpers/__tests__/user-provided-git.test.js +0 -119
  237. package/dist/helpers/__tests__/user-provided-git.test.js.map +0 -1
  238. package/dist/helpers/__tests__/utils.test.d.ts +0 -1
  239. package/dist/helpers/__tests__/utils.test.js +0 -429
  240. package/dist/helpers/__tests__/utils.test.js.map +0 -1
  241. package/dist/helpers/__tests__/validation.test.d.ts +0 -1
  242. package/dist/helpers/__tests__/validation.test.js +0 -25
  243. package/dist/helpers/__tests__/validation.test.js.map +0 -1
  244. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.d.ts +0 -1
  245. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js +0 -103
  246. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js.map +0 -1
  247. package/dist/helpers/git/__tests__/format-git-span-data.test.d.ts +0 -1
  248. package/dist/helpers/git/__tests__/format-git-span-data.test.js +0 -121
  249. package/dist/helpers/git/__tests__/format-git-span-data.test.js.map +0 -1
  250. package/dist/helpers/git/__tests__/get-git-data.test.d.ts +0 -1
  251. package/dist/helpers/git/__tests__/get-git-data.test.js +0 -72
  252. package/dist/helpers/git/__tests__/get-git-data.test.js.map +0 -1
@@ -1,1386 +0,0 @@
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
- const child_process_1 = __importDefault(require("child_process"));
16
- const fs_1 = __importDefault(require("fs"));
17
- const promises_1 = __importDefault(require("fs/promises"));
18
- const os_1 = __importDefault(require("os"));
19
- const path_1 = __importDefault(require("path"));
20
- const axios_1 = __importDefault(require("axios"));
21
- const logger_1 = require("../../../helpers/logger");
22
- const utils_1 = require("../../../helpers/utils");
23
- const gitdb_1 = require("../gitdb");
24
- describe('gitdb', () => {
25
- const tmpdir = path_1.default.join(os_1.default.tmpdir(), 'random');
26
- const temporaryPackFile = `${tmpdir}/1000-87ce64f636853fbebc05edfcefe9cccc28a7968b.pack`;
27
- const secondTemporaryPackFile = `${tmpdir}/1000-cc424c261da5e261b76d982d5d361a023556e2aa.pack`;
28
- beforeAll(() => {
29
- process.env.DD_API_KEY = 'api-key';
30
- jest.spyOn(global.Math, 'random').mockReturnValue(0.1);
31
- });
32
- beforeEach(() => {
33
- fs_1.default.mkdirSync(tmpdir, {
34
- recursive: true,
35
- });
36
- jest.spyOn(promises_1.default, 'mkdtemp').mockResolvedValue(tmpdir);
37
- fs_1.default.writeFileSync(temporaryPackFile, '');
38
- fs_1.default.writeFileSync(secondTemporaryPackFile, '');
39
- });
40
- afterEach(() => {
41
- jest.spyOn(promises_1.default, 'mkdtemp').mockRestore();
42
- });
43
- afterAll(() => {
44
- delete process.env.DD_API_KEY;
45
- jest.spyOn(global.Math, 'random').mockRestore();
46
- });
47
- const logger = new logger_1.Logger((_) => { }, logger_1.LogLevel.INFO);
48
- const request = (0, utils_1.getRequestBuilder)({
49
- apiKey: 'api-key',
50
- baseUrl: 'https://api.datadoghq.com',
51
- });
52
- const testError = new Error('call failed');
53
- // This is a bit hacky but the documentation of simpleGit asks you to depend on
54
- // a behavior of VersionResult which is not defined in its typings: it has an
55
- // override on toString. Here I am replicating this toString behavior so that
56
- // the tests pass. See https://github.com/steveukx/git-js/blob/d184c13273abca4b6572c260f9625c19f944d4f7/simple-git/src/lib/tasks/version.ts#L15-L39
57
- const newGitVersion = Object.defineProperty({
58
- major: 2,
59
- minor: 41,
60
- patch: 0,
61
- agent: '',
62
- installed: true,
63
- }, 'toString', {
64
- value() {
65
- return `${this.major}.${this.minor}.${this.patch}`;
66
- },
67
- configurable: false,
68
- enumerable: false,
69
- });
70
- const oldGitVersion = Object.defineProperty({
71
- major: 2,
72
- minor: 20,
73
- patch: 3,
74
- agent: '',
75
- installed: true,
76
- }, 'toString', {
77
- value() {
78
- return `${this.major}.${this.minor}.${this.patch}`;
79
- },
80
- configurable: false,
81
- enumerable: false,
82
- });
83
- const defaultRemoteNameNotConfigured = {
84
- key: 'clone.defaultRemoteName',
85
- paths: [],
86
- scopes: new Map(),
87
- // eslint-disable-next-line no-null/no-null
88
- value: null,
89
- values: [],
90
- };
91
- class MockAll {
92
- constructor(mockParams) {
93
- this.simpleGit = {
94
- getConfig: jest.fn(),
95
- fetch: jest.fn(),
96
- getRemotes: jest.fn(),
97
- log: jest.fn(),
98
- raw: jest.fn(),
99
- revparse: jest.fn(),
100
- version: jest.fn(),
101
- };
102
- // call spyOn on these two mocks to make sure the underlying implementation is never called
103
- // as the default behavior of spyOn is to actually call the initial implem if not overridden
104
- this.execSync = jest.spyOn(child_process_1.default, 'execSync').mockImplementation(() => '');
105
- this.axios = jest.spyOn(axios_1.default, 'create').mockImplementation(() => ((_) => { }));
106
- const initMockWithParams = (mock, params, promise, name = '') => {
107
- params.forEach((param) => {
108
- if (param.output instanceof Error) {
109
- mock = mock.mockImplementationOnce((..._) => {
110
- throw param.output;
111
- });
112
- }
113
- else {
114
- if (promise) {
115
- mock = mock.mockResolvedValueOnce(param.output);
116
- }
117
- else {
118
- mock = mock.mockReturnValueOnce(param.output);
119
- }
120
- }
121
- });
122
- return () => {
123
- try {
124
- expect(mock.mock.calls).toHaveLength(params.length);
125
- params.forEach((param, i) => {
126
- if (param.input !== undefined) {
127
- expect(mock.mock.calls[i][0]).toStrictEqual(param.input);
128
- }
129
- });
130
- }
131
- catch (e) {
132
- // To make it easier to debug the tests
133
- // eslint-disable-next-line
134
- console.log('Error in', name, 'mock');
135
- throw e;
136
- }
137
- };
138
- };
139
- this.getConfigMetExpectations = initMockWithParams(this.simpleGit.getConfig, mockParams.getConfig, true, 'getConfig');
140
- this.fetchMetExpectations = initMockWithParams(this.simpleGit.fetch, mockParams.fetch, true, 'fetch');
141
- this.getRemotesMetExpectations = initMockWithParams(this.simpleGit.getRemotes, mockParams.getRemotes, true, 'getRemotes');
142
- this.logMetExpectations = initMockWithParams(this.simpleGit.log, mockParams.log, true, 'log');
143
- this.rawMetExpectations = initMockWithParams(this.simpleGit.raw, mockParams.raw, true, 'raw');
144
- this.revparseMetExpectations = initMockWithParams(this.simpleGit.revparse, mockParams.revparse, true, 'revparse');
145
- this.versionMetExpectations = initMockWithParams(this.simpleGit.version, mockParams.version, true, 'version');
146
- this.execSyncMetExpectations = initMockWithParams(this.execSync, mockParams.execSync, false, 'execSync');
147
- this.axiosCalls = [];
148
- // custom way of handling axios
149
- mockParams.axios.forEach((param) => {
150
- this.axios = this.axios.mockImplementationOnce(() => (req) => {
151
- this.axiosCalls.push({ url: req.url, data: req.data });
152
- if (param.output instanceof Error) {
153
- throw param.output;
154
- }
155
- return param.output;
156
- });
157
- });
158
- this.axiosMetExpectations = () => {
159
- expect(this.axios.mock.calls).toHaveLength(mockParams.axios.length);
160
- mockParams.axios.forEach((param, i) => {
161
- if (param.input !== undefined) {
162
- expect(this.axiosCalls[i].url).toBe(param.input.url);
163
- if (param.input.data !== undefined) {
164
- const data = this.axiosCalls[i].data;
165
- expect(JSON.parse(data)).toStrictEqual(param.input.data);
166
- }
167
- }
168
- });
169
- };
170
- }
171
- expectCalls() {
172
- this.getConfigMetExpectations();
173
- this.fetchMetExpectations();
174
- this.getRemotesMetExpectations();
175
- this.logMetExpectations();
176
- this.rawMetExpectations();
177
- this.revparseMetExpectations();
178
- this.versionMetExpectations();
179
- this.execSyncMetExpectations();
180
- this.axiosMetExpectations();
181
- }
182
- }
183
- test('should not work when remote is not present', () => __awaiter(void 0, void 0, void 0, function* () {
184
- const mocks = new MockAll({
185
- getConfig: [],
186
- fetch: [],
187
- getRemotes: [{ input: undefined, output: testError }],
188
- log: [],
189
- raw: [],
190
- revparse: [],
191
- version: [],
192
- execSync: [],
193
- axios: [],
194
- });
195
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
196
- yield expect(upload).rejects.toThrow(testError);
197
- mocks.expectCalls();
198
- }));
199
- test('should unshallow repository if git version is recent and backend does not have all commits already', () => __awaiter(void 0, void 0, void 0, function* () {
200
- const mocks = new MockAll({
201
- getConfig: [
202
- {
203
- input: 'clone.defaultRemoteName',
204
- output: defaultRemoteNameNotConfigured,
205
- },
206
- {
207
- input: 'clone.defaultRemoteName',
208
- output: defaultRemoteNameNotConfigured,
209
- },
210
- ],
211
- fetch: [
212
- {
213
- input: [
214
- '--shallow-since="1 month ago"',
215
- '--update-shallow',
216
- '--filter=blob:none',
217
- '--recurse-submodules=no',
218
- 'origin',
219
- 'COMMIT',
220
- ],
221
- output: '',
222
- },
223
- ],
224
- getRemotes: [
225
- {
226
- input: undefined,
227
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
228
- },
229
- ],
230
- log: [
231
- {
232
- input: ['-n 1000', '--since="1 month ago"'],
233
- output: {
234
- all: [
235
- {
236
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
237
- },
238
- {
239
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
240
- },
241
- ],
242
- },
243
- },
244
- // throw an exception after the update shallow to shortcut the rest of the test as we only
245
- // care about updating the shallow clone, not about the rest of the process for this test
246
- { input: undefined, output: testError },
247
- ],
248
- raw: [],
249
- revparse: [
250
- { input: '--is-shallow-repository', output: 'true' },
251
- { input: 'HEAD', output: 'COMMIT' },
252
- ],
253
- version: [{ input: undefined, output: newGitVersion }],
254
- execSync: [],
255
- axios: [
256
- {
257
- input: {
258
- url: '/api/v2/git/repository/search_commits',
259
- data: {
260
- meta: {
261
- repository_url: 'https://github.com/DataDog/datadog-ci',
262
- },
263
- data: [
264
- {
265
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
266
- type: 'commit',
267
- },
268
- {
269
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
270
- type: 'commit',
271
- },
272
- ],
273
- },
274
- },
275
- output: { data: { data: [] } },
276
- },
277
- ],
278
- });
279
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
280
- yield expect(upload).rejects.toThrow(testError);
281
- mocks.expectCalls();
282
- }));
283
- test('should unshallow repository with custom origin value', () => __awaiter(void 0, void 0, void 0, function* () {
284
- // MockParam<string, simpleGit.ConfigGetResult>[]
285
- const mocks = new MockAll({
286
- getConfig: [
287
- {
288
- input: 'clone.defaultRemoteName',
289
- output: {
290
- key: 'clone.defaultRemoteName',
291
- paths: [],
292
- scopes: new Map(),
293
- value: 'myorigin',
294
- values: [],
295
- },
296
- },
297
- {
298
- input: 'clone.defaultRemoteName',
299
- output: {
300
- key: 'clone.defaultRemoteName',
301
- paths: [],
302
- scopes: new Map(),
303
- value: 'myorigin',
304
- values: [],
305
- },
306
- },
307
- ],
308
- fetch: [
309
- {
310
- input: [
311
- '--shallow-since="1 month ago"',
312
- '--update-shallow',
313
- '--filter=blob:none',
314
- '--recurse-submodules=no',
315
- 'myorigin',
316
- 'COMMIT',
317
- ],
318
- output: '',
319
- },
320
- ],
321
- getRemotes: [
322
- {
323
- input: undefined,
324
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
325
- },
326
- ],
327
- log: [
328
- {
329
- input: ['-n 1000', '--since="1 month ago"'],
330
- output: {
331
- all: [
332
- {
333
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
334
- },
335
- {
336
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
337
- },
338
- ],
339
- },
340
- },
341
- // throw an exception after the update shallow to shortcut the rest of the test as we only
342
- // care about updating the shallow clone, not about the rest of the process for this test
343
- { input: undefined, output: testError },
344
- ],
345
- raw: [],
346
- revparse: [
347
- { input: '--is-shallow-repository', output: 'true' },
348
- { input: 'HEAD', output: 'COMMIT' },
349
- ],
350
- version: [{ input: undefined, output: newGitVersion }],
351
- execSync: [],
352
- axios: [
353
- {
354
- input: {
355
- url: '/api/v2/git/repository/search_commits',
356
- data: {
357
- meta: {
358
- repository_url: 'https://github.com/DataDog/datadog-ci',
359
- },
360
- data: [
361
- {
362
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
363
- type: 'commit',
364
- },
365
- {
366
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
367
- type: 'commit',
368
- },
369
- ],
370
- },
371
- },
372
- output: { data: { data: [] } },
373
- },
374
- ],
375
- });
376
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
377
- yield expect(upload).rejects.toThrow(testError);
378
- mocks.expectCalls();
379
- }));
380
- test('should not unshallow repository if git version is old', () => __awaiter(void 0, void 0, void 0, function* () {
381
- const mocks = new MockAll({
382
- getConfig: [
383
- {
384
- input: 'clone.defaultRemoteName',
385
- output: defaultRemoteNameNotConfigured,
386
- },
387
- ],
388
- fetch: [],
389
- getRemotes: [
390
- {
391
- input: undefined,
392
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
393
- },
394
- ],
395
- log: [
396
- {
397
- input: ['-n 1000', '--since="1 month ago"'],
398
- output: {
399
- all: [
400
- {
401
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
402
- },
403
- {
404
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
405
- },
406
- ],
407
- },
408
- },
409
- ],
410
- // throw an exception after the failed unshallow to shortcut the rest of the test
411
- raw: [{ input: undefined, output: testError }],
412
- revparse: [],
413
- version: [{ input: undefined, output: oldGitVersion }],
414
- execSync: [],
415
- axios: [
416
- {
417
- input: {
418
- url: '/api/v2/git/repository/search_commits',
419
- data: {
420
- meta: {
421
- repository_url: 'https://github.com/DataDog/datadog-ci',
422
- },
423
- data: [
424
- {
425
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
426
- type: 'commit',
427
- },
428
- {
429
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
430
- type: 'commit',
431
- },
432
- ],
433
- },
434
- },
435
- output: { data: { data: [] } },
436
- },
437
- ],
438
- });
439
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
440
- yield expect(upload).rejects.toThrow(testError);
441
- mocks.expectCalls();
442
- }));
443
- test('should not unshallow repository if backend has all commits already', () => __awaiter(void 0, void 0, void 0, function* () {
444
- const mocks = new MockAll({
445
- getConfig: [
446
- {
447
- input: 'clone.defaultRemoteName',
448
- output: defaultRemoteNameNotConfigured,
449
- },
450
- ],
451
- fetch: [],
452
- getRemotes: [
453
- {
454
- input: undefined,
455
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
456
- },
457
- ],
458
- log: [
459
- {
460
- input: ['-n 1000', '--since="1 month ago"'],
461
- output: {
462
- all: [
463
- {
464
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
465
- },
466
- {
467
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
468
- },
469
- ],
470
- },
471
- },
472
- ],
473
- raw: [],
474
- revparse: [],
475
- version: [],
476
- execSync: [],
477
- axios: [
478
- {
479
- input: {
480
- url: '/api/v2/git/repository/search_commits',
481
- data: {
482
- meta: {
483
- repository_url: 'https://github.com/DataDog/datadog-ci',
484
- },
485
- data: [
486
- {
487
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
488
- type: 'commit',
489
- },
490
- {
491
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
492
- type: 'commit',
493
- },
494
- ],
495
- },
496
- },
497
- output: {
498
- data: {
499
- data: [
500
- {
501
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
502
- type: 'commit',
503
- },
504
- {
505
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
506
- type: 'commit',
507
- },
508
- ],
509
- },
510
- },
511
- },
512
- ],
513
- });
514
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
515
- yield expect(upload).resolves.toBe(undefined);
516
- mocks.expectCalls();
517
- }));
518
- test('should unshallow repository if the local HEAD is a commit not pushed to the remote', () => __awaiter(void 0, void 0, void 0, function* () {
519
- const mocks = new MockAll({
520
- getConfig: [
521
- {
522
- input: 'clone.defaultRemoteName',
523
- output: {
524
- key: 'clone.defaultRemoteName',
525
- paths: [],
526
- scopes: new Map(),
527
- value: 'origin',
528
- values: [],
529
- },
530
- },
531
- {
532
- input: 'clone.defaultRemoteName',
533
- output: {
534
- key: 'clone.defaultRemoteName',
535
- paths: [],
536
- scopes: new Map(),
537
- value: 'origin',
538
- values: [],
539
- },
540
- },
541
- ],
542
- fetch: [
543
- {
544
- input: [
545
- '--shallow-since="1 month ago"',
546
- '--update-shallow',
547
- '--filter=blob:none',
548
- '--recurse-submodules=no',
549
- 'origin',
550
- 'commit',
551
- ],
552
- output: new Error('commit not found'),
553
- },
554
- {
555
- input: [
556
- '--shallow-since="1 month ago"',
557
- '--update-shallow',
558
- '--filter=blob:none',
559
- '--recurse-submodules=no',
560
- 'origin',
561
- 'origin/branch',
562
- ],
563
- output: '',
564
- },
565
- ],
566
- getRemotes: [
567
- {
568
- input: undefined,
569
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
570
- },
571
- ],
572
- log: [
573
- {
574
- input: ['-n 1000', '--since="1 month ago"'],
575
- output: {
576
- all: [
577
- {
578
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
579
- },
580
- {
581
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
582
- },
583
- ],
584
- },
585
- },
586
- // we short circuit the test after the unshallow
587
- { input: undefined, output: testError },
588
- ],
589
- raw: [],
590
- revparse: [
591
- { input: '--is-shallow-repository', output: 'true' },
592
- { input: 'HEAD', output: 'commit' },
593
- { input: '--abbrev-ref --symbolic-full-name @{upstream}', output: 'origin/branch' },
594
- ],
595
- version: [{ input: undefined, output: newGitVersion }],
596
- execSync: [],
597
- axios: [
598
- {
599
- input: {
600
- url: '/api/v2/git/repository/search_commits',
601
- data: {
602
- meta: {
603
- repository_url: 'https://github.com/DataDog/datadog-ci',
604
- },
605
- data: [
606
- {
607
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
608
- type: 'commit',
609
- },
610
- {
611
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
612
- type: 'commit',
613
- },
614
- ],
615
- },
616
- },
617
- output: { data: { data: [] } },
618
- },
619
- ],
620
- });
621
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
622
- yield expect(upload).rejects.toThrow(testError);
623
- mocks.expectCalls();
624
- }));
625
- test("should unshallow repository if the CI is working on a detached HEAD or branch tracking hasn't been set up", () => __awaiter(void 0, void 0, void 0, function* () {
626
- const mocks = new MockAll({
627
- getConfig: [
628
- {
629
- input: 'clone.defaultRemoteName',
630
- output: {
631
- key: 'clone.defaultRemoteName',
632
- paths: [],
633
- scopes: new Map(),
634
- value: 'origin',
635
- values: [],
636
- },
637
- },
638
- {
639
- input: 'clone.defaultRemoteName',
640
- output: {
641
- key: 'clone.defaultRemoteName',
642
- paths: [],
643
- scopes: new Map(),
644
- value: 'origin',
645
- values: [],
646
- },
647
- },
648
- ],
649
- fetch: [
650
- {
651
- input: [
652
- '--shallow-since="1 month ago"',
653
- '--update-shallow',
654
- '--filter=blob:none',
655
- '--recurse-submodules=no',
656
- 'origin',
657
- 'commit',
658
- ],
659
- output: new Error('commit not found'),
660
- },
661
- {
662
- input: [
663
- '--shallow-since="1 month ago"',
664
- '--update-shallow',
665
- '--filter=blob:none',
666
- '--recurse-submodules=no',
667
- 'origin',
668
- 'origin/branch',
669
- ],
670
- output: new Error('working in detached mode'),
671
- },
672
- {
673
- input: [
674
- '--shallow-since="1 month ago"',
675
- '--update-shallow',
676
- '--filter=blob:none',
677
- '--recurse-submodules=no',
678
- 'origin',
679
- ],
680
- output: '',
681
- },
682
- ],
683
- getRemotes: [
684
- {
685
- input: undefined,
686
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
687
- },
688
- ],
689
- log: [
690
- {
691
- input: ['-n 1000', '--since="1 month ago"'],
692
- output: {
693
- all: [
694
- {
695
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
696
- },
697
- {
698
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
699
- },
700
- ],
701
- },
702
- },
703
- // we short circuit the test after the unshallow
704
- { input: undefined, output: testError },
705
- ],
706
- raw: [],
707
- revparse: [
708
- { input: '--is-shallow-repository', output: 'true' },
709
- { input: 'HEAD', output: 'commit' },
710
- { input: '--abbrev-ref --symbolic-full-name @{upstream}', output: 'origin/branch' },
711
- ],
712
- version: [{ input: undefined, output: newGitVersion }],
713
- execSync: [],
714
- axios: [
715
- {
716
- input: {
717
- url: '/api/v2/git/repository/search_commits',
718
- data: {
719
- meta: {
720
- repository_url: 'https://github.com/DataDog/datadog-ci',
721
- },
722
- data: [
723
- {
724
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
725
- type: 'commit',
726
- },
727
- {
728
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
729
- type: 'commit',
730
- },
731
- ],
732
- },
733
- },
734
- output: { data: { data: [] } },
735
- },
736
- ],
737
- });
738
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
739
- yield expect(upload).rejects.toThrow(testError);
740
- mocks.expectCalls();
741
- }));
742
- test('should send packfiles', () => __awaiter(void 0, void 0, void 0, function* () {
743
- const mocks = new MockAll({
744
- getConfig: [
745
- {
746
- input: 'clone.defaultRemoteName',
747
- output: defaultRemoteNameNotConfigured,
748
- },
749
- ],
750
- fetch: [],
751
- getRemotes: [
752
- {
753
- input: undefined,
754
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
755
- },
756
- ],
757
- log: [
758
- {
759
- input: ['-n 1000', '--since="1 month ago"'],
760
- output: {
761
- all: [
762
- {
763
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
764
- },
765
- {
766
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
767
- },
768
- ],
769
- },
770
- },
771
- ],
772
- raw: [
773
- {
774
- input: [
775
- 'rev-list',
776
- '--objects',
777
- '--no-object-names',
778
- '--filter=blob:none',
779
- '--since="1 month ago"',
780
- '87ce64f636853fbebc05edfcefe9cccc28a7968b',
781
- 'cc424c261da5e261b76d982d5d361a023556e2aa',
782
- ],
783
- output: '87ce64f636853fbebc05edfcefe9cccc28a7968b\ncc424c261da5e261b76d982d5d361a023556e2aa\n',
784
- },
785
- ],
786
- revparse: [{ input: '--is-shallow-repository', output: 'false' }],
787
- version: [{ input: undefined, output: newGitVersion }],
788
- execSync: [
789
- {
790
- input: `git pack-objects --compression=9 --max-pack-size=3m ${tmpdir}/1000`,
791
- output: Buffer.from('87ce64f636853fbebc05edfcefe9cccc28a7968b\ncc424c261da5e261b76d982d5d361a023556e2aa\n'),
792
- },
793
- ],
794
- axios: [
795
- {
796
- input: {
797
- url: '/api/v2/git/repository/search_commits',
798
- data: {
799
- meta: {
800
- repository_url: 'https://github.com/DataDog/datadog-ci',
801
- },
802
- data: [
803
- {
804
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
805
- type: 'commit',
806
- },
807
- {
808
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
809
- type: 'commit',
810
- },
811
- ],
812
- },
813
- },
814
- output: { data: { data: [] } },
815
- },
816
- {
817
- input: {
818
- url: '/api/v2/git/repository/packfile',
819
- data: undefined,
820
- },
821
- output: {},
822
- },
823
- {
824
- input: {
825
- url: '/api/v2/git/repository/packfile',
826
- data: undefined,
827
- },
828
- output: {},
829
- },
830
- ],
831
- });
832
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
833
- yield expect(upload).resolves.toBe(undefined);
834
- mocks.expectCalls();
835
- }));
836
- test('should override repository URL when specified', () => __awaiter(void 0, void 0, void 0, function* () {
837
- const mocks = new MockAll({
838
- getConfig: [],
839
- fetch: [],
840
- getRemotes: [],
841
- log: [
842
- {
843
- input: ['-n 1000', '--since="1 month ago"'],
844
- output: {
845
- all: [
846
- {
847
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
848
- },
849
- {
850
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
851
- },
852
- ],
853
- },
854
- },
855
- ],
856
- raw: [
857
- {
858
- input: [
859
- 'rev-list',
860
- '--objects',
861
- '--no-object-names',
862
- '--filter=blob:none',
863
- '--since="1 month ago"',
864
- '87ce64f636853fbebc05edfcefe9cccc28a7968b',
865
- 'cc424c261da5e261b76d982d5d361a023556e2aa',
866
- ],
867
- output: '87ce64f636853fbebc05edfcefe9cccc28a7968b\ncc424c261da5e261b76d982d5d361a023556e2aa\n',
868
- },
869
- ],
870
- revparse: [{ input: '--is-shallow-repository', output: 'false' }],
871
- version: [{ input: undefined, output: newGitVersion }],
872
- execSync: [
873
- {
874
- input: `git pack-objects --compression=9 --max-pack-size=3m ${tmpdir}/1000`,
875
- output: Buffer.from('87ce64f636853fbebc05edfcefe9cccc28a7968b\ncc424c261da5e261b76d982d5d361a023556e2aa\n'),
876
- },
877
- ],
878
- axios: [
879
- {
880
- input: {
881
- url: '/api/v2/git/repository/search_commits',
882
- data: {
883
- meta: {
884
- repository_url: 'https://github.com/DataDog/mycustomrepo',
885
- },
886
- data: [
887
- {
888
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
889
- type: 'commit',
890
- },
891
- {
892
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
893
- type: 'commit',
894
- },
895
- ],
896
- },
897
- },
898
- output: { data: { data: [] } },
899
- },
900
- {
901
- input: {
902
- url: '/api/v2/git/repository/packfile',
903
- data: undefined,
904
- },
905
- output: {},
906
- },
907
- {
908
- input: {
909
- url: '/api/v2/git/repository/packfile',
910
- data: undefined,
911
- },
912
- output: {},
913
- },
914
- ],
915
- });
916
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false, 'https://github.com/DataDog/mycustomrepo');
917
- yield expect(upload).resolves.toBe(undefined);
918
- mocks.expectCalls();
919
- }));
920
- test('should omit known commits', () => __awaiter(void 0, void 0, void 0, function* () {
921
- const mocks = new MockAll({
922
- getConfig: [
923
- {
924
- input: 'clone.defaultRemoteName',
925
- output: defaultRemoteNameNotConfigured,
926
- },
927
- ],
928
- fetch: [],
929
- getRemotes: [
930
- {
931
- input: undefined,
932
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
933
- },
934
- ],
935
- log: [
936
- {
937
- input: ['-n 1000', '--since="1 month ago"'],
938
- output: {
939
- all: [
940
- {
941
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
942
- },
943
- {
944
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
945
- },
946
- ],
947
- },
948
- },
949
- ],
950
- raw: [
951
- {
952
- input: [
953
- 'rev-list',
954
- '--objects',
955
- '--no-object-names',
956
- '--filter=blob:none',
957
- '--since="1 month ago"',
958
- '^87ce64f636853fbebc05edfcefe9cccc28a7968b',
959
- 'cc424c261da5e261b76d982d5d361a023556e2aa',
960
- ],
961
- output: 'cc424c261da5e261b76d982d5d361a023556e2aa\n',
962
- },
963
- ],
964
- revparse: [{ input: '--is-shallow-repository', output: 'false' }],
965
- version: [{ input: undefined, output: newGitVersion }],
966
- execSync: [
967
- {
968
- input: `git pack-objects --compression=9 --max-pack-size=3m ${tmpdir}/1000`,
969
- output: Buffer.from('cc424c261da5e261b76d982d5d361a023556e2aa\n'),
970
- },
971
- ],
972
- axios: [
973
- {
974
- input: {
975
- url: '/api/v2/git/repository/search_commits',
976
- data: {
977
- meta: {
978
- repository_url: 'https://github.com/DataDog/datadog-ci',
979
- },
980
- data: [
981
- {
982
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
983
- type: 'commit',
984
- },
985
- {
986
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
987
- type: 'commit',
988
- },
989
- ],
990
- },
991
- },
992
- output: {
993
- data: {
994
- data: [
995
- {
996
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
997
- type: 'commit',
998
- },
999
- ],
1000
- },
1001
- },
1002
- },
1003
- {
1004
- input: {
1005
- url: '/api/v2/git/repository/packfile',
1006
- data: undefined,
1007
- },
1008
- output: {},
1009
- },
1010
- ],
1011
- });
1012
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
1013
- yield expect(upload).resolves.toBe(undefined);
1014
- mocks.expectCalls();
1015
- }));
1016
- test('retries http requests', () => __awaiter(void 0, void 0, void 0, function* () {
1017
- const mocks = new MockAll({
1018
- getConfig: [
1019
- {
1020
- input: 'clone.defaultRemoteName',
1021
- output: defaultRemoteNameNotConfigured,
1022
- },
1023
- ],
1024
- fetch: [],
1025
- getRemotes: [
1026
- {
1027
- input: undefined,
1028
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
1029
- },
1030
- ],
1031
- log: [
1032
- {
1033
- input: ['-n 1000', '--since="1 month ago"'],
1034
- output: {
1035
- all: [
1036
- {
1037
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1038
- },
1039
- {
1040
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1041
- },
1042
- ],
1043
- },
1044
- },
1045
- ],
1046
- raw: [
1047
- {
1048
- input: [
1049
- 'rev-list',
1050
- '--objects',
1051
- '--no-object-names',
1052
- '--filter=blob:none',
1053
- '--since="1 month ago"',
1054
- '^87ce64f636853fbebc05edfcefe9cccc28a7968b',
1055
- 'cc424c261da5e261b76d982d5d361a023556e2aa',
1056
- ],
1057
- output: 'cc424c261da5e261b76d982d5d361a023556e2aa\n',
1058
- },
1059
- ],
1060
- revparse: [{ input: '--is-shallow-repository', output: 'false' }],
1061
- version: [{ input: undefined, output: newGitVersion }],
1062
- execSync: [
1063
- {
1064
- input: `git pack-objects --compression=9 --max-pack-size=3m ${tmpdir}/1000`,
1065
- output: Buffer.from('cc424c261da5e261b76d982d5d361a023556e2aa\n'),
1066
- },
1067
- ],
1068
- axios: [
1069
- {
1070
- input: {
1071
- url: '/api/v2/git/repository/search_commits',
1072
- data: {
1073
- meta: {
1074
- repository_url: 'https://github.com/DataDog/datadog-ci',
1075
- },
1076
- data: [
1077
- {
1078
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1079
- type: 'commit',
1080
- },
1081
- {
1082
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1083
- type: 'commit',
1084
- },
1085
- ],
1086
- },
1087
- },
1088
- output: new Error('http error'),
1089
- },
1090
- {
1091
- input: {
1092
- url: '/api/v2/git/repository/search_commits',
1093
- data: {
1094
- meta: {
1095
- repository_url: 'https://github.com/DataDog/datadog-ci',
1096
- },
1097
- data: [
1098
- {
1099
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1100
- type: 'commit',
1101
- },
1102
- {
1103
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1104
- type: 'commit',
1105
- },
1106
- ],
1107
- },
1108
- },
1109
- output: {
1110
- data: {
1111
- data: [
1112
- {
1113
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1114
- type: 'commit',
1115
- },
1116
- ],
1117
- },
1118
- },
1119
- },
1120
- {
1121
- input: {
1122
- url: '/api/v2/git/repository/packfile',
1123
- data: undefined,
1124
- },
1125
- output: {},
1126
- },
1127
- ],
1128
- });
1129
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
1130
- yield expect(upload).resolves.toBe(undefined);
1131
- mocks.expectCalls();
1132
- }));
1133
- test('fails after 3 http requests', () => __awaiter(void 0, void 0, void 0, function* () {
1134
- const mocks = new MockAll({
1135
- getConfig: [
1136
- {
1137
- input: 'clone.defaultRemoteName',
1138
- output: defaultRemoteNameNotConfigured,
1139
- },
1140
- ],
1141
- fetch: [],
1142
- getRemotes: [
1143
- {
1144
- input: undefined,
1145
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
1146
- },
1147
- ],
1148
- log: [
1149
- {
1150
- input: ['-n 1000', '--since="1 month ago"'],
1151
- output: {
1152
- all: [
1153
- {
1154
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1155
- },
1156
- {
1157
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1158
- },
1159
- ],
1160
- },
1161
- },
1162
- ],
1163
- raw: [],
1164
- revparse: [],
1165
- version: [],
1166
- execSync: [],
1167
- axios: [
1168
- {
1169
- input: {
1170
- url: '/api/v2/git/repository/search_commits',
1171
- data: {
1172
- meta: {
1173
- repository_url: 'https://github.com/DataDog/datadog-ci',
1174
- },
1175
- data: [
1176
- {
1177
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1178
- type: 'commit',
1179
- },
1180
- {
1181
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1182
- type: 'commit',
1183
- },
1184
- ],
1185
- },
1186
- },
1187
- output: new Error('http error'),
1188
- },
1189
- {
1190
- input: {
1191
- url: '/api/v2/git/repository/search_commits',
1192
- data: {
1193
- meta: {
1194
- repository_url: 'https://github.com/DataDog/datadog-ci',
1195
- },
1196
- data: [
1197
- {
1198
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1199
- type: 'commit',
1200
- },
1201
- {
1202
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1203
- type: 'commit',
1204
- },
1205
- ],
1206
- },
1207
- },
1208
- output: new Error('http error'),
1209
- },
1210
- {
1211
- input: {
1212
- url: '/api/v2/git/repository/search_commits',
1213
- data: {
1214
- meta: {
1215
- repository_url: 'https://github.com/DataDog/datadog-ci',
1216
- },
1217
- data: [
1218
- {
1219
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1220
- type: 'commit',
1221
- },
1222
- {
1223
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1224
- type: 'commit',
1225
- },
1226
- ],
1227
- },
1228
- },
1229
- output: new Error('http error'),
1230
- },
1231
- ],
1232
- });
1233
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
1234
- yield expect(upload).rejects.toThrow('http error');
1235
- mocks.expectCalls();
1236
- }));
1237
- test('fail immediately if returned format is incorrect', () => __awaiter(void 0, void 0, void 0, function* () {
1238
- const mocks = new MockAll({
1239
- getConfig: [
1240
- {
1241
- input: 'clone.defaultRemoteName',
1242
- output: defaultRemoteNameNotConfigured,
1243
- },
1244
- ],
1245
- fetch: [],
1246
- getRemotes: [
1247
- {
1248
- input: undefined,
1249
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
1250
- },
1251
- ],
1252
- log: [
1253
- {
1254
- input: ['-n 1000', '--since="1 month ago"'],
1255
- output: {
1256
- all: [
1257
- {
1258
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1259
- },
1260
- {
1261
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1262
- },
1263
- ],
1264
- },
1265
- },
1266
- ],
1267
- raw: [],
1268
- revparse: [],
1269
- version: [],
1270
- execSync: [],
1271
- axios: [
1272
- {
1273
- input: {
1274
- url: '/api/v2/git/repository/search_commits',
1275
- data: {
1276
- meta: {
1277
- repository_url: 'https://github.com/DataDog/datadog-ci',
1278
- },
1279
- data: [
1280
- {
1281
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1282
- type: 'commit',
1283
- },
1284
- {
1285
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1286
- type: 'commit',
1287
- },
1288
- ],
1289
- },
1290
- },
1291
- output: {
1292
- data: {
1293
- data: [
1294
- {
1295
- type: 'commit',
1296
- },
1297
- {
1298
- type: 'commit',
1299
- },
1300
- ],
1301
- },
1302
- },
1303
- },
1304
- ],
1305
- });
1306
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
1307
- yield expect(upload).rejects.toThrow('Invalid commit type response');
1308
- mocks.expectCalls();
1309
- }));
1310
- test('all commits are known, no packfile upload', () => __awaiter(void 0, void 0, void 0, function* () {
1311
- const mocks = new MockAll({
1312
- getConfig: [
1313
- {
1314
- input: 'clone.defaultRemoteName',
1315
- output: defaultRemoteNameNotConfigured,
1316
- },
1317
- ],
1318
- fetch: [],
1319
- getRemotes: [
1320
- {
1321
- input: undefined,
1322
- output: [{ name: 'origin', refs: { push: 'https://github.com/DataDog/datadog-ci' } }],
1323
- },
1324
- ],
1325
- log: [
1326
- {
1327
- input: ['-n 1000', '--since="1 month ago"'],
1328
- output: {
1329
- all: [
1330
- {
1331
- hash: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1332
- },
1333
- {
1334
- hash: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1335
- },
1336
- ],
1337
- },
1338
- },
1339
- ],
1340
- raw: [],
1341
- revparse: [],
1342
- version: [],
1343
- execSync: [],
1344
- axios: [
1345
- {
1346
- input: {
1347
- url: '/api/v2/git/repository/search_commits',
1348
- data: {
1349
- meta: {
1350
- repository_url: 'https://github.com/DataDog/datadog-ci',
1351
- },
1352
- data: [
1353
- {
1354
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1355
- type: 'commit',
1356
- },
1357
- {
1358
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1359
- type: 'commit',
1360
- },
1361
- ],
1362
- },
1363
- },
1364
- output: {
1365
- data: {
1366
- data: [
1367
- {
1368
- id: '87ce64f636853fbebc05edfcefe9cccc28a7968b',
1369
- type: 'commit',
1370
- },
1371
- {
1372
- id: 'cc424c261da5e261b76d982d5d361a023556e2aa',
1373
- type: 'commit',
1374
- },
1375
- ],
1376
- },
1377
- },
1378
- },
1379
- ],
1380
- });
1381
- const upload = (0, gitdb_1.uploadToGitDB)(logger, request, mocks.simpleGit, false);
1382
- yield expect(upload).resolves.toBe(undefined);
1383
- mocks.expectCalls();
1384
- }));
1385
- });
1386
- //# sourceMappingURL=gitdb.test.js.map