backport 7.2.0-beta.2 → 7.2.0-beta.3

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 (104) hide show
  1. package/dist/entrypoint.cli.private.test.d.ts +1 -0
  2. package/dist/entrypoint.cli.private.test.js +46 -0
  3. package/dist/options/cliArgs.test.d.ts +1 -0
  4. package/dist/options/cliArgs.test.js +182 -0
  5. package/dist/options/config/config.test.d.ts +1 -0
  6. package/dist/options/config/config.test.js +32 -0
  7. package/dist/options/config/globalConfig.test.d.ts +1 -0
  8. package/dist/options/config/globalConfig.test.js +61 -0
  9. package/dist/options/config/projectConfig.test.d.ts +1 -0
  10. package/dist/options/config/projectConfig.test.js +109 -0
  11. package/dist/options/options.test.d.ts +1 -0
  12. package/dist/options/options.test.js +384 -0
  13. package/dist/runSequentially.test.d.ts +1 -0
  14. package/dist/runSequentially.test.js +243 -0
  15. package/dist/scripts/postinstall.test.d.ts +1 -0
  16. package/dist/scripts/postinstall.test.js +53 -0
  17. package/dist/services/env.test.d.ts +1 -0
  18. package/dist/services/env.test.js +21 -0
  19. package/dist/services/git.d.ts +1 -3
  20. package/dist/services/git.integration.test.d.ts +1 -0
  21. package/dist/services/git.integration.test.js +320 -0
  22. package/dist/services/git.js +5 -3
  23. package/dist/services/git.test.d.ts +1 -0
  24. package/dist/services/git.test.js +532 -0
  25. package/dist/services/github/commitFormatters.test.d.ts +1 -0
  26. package/dist/services/github/commitFormatters.test.js +11 -0
  27. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  28. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
  29. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  30. package/dist/services/github/v3/createPullRequest.test.js +325 -0
  31. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  32. package/dist/services/github/v3/createStatusComment.test.js +386 -0
  33. package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
  34. package/dist/services/github/v4/apiRequestV4.test.js +109 -0
  35. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  36. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  37. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  38. package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
  39. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  40. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  41. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  42. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +134 -0
  43. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  44. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +116 -0
  45. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  46. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
  47. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +152 -0
  49. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  50. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
  51. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  52. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
  53. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  54. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  55. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  56. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -0
  57. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  58. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  59. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  60. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +156 -0
  61. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  62. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  63. package/dist/services/prompt.test.d.ts +1 -0
  64. package/dist/services/prompt.test.js +134 -0
  65. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  66. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  67. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  68. package/dist/services/sourceCommit/parseSourceCommit.test.js +225 -0
  69. package/dist/test/ExecError.d.ts +16 -0
  70. package/dist/test/ExecError.js +15 -0
  71. package/dist/test/e2e/cli.e2e.private.test.d.ts +1 -0
  72. package/dist/test/e2e/cli.e2e.private.test.js +433 -0
  73. package/dist/test/e2e/module.e2e.private.test.d.ts +1 -0
  74. package/dist/test/e2e/module.e2e.private.test.js +363 -0
  75. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  76. package/dist/test/handleUnbackportedPullRequests.private.test.js +55 -0
  77. package/dist/test/mockConfigFiles.d.ts +5 -0
  78. package/dist/test/mockConfigFiles.js +21 -0
  79. package/dist/test/mocks.d.ts +10 -0
  80. package/dist/test/mocks.js +23 -0
  81. package/dist/test/nockHelpers.d.ts +16 -0
  82. package/dist/test/nockHelpers.js +36 -0
  83. package/dist/test/private/getDevAccessToken.d.ts +2 -0
  84. package/dist/test/private/getDevAccessToken.js +12 -0
  85. package/dist/test/sandbox.d.ts +5 -0
  86. package/dist/test/sandbox.js +43 -0
  87. package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
  88. package/dist/test/setupFiles/automatic-mocks.js +63 -0
  89. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  90. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +459 -0
  91. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  92. package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
  93. package/dist/ui/getTargetBranches.test.d.ts +1 -0
  94. package/dist/ui/getTargetBranches.test.js +198 -0
  95. package/dist/ui/maybeSetupRepo.js +7 -3
  96. package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
  97. package/dist/ui/maybeSetupRepo.test.js +238 -0
  98. package/dist/ui/ora.d.ts +1 -1
  99. package/dist/ui/ora.js +2 -2
  100. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  101. package/dist/utils/excludeUndefined.test.js +24 -0
  102. package/dist/utils/packageVersion.d.ts +1 -1
  103. package/dist/utils/packageVersion.js +1 -1
  104. package/package.json +1 -1
@@ -0,0 +1,238 @@
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 del_1 = __importDefault(require("del"));
27
+ const childProcess = __importStar(require("../services/child-process-promisified"));
28
+ const git = __importStar(require("../services/git"));
29
+ const mocks_1 = require("../test/mocks");
30
+ const maybeSetupRepo_1 = require("./maybeSetupRepo");
31
+ describe('maybeSetupRepo', () => {
32
+ let execSpy;
33
+ beforeEach(() => {
34
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
35
+ execSpy = jest
36
+ .spyOn(childProcess, 'exec')
37
+ .mockResolvedValue({ stderr: '', stdout: '' });
38
+ });
39
+ afterEach(() => {
40
+ jest.restoreAllMocks();
41
+ });
42
+ describe('if an error occurs while cloning', () => {
43
+ it('should delete repo', async () => {
44
+ expect.assertions(2);
45
+ execSpy = jest
46
+ .spyOn(childProcess, 'execAsCallback')
47
+ .mockImplementation((cmd) => {
48
+ if (cmd.startsWith('git clone')) {
49
+ throw new Error('Simulated git clone failure');
50
+ }
51
+ throw new Error('unknown error');
52
+ });
53
+ await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
54
+ repoName: 'kibana',
55
+ repoOwner: 'elastic',
56
+ cwd: '/path/to/source/repo',
57
+ })).rejects.toThrowError('Simulated git clone failure');
58
+ expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana', { force: true });
59
+ });
60
+ });
61
+ describe('while cloning the repo', () => {
62
+ it('updates the progress', async () => {
63
+ let onCloneComplete;
64
+ let dataHandler;
65
+ const oraMock = (0, mocks_1.getOraMock)();
66
+ const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
67
+ const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
68
+ jest
69
+ .spyOn(git, 'getSourceRepoPath')
70
+ .mockResolvedValue('/path/to/source/repo');
71
+ jest
72
+ .spyOn(childProcess, 'execAsCallback')
73
+ //@ts-expect-error
74
+ .mockImplementation((cmdString, cmdOptions, onComplete) => {
75
+ // callback should be called to finalize the operation
76
+ if (onComplete) {
77
+ //@ts-expect-error
78
+ onCloneComplete = onComplete;
79
+ }
80
+ return {
81
+ stderr: {
82
+ on: (name, handler) => {
83
+ dataHandler = handler;
84
+ },
85
+ },
86
+ };
87
+ });
88
+ setTimeout(() => {
89
+ dataHandler('Receiving objects: 1%');
90
+ dataHandler('Receiving objects: 10%');
91
+ dataHandler('Receiving objects: 20%');
92
+ dataHandler('Receiving objects: 100%');
93
+ dataHandler('Updating files: 1%');
94
+ dataHandler('Updating files: 10%');
95
+ dataHandler('Updating files: 20%');
96
+ dataHandler('Updating files: 100%');
97
+ onCloneComplete();
98
+ }, 50);
99
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
100
+ repoName: 'kibana',
101
+ repoOwner: 'elastic',
102
+ cwd: '/path/to/source/repo',
103
+ });
104
+ expect(spinnerTextSpy.mock.calls.map((call) => call[0]))
105
+ .toMatchInlineSnapshot(`
106
+ Array [
107
+ "0% Cloning repository from /path/to/source/repo (one-time operation)",
108
+ "1% Cloning repository from /path/to/source/repo (one-time operation)",
109
+ "9% Cloning repository from /path/to/source/repo (one-time operation)",
110
+ "18% Cloning repository from /path/to/source/repo (one-time operation)",
111
+ "90% Cloning repository from /path/to/source/repo (one-time operation)",
112
+ "90% Cloning repository from /path/to/source/repo (one-time operation)",
113
+ "91% Cloning repository from /path/to/source/repo (one-time operation)",
114
+ "92% Cloning repository from /path/to/source/repo (one-time operation)",
115
+ "100% Cloning repository from /path/to/source/repo (one-time operation)",
116
+ ]
117
+ `);
118
+ expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
119
+ });
120
+ });
121
+ describe('if repo already exists', () => {
122
+ beforeEach(() => {
123
+ jest
124
+ .spyOn(childProcess, 'execAsCallback')
125
+ //@ts-expect-error
126
+ .mockImplementation((cmdString, cmdOptions, callback) => {
127
+ //@ts-expect-error
128
+ callback();
129
+ return {
130
+ stderr: { on: () => null },
131
+ };
132
+ });
133
+ });
134
+ it('should re-create remotes for both source repo and fork', async () => {
135
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
136
+ accessToken: 'myAccessToken',
137
+ authenticatedUsername: 'sqren_authenticated',
138
+ repoName: 'kibana',
139
+ repoOwner: 'elastic',
140
+ cwd: '/path/to/source/repo',
141
+ });
142
+ expect(execSpy.mock.calls.map(([cmd, { cwd }]) => ({ cmd, cwd }))).toEqual([
143
+ {
144
+ cmd: 'git rev-parse --show-toplevel',
145
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
146
+ },
147
+ {
148
+ cmd: 'git remote --verbose',
149
+ cwd: '/path/to/source/repo',
150
+ },
151
+ {
152
+ cmd: 'git remote rm origin',
153
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
154
+ },
155
+ {
156
+ cmd: 'git remote rm sqren_authenticated',
157
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
158
+ },
159
+ {
160
+ cmd: 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
161
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
162
+ },
163
+ {
164
+ cmd: 'git remote rm elastic',
165
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
166
+ },
167
+ {
168
+ cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
169
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
170
+ },
171
+ ]);
172
+ });
173
+ });
174
+ describe('if repo does not exists locally', () => {
175
+ beforeEach(() => {
176
+ jest
177
+ .spyOn(childProcess, 'execAsCallback')
178
+ //@ts-expect-error
179
+ .mockImplementation((cmdString, cmdOptions, callback) => {
180
+ //@ts-expect-error
181
+ callback();
182
+ return {
183
+ stderr: { on: () => null },
184
+ };
185
+ });
186
+ });
187
+ it('should clone it from github.com', async () => {
188
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
189
+ accessToken: 'myAccessToken',
190
+ gitHostname: 'github.com',
191
+ repoName: 'kibana',
192
+ repoOwner: 'elastic',
193
+ cwd: '/path/to/source/repo',
194
+ });
195
+ expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
196
+ });
197
+ });
198
+ describe('if repo does exist locally', () => {
199
+ beforeEach(() => {
200
+ jest
201
+ .spyOn(git, 'getSourceRepoPath')
202
+ .mockResolvedValue('/path/to/source/repo');
203
+ jest
204
+ .spyOn(childProcess, 'execAsCallback')
205
+ //@ts-expect-error
206
+ .mockImplementation((cmdString, cmdOptions, callback) => {
207
+ //@ts-expect-error
208
+ callback();
209
+ return {
210
+ stderr: { on: () => null },
211
+ };
212
+ });
213
+ });
214
+ it('should clone it from local folder', async () => {
215
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
216
+ repoName: 'kibana',
217
+ repoOwner: 'elastic',
218
+ cwd: '/path/to/source/repo',
219
+ });
220
+ expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone /path/to/source/repo /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
221
+ });
222
+ });
223
+ describe('if `repoPath` is a parent of current working directory (cwd)', () => {
224
+ beforeEach(() => {
225
+ jest
226
+ .spyOn(git, 'getSourceRepoPath')
227
+ .mockResolvedValue('/path/to/source/repo');
228
+ jest.spyOn(childProcess, 'execAsCallback');
229
+ });
230
+ it('should clone it from local folder', async () => {
231
+ await expect(() => (0, maybeSetupRepo_1.maybeSetupRepo)({
232
+ repoName: 'kibana',
233
+ repoOwner: 'elastic',
234
+ cwd: '/myHomeDir/.backport/repositories/elastic/kibana/foo',
235
+ })).rejects.toThrowError('Refusing to clone repo into "/myHomeDir/.backport/repositories/elastic/kibana" when current working directory is "/myHomeDir/.backport/repositories/elastic/kibana/foo". Please change backport directory via `--dir` option or run backport from another location');
236
+ });
237
+ });
238
+ });
package/dist/ui/ora.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import oraOriginal from 'ora';
2
- export declare function ora(ci: boolean | undefined, options?: string | oraOriginal.Options | undefined): oraOriginal.Ora | {
2
+ export declare function ora(ci: boolean | undefined, text?: string | undefined): oraOriginal.Ora | {
3
3
  start: (text?: string | undefined) => any;
4
4
  succeed: () => void;
5
5
  stop: () => void;
package/dist/ui/ora.js CHANGED
@@ -15,7 +15,7 @@ const oraMock = {
15
15
  stopAndPersist: () => { },
16
16
  set text(value) { },
17
17
  };
18
- function ora(ci, options) {
19
- return ci ? oraMock : (0, ora_1.default)(options);
18
+ function ora(ci, text) {
19
+ return ci ? oraMock : (0, ora_1.default)({ text });
20
20
  }
21
21
  exports.ora = ora;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const excludeUndefined_1 = require("./excludeUndefined");
4
+ describe('excludeUndefined', () => {
5
+ it('removes undefined values', () => {
6
+ expect((0, excludeUndefined_1.excludeUndefined)({
7
+ foo: 'foo',
8
+ bar: undefined,
9
+ baz: null,
10
+ })).toEqual({ foo: 'foo', baz: null });
11
+ });
12
+ it('has the correct types after merging', () => {
13
+ const obj = (0, excludeUndefined_1.excludeUndefined)({
14
+ foo: 'foo',
15
+ bar: undefined,
16
+ baz: null,
17
+ });
18
+ const res = {
19
+ bar: 'bar',
20
+ ...obj,
21
+ };
22
+ expect(res).toEqual({ bar: 'bar', foo: 'foo', baz: null });
23
+ });
24
+ });
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "7.2.0-beta.2";
1
+ export declare const PACKAGE_VERSION = "7.2.0-beta.3";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PACKAGE_VERSION = void 0;
4
- exports.PACKAGE_VERSION = '7.2.0-beta.2';
4
+ exports.PACKAGE_VERSION = '7.2.0-beta.3';
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "7.2.0-beta.2",
17
+ "version": "7.2.0-beta.3",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {