@datadog/datadog-ci 0.17.12 → 0.18.1

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 (60) hide show
  1. package/README.md +6 -1
  2. package/dist/commands/git-metadata/__tests__/git.test.js +44 -2
  3. package/dist/commands/git-metadata/__tests__/library.test.d.ts +1 -0
  4. package/dist/commands/git-metadata/__tests__/library.test.js +82 -0
  5. package/dist/commands/git-metadata/git.d.ts +1 -2
  6. package/dist/commands/git-metadata/git.js +13 -25
  7. package/dist/commands/git-metadata/index.d.ts +1 -0
  8. package/dist/commands/git-metadata/index.js +13 -0
  9. package/dist/commands/git-metadata/library.d.ts +6 -0
  10. package/dist/commands/git-metadata/library.js +68 -0
  11. package/dist/commands/git-metadata/upload.d.ts +1 -2
  12. package/dist/commands/git-metadata/upload.js +31 -27
  13. package/dist/commands/junit/upload.js +1 -1
  14. package/dist/commands/lambda/__tests__/fixtures.d.ts +5 -1
  15. package/dist/commands/lambda/__tests__/fixtures.js +13 -2
  16. package/dist/commands/lambda/__tests__/functions/commons.test.js +267 -2
  17. package/dist/commands/lambda/__tests__/functions/instrument.test.js +64 -42
  18. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +34 -0
  19. package/dist/commands/lambda/__tests__/instrument.test.js +644 -5
  20. package/dist/commands/lambda/__tests__/prompt.test.d.ts +1 -0
  21. package/dist/commands/lambda/__tests__/prompt.test.js +216 -0
  22. package/dist/commands/lambda/__tests__/uninstrument.test.js +310 -4
  23. package/dist/commands/lambda/constants.d.ts +46 -16
  24. package/dist/commands/lambda/constants.js +66 -18
  25. package/dist/commands/lambda/functions/commons.d.ts +20 -3
  26. package/dist/commands/lambda/functions/commons.js +116 -9
  27. package/dist/commands/lambda/functions/instrument.d.ts +1 -1
  28. package/dist/commands/lambda/functions/instrument.js +69 -26
  29. package/dist/commands/lambda/functions/uninstrument.js +23 -7
  30. package/dist/commands/lambda/instrument.d.ts +2 -0
  31. package/dist/commands/lambda/instrument.js +104 -48
  32. package/dist/commands/lambda/interfaces.d.ts +4 -0
  33. package/dist/commands/lambda/prompt.d.ts +9 -0
  34. package/dist/commands/lambda/prompt.js +187 -0
  35. package/dist/commands/lambda/uninstrument.d.ts +1 -0
  36. package/dist/commands/lambda/uninstrument.js +68 -30
  37. package/dist/commands/synthetics/__tests__/cli.test.js +1 -0
  38. package/dist/commands/synthetics/__tests__/fixtures.js +1 -0
  39. package/dist/commands/synthetics/__tests__/run-test.test.js +48 -2
  40. package/dist/commands/synthetics/__tests__/utils.test.js +38 -0
  41. package/dist/commands/synthetics/command.d.ts +1 -0
  42. package/dist/commands/synthetics/command.js +11 -5
  43. package/dist/commands/synthetics/crypto.d.ts +2 -1
  44. package/dist/commands/synthetics/interfaces.d.ts +13 -4
  45. package/dist/commands/synthetics/interfaces.js +7 -3
  46. package/dist/commands/synthetics/reporters/default.js +5 -1
  47. package/dist/commands/synthetics/run-test.d.ts +2 -0
  48. package/dist/commands/synthetics/run-test.js +3 -1
  49. package/dist/commands/synthetics/utils.d.ts +4 -0
  50. package/dist/commands/synthetics/utils.js +44 -16
  51. package/dist/commands/trace/api.js +1 -1
  52. package/dist/helpers/__tests__/ci.test.js +71 -24
  53. package/dist/helpers/__tests__/user-provided-git.test.js +69 -27
  54. package/dist/helpers/ci.js +1 -1
  55. package/dist/helpers/git.js +1 -1
  56. package/dist/helpers/user-provided-git.d.ts +2 -1
  57. package/dist/helpers/user-provided-git.js +18 -3
  58. package/dist/index.d.ts +2 -1
  59. package/dist/index.js +3 -1
  60. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![Continuous Integration](https://github.com/DataDog/datadog-ci/workflows/Continuous%20Integration/badge.svg) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![NodeJS Version](https://img.shields.io/badge/Node.js-10.24.1+-green)
4
4
 
5
- Execute commands with Datadog from within your Continuous Integration/Continuous Deployment scripts. A good way to perform end to end tests of your application before applying you changes or deploying. It currently features running synthetics tests and waiting for the results.
5
+ Execute commands with Datadog from within your Continuous Integration/Continuous Deployment scripts. A good way to perform end to end tests of your application before applying your changes or deploying. It currently features running synthetics tests and waiting for the results.
6
6
 
7
7
  ## How to install the CLI
8
8
 
@@ -28,6 +28,7 @@ npm install -g @datadog/datadog-ci
28
28
  # Yarn v1 add globally
29
29
  yarn global add @datadog/datadog-ci
30
30
  ```
31
+
31
32
  ## Usage
32
33
 
33
34
  ```bash
@@ -40,6 +41,8 @@ Available commands:
40
41
  - synthetics
41
42
  - dsyms
42
43
  - git-metadata
44
+ - junit
45
+ - trace
43
46
  ```
44
47
 
45
48
  Each command allows interacting with a product of the Datadog platform. The commands are defined in the [src/commands](/src/commands) folder.
@@ -52,6 +55,8 @@ Further documentation for each command can be found in its folder, ie:
52
55
  - [Synthetics CI/CD Testing](src/commands/synthetics/)
53
56
  - [iOS dSYM Files](src/commands/dsyms/)
54
57
  - [Git metadata](src/commands/git-metadata)
58
+ - [JUnit XML](src/commands/junit)
59
+ - [Trace](src/commands/trace)
55
60
 
56
61
  ## Contributing
57
62
 
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -9,6 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
28
  });
10
29
  };
11
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
+ const simpleGit = __importStar(require("simple-git"));
12
32
  const git_1 = require("../git");
13
33
  const createMockSimpleGit = (conf) => ({
14
34
  getRemotes: (_) => __awaiter(void 0, void 0, void 0, function* () {
@@ -84,7 +104,7 @@ describe('git', () => {
84
104
  remotes: [{ name: 'first', refs: { push: 'https://git-repo' } }],
85
105
  trackedFiles: ['myfile.js'],
86
106
  });
87
- const commitInfo = yield git_1.getCommitInfo(mock, process.stdout);
107
+ const commitInfo = yield git_1.getCommitInfo(mock);
88
108
  expect(commitInfo).toBeDefined();
89
109
  expect(commitInfo.hash).toBe('abcd');
90
110
  expect(commitInfo.trackedFiles).toStrictEqual(['myfile.js']);
@@ -95,11 +115,33 @@ describe('git', () => {
95
115
  hash: 'abcd',
96
116
  trackedFiles: ['myfile.js'],
97
117
  });
98
- const commitInfo = yield git_1.getCommitInfo(mock, process.stdout, 'https://overridden');
118
+ const commitInfo = yield git_1.getCommitInfo(mock, 'https://overridden');
99
119
  expect(commitInfo).toBeDefined();
100
120
  expect(commitInfo.hash).toBe('abcd');
101
121
  expect(commitInfo.trackedFiles).toStrictEqual(['myfile.js']);
102
122
  expect(commitInfo.remote).toBe('https://overridden');
103
123
  }));
104
124
  });
125
+ describe('newSimpleGit', () => {
126
+ test('should throw an error if git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
127
+ jest.spyOn(simpleGit, 'gitP').mockImplementation(() => {
128
+ throw Error('gitp error');
129
+ });
130
+ yield expect(git_1.newSimpleGit()).rejects.toThrow('gitp error');
131
+ }));
132
+ test('should throw an error if revparse throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
133
+ const mock = createMockSimpleGit({});
134
+ jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock);
135
+ jest.spyOn(mock, 'revparse').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () {
136
+ throw Error('revparse error');
137
+ }));
138
+ yield expect(git_1.newSimpleGit()).rejects.toThrow('revparse error');
139
+ }));
140
+ test('should not throw any errors', () => __awaiter(void 0, void 0, void 0, function* () {
141
+ const mock = createMockSimpleGit({});
142
+ jest.spyOn(simpleGit, 'gitP').mockReturnValue(mock);
143
+ jest.spyOn(mock, 'revparse').mockResolvedValue('1234');
144
+ yield expect(git_1.newSimpleGit()).resolves.not.toThrow();
145
+ }));
146
+ });
105
147
  });
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ const apikey = __importStar(require("../../../helpers/apikey"));
32
+ const upload = __importStar(require("../../../helpers/upload"));
33
+ const git = __importStar(require("../git"));
34
+ const interfaces_1 = require("../interfaces");
35
+ const library_1 = require("../library");
36
+ describe('library', () => {
37
+ describe('isGitRepo', () => {
38
+ test('should return false if checkIsRepo fails', () => __awaiter(void 0, void 0, void 0, function* () {
39
+ const simpleGitClient = {
40
+ checkIsRepo: () => {
41
+ throw Error();
42
+ },
43
+ };
44
+ jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
45
+ yield expect(library_1.isGitRepo()).resolves.toEqual(false);
46
+ }));
47
+ test('should return false git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
48
+ jest.spyOn(git, 'newSimpleGit').mockImplementation(() => {
49
+ throw new Error('git is not installed');
50
+ });
51
+ yield expect(library_1.isGitRepo()).resolves.toEqual(false);
52
+ }));
53
+ test('should return true if datadog API key is set, git is installed, and we are in a repo', () => __awaiter(void 0, void 0, void 0, function* () {
54
+ const simpleGitClient = { checkIsRepo: () => true };
55
+ jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
56
+ yield expect(library_1.isGitRepo()).resolves.toEqual(true);
57
+ }));
58
+ });
59
+ describe('addSourceCodeIntegration', () => {
60
+ test('source code integration fails if simpleGitOrFail throws an exception', () => __awaiter(void 0, void 0, void 0, function* () {
61
+ jest.spyOn(git, 'newSimpleGit').mockImplementation(() => {
62
+ throw new Error('git is not installed');
63
+ });
64
+ jest.spyOn(apikey, 'newApiKeyValidator').mockReturnValue({});
65
+ yield expect(library_1.uploadGitCommitHash('dummy', 'fake.site')).rejects.toThrowError('git is not installed');
66
+ }));
67
+ test('source code integration returns the correct hash', () => __awaiter(void 0, void 0, void 0, function* () {
68
+ const simpleGitClient = { checkIsRepo: () => true };
69
+ jest.spyOn(git, 'newSimpleGit').mockResolvedValue(simpleGitClient);
70
+ jest.spyOn(git, 'getCommitInfo').mockImplementation(() => __awaiter(void 0, void 0, void 0, function* () { return new interfaces_1.CommitInfo('hash', 'url', ['file1', 'file2']); }));
71
+ jest.spyOn(upload, 'upload').mockReturnValue((a, b) => {
72
+ {
73
+ return new Promise((resolve) => {
74
+ resolve(upload.UploadStatus.Success);
75
+ });
76
+ }
77
+ });
78
+ jest.spyOn(apikey, 'newApiKeyValidator').mockReturnValue({});
79
+ expect(yield library_1.uploadGitCommitHash('dummy', 'fake.site')).toBe('hash');
80
+ }));
81
+ });
82
+ });
@@ -1,8 +1,7 @@
1
1
  import * as simpleGit from 'simple-git';
2
- import { Writable } from 'stream';
3
2
  import { CommitInfo } from './interfaces';
4
3
  export declare const newSimpleGit: () => Promise<simpleGit.SimpleGit>;
5
4
  export declare const gitRemote: (git: simpleGit.SimpleGit) => Promise<string>;
6
5
  export declare const stripCredentials: (remote: string) => string;
7
6
  export declare const gitTrackedFiles: (git: simpleGit.SimpleGit) => Promise<string[]>;
8
- export declare const getCommitInfo: (git: simpleGit.SimpleGit, stdout: Writable, repositoryURL?: string | undefined) => Promise<CommitInfo | undefined>;
7
+ export declare const getCommitInfo: (git: simpleGit.SimpleGit, repositoryURL?: string | undefined) => Promise<CommitInfo>;
@@ -31,7 +31,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
31
31
  exports.getCommitInfo = exports.gitTrackedFiles = exports.stripCredentials = exports.gitRemote = exports.newSimpleGit = void 0;
32
32
  const simpleGit = __importStar(require("simple-git"));
33
33
  const url_1 = require("url");
34
- const renderer_1 = require("./renderer");
35
34
  const interfaces_1 = require("./interfaces");
36
35
  // Returns a configured SimpleGit.
37
36
  const newSimpleGit = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -40,16 +39,11 @@ const newSimpleGit = () => __awaiter(void 0, void 0, void 0, function* () {
40
39
  binary: 'git',
41
40
  maxConcurrentProcesses: 1,
42
41
  };
43
- try {
44
- // Attempt to set the baseDir to the root of the repository so the 'git ls-files' command
45
- // returns the tracked files paths relative to the root of the repository.
46
- const git = simpleGit.gitP(options);
47
- const root = yield git.revparse('--show-toplevel');
48
- options.baseDir = root;
49
- }
50
- catch (_a) {
51
- // Ignore exception as it will fail if we are not inside a git repository.
52
- }
42
+ // Attempt to set the baseDir to the root of the repository so the 'git ls-files' command
43
+ // returns the tracked files paths relative to the root of the repository.
44
+ const git = simpleGit.gitP(options);
45
+ const root = yield git.revparse('--show-toplevel');
46
+ options.baseDir = root;
53
47
  return simpleGit.gitP(options);
54
48
  });
55
49
  exports.newSimpleGit = newSimpleGit;
@@ -91,27 +85,21 @@ const gitTrackedFiles = (git) => __awaiter(void 0, void 0, void 0, function* ()
91
85
  });
92
86
  exports.gitTrackedFiles = gitTrackedFiles;
93
87
  // Returns the current hash, remote URL and tracked files paths.
94
- const getCommitInfo = (git, stdout, repositoryURL) => __awaiter(void 0, void 0, void 0, function* () {
88
+ const getCommitInfo = (git, repositoryURL) => __awaiter(void 0, void 0, void 0, function* () {
95
89
  // Invoke git commands to retrieve the remote, hash and tracked files.
96
90
  // We're using Promise.all instead of Promive.allSettled since we want to fail early if
97
91
  // any of the promises fails.
98
92
  let remote;
99
93
  let hash;
100
94
  let trackedFiles;
101
- try {
102
- if (repositoryURL) {
103
- ;
104
- [hash, trackedFiles] = yield Promise.all([gitHash(git), exports.gitTrackedFiles(git)]);
105
- remote = repositoryURL;
106
- }
107
- else {
108
- ;
109
- [remote, hash, trackedFiles] = yield Promise.all([exports.gitRemote(git), gitHash(git), exports.gitTrackedFiles(git)]);
110
- }
95
+ if (repositoryURL) {
96
+ ;
97
+ [hash, trackedFiles] = yield Promise.all([gitHash(git), exports.gitTrackedFiles(git)]);
98
+ remote = repositoryURL;
111
99
  }
112
- catch (e) {
113
- stdout.write(renderer_1.renderGitError(e));
114
- return;
100
+ else {
101
+ ;
102
+ [remote, hash, trackedFiles] = yield Promise.all([exports.gitRemote(git), gitHash(git), exports.gitTrackedFiles(git)]);
115
103
  }
116
104
  return new interfaces_1.CommitInfo(hash, remote, trackedFiles);
117
105
  });
@@ -0,0 +1 @@
1
+ export * from './library';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./library"), exports);
@@ -0,0 +1,6 @@
1
+ import { RequestBuilder } from '../../helpers/interfaces';
2
+ import { UploadOptions, UploadStatus } from '../../helpers/upload';
3
+ import { CommitInfo } from './interfaces';
4
+ export declare const isGitRepo: () => Promise<boolean>;
5
+ export declare const uploadGitCommitHash: (apiKey: string, datadogSite: string) => Promise<string>;
6
+ export declare const uploadRepository: (requestBuilder: RequestBuilder, libraryVersion: string) => (commitInfo: CommitInfo, opts: UploadOptions) => Promise<UploadStatus>;
@@ -0,0 +1,68 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.uploadRepository = exports.uploadGitCommitHash = exports.isGitRepo = void 0;
13
+ const apikey_1 = require("../../helpers/apikey");
14
+ const upload_1 = require("../../helpers/upload");
15
+ const utils_1 = require("../../helpers/utils");
16
+ const git_1 = require("./git");
17
+ const isGitRepo = () => __awaiter(void 0, void 0, void 0, function* () {
18
+ try {
19
+ const simpleGit = yield git_1.newSimpleGit();
20
+ const isRepo = simpleGit.checkIsRepo();
21
+ return isRepo;
22
+ }
23
+ catch (_a) {
24
+ return false;
25
+ }
26
+ });
27
+ exports.isGitRepo = isGitRepo;
28
+ const uploadGitCommitHash = (apiKey, datadogSite) => __awaiter(void 0, void 0, void 0, function* () {
29
+ const apiKeyValidator = apikey_1.newApiKeyValidator({
30
+ apiKey,
31
+ datadogSite,
32
+ });
33
+ const simpleGit = yield git_1.newSimpleGit();
34
+ const payload = yield git_1.getCommitInfo(simpleGit);
35
+ const version = require('../../../package.json').version;
36
+ const requestBuilder = utils_1.getRequestBuilder({
37
+ apiKey,
38
+ baseUrl: 'https://sourcemap-intake.' + datadogSite,
39
+ headers: new Map([
40
+ ['DD-EVP-ORIGIN', 'datadog-ci sci'],
41
+ ['DD-EVP-ORIGIN-VERSION', version],
42
+ ]),
43
+ overrideUrl: 'api/v2/srcmap',
44
+ });
45
+ const status = yield exports.uploadRepository(requestBuilder, version)(payload, {
46
+ apiKeyValidator,
47
+ onError: (e) => {
48
+ throw e;
49
+ },
50
+ onRetry: () => {
51
+ // Do nothing
52
+ },
53
+ onUpload: () => {
54
+ return;
55
+ },
56
+ retries: 5,
57
+ });
58
+ if (status !== upload_1.UploadStatus.Success) {
59
+ throw new Error('Error uploading commit information.');
60
+ }
61
+ return payload.hash;
62
+ });
63
+ exports.uploadGitCommitHash = uploadGitCommitHash;
64
+ const uploadRepository = (requestBuilder, libraryVersion) => (commitInfo, opts) => __awaiter(void 0, void 0, void 0, function* () {
65
+ const payload = commitInfo.asMultipartPayload(libraryVersion);
66
+ return upload_1.upload(requestBuilder)(payload, opts);
67
+ });
68
+ exports.uploadRepository = uploadRepository;
@@ -6,7 +6,6 @@ export declare class UploadCommand extends Command {
6
6
  private config;
7
7
  private dryRun;
8
8
  constructor();
9
- execute(): Promise<1 | 0>;
9
+ execute(): Promise<1 | 0 | undefined>;
10
10
  private getRequestBuilder;
11
- private uploadRepository;
12
11
  }
@@ -23,6 +23,7 @@ const upload_1 = require("../../helpers/upload");
23
23
  const utils_1 = require("../../helpers/utils");
24
24
  const api_1 = require("./api");
25
25
  const git_1 = require("./git");
26
+ const library_1 = require("./library");
26
27
  const renderer_1 = require("./renderer");
27
28
  class UploadCommand extends clipanion_1.Command {
28
29
  constructor() {
@@ -49,28 +50,40 @@ class UploadCommand extends clipanion_1.Command {
49
50
  datadogSite: api_1.datadogSite,
50
51
  metricsLogger: metricsLogger.logger,
51
52
  });
52
- const payload = yield git_1.getCommitInfo(yield git_1.newSimpleGit(), this.context.stdout, this.repositoryURL);
53
- if (payload === undefined) {
54
- return 1;
53
+ let payload;
54
+ try {
55
+ payload = yield git_1.getCommitInfo(yield git_1.newSimpleGit(), this.repositoryURL);
56
+ }
57
+ catch (e) {
58
+ if (e instanceof Error) {
59
+ this.context.stdout.write(renderer_1.renderFailedUpload(e.message));
60
+ }
61
+ return;
55
62
  }
56
63
  this.context.stdout.write(renderer_1.renderCommandInfo(payload));
64
+ let status;
57
65
  try {
58
66
  const requestBuilder = this.getRequestBuilder();
59
- const status = yield this.uploadRepository(requestBuilder)(payload, {
60
- apiKeyValidator,
61
- onError: (e) => {
62
- this.context.stdout.write(renderer_1.renderFailedUpload(e.message));
63
- metricsLogger.logger.increment('failed', 1);
64
- },
65
- onRetry: (e, attempt) => {
66
- this.context.stdout.write(renderer_1.renderRetriedUpload(e.message, attempt));
67
- metricsLogger.logger.increment('retries', 1);
68
- },
69
- onUpload: () => {
70
- return;
71
- },
72
- retries: 5,
73
- });
67
+ if (this.dryRun) {
68
+ status = upload_1.UploadStatus.Success;
69
+ }
70
+ else {
71
+ status = yield library_1.uploadRepository(requestBuilder, this.cliVersion)(payload, {
72
+ apiKeyValidator,
73
+ onError: (e) => {
74
+ this.context.stdout.write(renderer_1.renderFailedUpload(e.message));
75
+ metricsLogger.logger.increment('failed', 1);
76
+ },
77
+ onRetry: (e, attempt) => {
78
+ this.context.stdout.write(renderer_1.renderRetriedUpload(e.message, attempt));
79
+ metricsLogger.logger.increment('retries', 1);
80
+ },
81
+ onUpload: () => {
82
+ return;
83
+ },
84
+ retries: 5,
85
+ });
86
+ }
74
87
  metricsLogger.logger.increment('success', 1);
75
88
  const totalTime = (Date.now() - initialTime) / 1000;
76
89
  if (status !== upload_1.UploadStatus.Success) {
@@ -113,15 +126,6 @@ class UploadCommand extends clipanion_1.Command {
113
126
  overrideUrl: 'api/v2/srcmap',
114
127
  });
115
128
  }
116
- uploadRepository(requestBuilder) {
117
- return (commitInfo, opts) => __awaiter(this, void 0, void 0, function* () {
118
- const payload = commitInfo.asMultipartPayload(this.cliVersion);
119
- if (this.dryRun) {
120
- return upload_1.UploadStatus.Success;
121
- }
122
- return upload_1.upload(requestBuilder)(payload, opts);
123
- });
124
- }
125
129
  }
126
130
  exports.UploadCommand = UploadCommand;
127
131
  UploadCommand.usage = clipanion_1.Command.Usage({
@@ -100,7 +100,7 @@ class UploadJUnitXMLCommand extends clipanion_1.Command {
100
100
  }, []);
101
101
  const ciSpanTags = ci_1.getCISpanTags();
102
102
  const gitSpanTags = yield git_1.getGitMetadata();
103
- const userGitSpanTags = user_provided_git_1.getUserGitMetadata();
103
+ const userGitSpanTags = user_provided_git_1.getUserGitSpanTags();
104
104
  const envVarTags = this.config.envVarTags ? tags_1.parseTags(this.config.envVarTags.split(',')) : {};
105
105
  const cliTags = this.tags ? tags_1.parseTags(this.tags) : {};
106
106
  const spanTags = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, gitSpanTags), ciSpanTags), userGitSpanTags), cliTags), envVarTags), (this.config.env ? { env: this.config.env } : {}));
@@ -22,8 +22,9 @@ export declare type ConstructorOf<T> = new (...args: any[]) => T;
22
22
  * @returns the instance of the given command with a mock context attatched.
23
23
  */
24
24
  export declare const createCommand: <T extends Command<import("clipanion/lib/advanced").BaseContext>>(commandClass: ConstructorOf<T>, ...parameters: any[]) => T;
25
- export declare const makeMockLambda: (functionConfigs: Record<string, Lambda.FunctionConfiguration>) => {
25
+ export declare const makeMockLambda: (functionConfigs: Record<string, Lambda.FunctionConfiguration>, layers?: Record<string, Lambda.LayerVersionsListItem> | undefined) => {
26
26
  getFunction: jest.Mock<any, any>;
27
+ getLayerVersion: jest.Mock<any, any>;
27
28
  listFunctions: jest.Mock<any, any>;
28
29
  listTags: jest.Mock<any, any>;
29
30
  tagResource: jest.Mock<any, any>;
@@ -40,3 +41,6 @@ export declare const makeMockCloudWatchLogs: (logGroups: Record<string, {
40
41
  putSubscriptionFilter: jest.Mock<any, any>;
41
42
  };
42
43
  export declare const mockAwsAccount = "123456789012";
44
+ export declare const mockAwsAccessKeyId = "M0CKAWS4CC3SSK3Y1DSL";
45
+ export declare const mockAwsSecretAccessKey = "M0CKAWSs3cR3T4cC3SSK3YS3rv3rL3SSD4tad0g0";
46
+ export declare const mockDatadogApiKey = "02aeb762fff59ac0d5ad1536cd9633bd";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mockAwsAccount = exports.makeMockCloudWatchLogs = exports.makeMockLambda = exports.createCommand = exports.makeCli = exports.createMockContext = void 0;
3
+ exports.mockDatadogApiKey = exports.mockAwsSecretAccessKey = exports.mockAwsAccessKeyId = exports.mockAwsAccount = exports.makeMockCloudWatchLogs = exports.makeMockLambda = exports.createCommand = exports.makeCli = exports.createMockContext = void 0;
4
4
  const advanced_1 = require("clipanion/lib/advanced");
5
5
  const instrument_1 = require("../instrument");
6
6
  const uninstrument_1 = require("../uninstrument");
@@ -38,10 +38,18 @@ const createCommand = (commandClass, ...parameters) => {
38
38
  return command;
39
39
  };
40
40
  exports.createCommand = createCommand;
41
- const makeMockLambda = (functionConfigs) => ({
41
+ const makeMockLambda = (functionConfigs, layers) => ({
42
42
  getFunction: jest.fn().mockImplementation(({ FunctionName }) => ({
43
43
  promise: () => Promise.resolve({ Configuration: functionConfigs[FunctionName] }),
44
44
  })),
45
+ getLayerVersion: jest.fn().mockImplementation(({ LayerName, VersionNumber }) => ({
46
+ promise: () => {
47
+ const layer = LayerName + ':' + VersionNumber;
48
+ return layers && layers[layer] && layers[layer].Version === VersionNumber
49
+ ? Promise.resolve(layers[layer])
50
+ : Promise.reject();
51
+ },
52
+ })),
45
53
  listFunctions: jest.fn().mockImplementation(() => ({
46
54
  promise: () => Promise.resolve({ Functions: Object.values(functionConfigs) }),
47
55
  })),
@@ -71,3 +79,6 @@ const makeMockCloudWatchLogs = (logGroups) => ({
71
79
  });
72
80
  exports.makeMockCloudWatchLogs = makeMockCloudWatchLogs;
73
81
  exports.mockAwsAccount = '123456789012';
82
+ exports.mockAwsAccessKeyId = 'M0CKAWS4CC3SSK3Y1DSL';
83
+ exports.mockAwsSecretAccessKey = 'M0CKAWSs3cR3T4cC3SSK3YS3rv3rL3SSD4tad0g0';
84
+ exports.mockDatadogApiKey = '02aeb762fff59ac0d5ad1536cd9633bd';