@datadog/datadog-ci 2.40.0 → 2.40.2

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 (271) hide show
  1. package/dist/__tests__/cli.test.d.ts +1 -0
  2. package/dist/__tests__/cli.test.js +41 -0
  3. package/dist/__tests__/cli.test.js.map +1 -0
  4. package/dist/commands/cloud-run/__tests__/fixtures.d.ts +2 -0
  5. package/dist/commands/cloud-run/__tests__/fixtures.js +12 -0
  6. package/dist/commands/cloud-run/__tests__/fixtures.js.map +1 -0
  7. package/dist/commands/cloud-run/__tests__/flare.test.d.ts +1 -0
  8. package/dist/commands/cloud-run/__tests__/flare.test.js +557 -0
  9. package/dist/commands/cloud-run/__tests__/flare.test.js.map +1 -0
  10. package/dist/commands/deployment/__tests__/mark.test.d.ts +1 -0
  11. package/dist/commands/deployment/__tests__/mark.test.js +47 -0
  12. package/dist/commands/deployment/__tests__/mark.test.js.map +1 -0
  13. package/dist/commands/dora/__tests__/deployment.test.d.ts +1 -0
  14. package/dist/commands/dora/__tests__/deployment.test.js +201 -0
  15. package/dist/commands/dora/__tests__/deployment.test.js.map +1 -0
  16. package/dist/commands/dsyms/__tests__/upload.test.d.ts +1 -0
  17. package/dist/commands/dsyms/__tests__/upload.test.js +346 -0
  18. package/dist/commands/dsyms/__tests__/upload.test.js.map +1 -0
  19. package/dist/commands/dsyms/__tests__/utils.test.d.ts +1 -0
  20. package/dist/commands/dsyms/__tests__/utils.test.js +100 -0
  21. package/dist/commands/dsyms/__tests__/utils.test.js.map +1 -0
  22. package/dist/commands/dsyms/upload.js +3 -3
  23. package/dist/commands/dsyms/upload.js.map +1 -1
  24. package/dist/commands/dsyms/utils.js +4 -2
  25. package/dist/commands/dsyms/utils.js.map +1 -1
  26. package/dist/commands/elf-symbols/__tests__/elf.test.d.ts +1 -0
  27. package/dist/commands/elf-symbols/__tests__/elf.test.js +813 -0
  28. package/dist/commands/elf-symbols/__tests__/elf.test.js.map +1 -0
  29. package/dist/commands/elf-symbols/__tests__/upload.test.d.ts +1 -0
  30. package/dist/commands/elf-symbols/__tests__/upload.test.js +249 -0
  31. package/dist/commands/elf-symbols/__tests__/upload.test.js.map +1 -0
  32. package/dist/commands/elf-symbols/upload.js +2 -3
  33. package/dist/commands/elf-symbols/upload.js.map +1 -1
  34. package/dist/commands/flutter-symbols/__tests__/upload.test.d.ts +1 -0
  35. package/dist/commands/flutter-symbols/__tests__/upload.test.js +617 -0
  36. package/dist/commands/flutter-symbols/__tests__/upload.test.js.map +1 -0
  37. package/dist/commands/flutter-symbols/upload.js +2 -2
  38. package/dist/commands/flutter-symbols/upload.js.map +1 -1
  39. package/dist/commands/gate/__tests__/evaluate.test.d.ts +1 -0
  40. package/dist/commands/gate/__tests__/evaluate.test.js +398 -0
  41. package/dist/commands/gate/__tests__/evaluate.test.js.map +1 -0
  42. package/dist/commands/gate/__tests__/scope.test.d.ts +1 -0
  43. package/dist/commands/gate/__tests__/scope.test.js +29 -0
  44. package/dist/commands/gate/__tests__/scope.test.js.map +1 -0
  45. package/dist/commands/git-metadata/__tests__/git.test.d.ts +1 -0
  46. package/dist/commands/git-metadata/__tests__/git.test.js +132 -0
  47. package/dist/commands/git-metadata/__tests__/git.test.js.map +1 -0
  48. package/dist/commands/git-metadata/__tests__/gitdb.test.d.ts +1 -0
  49. package/dist/commands/git-metadata/__tests__/gitdb.test.js +1386 -0
  50. package/dist/commands/git-metadata/__tests__/gitdb.test.js.map +1 -0
  51. package/dist/commands/git-metadata/__tests__/library.test.d.ts +1 -0
  52. package/dist/commands/git-metadata/__tests__/library.test.js +118 -0
  53. package/dist/commands/git-metadata/__tests__/library.test.js.map +1 -0
  54. package/dist/commands/git-metadata/__tests__/upload.test.d.ts +1 -0
  55. package/dist/commands/git-metadata/__tests__/upload.test.js +52 -0
  56. package/dist/commands/git-metadata/__tests__/upload.test.js.map +1 -0
  57. package/dist/commands/junit/__tests__/id.test.d.ts +1 -0
  58. package/dist/commands/junit/__tests__/id.test.js +24 -0
  59. package/dist/commands/junit/__tests__/id.test.js.map +1 -0
  60. package/dist/commands/junit/__tests__/upload.test.d.ts +1 -0
  61. package/dist/commands/junit/__tests__/upload.test.js +495 -0
  62. package/dist/commands/junit/__tests__/upload.test.js.map +1 -0
  63. package/dist/commands/junit/upload.js +5 -3
  64. package/dist/commands/junit/upload.js.map +1 -1
  65. package/dist/commands/lambda/__tests__/fixtures.d.ts +51 -0
  66. package/dist/commands/lambda/__tests__/fixtures.js +146 -0
  67. package/dist/commands/lambda/__tests__/fixtures.js.map +1 -0
  68. package/dist/commands/lambda/__tests__/flare.test.d.ts +1 -0
  69. package/dist/commands/lambda/__tests__/flare.test.js +730 -0
  70. package/dist/commands/lambda/__tests__/flare.test.js.map +1 -0
  71. package/dist/commands/lambda/__tests__/functions/commons.test.d.ts +1 -0
  72. package/dist/commands/lambda/__tests__/functions/commons.test.js +791 -0
  73. package/dist/commands/lambda/__tests__/functions/commons.test.js.map +1 -0
  74. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.d.ts +1 -0
  75. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js +386 -0
  76. package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js.map +1 -0
  77. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.d.ts +1 -0
  78. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js +721 -0
  79. package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js.map +1 -0
  80. package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +1 -0
  81. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +513 -0
  82. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js.map +1 -0
  83. package/dist/commands/lambda/__tests__/functions/versionChecker.test.d.ts +1 -0
  84. package/dist/commands/lambda/__tests__/functions/versionChecker.test.js +33 -0
  85. package/dist/commands/lambda/__tests__/functions/versionChecker.test.js.map +1 -0
  86. package/dist/commands/lambda/__tests__/instrument.test.d.ts +1 -0
  87. package/dist/commands/lambda/__tests__/instrument.test.js +1511 -0
  88. package/dist/commands/lambda/__tests__/instrument.test.js.map +1 -0
  89. package/dist/commands/lambda/__tests__/loggroup.test.d.ts +1 -0
  90. package/dist/commands/lambda/__tests__/loggroup.test.js +340 -0
  91. package/dist/commands/lambda/__tests__/loggroup.test.js.map +1 -0
  92. package/dist/commands/lambda/__tests__/prompt.test.d.ts +1 -0
  93. package/dist/commands/lambda/__tests__/prompt.test.js +206 -0
  94. package/dist/commands/lambda/__tests__/prompt.test.js.map +1 -0
  95. package/dist/commands/lambda/__tests__/tags.test.d.ts +1 -0
  96. package/dist/commands/lambda/__tests__/tags.test.js +305 -0
  97. package/dist/commands/lambda/__tests__/tags.test.js.map +1 -0
  98. package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +1 -0
  99. package/dist/commands/lambda/__tests__/uninstrument.test.js +722 -0
  100. package/dist/commands/lambda/__tests__/uninstrument.test.js.map +1 -0
  101. package/dist/commands/measure/__tests__/measure.test.d.ts +1 -0
  102. package/dist/commands/measure/__tests__/measure.test.js +110 -0
  103. package/dist/commands/measure/__tests__/measure.test.js.map +1 -0
  104. package/dist/commands/react-native/__tests__/codepush.test.d.ts +1 -0
  105. package/dist/commands/react-native/__tests__/codepush.test.js +161 -0
  106. package/dist/commands/react-native/__tests__/codepush.test.js.map +1 -0
  107. package/dist/commands/react-native/__tests__/interfaces.test.d.ts +1 -0
  108. package/dist/commands/react-native/__tests__/interfaces.test.js +33 -0
  109. package/dist/commands/react-native/__tests__/interfaces.test.js.map +1 -0
  110. package/dist/commands/react-native/__tests__/upload.test.d.ts +1 -0
  111. package/dist/commands/react-native/__tests__/upload.test.js +238 -0
  112. package/dist/commands/react-native/__tests__/upload.test.js.map +1 -0
  113. package/dist/commands/react-native/__tests__/utils.test.d.ts +1 -0
  114. package/dist/commands/react-native/__tests__/utils.test.js +27 -0
  115. package/dist/commands/react-native/__tests__/utils.test.js.map +1 -0
  116. package/dist/commands/react-native/__tests__/xcode.test.d.ts +1 -0
  117. package/dist/commands/react-native/__tests__/xcode.test.js +465 -0
  118. package/dist/commands/react-native/__tests__/xcode.test.js.map +1 -0
  119. package/dist/commands/sarif/__tests__/upload.test.d.ts +1 -0
  120. package/dist/commands/sarif/__tests__/upload.test.js +228 -0
  121. package/dist/commands/sarif/__tests__/upload.test.js.map +1 -0
  122. package/dist/commands/sarif/upload.js +2 -2
  123. package/dist/commands/sarif/upload.js.map +1 -1
  124. package/dist/commands/sbom/__tests__/payload.test.d.ts +1 -0
  125. package/dist/commands/sbom/__tests__/payload.test.js +262 -0
  126. package/dist/commands/sbom/__tests__/payload.test.js.map +1 -0
  127. package/dist/commands/sbom/__tests__/validation.test.d.ts +1 -0
  128. package/dist/commands/sbom/__tests__/validation.test.js +41 -0
  129. package/dist/commands/sbom/__tests__/validation.test.js.map +1 -0
  130. package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +1 -0
  131. package/dist/commands/sourcemaps/__tests__/upload.test.js +270 -0
  132. package/dist/commands/sourcemaps/__tests__/upload.test.js.map +1 -0
  133. package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +1 -0
  134. package/dist/commands/sourcemaps/__tests__/utils.test.js +31 -0
  135. package/dist/commands/sourcemaps/__tests__/utils.test.js.map +1 -0
  136. package/dist/commands/sourcemaps/upload.js +2 -2
  137. package/dist/commands/sourcemaps/upload.js.map +1 -1
  138. package/dist/commands/stepfunctions/__tests__/awsCommands.test.d.ts +1 -0
  139. package/dist/commands/stepfunctions/__tests__/awsCommands.test.js +192 -0
  140. package/dist/commands/stepfunctions/__tests__/awsCommands.test.js.map +1 -0
  141. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.d.ts +6 -0
  142. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.js +45 -0
  143. package/dist/commands/stepfunctions/__tests__/fixtures/aws-resources.js.map +1 -0
  144. package/dist/commands/stepfunctions/__tests__/fixtures/cli.d.ts +5 -0
  145. package/dist/commands/stepfunctions/__tests__/fixtures/cli.js +19 -0
  146. package/dist/commands/stepfunctions/__tests__/fixtures/cli.js.map +1 -0
  147. package/dist/commands/stepfunctions/__tests__/helpers.test.d.ts +1 -0
  148. package/dist/commands/stepfunctions/__tests__/helpers.test.js +205 -0
  149. package/dist/commands/stepfunctions/__tests__/helpers.test.js.map +1 -0
  150. package/dist/commands/stepfunctions/__tests__/instrument.test.d.ts +1 -0
  151. package/dist/commands/stepfunctions/__tests__/instrument.test.js +431 -0
  152. package/dist/commands/stepfunctions/__tests__/instrument.test.js.map +1 -0
  153. package/dist/commands/stepfunctions/__tests__/uninstrument.test.d.ts +1 -0
  154. package/dist/commands/stepfunctions/__tests__/uninstrument.test.js +166 -0
  155. package/dist/commands/stepfunctions/__tests__/uninstrument.test.js.map +1 -0
  156. package/dist/commands/synthetics/__tests__/api.test.d.ts +1 -0
  157. package/dist/commands/synthetics/__tests__/api.test.js +422 -0
  158. package/dist/commands/synthetics/__tests__/api.test.js.map +1 -0
  159. package/dist/commands/synthetics/__tests__/cli.test.d.ts +1 -0
  160. package/dist/commands/synthetics/__tests__/cli.test.js +1325 -0
  161. package/dist/commands/synthetics/__tests__/cli.test.js.map +1 -0
  162. package/dist/commands/synthetics/__tests__/fixtures.d.ts +149 -0
  163. package/dist/commands/synthetics/__tests__/fixtures.js +507 -0
  164. package/dist/commands/synthetics/__tests__/fixtures.js.map +1 -0
  165. package/dist/commands/synthetics/__tests__/mobile.test.d.ts +1 -0
  166. package/dist/commands/synthetics/__tests__/mobile.test.js +376 -0
  167. package/dist/commands/synthetics/__tests__/mobile.test.js.map +1 -0
  168. package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +1 -0
  169. package/dist/commands/synthetics/__tests__/reporters/default.test.js +354 -0
  170. package/dist/commands/synthetics/__tests__/reporters/default.test.js.map +1 -0
  171. package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +1 -0
  172. package/dist/commands/synthetics/__tests__/reporters/junit.test.js +353 -0
  173. package/dist/commands/synthetics/__tests__/reporters/junit.test.js.map +1 -0
  174. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.d.ts +1 -0
  175. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.js +232 -0
  176. package/dist/commands/synthetics/__tests__/reporters/mobile/app-upload.test.js.map +1 -0
  177. package/dist/commands/synthetics/__tests__/run-tests-lib.test.d.ts +1 -0
  178. package/dist/commands/synthetics/__tests__/run-tests-lib.test.js +735 -0
  179. package/dist/commands/synthetics/__tests__/run-tests-lib.test.js.map +1 -0
  180. package/dist/commands/synthetics/__tests__/test.test.d.ts +1 -0
  181. package/dist/commands/synthetics/__tests__/test.test.js +33 -0
  182. package/dist/commands/synthetics/__tests__/test.test.js.map +1 -0
  183. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.d.ts +1 -0
  184. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js +21 -0
  185. package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js.map +1 -0
  186. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.d.ts +1 -0
  187. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js +80 -0
  188. package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js.map +1 -0
  189. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.d.ts +1 -0
  190. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js +109 -0
  191. package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js.map +1 -0
  192. package/dist/commands/synthetics/__tests__/utils/internal.test.d.ts +1 -0
  193. package/dist/commands/synthetics/__tests__/utils/internal.test.js +186 -0
  194. package/dist/commands/synthetics/__tests__/utils/internal.test.js.map +1 -0
  195. package/dist/commands/synthetics/__tests__/utils/public.test.d.ts +1 -0
  196. package/dist/commands/synthetics/__tests__/utils/public.test.js +1526 -0
  197. package/dist/commands/synthetics/__tests__/utils/public.test.js.map +1 -0
  198. package/dist/commands/synthetics/api.d.ts +1 -1
  199. package/dist/commands/synthetics/api.js +10 -5
  200. package/dist/commands/synthetics/api.js.map +1 -1
  201. package/dist/commands/synthetics/run-tests-command.d.ts +1 -0
  202. package/dist/commands/synthetics/run-tests-command.js +3 -2
  203. package/dist/commands/synthetics/run-tests-command.js.map +1 -1
  204. package/dist/commands/synthetics/run-tests-lib.js +0 -4
  205. package/dist/commands/synthetics/run-tests-lib.js.map +1 -1
  206. package/dist/commands/synthetics/test.js +9 -1
  207. package/dist/commands/synthetics/test.js.map +1 -1
  208. package/dist/commands/synthetics/utils/public.js +3 -3
  209. package/dist/commands/synthetics/utils/public.js.map +1 -1
  210. package/dist/commands/tag/__tests__/tag.test.d.ts +1 -0
  211. package/dist/commands/tag/__tests__/tag.test.js +75 -0
  212. package/dist/commands/tag/__tests__/tag.test.js.map +1 -0
  213. package/dist/commands/trace/__tests__/trace.test.d.ts +1 -0
  214. package/dist/commands/trace/__tests__/trace.test.js +145 -0
  215. package/dist/commands/trace/__tests__/trace.test.js.map +1 -0
  216. package/dist/commands/trace/trace.js +1 -1
  217. package/dist/commands/trace/trace.js.map +1 -1
  218. package/dist/commands/unity-symbols/__tests__/upload.test.d.ts +1 -0
  219. package/dist/commands/unity-symbols/__tests__/upload.test.js +369 -0
  220. package/dist/commands/unity-symbols/__tests__/upload.test.js.map +1 -0
  221. package/dist/commands/unity-symbols/upload.js +2 -2
  222. package/dist/commands/unity-symbols/upload.js.map +1 -1
  223. package/dist/helpers/__tests__/app.test.d.ts +1 -0
  224. package/dist/helpers/__tests__/app.test.js +31 -0
  225. package/dist/helpers/__tests__/app.test.js.map +1 -0
  226. package/dist/helpers/__tests__/ci.test.d.ts +1 -0
  227. package/dist/helpers/__tests__/ci.test.js +252 -0
  228. package/dist/helpers/__tests__/ci.test.js.map +1 -0
  229. package/dist/helpers/__tests__/fixtures.d.ts +33 -0
  230. package/dist/helpers/__tests__/fixtures.js +71 -0
  231. package/dist/helpers/__tests__/fixtures.js.map +1 -0
  232. package/dist/helpers/__tests__/flare.test.d.ts +1 -0
  233. package/dist/helpers/__tests__/flare.test.js +226 -0
  234. package/dist/helpers/__tests__/flare.test.js.map +1 -0
  235. package/dist/helpers/__tests__/fs.test.d.ts +1 -0
  236. package/dist/helpers/__tests__/fs.test.js +189 -0
  237. package/dist/helpers/__tests__/fs.test.js.map +1 -0
  238. package/dist/helpers/__tests__/plist.test.d.ts +1 -0
  239. package/dist/helpers/__tests__/plist.test.js +43 -0
  240. package/dist/helpers/__tests__/plist.test.js.map +1 -0
  241. package/dist/helpers/__tests__/prompt.test.d.ts +1 -0
  242. package/dist/helpers/__tests__/prompt.test.js +71 -0
  243. package/dist/helpers/__tests__/prompt.test.js.map +1 -0
  244. package/dist/helpers/__tests__/retry.test.d.ts +1 -0
  245. package/dist/helpers/__tests__/retry.test.js +99 -0
  246. package/dist/helpers/__tests__/retry.test.js.map +1 -0
  247. package/dist/helpers/__tests__/tags.test.d.ts +1 -0
  248. package/dist/helpers/__tests__/tags.test.js +71 -0
  249. package/dist/helpers/__tests__/tags.test.js.map +1 -0
  250. package/dist/helpers/__tests__/upload.test.d.ts +1 -0
  251. package/dist/helpers/__tests__/upload.test.js +231 -0
  252. package/dist/helpers/__tests__/upload.test.js.map +1 -0
  253. package/dist/helpers/__tests__/user-provided-git.test.d.ts +1 -0
  254. package/dist/helpers/__tests__/user-provided-git.test.js +119 -0
  255. package/dist/helpers/__tests__/user-provided-git.test.js.map +1 -0
  256. package/dist/helpers/__tests__/utils.test.d.ts +1 -0
  257. package/dist/helpers/__tests__/utils.test.js +429 -0
  258. package/dist/helpers/__tests__/utils.test.js.map +1 -0
  259. package/dist/helpers/__tests__/validation.test.d.ts +1 -0
  260. package/dist/helpers/__tests__/validation.test.js +25 -0
  261. package/dist/helpers/__tests__/validation.test.js.map +1 -0
  262. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.d.ts +1 -0
  263. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js +103 -0
  264. package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js.map +1 -0
  265. package/dist/helpers/git/__tests__/format-git-span-data.test.d.ts +1 -0
  266. package/dist/helpers/git/__tests__/format-git-span-data.test.js +121 -0
  267. package/dist/helpers/git/__tests__/format-git-span-data.test.js.map +1 -0
  268. package/dist/helpers/git/__tests__/get-git-data.test.d.ts +1 -0
  269. package/dist/helpers/git/__tests__/get-git-data.test.js +72 -0
  270. package/dist/helpers/git/__tests__/get-git-data.test.js.map +1 -0
  271. package/package.json +4 -6
@@ -0,0 +1,1386 @@
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