backport 5.6.6 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +48 -39
  2. package/dist/entrypoint.cli.js +1 -1
  3. package/dist/entrypoint.module.d.ts +6 -5
  4. package/dist/entrypoint.module.js +8 -6
  5. package/dist/ink.d.ts +1 -0
  6. package/dist/ink.js +49 -0
  7. package/dist/main.d.ts +11 -6
  8. package/dist/main.js +40 -24
  9. package/dist/options/ConfigOptions.d.ts +13 -8
  10. package/dist/options/cliArgs.d.ts +11 -9
  11. package/dist/options/cliArgs.js +74 -36
  12. package/dist/options/cliArgs.test.js +33 -37
  13. package/dist/options/config/config.d.ts +17 -15
  14. package/dist/options/config/config.js +8 -8
  15. package/dist/options/config/config.test.js +3 -2
  16. package/dist/options/config/getOptionsFromGit.js +1 -1
  17. package/dist/options/config/globalConfig.d.ts +2 -51
  18. package/dist/options/config/globalConfig.js +8 -8
  19. package/dist/options/config/globalConfig.test.js +7 -3
  20. package/dist/options/config/projectConfig.d.ts +2 -51
  21. package/dist/options/config/projectConfig.js +2 -2
  22. package/dist/options/config/projectConfig.test.js +3 -3
  23. package/dist/options/config/readConfigFile.d.ts +2 -51
  24. package/dist/options/config/readConfigFile.js +2 -2
  25. package/dist/options/options.d.ts +19 -14
  26. package/dist/options/options.js +5 -6
  27. package/dist/options/options.test.js +48 -11
  28. package/dist/options/parseRequiredOptions.d.ts +18 -13
  29. package/dist/options/parseRequiredOptions.js +8 -12
  30. package/dist/options/parseRequiredOptions.test.js +25 -16
  31. package/dist/runSequentially.d.ts +20 -0
  32. package/dist/runSequentially.js +41 -0
  33. package/dist/runSequentially.test.d.ts +1 -0
  34. package/dist/runSequentially.test.js +235 -0
  35. package/dist/runWithOptions.js +7 -14
  36. package/dist/runWithOptions.test.js +138 -17
  37. package/dist/scripts/generate-gql.d.ts +1 -0
  38. package/dist/scripts/generate-gql.js +15 -0
  39. package/dist/scripts/postinstall.js +4 -4
  40. package/dist/scripts/postinstall.test.js +9 -2
  41. package/dist/scripts/runPostinstall.js +1 -1
  42. package/dist/services/HandledError.d.ts +11 -1
  43. package/dist/services/HandledError.js +2 -1
  44. package/dist/services/child-process-promisified.d.ts +1 -1
  45. package/dist/services/child-process-promisified.js +1 -1
  46. package/dist/services/env.js +5 -5
  47. package/dist/services/env.test.js +11 -4
  48. package/dist/services/fs-promisified.js +4 -4
  49. package/dist/services/getExpectedTarget.d.ts +9 -0
  50. package/dist/services/getExpectedTarget.js +77 -0
  51. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  52. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  53. package/dist/services/git.d.ts +15 -4
  54. package/dist/services/git.integration.test.d.ts +1 -0
  55. package/dist/services/git.integration.test.js +168 -0
  56. package/dist/services/git.js +86 -61
  57. package/dist/services/git.test.js +61 -64
  58. package/dist/services/github/commitFormatters.d.ts +3 -7
  59. package/dist/services/github/commitFormatters.js +10 -19
  60. package/dist/services/github/commitFormatters.test.js +2 -24
  61. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  62. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
  63. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
  64. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  66. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  67. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  68. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  69. package/dist/services/github/v3/createPullRequest.js +32 -23
  70. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  71. package/dist/services/github/v3/createStatusComment.js +97 -0
  72. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  73. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  74. package/dist/services/github/v4/FetchPullRequestId.js +1 -1
  75. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  76. package/dist/services/github/v4/apiRequestV4.js +5 -7
  77. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  78. package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
  79. package/dist/services/github/v4/enablePullRequestAutoMerge.js +8 -7
  80. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +94 -33
  81. package/dist/services/github/v4/fetchAuthorId.js +1 -1
  82. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
  83. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  84. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  85. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  86. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  87. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
  88. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  89. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  90. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
  91. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
  92. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  93. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  94. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  103. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  104. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  105. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  106. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
  107. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  109. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  110. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  111. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  112. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  113. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  114. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  115. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
  116. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  117. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  118. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  119. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
  120. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  121. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  122. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  123. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  124. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  125. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +16 -10
  126. package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
  127. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +25 -7
  128. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +13 -16
  129. package/dist/services/github/v4/getOptionsFromGithub/query.js +13 -15
  130. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  131. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  132. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  133. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  134. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  135. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  136. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  137. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  138. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  139. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  140. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  141. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  142. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  143. package/dist/services/logger.d.ts +3 -3
  144. package/dist/services/logger.js +16 -15
  145. package/dist/services/prompt.test.d.ts +1 -0
  146. package/dist/services/prompt.test.js +87 -0
  147. package/dist/services/prompts.d.ts +10 -4
  148. package/dist/services/prompts.js +85 -22
  149. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  150. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  151. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  152. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  153. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  154. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  155. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  156. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  157. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  158. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  159. package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
  160. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  161. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  162. package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
  163. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  164. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  165. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  166. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  167. package/dist/services/sourceCommit.d.ts +78 -0
  168. package/dist/services/sourceCommit.js +86 -0
  169. package/dist/services/sourceCommit.test.d.ts +1 -0
  170. package/dist/services/sourceCommit.test.js +280 -0
  171. package/dist/test/inquirer.private.test.js +22 -15
  172. package/dist/test/integration/createSpies.js +6 -6
  173. package/dist/test/integration/envConstants.js +5 -6
  174. package/dist/test/integration/helpers.js +1 -1
  175. package/dist/test/integration/integration.private.test.d.ts +1 -0
  176. package/dist/test/integration/integration.private.test.js +308 -0
  177. package/dist/test/integration/integration.test.js +28 -29
  178. package/dist/test/nockHelpers.js +3 -7
  179. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  180. package/dist/test/setupFiles/automatic-mocks.js +0 -22
  181. package/dist/types/Commit.d.ts +85 -0
  182. package/dist/types/Commit.js +139 -0
  183. package/dist/types/commitNode.d.ts +89 -0
  184. package/dist/types/commitNode.js +139 -0
  185. package/dist/types/commitNode.test.d.ts +1 -0
  186. package/dist/types/commitNode.test.js +255 -0
  187. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  188. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  189. package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
  190. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  191. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +131 -68
  192. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  193. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  194. package/dist/ui/getCommits.d.ts +1 -1
  195. package/dist/ui/getCommits.js +55 -25
  196. package/dist/ui/getTargetBranches.d.ts +2 -2
  197. package/dist/ui/getTargetBranches.js +16 -17
  198. package/dist/ui/getTargetBranches.test.js +75 -99
  199. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  200. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  201. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  202. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  203. package/dist/ui/maybeSetupRepo.js +9 -9
  204. package/dist/ui/maybeSetupRepo.test.js +5 -1
  205. package/package.json +36 -51
  206. package/yarn.lock +2387 -2987
@@ -0,0 +1,20 @@
1
+ import { ValidConfigOptions } from './options/options';
2
+ import { HandledError } from './services/HandledError';
3
+ import { Commit } from './services/sourceCommit/parseSourceCommit';
4
+ export declare type Result = {
5
+ status: 'success';
6
+ didUpdate: boolean;
7
+ targetBranch: string;
8
+ pullRequestUrl: string;
9
+ pullRequestNumber: number;
10
+ } | {
11
+ status: 'failure';
12
+ targetBranch: string;
13
+ errorMessage: string;
14
+ error: HandledError;
15
+ };
16
+ export declare function runSequentially({ options, commits, targetBranches, }: {
17
+ options: ValidConfigOptions;
18
+ commits: Commit[];
19
+ targetBranches: string[];
20
+ }): Promise<Result[]>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSequentially = void 0;
4
+ const logger_1 = require("./services/logger");
5
+ const sequentially_1 = require("./services/sequentially");
6
+ const cherrypickAndCreateTargetPullRequest_1 = require("./ui/cherrypickAndCreateTargetPullRequest");
7
+ const maybeSetupRepo_1 = require("./ui/maybeSetupRepo");
8
+ async function runSequentially({ options, commits, targetBranches, }) {
9
+ logger_1.logger.verbose('Backport options', options);
10
+ await (0, maybeSetupRepo_1.maybeSetupRepo)(options);
11
+ const results = [];
12
+ await (0, sequentially_1.sequentially)(targetBranches, async (targetBranch) => {
13
+ logger_1.logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
14
+ try {
15
+ const { number, url, didUpdate } = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
16
+ options,
17
+ commits,
18
+ targetBranch,
19
+ });
20
+ results.push({
21
+ targetBranch,
22
+ status: 'success',
23
+ didUpdate,
24
+ pullRequestUrl: url,
25
+ pullRequestNumber: number,
26
+ });
27
+ }
28
+ catch (e) {
29
+ results.push({
30
+ targetBranch,
31
+ status: 'failure',
32
+ errorMessage: e.message,
33
+ error: e,
34
+ });
35
+ (0, logger_1.consoleLog)(e.message);
36
+ }
37
+ });
38
+ // return the results for consumers to programatically read
39
+ return results;
40
+ }
41
+ exports.runSequentially = runSequentially;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,235 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const os_1 = __importDefault(require("os"));
26
+ const lodash_1 = require("lodash");
27
+ const nock_1 = __importDefault(require("nock"));
28
+ const runSequentially_1 = require("./runSequentially");
29
+ const childProcess = __importStar(require("./services/child-process-promisified"));
30
+ const nockHelpers_1 = require("./test/nockHelpers");
31
+ jest.mock('./services/child-process-promisified', () => {
32
+ return {
33
+ exec: jest.fn(async (cmd) => {
34
+ throw new Error(`Mock required for exec with cmd: "${cmd}"`);
35
+ }),
36
+ execAsCallback: jest.fn((...args) => {
37
+ (0, lodash_1.last)(args)();
38
+ return {
39
+ stderr: {
40
+ on: () => null,
41
+ },
42
+ };
43
+ }),
44
+ };
45
+ });
46
+ describe('runSequentially', () => {
47
+ let rpcExecMock;
48
+ let rpcExecOriginalMock;
49
+ let res;
50
+ let createPullRequestCalls;
51
+ afterEach(() => {
52
+ jest.clearAllMocks();
53
+ nock_1.default.cleanAll();
54
+ });
55
+ beforeEach(async () => {
56
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
57
+ const options = {
58
+ accessToken: 'myAccessToken',
59
+ all: false,
60
+ assignees: [],
61
+ author: 'sqren',
62
+ autoAssign: false,
63
+ autoFixConflicts: undefined,
64
+ autoMerge: false,
65
+ autoMergeMethod: 'merge',
66
+ branchLabelMapping: undefined,
67
+ historicalBranchLabelMappings: [],
68
+ cherrypickRef: true,
69
+ ci: false,
70
+ commitPaths: [],
71
+ details: false,
72
+ editor: 'code',
73
+ forceLocalConfig: undefined,
74
+ fork: true,
75
+ gitHostname: 'github.com',
76
+ githubApiBaseUrlV3: 'https://api.github.com',
77
+ githubApiBaseUrlV4: 'http://localhost/graphql',
78
+ mainline: undefined,
79
+ maxNumber: 10,
80
+ multipleBranches: false,
81
+ multipleCommits: false,
82
+ noVerify: true,
83
+ prDescription: 'myPrDescription',
84
+ prFilter: undefined,
85
+ prTitle: 'myPrTitle {targetBranch} {commitMessages}',
86
+ pullNumber: undefined,
87
+ repoName: 'kibana',
88
+ repoOwner: 'elastic',
89
+ resetAuthor: false,
90
+ reviewers: [],
91
+ sha: undefined,
92
+ sourceBranch: 'my-source-branch-from-options',
93
+ sourcePRLabels: [],
94
+ targetBranches: [],
95
+ upstream: 'elastic/kibana',
96
+ targetBranchChoices: [
97
+ { name: '6.x' },
98
+ { name: '6.0' },
99
+ { name: '5.6' },
100
+ { name: '5.5' },
101
+ { name: '5.4' },
102
+ ],
103
+ targetPRLabels: [],
104
+ username: 'sqren',
105
+ verbose: false,
106
+ };
107
+ rpcExecMock = jest
108
+ .spyOn(childProcess, 'exec')
109
+ .mockResolvedValue({ stdout: 'success', stderr: '' });
110
+ rpcExecOriginalMock = jest.spyOn(childProcess, 'execAsCallback');
111
+ const scope = (0, nock_1.default)('https://api.github.com')
112
+ .post('/repos/elastic/kibana/pulls')
113
+ .reply(200, {
114
+ number: 1337,
115
+ html_url: 'myHtmlUrl',
116
+ });
117
+ createPullRequestCalls = (0, nockHelpers_1.getNockCallsForScope)(scope);
118
+ const commits = [
119
+ {
120
+ sha: 'abcd',
121
+ committedDate: '1',
122
+ expectedTargetPullRequests: [],
123
+ originalMessage: 'My commit message',
124
+ sourceBranch: 'master',
125
+ pullNumber: 55,
126
+ },
127
+ ];
128
+ const targetBranches = ['7.x'];
129
+ res = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
130
+ scope.done();
131
+ });
132
+ it('returns pull request', () => {
133
+ expect(res).toEqual([
134
+ {
135
+ didUpdate: false,
136
+ pullRequestNumber: 1337,
137
+ pullRequestUrl: 'myHtmlUrl',
138
+ status: 'success',
139
+ targetBranch: '7.x',
140
+ },
141
+ ]);
142
+ });
143
+ it('creates pull request', () => {
144
+ expect(createPullRequestCalls).toEqual([
145
+ {
146
+ base: '7.x',
147
+ body: 'Backports the following commits to 7.x:\n - #55\n\nmyPrDescription',
148
+ head: 'sqren:backport/7.x/pr-55',
149
+ title: 'myPrTitle 7.x My commit message',
150
+ },
151
+ ]);
152
+ });
153
+ it('exec should be called with correct args', () => {
154
+ expect(rpcExecMock).toHaveBeenCalledTimes(10);
155
+ expect(rpcExecMock.mock.calls).toMatchInlineSnapshot(`
156
+ Array [
157
+ Array [
158
+ "git remote rm origin",
159
+ Object {
160
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
161
+ },
162
+ ],
163
+ Array [
164
+ "git remote rm sqren",
165
+ Object {
166
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
167
+ },
168
+ ],
169
+ Array [
170
+ "git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git",
171
+ Object {
172
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
173
+ },
174
+ ],
175
+ Array [
176
+ "git remote rm elastic",
177
+ Object {
178
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
179
+ },
180
+ ],
181
+ Array [
182
+ "git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git",
183
+ Object {
184
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
185
+ },
186
+ ],
187
+ Array [
188
+ "git reset --hard && git clean -d --force && git fetch elastic 7.x && git checkout -B backport/7.x/pr-55 elastic/7.x --no-track",
189
+ Object {
190
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
191
+ },
192
+ ],
193
+ Array [
194
+ "git fetch elastic master:master --force",
195
+ Object {
196
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
197
+ },
198
+ ],
199
+ Array [
200
+ "git cherry-pick -x abcd",
201
+ Object {
202
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
203
+ },
204
+ ],
205
+ Array [
206
+ "git push sqren backport/7.x/pr-55:backport/7.x/pr-55 --force",
207
+ Object {
208
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
209
+ },
210
+ ],
211
+ Array [
212
+ "git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55",
213
+ Object {
214
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
215
+ },
216
+ ],
217
+ ]
218
+ `);
219
+ });
220
+ it('git clone should be called with correct args', () => {
221
+ expect(rpcExecOriginalMock).toHaveBeenCalledTimes(1);
222
+ expect(rpcExecOriginalMock.mock.calls).toMatchInlineSnapshot(`
223
+ Array [
224
+ Array [
225
+ "git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git --progress",
226
+ Object {
227
+ "cwd": "/myHomeDir/.backport/repositories/elastic",
228
+ "maxBuffer": 104857600,
229
+ },
230
+ [Function],
231
+ ],
232
+ ]
233
+ `);
234
+ });
235
+ });
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.runWithOptions = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
4
  const HandledError_1 = require("./services/HandledError");
9
5
  const logger_1 = require("./services/logger");
10
6
  const sequentially_1 = require("./services/sequentially");
@@ -14,17 +10,14 @@ const getTargetBranches_1 = require("./ui/getTargetBranches");
14
10
  const maybeSetupRepo_1 = require("./ui/maybeSetupRepo");
15
11
  async function runWithOptions(options) {
16
12
  logger_1.logger.verbose('Backport options', options);
17
- if (options.dryRun) {
18
- logger_1.consoleLog(chalk_1.default.red('Dry run: Nothing will be pushed to Github\n'));
19
- }
20
- const commits = await getCommits_1.getCommits(options);
21
- const targetBranches = await getTargetBranches_1.getTargetBranches(options, commits);
22
- await maybeSetupRepo_1.maybeSetupRepo(options);
13
+ const commits = await (0, getCommits_1.getCommits)(options);
14
+ const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
15
+ await (0, maybeSetupRepo_1.maybeSetupRepo)(options);
23
16
  const results = [];
24
- await sequentially_1.sequentially(targetBranches, async (targetBranch) => {
17
+ await (0, sequentially_1.sequentially)(targetBranches, async (targetBranch) => {
25
18
  logger_1.logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
26
19
  try {
27
- const pullRequest = await cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest({
20
+ const pullRequest = await (0, cherrypickAndCreateTargetPullRequest_1.cherrypickAndCreateTargetPullRequest)({
28
21
  options,
29
22
  commits,
30
23
  targetBranch,
@@ -38,10 +31,10 @@ async function runWithOptions(options) {
38
31
  catch (e) {
39
32
  const isHandledError = e instanceof HandledError_1.HandledError;
40
33
  const errorMessage = isHandledError
41
- ? logger_1.redact(e.message)
34
+ ? (0, logger_1.redact)(e.message)
42
35
  : 'An unhandled error occurred. Please consult the logs';
43
36
  results.push({ targetBranch, success: false, errorMessage, error: e });
44
- logger_1.consoleLog(errorMessage);
37
+ (0, logger_1.consoleLog)(errorMessage);
45
38
  }
46
39
  });
47
40
  // return the results for consumers to programatically read
@@ -22,13 +22,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const os_1 = __importDefault(require("os"));
25
26
  const inquirer_1 = __importDefault(require("inquirer"));
27
+ const lodash_1 = require("lodash");
26
28
  const nock_1 = __importDefault(require("nock"));
27
29
  const runWithOptions_1 = require("./runWithOptions");
28
30
  const childProcess = __importStar(require("./services/child-process-promisified"));
29
31
  const fs = __importStar(require("./services/fs-promisified"));
30
32
  const commitsByAuthorMock_1 = require("./services/github/v4/mocks/commitsByAuthorMock");
31
33
  const nockHelpers_1 = require("./test/nockHelpers");
34
+ jest.mock('./services/child-process-promisified', () => {
35
+ return {
36
+ exec: jest.fn(async (cmd) => {
37
+ throw new Error(`Mock required for exec with cmd: "${cmd}"`);
38
+ }),
39
+ execAsCallback: jest.fn((...args) => {
40
+ (0, lodash_1.last)(args)();
41
+ return {
42
+ stderr: {
43
+ on: () => null,
44
+ },
45
+ };
46
+ }),
47
+ };
48
+ });
32
49
  describe('runWithOptions', () => {
33
50
  let rpcExecMock;
34
51
  let rpcExecOriginalMock;
@@ -42,6 +59,7 @@ describe('runWithOptions', () => {
42
59
  nock_1.default.cleanAll();
43
60
  });
44
61
  beforeEach(async () => {
62
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
45
63
  const options = {
46
64
  accessToken: 'myAccessToken',
47
65
  all: false,
@@ -53,7 +71,9 @@ describe('runWithOptions', () => {
53
71
  autoMergeMethod: 'merge',
54
72
  branchLabelMapping: undefined,
55
73
  ci: false,
56
- dryRun: false,
74
+ cherrypickRef: true,
75
+ commitPaths: [],
76
+ details: false,
57
77
  editor: 'code',
58
78
  forceLocalConfig: undefined,
59
79
  fork: true,
@@ -65,19 +85,18 @@ describe('runWithOptions', () => {
65
85
  multipleBranches: false,
66
86
  multipleCommits: false,
67
87
  noVerify: true,
68
- path: undefined,
69
88
  prDescription: 'myPrDescription',
89
+ prFilter: undefined,
70
90
  prTitle: 'myPrTitle {targetBranch} {commitMessages}',
71
91
  pullNumber: undefined,
72
- upstream: 'elastic/kibana',
73
92
  repoName: 'kibana',
74
93
  repoOwner: 'elastic',
75
94
  resetAuthor: false,
76
95
  sha: undefined,
77
- sourceBranch: 'mySourceBranch',
96
+ sourceBranch: 'my-source-branch-from-options',
78
97
  sourcePRLabels: [],
79
- prFilter: undefined,
80
98
  targetBranches: [],
99
+ upstream: 'elastic/kibana',
81
100
  targetBranchChoices: [
82
101
  { name: '6.x' },
83
102
  { name: '6.0' },
@@ -102,21 +121,21 @@ describe('runWithOptions', () => {
102
121
  .mockImplementationOnce((async (args) => {
103
122
  return { promptResult: args[0].choices[0].name };
104
123
  }));
105
- authorIdCalls = nockHelpers_1.mockGqlRequest({
124
+ authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
106
125
  name: 'AuthorId',
107
126
  statusCode: 200,
108
127
  body: { data: { user: { id: 'sqren_author_id' } } },
109
128
  });
110
- commitsByAuthorCalls = nockHelpers_1.mockGqlRequest({
129
+ commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
111
130
  name: 'CommitsByAuthor',
112
131
  statusCode: 200,
113
- body: { data: commitsByAuthorMock_1.commitsWithPullRequestsMock },
132
+ body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
114
133
  });
115
- const scope = nock_1.default('https://api.github.com')
134
+ const scope = (0, nock_1.default)('https://api.github.com')
116
135
  .post('/repos/elastic/kibana/pulls')
117
136
  .reply(200, { html_url: 'pull request url', number: 1337 });
118
- createPullRequestCalls = nockHelpers_1.getNockCallsForScope(scope);
119
- res = await runWithOptions_1.runWithOptions(options);
137
+ createPullRequestCalls = (0, nockHelpers_1.getNockCallsForScope)(scope);
138
+ res = await (0, runWithOptions_1.runWithOptions)(options);
120
139
  scope.done();
121
140
  });
122
141
  it('returns pull request', () => {
@@ -134,7 +153,7 @@ describe('runWithOptions', () => {
134
153
  base: '6.x',
135
154
  body: 'Backports the following commits to 6.x:\n - Add 👻 (2e63475c)\n\nmyPrDescription',
136
155
  head: 'sqren:backport/6.x/commit-2e63475c',
137
- title: 'myPrTitle 6.x Add 👻 (2e63475c)',
156
+ title: 'myPrTitle 6.x Add 👻',
138
157
  },
139
158
  ]);
140
159
  });
@@ -160,24 +179,126 @@ describe('runWithOptions', () => {
160
179
  expect(commitsByAuthorCalls.map((body) => body.variables)).toEqual([
161
180
  {
162
181
  authorId: 'sqren_author_id',
163
- historyPath: null,
164
182
  maxNumber: 10,
183
+ commitPath: null,
165
184
  repoName: 'kibana',
166
185
  repoOwner: 'elastic',
167
- sourceBranch: 'mySourceBranch',
186
+ sourceBranch: 'my-source-branch-from-options',
168
187
  },
169
188
  ]);
170
189
  });
171
190
  it('prompt calls should match snapshot', () => {
172
191
  expect(inquirer_1.default.prompt).toHaveBeenCalledTimes(2);
173
- expect(inquirerPromptMock.mock.calls).toMatchSnapshot();
192
+ expect(
193
+ // @ts-expect-error
194
+ inquirerPromptMock.mock.calls[0][0][0].choices.map(({ name, short }) => ({
195
+ name,
196
+ short,
197
+ }))).toMatchInlineSnapshot(`
198
+ Array [
199
+ Object {
200
+ "name": "1. Add 👻 ",
201
+ "short": "2e63475c",
202
+ },
203
+ Object {
204
+ "name": "2. Add witch (#85) ",
205
+ "short": "#85 (f3b618b9)",
206
+ },
207
+ Object {
208
+ "name": "3. Add SF mention (#80) 6.3",
209
+ "short": "#80 (79cf1845)",
210
+ },
211
+ Object {
212
+ "name": "4. Add backport config ",
213
+ "short": "3827bbba",
214
+ },
215
+ Object {
216
+ "name": "5. Initial commit ",
217
+ "short": "5ea0da55",
218
+ },
219
+ ]
220
+ `);
174
221
  });
175
222
  it('exec should be called with correct args', () => {
176
223
  expect(rpcExecMock).toHaveBeenCalledTimes(10);
177
- expect(rpcExecMock.mock.calls).toMatchSnapshot();
224
+ expect(rpcExecMock.mock.calls).toMatchInlineSnapshot(`
225
+ Array [
226
+ Array [
227
+ "git remote rm origin",
228
+ Object {
229
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
230
+ },
231
+ ],
232
+ Array [
233
+ "git remote rm sqren",
234
+ Object {
235
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
236
+ },
237
+ ],
238
+ Array [
239
+ "git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git",
240
+ Object {
241
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
242
+ },
243
+ ],
244
+ Array [
245
+ "git remote rm elastic",
246
+ Object {
247
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
248
+ },
249
+ ],
250
+ Array [
251
+ "git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git",
252
+ Object {
253
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
254
+ },
255
+ ],
256
+ Array [
257
+ "git reset --hard && git clean -d --force && git fetch elastic 6.x && git checkout -B backport/6.x/commit-2e63475c elastic/6.x --no-track",
258
+ Object {
259
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
260
+ },
261
+ ],
262
+ Array [
263
+ "git fetch elastic my-source-branch-from-options:my-source-branch-from-options --force",
264
+ Object {
265
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
266
+ },
267
+ ],
268
+ Array [
269
+ "git cherry-pick 2e63475c483f7844b0f2833bc57fdee32095bacb",
270
+ Object {
271
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
272
+ },
273
+ ],
274
+ Array [
275
+ "git push sqren backport/6.x/commit-2e63475c:backport/6.x/commit-2e63475c --force",
276
+ Object {
277
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
278
+ },
279
+ ],
280
+ Array [
281
+ "git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/6.x/commit-2e63475c",
282
+ Object {
283
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
284
+ },
285
+ ],
286
+ ]
287
+ `);
178
288
  });
179
289
  it('git clone should be called with correct args', () => {
180
290
  expect(rpcExecOriginalMock).toHaveBeenCalledTimes(1);
181
- expect(rpcExecOriginalMock.mock.calls).toMatchSnapshot();
291
+ expect(rpcExecOriginalMock.mock.calls).toMatchInlineSnapshot(`
292
+ Array [
293
+ Array [
294
+ "git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git --progress",
295
+ Object {
296
+ "cwd": "/myHomeDir/.backport/repositories/elastic",
297
+ "maxBuffer": 104857600,
298
+ },
299
+ [Function],
300
+ ],
301
+ ]
302
+ `);
182
303
  });
183
304
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
4
+ const getDevAccessToken_1 = require("../test/private/getDevAccessToken");
5
+ async function init() {
6
+ const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
7
+ const res = (0, fetchCommitBySha_1.fetchCommitBySha)({
8
+ accessToken,
9
+ githubApiBaseUrlV4: 'https://api.github.com/graphql',
10
+ repoName: 'backport-org',
11
+ repoOwner: 'backport-e2e',
12
+ sha: 'b484e161b705b39dbbfc5005e67ca24d05b23c37',
13
+ sourceBranch: 'main',
14
+ });
15
+ }
@@ -6,14 +6,14 @@ const env_1 = require("../services/env");
6
6
  const logger_1 = require("../services/logger");
7
7
  async function postinstall() {
8
8
  try {
9
- const didCreate = await globalConfig_1.createGlobalConfigAndFolderIfNotExist();
9
+ const didCreate = await (0, globalConfig_1.createGlobalConfigAndFolderIfNotExist)();
10
10
  if (didCreate) {
11
- const GLOBAL_CONFIG_PATH = env_1.getGlobalConfigPath();
12
- logger_1.consoleLog(`Global config successfully created in ${GLOBAL_CONFIG_PATH}`);
11
+ const GLOBAL_CONFIG_PATH = (0, env_1.getGlobalConfigPath)();
12
+ (0, logger_1.consoleLog)(`Global config successfully created in ${GLOBAL_CONFIG_PATH}`);
13
13
  }
14
14
  }
15
15
  catch (e) {
16
- logger_1.consoleLog(`Global config could not be created:\n${e.stack}`);
16
+ (0, logger_1.consoleLog)(`Global config could not be created:\n${e.stack}`);
17
17
  }
18
18
  }
19
19
  exports.postinstall = postinstall;
@@ -18,19 +18,26 @@ 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
+ };
21
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const os_1 = __importDefault(require("os"));
22
26
  const globalConfig = __importStar(require("../options/config/globalConfig"));
23
27
  const logger = __importStar(require("../services/logger"));
24
28
  const postinstall_1 = require("./postinstall");
25
29
  describe('postinstall', () => {
26
30
  beforeEach(() => {
31
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
32
+ });
33
+ afterEach(() => {
27
34
  jest.clearAllMocks();
28
35
  });
29
36
  it("should create global config if it doesn't exist", async () => {
30
37
  const createGlobalConfigAndFolderIfNotExistSpy = jest
31
38
  .spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
32
39
  .mockResolvedValueOnce(true);
33
- await postinstall_1.postinstall();
40
+ await (0, postinstall_1.postinstall)();
34
41
  expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
35
42
  expect(logger.consoleLog).toBeCalledWith('Global config successfully created in /myHomeDir/.backport/config.json');
36
43
  });
@@ -39,7 +46,7 @@ describe('postinstall', () => {
39
46
  const createGlobalConfigAndFolderIfNotExistSpy = jest
40
47
  .spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
41
48
  .mockResolvedValueOnce(false);
42
- await postinstall_1.postinstall();
49
+ await (0, postinstall_1.postinstall)();
43
50
  expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
44
51
  expect(consoleSpy).toBeCalledTimes(0);
45
52
  });
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const postinstall_1 = require("./postinstall");
4
- postinstall_1.postinstall();
4
+ (0, postinstall_1.postinstall)();