backport 6.3.0-beta → 6.3.0-beta-5

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 (118) hide show
  1. package/dist/backportRun.js +3 -2
  2. package/dist/entrypoint.cli.e2e.private.test.d.ts +1 -0
  3. package/dist/entrypoint.cli.e2e.private.test.js +278 -0
  4. package/dist/entrypoint.cli.js +0 -0
  5. package/dist/entrypoint.cli.private.test.d.ts +1 -0
  6. package/dist/entrypoint.cli.private.test.js +46 -0
  7. package/dist/options/ConfigOptions.d.ts +3 -2
  8. package/dist/options/cliArgs.d.ts +1 -0
  9. package/dist/options/cliArgs.js +24 -4
  10. package/dist/options/cliArgs.test.d.ts +1 -0
  11. package/dist/options/cliArgs.test.js +170 -0
  12. package/dist/options/config/config.d.ts +2 -7
  13. package/dist/options/config/config.test.d.ts +1 -0
  14. package/dist/options/config/config.test.js +32 -0
  15. package/dist/options/config/globalConfig.test.d.ts +1 -0
  16. package/dist/options/config/globalConfig.test.js +61 -0
  17. package/dist/options/config/projectConfig.test.d.ts +1 -0
  18. package/dist/options/config/projectConfig.test.js +109 -0
  19. package/dist/options/config/readConfigFile.d.ts +2 -7
  20. package/dist/options/options.d.ts +2 -7
  21. package/dist/options/options.test.d.ts +1 -0
  22. package/dist/options/options.test.js +369 -0
  23. package/dist/runSequentially.js +1 -0
  24. package/dist/runSequentially.test.d.ts +1 -0
  25. package/dist/runSequentially.test.js +218 -0
  26. package/dist/scripts/postinstall.test.d.ts +1 -0
  27. package/dist/scripts/postinstall.test.js +53 -0
  28. package/dist/services/env.test.d.ts +1 -0
  29. package/dist/services/env.test.js +21 -0
  30. package/dist/services/git.integration.test.d.ts +1 -0
  31. package/dist/services/git.integration.test.js +267 -0
  32. package/dist/services/git.test.d.ts +1 -0
  33. package/dist/services/git.test.js +518 -0
  34. package/dist/services/github/commitFormatters.test.d.ts +1 -0
  35. package/dist/services/github/commitFormatters.test.js +11 -0
  36. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  37. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
  38. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  39. package/dist/services/github/v3/createPullRequest.test.js +325 -0
  40. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  41. package/dist/services/github/v3/createStatusComment.test.js +386 -0
  42. package/dist/services/github/v3/index.d.ts +1 -0
  43. package/dist/services/github/v3/index.js +61 -0
  44. package/dist/services/github/v4/apiRequestV4.js +10 -2
  45. package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
  46. package/dist/services/github/v4/apiRequestV4.test.js +82 -0
  47. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  48. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  49. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  50. package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
  51. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  52. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +96 -0
  53. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  54. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +143 -0
  55. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  56. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +124 -0
  57. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  58. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +200 -0
  59. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  60. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +153 -0
  61. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  62. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
  63. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  64. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
  65. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  66. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  67. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +3 -7
  68. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -10
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  70. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +136 -0
  71. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +15 -24
  72. package/dist/services/github/v4/getOptionsFromGithub/query.js +17 -25
  73. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  74. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  75. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  76. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +154 -0
  77. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  78. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  79. package/dist/services/logger.d.ts +3 -15
  80. package/dist/services/logger.js +10 -50
  81. package/dist/services/prompt.test.d.ts +1 -0
  82. package/dist/services/prompt.test.js +134 -0
  83. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  84. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +433 -0
  85. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  86. package/dist/services/sourceCommit/parseSourceCommit.test.js +235 -0
  87. package/dist/test/ExecError.d.ts +16 -0
  88. package/dist/test/ExecError.js +15 -0
  89. package/dist/test/backport-e2e.mutation.test.d.ts +1 -0
  90. package/dist/test/backport-e2e.mutation.test.js +347 -0
  91. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  92. package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -0
  93. package/dist/test/mockConfigFiles.d.ts +5 -0
  94. package/dist/test/mockConfigFiles.js +21 -0
  95. package/dist/test/mocks.d.ts +10 -0
  96. package/dist/test/mocks.js +23 -0
  97. package/dist/test/nockHelpers.d.ts +16 -0
  98. package/dist/test/nockHelpers.js +32 -0
  99. package/dist/test/private/getDevAccessToken.d.ts +2 -0
  100. package/dist/test/private/getDevAccessToken.js +12 -0
  101. package/dist/test/sandbox.d.ts +5 -0
  102. package/dist/test/sandbox.js +43 -0
  103. package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
  104. package/dist/test/setupFiles/automatic-mocks.js +59 -0
  105. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  106. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +455 -0
  107. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  108. package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
  109. package/dist/ui/getTargetBranches.test.d.ts +1 -0
  110. package/dist/ui/getTargetBranches.test.js +198 -0
  111. package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
  112. package/dist/ui/maybeSetupRepo.test.js +204 -0
  113. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  114. package/dist/utils/excludeUndefined.test.js +24 -0
  115. package/dist/utils/packageVersion.d.ts +1 -1
  116. package/dist/utils/packageVersion.js +1 -1
  117. package/package.json +5 -3
  118. package/yarn.lock +5 -0
@@ -7,32 +7,24 @@ exports.query = `
7
7
  login
8
8
  }
9
9
  repository(owner: $repoOwner, name: $repoName) {
10
- isFork
11
- ...Repo
12
- parent {
13
- ...Repo
10
+ # check to see if a branch named "backport" exists
11
+ illegalBackportBranch: ref(qualifiedName: "refs/heads/backport") {
12
+ id
14
13
  }
15
- }
16
- }
17
-
18
- fragment Repo on Repository {
19
- # check to see if a branch named "backport" exists
20
- ref(qualifiedName: "refs/heads/backport") {
21
- name
22
- }
23
- defaultBranchRef {
24
- name
25
- target {
26
- ... on Commit {
27
- history(first: 20, path: ".backportrc.json") {
28
- edges {
29
- remoteConfig: node {
30
- committedDate
31
- file(path: ".backportrc.json") {
32
- ... on TreeEntry {
33
- object {
34
- ... on Blob {
35
- text
14
+ defaultBranchRef {
15
+ name
16
+ target {
17
+ ... on Commit {
18
+ history(first: 20, path: ".backportrc.json") {
19
+ edges {
20
+ remoteConfig: node {
21
+ committedDate
22
+ file(path: ".backportrc.json") {
23
+ ... on TreeEntry {
24
+ object {
25
+ ... on Blob {
26
+ text
27
+ }
36
28
  }
37
29
  }
38
30
  }
@@ -0,0 +1,71 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
23
+ const sandbox_1 = require("../../../test/sandbox");
24
+ const childProcess = __importStar(require("../../child-process-promisified"));
25
+ const getRepoOwnerAndNameFromGitRemotes_1 = require("./getRepoOwnerAndNameFromGitRemotes");
26
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
27
+ describe('fetchRemoteProjectConfig', () => {
28
+ let devAccessToken;
29
+ beforeEach(() => {
30
+ devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
31
+ });
32
+ describe('when the remote is a fork', () => {
33
+ it('retrives the original owner from github', async () => {
34
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
35
+ const execOpts = { cwd: sandboxPath };
36
+ await childProcess.exec(`git init`, execOpts);
37
+ await childProcess.exec(`git remote add sqren git@github.com:sqren/kibana.git`, execOpts);
38
+ expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
39
+ accessToken: devAccessToken,
40
+ cwd: sandboxPath,
41
+ })).toEqual({
42
+ repoName: 'kibana',
43
+ repoOwner: 'elastic',
44
+ });
45
+ });
46
+ });
47
+ describe('when none of the git remotes are found', () => {
48
+ it('swallows the error and returns empty', async () => {
49
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
50
+ const execOpts = { cwd: sandboxPath };
51
+ await childProcess.exec(`git init`, execOpts);
52
+ await childProcess.exec(`git remote add foo git@github.com:foo/kibana.git`, execOpts);
53
+ await childProcess.exec(`git remote add bar git@github.com:bar/kibana.git`, execOpts);
54
+ expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
55
+ accessToken: devAccessToken,
56
+ cwd: sandboxPath,
57
+ })).toEqual({});
58
+ });
59
+ });
60
+ describe('when there are no git remotes', () => {
61
+ it('returns empty', async () => {
62
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
63
+ const execOpts = { cwd: sandboxPath };
64
+ await childProcess.exec(`git init`, execOpts);
65
+ expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
66
+ accessToken: devAccessToken,
67
+ cwd: sandboxPath,
68
+ })).toEqual({});
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,2 @@
1
+ import { CommitByAuthorResponse } from '../fetchCommits/fetchCommitsByAuthor';
2
+ export declare const commitsByAuthorMock: CommitByAuthorResponse;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commitsByAuthorMock = void 0;
4
+ exports.commitsByAuthorMock = {
5
+ repository: {
6
+ ref: {
7
+ target: {
8
+ history: {
9
+ edges: [
10
+ {
11
+ node: {
12
+ repository: {
13
+ name: 'kibana',
14
+ owner: { login: 'elastic' },
15
+ },
16
+ committedDate: '2021-12-24T00:00:00Z',
17
+ sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
18
+ message: 'Add 👻',
19
+ associatedPullRequests: {
20
+ edges: [],
21
+ },
22
+ },
23
+ },
24
+ {
25
+ node: {
26
+ repository: {
27
+ name: 'kibana',
28
+ owner: { login: 'elastic' },
29
+ },
30
+ committedDate: '2021-12-23T00:00:00Z',
31
+ sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
32
+ message: 'Add witch (#85)',
33
+ associatedPullRequests: {
34
+ edges: [
35
+ {
36
+ node: {
37
+ url: 'https://github.com/elastic/kibana/pull/85',
38
+ baseRefName: 'master',
39
+ labels: {
40
+ nodes: [{ name: 'my-label-b' }],
41
+ },
42
+ number: 85,
43
+ mergeCommit: {
44
+ sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
45
+ message: 'Add witch (#85)',
46
+ },
47
+ timelineItems: {
48
+ edges: [],
49
+ },
50
+ },
51
+ },
52
+ ],
53
+ },
54
+ },
55
+ },
56
+ {
57
+ node: {
58
+ repository: {
59
+ name: 'kibana',
60
+ owner: { login: 'elastic' },
61
+ },
62
+ committedDate: '2021-12-22T00:00:00Z',
63
+ sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
64
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
65
+ associatedPullRequests: {
66
+ edges: [
67
+ {
68
+ node: {
69
+ url: 'https://github.com/elastic/kibana/pull/80',
70
+ labels: {
71
+ nodes: [{ name: 'v6.3.0' }],
72
+ },
73
+ baseRefName: 'master',
74
+ number: 80,
75
+ mergeCommit: {
76
+ sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
77
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
78
+ },
79
+ timelineItems: {
80
+ edges: [
81
+ {
82
+ node: {
83
+ targetPullRequest: {
84
+ __typename: 'PullRequest',
85
+ targetMergeCommit: {
86
+ sha: 'target-merge-commit-sha',
87
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
88
+ },
89
+ repository: {
90
+ name: 'kibana',
91
+ owner: { login: 'elastic' },
92
+ },
93
+ url: 'https://github.com/elastic/kibana/pull/99',
94
+ title: 'some title',
95
+ state: 'MERGED',
96
+ number: 99,
97
+ baseRefName: '6.3',
98
+ commits: {
99
+ edges: [
100
+ {
101
+ node: {
102
+ targetCommit: {
103
+ sha: 'abc',
104
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
105
+ },
106
+ },
107
+ },
108
+ ],
109
+ },
110
+ },
111
+ },
112
+ },
113
+ ],
114
+ },
115
+ },
116
+ },
117
+ ],
118
+ },
119
+ },
120
+ },
121
+ {
122
+ node: {
123
+ repository: {
124
+ name: 'kibana',
125
+ owner: { login: 'elastic' },
126
+ },
127
+ committedDate: '2021-12-21T00:00:00Z',
128
+ sha: '3827bbbaf39914eda4f02f6940189844375fd097',
129
+ message: 'Add backport config',
130
+ associatedPullRequests: {
131
+ edges: [],
132
+ },
133
+ },
134
+ },
135
+ {
136
+ node: {
137
+ repository: {
138
+ name: 'kibana',
139
+ owner: { login: 'elastic' },
140
+ },
141
+ committedDate: '2021-12-20T00:00:00Z',
142
+ sha: '5ea0da550ac191029459289d67f99ad7d310812b',
143
+ message: 'Initial commit',
144
+ associatedPullRequests: {
145
+ edges: [],
146
+ },
147
+ },
148
+ },
149
+ ],
150
+ },
151
+ },
152
+ },
153
+ },
154
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const throwOnInvalidAccessToken_1 = require("./throwOnInvalidAccessToken");
4
+ describe('throwOnInvalidAccessToken', () => {
5
+ describe('when status code is', () => {
6
+ it('should handle invalid access token', () => {
7
+ const error = {
8
+ axiosResponse: {
9
+ status: 401,
10
+ headers: {},
11
+ },
12
+ };
13
+ return expect(() => (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
14
+ repoOwner: 'elastic',
15
+ repoName: 'kibana',
16
+ error,
17
+ })).toThrowError('Please check your access token and make sure it is valid');
18
+ });
19
+ it('should handle SSO error', () => {
20
+ const error = {
21
+ axiosResponse: {
22
+ status: 200,
23
+ headers: { 'x-github-sso': 'required; url=https://ssourl.com' },
24
+ data: {
25
+ errors: [{ type: 'FORBIDDEN' }],
26
+ },
27
+ },
28
+ };
29
+ return expect(() => (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
30
+ repoOwner: 'elastic',
31
+ repoName: 'kibana',
32
+ error,
33
+ })).toThrowErrorMatchingSnapshot();
34
+ });
35
+ it('should handle non-existing repo', () => {
36
+ const error = {
37
+ axiosResponse: {
38
+ status: 200,
39
+ headers: {
40
+ 'x-oauth-scopes': 'a,b,c',
41
+ 'x-accepted-oauth-scopes': 'a,b,c',
42
+ },
43
+ data: {
44
+ errors: [{ type: 'NOT_FOUND', path: ['repository'] }],
45
+ },
46
+ },
47
+ };
48
+ return expect(() => (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
49
+ repoOwner: 'elastic',
50
+ repoName: 'kibana',
51
+ error,
52
+ })).toThrowError(`The repository "elastic/kibana" doesn't exist`);
53
+ });
54
+ it('should handle insufficient permissions (oauth scopes)', () => {
55
+ const error = {
56
+ axiosResponse: {
57
+ status: 200,
58
+ headers: {
59
+ 'x-oauth-scopes': 'a,b',
60
+ 'x-accepted-oauth-scopes': 'a,b,c',
61
+ },
62
+ data: {
63
+ errors: [{ type: 'NOT_FOUND', path: ['repository'] }],
64
+ },
65
+ },
66
+ };
67
+ return expect(() => (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
68
+ repoOwner: 'elastic',
69
+ repoName: 'kibana',
70
+ error,
71
+ })).toThrowErrorMatchingSnapshot();
72
+ });
73
+ it('should not handle unknown cases', () => {
74
+ const error = {
75
+ axiosResponse: {
76
+ status: 500,
77
+ headers: {},
78
+ },
79
+ };
80
+ return expect((0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
81
+ repoOwner: 'elastic',
82
+ repoName: 'kibana',
83
+ error,
84
+ })).toBe(undefined);
85
+ });
86
+ });
87
+ });
@@ -1,12 +1,6 @@
1
+ import winston from 'winston';
2
+ export declare let logger: winston.Logger;
1
3
  export declare function consoleLog(message: string): void;
2
- export declare type Logger = typeof logger;
3
- export declare const logger: {
4
- error: (message: string, meta?: unknown) => void;
5
- warn: (message: string, meta?: unknown) => void;
6
- info: (message: string, meta?: unknown) => void;
7
- verbose: (message: string, meta?: unknown) => void;
8
- debug: (message: string, meta?: unknown) => void;
9
- };
10
4
  export declare function updateLogger({ accessToken, verbose, }: {
11
5
  accessToken: string;
12
6
  verbose?: boolean;
@@ -15,10 +9,4 @@ export declare function initLogger({ ci, accessToken, logFilePath, }: {
15
9
  ci?: boolean;
16
10
  accessToken?: string;
17
11
  logFilePath?: string;
18
- }): {
19
- error: (message: string, meta?: unknown) => void;
20
- warn: (message: string, meta?: unknown) => void;
21
- info: (message: string, meta?: unknown) => void;
22
- verbose: (message: string, meta?: unknown) => void;
23
- debug: (message: string, meta?: unknown) => void;
24
- };
12
+ }): winston.Logger;
@@ -18,19 +18,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
21
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.initLogger = exports.updateLogger = exports.logger = exports.consoleLog = void 0;
26
- const dedent_1 = __importDefault(require("dedent"));
27
- const lodash_1 = require("lodash");
28
- const safe_json_stringify_1 = __importDefault(require("safe-json-stringify"));
22
+ exports.initLogger = exports.updateLogger = exports.consoleLog = exports.logger = void 0;
29
23
  const winston_1 = __importStar(require("winston"));
30
24
  const redact_1 = require("../utils/redact");
31
25
  const env_1 = require("./env");
32
- const { combine } = winston_1.format;
33
- let winstonInstance;
34
26
  // wrapper around console.log
35
27
  function consoleLog(message) {
36
28
  // eslint-disable-next-line no-console
@@ -38,29 +30,12 @@ function consoleLog(message) {
38
30
  //process.stdout.write(message);
39
31
  }
40
32
  exports.consoleLog = consoleLog;
41
- exports.logger = {
42
- error: (message, meta) => {
43
- winstonInstance.error(message, null, { meta });
44
- },
45
- warn: (message, meta) => {
46
- winstonInstance.warn(message, null, { meta });
47
- },
48
- info: (message, meta) => {
49
- winstonInstance.info(message, null, { meta });
50
- },
51
- verbose: (message, meta) => {
52
- winstonInstance.verbose(message, null, { meta });
53
- },
54
- debug: (message, meta) => {
55
- winstonInstance.debug(message, null, { meta });
56
- },
57
- };
58
33
  let _accessToken;
59
34
  function updateLogger({ accessToken, verbose, }) {
60
35
  // set access token
61
36
  _accessToken = accessToken;
62
37
  // set log level
63
- winstonInstance.level = verbose ? 'debug' : 'info';
38
+ exports.logger.level = verbose ? 'debug' : 'info';
64
39
  }
65
40
  exports.updateLogger = updateLogger;
66
41
  function redactAccessToken(str) {
@@ -75,39 +50,24 @@ function initLogger({ ci, accessToken, logFilePath, }) {
75
50
  if (accessToken) {
76
51
  _accessToken = accessToken;
77
52
  }
78
- winstonInstance = winston_1.default.createLogger({
53
+ exports.logger = winston_1.default.createLogger({
54
+ format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
55
+ // Format the metadata object
56
+ winston_1.format.metadata({
57
+ fillExcept: ['message', 'level', 'timestamp', 'label'],
58
+ })),
79
59
  transports: ci
80
60
  ? [fileTransport, new winston_1.default.transports.Console()]
81
61
  : [fileTransport],
82
62
  });
83
- // wait exiting until logs have been flushed to disk
84
- winstonInstance.on('finish', () => {
85
- process.exit(1);
86
- });
87
63
  return exports.logger;
88
64
  }
89
65
  exports.initLogger = initLogger;
90
66
  function getFileTransport({ logFilePath }) {
91
67
  return new winston_1.default.transports.File({
92
- level: 'debug',
93
- format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
94
- fillExcept: ['message', 'level', 'timestamp', 'label'],
95
- }), winston_1.format.printf((info) => {
96
- // format without metadata
97
- if (!info.metadata.meta) {
98
- return redactAccessToken(`${info.timestamp}: ${info.message}`);
99
- }
100
- // format when metadata is a string
101
- if ((0, lodash_1.isString)(info.metadata.meta)) {
102
- return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
103
- }
104
- if (info.metadata.meta.stack) {
105
- return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
106
- }
107
- // format when metadata is an object
108
- return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
109
- })),
110
68
  filename: (0, env_1.getLogfilePath)({ logFilePath }),
69
+ level: 'debug',
70
+ format: winston_1.format.combine(winston_1.format.json()),
111
71
  });
112
72
  }
113
73
  // log levels:
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const strip_ansi_1 = __importDefault(require("strip-ansi"));
7
+ const prompts_1 = require("./prompts");
8
+ describe('prompt', () => {
9
+ describe('getChoicesForCommitPrompt', () => {
10
+ it('should display status badges via `expectedTargetPullRequests`', () => {
11
+ const commits = [
12
+ {
13
+ sourceBranch: 'master',
14
+ sourceCommit: {
15
+ committedDate: '1',
16
+ sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
17
+ message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
18
+ },
19
+ sourcePullRequest: {
20
+ number: 119700,
21
+ url: 'foo',
22
+ mergeCommit: {
23
+ sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
24
+ message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
25
+ },
26
+ },
27
+ expectedTargetPullRequests: [
28
+ { number: 120178, branch: '8.0', state: 'MERGED' },
29
+ { number: 120179, branch: '7.16', state: 'MERGED' },
30
+ { number: 120179, branch: '7.15', state: 'MISSING' },
31
+ ],
32
+ },
33
+ ];
34
+ const choices = (0, prompts_1.getChoicesForCommitPrompt)(commits, false).map(({ name, short }) => ({ name: (0, strip_ansi_1.default)(name), short }));
35
+ expect(choices).toEqual([
36
+ {
37
+ name: '1. [APM] Remove log-log descriptions from correlation charts (#119700) 8.0, 7.16, 7.15',
38
+ short: '#119700 (ae9d51b7)',
39
+ },
40
+ ]);
41
+ });
42
+ it('should list choices', () => {
43
+ const commits = [
44
+ {
45
+ sourceBranch: 'master',
46
+ sourceCommit: {
47
+ committedDate: '',
48
+ sha: 'b1b491959dab47aeb83c88ee2accb2db46d23793',
49
+ message: '[APM] Prefer service.name for logs correlation (#120694)',
50
+ },
51
+ sourcePullRequest: {
52
+ number: 120694,
53
+ url: 'foo',
54
+ mergeCommit: {
55
+ sha: 'b1b491959dab47aeb83c88ee2accb2db46d23793',
56
+ message: '[APM] Prefer service.name for logs correlation (#120694)',
57
+ },
58
+ },
59
+ expectedTargetPullRequests: [],
60
+ },
61
+ {
62
+ sourceBranch: 'master',
63
+ sourceCommit: {
64
+ committedDate: '',
65
+ sha: 'b1bb4a93959f19a653b9cfb207a5c6acb6559482',
66
+ message: '[APM] Disable telemetry in agent config endpoint (#120106)',
67
+ },
68
+ sourcePullRequest: {
69
+ number: 120106,
70
+ url: 'foo',
71
+ mergeCommit: {
72
+ sha: 'b1bb4a93959f19a653b9cfb207a5c6acb6559482',
73
+ message: '[APM] Disable telemetry in agent config endpoint (#120106)',
74
+ },
75
+ },
76
+ expectedTargetPullRequests: [],
77
+ },
78
+ {
79
+ sourceBranch: 'master',
80
+ sourceCommit: {
81
+ committedDate: '',
82
+ sha: '434f6e6a88faf24dc1ea41f9f726db78e46355a7',
83
+ message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
84
+ },
85
+ sourcePullRequest: {
86
+ number: 119915,
87
+ url: 'foo',
88
+ mergeCommit: {
89
+ sha: '434f6e6a88faf24dc1ea41f9f726db78e46355a7',
90
+ message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
91
+ },
92
+ },
93
+ expectedTargetPullRequests: [],
94
+ },
95
+ {
96
+ sourceBranch: 'master',
97
+ sourceCommit: {
98
+ committedDate: '',
99
+ sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
100
+ message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
101
+ },
102
+ sourcePullRequest: {
103
+ number: 119700,
104
+ url: 'foo',
105
+ mergeCommit: {
106
+ sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
107
+ message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
108
+ },
109
+ },
110
+ expectedTargetPullRequests: [],
111
+ },
112
+ ];
113
+ const choices = (0, prompts_1.getChoicesForCommitPrompt)(commits, false).map(({ name, short }) => ({ name: (0, strip_ansi_1.default)(name), short }));
114
+ expect(choices).toEqual([
115
+ {
116
+ name: '1. [APM] Prefer service.name for logs correlation (#120694) ',
117
+ short: '#120694 (b1b49195)',
118
+ },
119
+ {
120
+ name: '2. [APM] Disable telemetry in agent config endpoint (#120106) ',
121
+ short: '#120106 (b1bb4a93)',
122
+ },
123
+ {
124
+ name: '3. [APM] Remove index_pattern.json and add custom field formatters (#119915) ',
125
+ short: '#119915 (434f6e6a)',
126
+ },
127
+ {
128
+ name: '4. [APM] Remove log-log descriptions from correlation charts (#119700) ',
129
+ short: '#119700 (ae9d51b7)',
130
+ },
131
+ ]);
132
+ });
133
+ });
134
+ });