backport 7.4.0 → 8.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 (69) hide show
  1. package/README.md +12 -13
  2. package/dist/backportRun.d.ts +8 -3
  3. package/dist/backportRun.js +54 -42
  4. package/dist/entrypoint.cli.js +1 -1
  5. package/dist/entrypoint.module.d.ts +8 -3
  6. package/dist/entrypoint.module.js +3 -11
  7. package/dist/entrypoint.module.private.test.js +47 -346
  8. package/dist/options/cliArgs.d.ts +9 -4
  9. package/dist/options/cliArgs.js +28 -15
  10. package/dist/options/cliArgs.test.js +3 -3
  11. package/dist/options/config/globalConfig.d.ts +2 -2
  12. package/dist/options/config/globalConfig.js +13 -10
  13. package/dist/options/config/readConfigFile.d.ts +2 -2
  14. package/dist/options/options.d.ts +3 -3
  15. package/dist/options/options.test.js +5 -1
  16. package/dist/runSequentially.d.ts +6 -2
  17. package/dist/runSequentially.js +23 -7
  18. package/dist/scripts/postinstall.js +1 -0
  19. package/dist/scripts/postinstall.test.js +5 -1
  20. package/dist/services/HandledError.d.ts +1 -1
  21. package/dist/services/HandledError.js +2 -2
  22. package/dist/services/child-process-promisified.d.ts +19 -3
  23. package/dist/services/child-process-promisified.js +46 -17
  24. package/dist/services/git.d.ts +6 -7
  25. package/dist/services/git.integration.test.js +381 -65
  26. package/dist/services/git.js +188 -122
  27. package/dist/services/git.private.test.d.ts +1 -0
  28. package/dist/services/git.private.test.js +618 -0
  29. package/dist/services/git.test.js +167 -124
  30. package/dist/services/github/v3/addAssigneesToPullRequest.js +1 -1
  31. package/dist/services/github/v3/addLabelsToPullRequest.js +1 -1
  32. package/dist/services/github/v3/addReviewersToPullRequest.js +2 -1
  33. package/dist/services/github/v3/createPullRequest.js +3 -1
  34. package/dist/services/github/v3/createStatusComment.js +14 -15
  35. package/dist/services/github/v3/createStatusComment.test.js +15 -5
  36. package/dist/services/github/v4/enablePullRequestAutoMerge.js +2 -4
  37. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -0
  38. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
  39. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -0
  40. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +5 -1
  41. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +1 -0
  42. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +5 -1
  43. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +1 -0
  44. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +5 -1
  45. package/dist/services/logger.js +5 -1
  46. package/dist/services/test.d.ts +1 -0
  47. package/dist/services/test.js +23 -0
  48. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +194 -12
  49. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +17 -16
  50. package/dist/test/e2e/cli/runBackportViaCli.d.ts +2 -1
  51. package/dist/test/e2e/cli/runBackportViaCli.js +10 -2
  52. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +26 -19
  53. package/dist/test/handleUnbackportedPullRequests.private.test.js +10 -8
  54. package/dist/test/sandbox.js +5 -1
  55. package/dist/test/setupFiles/automatic-mocks.js +5 -1
  56. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +1 -1
  57. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +7 -159
  58. package/dist/ui/getCommitsWithoutBackports.test.js +5 -1
  59. package/dist/ui/getGitConfigAuthor.js +1 -1
  60. package/dist/ui/getTargetBranches.test.js +5 -1
  61. package/dist/ui/ora.d.ts +1 -8
  62. package/dist/ui/setupRepo.js +1 -1
  63. package/dist/ui/setupRepo.test.js +98 -61
  64. package/dist/utils/isErrnoError.d.ts +2 -0
  65. package/dist/utils/isErrnoError.js +7 -0
  66. package/dist/utils/packageVersion.d.ts +1 -1
  67. package/dist/utils/packageVersion.js +1 -1
  68. package/package.json +13 -13
  69. package/yarn.lock +414 -695
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -29,12 +33,12 @@ const gitModule = __importStar(require("../services/git"));
29
33
  const mocks_1 = require("../test/mocks");
30
34
  const setupRepo_1 = require("./setupRepo");
31
35
  describe('setupRepo', () => {
32
- let execSpy;
36
+ let spawnSpy;
33
37
  beforeEach(() => {
34
38
  jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
35
- execSpy = jest
36
- .spyOn(childProcess, 'exec')
37
- .mockResolvedValue({ stderr: '', stdout: '' });
39
+ spawnSpy = jest
40
+ .spyOn(childProcess, 'spawnPromise')
41
+ .mockResolvedValue({ stderr: '', stdout: '', code: 0, cmdArgs: [] });
38
42
  });
39
43
  afterEach(() => {
40
44
  jest.restoreAllMocks();
@@ -42,10 +46,10 @@ describe('setupRepo', () => {
42
46
  describe('if an error occurs while cloning', () => {
43
47
  it('should delete repo', async () => {
44
48
  expect.assertions(2);
45
- execSpy = jest
46
- .spyOn(childProcess, 'execAsCallback')
47
- .mockImplementation((cmd) => {
48
- if (cmd.startsWith('git clone')) {
49
+ jest
50
+ .spyOn(childProcess, 'spawnOriginal')
51
+ .mockImplementation((cmd, cmdArgs) => {
52
+ if (cmdArgs.includes('clone')) {
49
53
  throw new Error('Simulated git clone failure');
50
54
  }
51
55
  throw new Error('unknown error');
@@ -60,39 +64,43 @@ describe('setupRepo', () => {
60
64
  });
61
65
  describe('while cloning the repo', () => {
62
66
  it('updates the progress', async () => {
63
- let onCloneComplete;
64
- let dataHandler;
67
+ let onClose;
68
+ let onData;
65
69
  const oraMock = (0, mocks_1.getOraMock)();
66
70
  const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
67
71
  const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
68
- jest.spyOn(gitModule, 'getLocalRepoPath').mockResolvedValue(undefined);
69
72
  jest
70
- .spyOn(childProcess, 'execAsCallback')
73
+ .spyOn(gitModule, 'getLocalSourceRepoPath')
74
+ .mockResolvedValue(undefined);
75
+ jest
76
+ .spyOn(childProcess, 'spawnOriginal')
71
77
  //@ts-expect-error
72
- .mockImplementation((cmdString, cmdOptions, onComplete) => {
73
- // callback should be called to finalize the operation
74
- if (onComplete) {
75
- //@ts-expect-error
76
- onCloneComplete = onComplete;
77
- }
78
+ .mockImplementation(() => {
78
79
  return {
80
+ on: (name, cb) => {
81
+ if (name === 'close') {
82
+ onClose = cb;
83
+ }
84
+ },
79
85
  stderr: {
80
86
  on: (name, handler) => {
81
- dataHandler = handler;
87
+ if (name === 'data') {
88
+ onData = handler;
89
+ }
82
90
  },
83
91
  },
84
92
  };
85
93
  });
86
94
  setTimeout(() => {
87
- dataHandler('Receiving objects: 1%');
88
- dataHandler('Receiving objects: 10%');
89
- dataHandler('Receiving objects: 20%');
90
- dataHandler('Receiving objects: 100%');
91
- dataHandler('Updating files: 1%');
92
- dataHandler('Updating files: 10%');
93
- dataHandler('Updating files: 20%');
94
- dataHandler('Updating files: 100%');
95
- onCloneComplete();
95
+ onData('Receiving objects: 1%');
96
+ onData('Receiving objects: 10%');
97
+ onData('Receiving objects: 20%');
98
+ onData('Receiving objects: 100%');
99
+ onData('Updating files: 1%');
100
+ onData('Updating files: 10%');
101
+ onData('Updating files: 20%');
102
+ onData('Updating files: 100%');
103
+ onClose(0);
96
104
  }, 50);
97
105
  await (0, setupRepo_1.setupRepo)({
98
106
  repoName: 'kibana',
@@ -117,18 +125,23 @@ describe('setupRepo', () => {
117
125
  expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
118
126
  });
119
127
  });
120
- describe('if repo already exists', () => {
121
- beforeEach(() => {
122
- jest
123
- .spyOn(childProcess, 'execAsCallback')
124
- //@ts-expect-error
125
- .mockImplementation((cmdString, cmdOptions, callback) => {
128
+ describe('if repo is already cloned', () => {
129
+ function mockGitProjectRootPath(value) {
130
+ return (jest
131
+ .spyOn(childProcess, 'spawnPromise')
126
132
  //@ts-expect-error
127
- callback();
128
- return { stderr: { on: () => null } };
129
- });
130
- });
131
- it('should re-create remotes for both source repo and fork', async () => {
133
+ .mockImplementationOnce(async (cmd, cmdArgs) => {
134
+ if (cmdArgs.includes('rev-parse')) {
135
+ return {
136
+ stdout: value,
137
+ };
138
+ }
139
+ }));
140
+ }
141
+ beforeEach(async () => {
142
+ jest.clearAllMocks();
143
+ mockGitProjectRootPath('/myHomeDir/.backport/repositories/elastic/kibana');
144
+ jest.spyOn(gitModule, 'cloneRepo');
132
145
  await (0, setupRepo_1.setupRepo)({
133
146
  accessToken: 'myAccessToken',
134
147
  authenticatedUsername: 'sqren_authenticated',
@@ -138,12 +151,22 @@ describe('setupRepo', () => {
138
151
  repoName: 'kibana',
139
152
  repoOwner: 'elastic',
140
153
  });
141
- expect(execSpy.mock.calls.map(([cmd, { cwd }]) => ({ cmd, cwd }))).toEqual([
154
+ });
155
+ it('should not delete the existing repo', () => {
156
+ expect(del_1.default).not.toHaveBeenCalled();
157
+ });
158
+ it('should not clone repo', () => {
159
+ expect(gitModule.cloneRepo).not.toHaveBeenCalled();
160
+ });
161
+ it('should re-create remotes for both source repo and fork', () => {
162
+ expect(spawnSpy.mock.calls.map(([cmd, cmdArgs, cwd]) => ({
163
+ cmd: `${cmd} ${cmdArgs.join(' ')}`,
164
+ cwd,
165
+ }))).toEqual([
142
166
  {
143
167
  cmd: 'git rev-parse --show-toplevel',
144
168
  cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
145
169
  },
146
- { cmd: 'git remote --verbose', cwd: '/path/to/source/repo' },
147
170
  {
148
171
  cmd: 'git remote rm origin',
149
172
  cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
@@ -167,19 +190,30 @@ describe('setupRepo', () => {
167
190
  ]);
168
191
  });
169
192
  });
193
+ function mockGitClone() {
194
+ jest
195
+ .spyOn(childProcess, 'spawnOriginal')
196
+ //@ts-expect-error
197
+ .mockImplementation((cmd, cmdArgs) => {
198
+ if (cmdArgs.includes('clone')) {
199
+ return {
200
+ on: (name, cb) => {
201
+ if (name === 'close') {
202
+ //@ts-expect-error
203
+ cb(0);
204
+ }
205
+ },
206
+ stderr: { on: () => null },
207
+ };
208
+ }
209
+ });
210
+ }
170
211
  describe('if repo does not exists locally', () => {
171
212
  let spinnerSuccessSpy;
172
213
  beforeEach(async () => {
173
214
  const oraMock = (0, mocks_1.getOraMock)();
174
215
  spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
175
- jest
176
- .spyOn(childProcess, 'execAsCallback')
177
- //@ts-expect-error
178
- .mockImplementation((cmdString, cmdOptions, callback) => {
179
- //@ts-expect-error
180
- callback();
181
- return { stderr: { on: () => null } };
182
- });
216
+ mockGitClone();
183
217
  await (0, setupRepo_1.setupRepo)({
184
218
  accessToken: 'myAccessToken',
185
219
  gitHostname: 'github.com',
@@ -190,7 +224,12 @@ describe('setupRepo', () => {
190
224
  });
191
225
  it('should clone it from github.com', async () => {
192
226
  expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from github.com (one-time operation)');
193
- 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));
227
+ expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
228
+ 'clone',
229
+ 'https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
230
+ '/myHomeDir/.backport/repositories/elastic/kibana',
231
+ '--progress',
232
+ ]);
194
233
  });
195
234
  });
196
235
  describe('if repo exists locally', () => {
@@ -199,19 +238,12 @@ describe('setupRepo', () => {
199
238
  const oraMock = (0, mocks_1.getOraMock)();
200
239
  spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
201
240
  jest
202
- .spyOn(gitModule, 'getLocalRepoPath')
241
+ .spyOn(gitModule, 'getLocalSourceRepoPath')
203
242
  .mockResolvedValue('/path/to/source/repo');
204
243
  jest
205
244
  .spyOn(gitModule, 'getGitConfig')
206
245
  .mockResolvedValue('email-or-username');
207
- jest
208
- .spyOn(childProcess, 'execAsCallback')
209
- //@ts-expect-error
210
- .mockImplementation((cmdString, cmdOptions, callback) => {
211
- //@ts-expect-error
212
- callback();
213
- return { stderr: { on: () => null } };
214
- });
246
+ mockGitClone();
215
247
  await (0, setupRepo_1.setupRepo)({
216
248
  repoName: 'kibana',
217
249
  repoOwner: 'elastic',
@@ -220,7 +252,12 @@ describe('setupRepo', () => {
220
252
  });
221
253
  it('should clone it from local folder', async () => {
222
254
  expect(spinnerSuccessSpy).toHaveBeenCalledWith('100% Cloning repository from /path/to/source/repo (one-time operation)');
223
- expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone /path/to/source/repo /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
255
+ expect(childProcess.spawnOriginal).toHaveBeenCalledWith('git', [
256
+ 'clone',
257
+ '/path/to/source/repo',
258
+ '/myHomeDir/.backport/repositories/elastic/kibana',
259
+ '--progress',
260
+ ]);
224
261
  });
225
262
  });
226
263
  describe('if `repoPath` is a parent of current working directory (cwd)', () => {
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" />
2
+ export declare function isErrnoError(error: unknown): error is NodeJS.ErrnoException;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isErrnoError = void 0;
4
+ function isErrnoError(error) {
5
+ return error instanceof Error && 'code' in error;
6
+ }
7
+ exports.isErrnoError = isErrnoError;
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "7.4.0";
1
+ export declare const PACKAGE_VERSION = "8.0.0";
@@ -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.4.0';
4
+ exports.PACKAGE_VERSION = '8.0.0';
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "7.4.0",
17
+ "version": "8.0.0",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@octokit/rest": "^18.12.0",
68
- "axios": "^0.25.0",
68
+ "axios": "^0.26.0",
69
69
  "dedent": "^0.7.0",
70
70
  "del": "^6.0.0",
71
71
  "dotenv": "^16.0.0",
@@ -82,22 +82,22 @@
82
82
  "utility-types": "^3.10.0",
83
83
  "winston": "^3.6.0",
84
84
  "yargs": "^17.3.1",
85
- "yargs-parser": "^21.0.0"
85
+ "yargs-parser": "^21.0.1"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/core-js": "^2.5.5",
89
89
  "@types/dedent": "^0.7.0",
90
90
  "@types/inquirer": "^8.2.0",
91
91
  "@types/jest": "^27.4.1",
92
- "@types/lodash": "^4.14.178",
92
+ "@types/lodash": "^4.14.179",
93
93
  "@types/node": "^17.0.21",
94
94
  "@types/safe-json-stringify": "^1.1.2",
95
- "@types/yargs": "^17.0.8",
96
- "@types/yargs-parser": "^20.2.1",
97
- "@typescript-eslint/eslint-plugin": "^5.12.1",
98
- "@typescript-eslint/parser": "^5.12.1",
99
- "eslint": "^8.9.0",
100
- "eslint-config-prettier": "^8.4.0",
95
+ "@types/yargs": "^17.0.9",
96
+ "@types/yargs-parser": "^21.0.0",
97
+ "@typescript-eslint/eslint-plugin": "^5.14.0",
98
+ "@typescript-eslint/parser": "^5.14.0",
99
+ "eslint": "^8.10.0",
100
+ "eslint-config-prettier": "^8.5.0",
101
101
  "eslint-plugin-import": "^2.25.4",
102
102
  "eslint-plugin-jest": "^26.1.1",
103
103
  "eslint-plugin-prettier": "^4.0.0",
@@ -105,12 +105,12 @@
105
105
  "husky": "^7.0.4",
106
106
  "jest": "^27.5.1",
107
107
  "jest-snapshot-serializer-ansi": "^1.0.0",
108
- "lint-staged": "^12.3.4",
108
+ "lint-staged": "^12.3.5",
109
109
  "nock": "^13.2.4",
110
110
  "prettier": "^2.5.1",
111
111
  "strip-ansi": "^6.0.1",
112
112
  "ts-jest": "^27.1.3",
113
- "ts-node": "^10.5.0",
114
- "typescript": "^4.5.5"
113
+ "ts-node": "^10.7.0",
114
+ "typescript": "^4.6.2"
115
115
  }
116
116
  }