backport 6.3.0-beta → 6.3.0-beta-2

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 (99) hide show
  1. package/dist/entrypoint.cli.e2e.private.test.d.ts +1 -0
  2. package/dist/entrypoint.cli.e2e.private.test.js +277 -0
  3. package/dist/entrypoint.cli.js +0 -0
  4. package/dist/entrypoint.cli.private.test.d.ts +1 -0
  5. package/dist/entrypoint.cli.private.test.js +46 -0
  6. package/dist/options/cliArgs.test.d.ts +1 -0
  7. package/dist/options/cliArgs.test.js +170 -0
  8. package/dist/options/config/config.test.d.ts +1 -0
  9. package/dist/options/config/config.test.js +32 -0
  10. package/dist/options/config/globalConfig.test.d.ts +1 -0
  11. package/dist/options/config/globalConfig.test.js +61 -0
  12. package/dist/options/config/projectConfig.test.d.ts +1 -0
  13. package/dist/options/config/projectConfig.test.js +109 -0
  14. package/dist/options/options.test.d.ts +1 -0
  15. package/dist/options/options.test.js +371 -0
  16. package/dist/runSequentially.test.d.ts +1 -0
  17. package/dist/runSequentially.test.js +218 -0
  18. package/dist/scripts/postinstall.test.d.ts +1 -0
  19. package/dist/scripts/postinstall.test.js +53 -0
  20. package/dist/services/env.test.d.ts +1 -0
  21. package/dist/services/env.test.js +21 -0
  22. package/dist/services/git.integration.test.d.ts +1 -0
  23. package/dist/services/git.integration.test.js +267 -0
  24. package/dist/services/git.test.d.ts +1 -0
  25. package/dist/services/git.test.js +518 -0
  26. package/dist/services/github/commitFormatters.test.d.ts +1 -0
  27. package/dist/services/github/commitFormatters.test.js +11 -0
  28. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  29. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
  30. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  31. package/dist/services/github/v3/createPullRequest.test.js +325 -0
  32. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  33. package/dist/services/github/v3/createStatusComment.test.js +386 -0
  34. package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
  35. package/dist/services/github/v4/apiRequestV4.test.js +82 -0
  36. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  37. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  38. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  39. package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
  40. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  41. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +96 -0
  42. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  43. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +143 -0
  44. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  45. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +124 -0
  46. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  47. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +200 -0
  48. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  49. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +153 -0
  50. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  51. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
  52. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  53. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
  54. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  55. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  56. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +4 -3
  57. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  58. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +136 -0
  59. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  60. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
  61. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  62. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +154 -0
  63. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  64. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  65. package/dist/services/prompt.test.d.ts +1 -0
  66. package/dist/services/prompt.test.js +134 -0
  67. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  68. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +433 -0
  69. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  70. package/dist/services/sourceCommit/parseSourceCommit.test.js +235 -0
  71. package/dist/test/ExecError.d.ts +16 -0
  72. package/dist/test/ExecError.js +15 -0
  73. package/dist/test/backport-e2e.mutation.test.d.ts +1 -0
  74. package/dist/test/backport-e2e.mutation.test.js +347 -0
  75. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  76. package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -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 +32 -0
  83. package/dist/test/private/getDevAccessToken.d.ts +1 -0
  84. package/dist/test/private/getDevAccessToken.js +25 -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 +59 -0
  89. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  90. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +455 -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.test.d.ts +1 -0
  96. package/dist/ui/maybeSetupRepo.test.js +204 -0
  97. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  98. package/dist/utils/excludeUndefined.test.js +24 -0
  99. package/package.json +1 -1
@@ -0,0 +1,204 @@
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 promises_1 = require("fs/promises");
26
+ const os_1 = __importDefault(require("os"));
27
+ const del_1 = __importDefault(require("del"));
28
+ const childProcess = __importStar(require("../services/child-process-promisified"));
29
+ const git = __importStar(require("../services/git"));
30
+ const mocks_1 = require("../test/mocks");
31
+ const maybeSetupRepo_1 = require("./maybeSetupRepo");
32
+ const fs = { stat: promises_1.stat };
33
+ describe('maybeSetupRepo', () => {
34
+ let execSpy;
35
+ beforeEach(() => {
36
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
37
+ execSpy = jest
38
+ .spyOn(childProcess, 'exec')
39
+ .mockResolvedValue({ stderr: '', stdout: '' });
40
+ });
41
+ afterEach(() => {
42
+ jest.restoreAllMocks();
43
+ });
44
+ describe('if an error occurs while cloning', () => {
45
+ it('should delete repo', async () => {
46
+ expect.assertions(2);
47
+ execSpy = jest
48
+ .spyOn(childProcess, 'execAsCallback')
49
+ .mockImplementation((cmd) => {
50
+ if (cmd.startsWith('git clone')) {
51
+ throw new Error('Simulated git clone failure');
52
+ }
53
+ throw new Error('unknown error');
54
+ });
55
+ await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
56
+ repoName: 'kibana',
57
+ repoOwner: 'elastic',
58
+ })).rejects.toThrowError('Simulated git clone failure');
59
+ expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana');
60
+ });
61
+ });
62
+ describe('while cloning the repo', () => {
63
+ it('updates the progress', async () => {
64
+ let onCloneComplete;
65
+ let dataHandler;
66
+ const oraMock = (0, mocks_1.getOraMock)();
67
+ const spinnerTextSpy = jest.spyOn(oraMock, 'text', 'set');
68
+ const spinnerSuccessSpy = jest.spyOn(oraMock, 'succeed');
69
+ jest
70
+ .spyOn(git, 'getSourceRepoPath')
71
+ .mockResolvedValue('/path/to/source/repo');
72
+ jest
73
+ .spyOn(childProcess, 'execAsCallback')
74
+ //@ts-expect-error
75
+ .mockImplementation((cmdString, cmdOptions, onComplete) => {
76
+ // callback should be called to finalize the operation
77
+ if (onComplete) {
78
+ //@ts-expect-error
79
+ onCloneComplete = onComplete;
80
+ }
81
+ return {
82
+ stderr: {
83
+ on: (name, handler) => {
84
+ dataHandler = handler;
85
+ },
86
+ },
87
+ };
88
+ });
89
+ setTimeout(() => {
90
+ dataHandler('Receiving objects: 1%');
91
+ dataHandler('Receiving objects: 10%');
92
+ dataHandler('Receiving objects: 20%');
93
+ dataHandler('Receiving objects: 100%');
94
+ dataHandler('Updating files: 1%');
95
+ dataHandler('Updating files: 10%');
96
+ dataHandler('Updating files: 20%');
97
+ dataHandler('Updating files: 100%');
98
+ onCloneComplete();
99
+ }, 50);
100
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
101
+ repoName: 'kibana',
102
+ repoOwner: 'elastic',
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
+ // @ts-expect-error
124
+ jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
125
+ jest
126
+ .spyOn(childProcess, 'execAsCallback')
127
+ //@ts-expect-error
128
+ .mockImplementation((cmdString, cmdOptions, callback) => {
129
+ //@ts-expect-error
130
+ callback();
131
+ return {
132
+ stderr: { on: () => null },
133
+ };
134
+ });
135
+ });
136
+ it('should re-create remotes for both source repo and fork', async () => {
137
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
138
+ accessToken: 'myAccessToken',
139
+ authenticatedUsername: 'sqren_authenticated',
140
+ repoName: 'kibana',
141
+ repoOwner: 'elastic',
142
+ });
143
+ expect(execSpy.mock.calls.map(([cmd]) => cmd)).toEqual([
144
+ 'git remote --verbose',
145
+ 'git remote rm origin',
146
+ 'git remote rm sqren_authenticated',
147
+ 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
148
+ 'git remote rm elastic',
149
+ 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
150
+ ]);
151
+ });
152
+ });
153
+ describe('if repo does not exists locally', () => {
154
+ beforeEach(() => {
155
+ // @ts-expect-error
156
+ jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
157
+ jest
158
+ .spyOn(childProcess, 'execAsCallback')
159
+ //@ts-expect-error
160
+ .mockImplementation((cmdString, cmdOptions, callback) => {
161
+ //@ts-expect-error
162
+ callback();
163
+ return {
164
+ stderr: { on: () => null },
165
+ };
166
+ });
167
+ });
168
+ it('should clone it from github.com', async () => {
169
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
170
+ accessToken: 'myAccessToken',
171
+ gitHostname: 'github.com',
172
+ repoName: 'kibana',
173
+ repoOwner: 'elastic',
174
+ });
175
+ 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));
176
+ });
177
+ });
178
+ describe('if repo does exist locally', () => {
179
+ beforeEach(() => {
180
+ // @ts-expect-error
181
+ jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
182
+ jest
183
+ .spyOn(git, 'getSourceRepoPath')
184
+ .mockResolvedValue('/path/to/source/repo');
185
+ jest
186
+ .spyOn(childProcess, 'execAsCallback')
187
+ //@ts-expect-error
188
+ .mockImplementation((cmdString, cmdOptions, callback) => {
189
+ //@ts-expect-error
190
+ callback();
191
+ return {
192
+ stderr: { on: () => null },
193
+ };
194
+ });
195
+ });
196
+ it('should clone it from local folder', async () => {
197
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
198
+ repoName: 'kibana',
199
+ repoOwner: 'elastic',
200
+ });
201
+ expect(childProcess.execAsCallback).toHaveBeenCalledWith('git clone /path/to/source/repo /myHomeDir/.backport/repositories/elastic/kibana --progress', expect.any(Object), expect.any(Function));
202
+ });
203
+ });
204
+ });
@@ -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
+ });
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "6.3.0-beta",
17
+ "version": "6.3.0-beta-2",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {