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
@@ -43,6 +43,7 @@ async function backportRun(processArgs, optionsFromModule = {}) {
43
43
  options,
44
44
  backportResponse,
45
45
  });
46
+ logger_1.logger.info('backportResponse', backportResponse);
46
47
  return backportResponse;
47
48
  }
48
49
  catch (e) {
@@ -70,9 +71,9 @@ async function backportRun(processArgs, optionsFromModule = {}) {
70
71
  (0, logger_1.consoleLog)(chalk_1.default.italic(`For additional details see the logs: ${(0, env_1.getLogfilePath)({
71
72
  logFilePath,
72
73
  })}`));
73
- // write to log
74
- logger_1.logger.info('Unknown error:', e);
75
74
  }
75
+ logger_1.logger.error('Unhandled exception', e);
76
+ process.exitCode = 1;
76
77
  return backportResponse;
77
78
  }
78
79
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,278 @@
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 child_process_1 = require("child_process");
7
+ const path_1 = __importDefault(require("path"));
8
+ const strip_ansi_1 = __importDefault(require("strip-ansi"));
9
+ const child_process_promisified_1 = require("./services/child-process-promisified");
10
+ const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
11
+ const sandbox_1 = require("./test/sandbox");
12
+ const TIMEOUT_IN_SECONDS = 10;
13
+ jest.setTimeout(15000);
14
+ describe('inquirer cli', () => {
15
+ let devAccessToken;
16
+ beforeAll(() => {
17
+ devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
18
+ });
19
+ it('--version', async () => {
20
+ const res = await runBackportAsync([`--version`]);
21
+ expect(res).toContain(process.env.npm_package_version);
22
+ });
23
+ it('-v', async () => {
24
+ const res = await runBackportAsync([`-v`]);
25
+ expect(res).toContain(process.env.npm_package_version);
26
+ });
27
+ it('--help', async () => {
28
+ const res = await runBackportAsync([`--help`]);
29
+ expect(res).toMatchInlineSnapshot(`
30
+ "entrypoint.cli.ts [args]
31
+ Options:
32
+ -v, -V, --version Show version number [boolean]
33
+ --accessToken, --accesstoken Github access token [string]
34
+ -a, --all List all commits [boolean]
35
+ --assignee, --assign Add assignees to the target pull request [array]
36
+ --autoAssign Auto assign the target pull request to yourself [boolean]
37
+ --autoMerge Enable auto-merge for created pull requests [boolean]
38
+ --autoMergeMethod Sets auto-merge method when using --auto-merge. Default:
39
+ merge [string] [choices: \\"merge\\", \\"rebase\\", \\"squash\\"]
40
+ --ci Disable interactive prompts [boolean]
41
+ --cherrypickRef Append commit message with \\"(cherry picked from commit...)
42
+ [boolean]
43
+ --configFile, --config Path to project config [string]
44
+ --since ISO-8601 date for filtering commits [string]
45
+ --until ISO-8601 date for filtering commits [string]
46
+ --dir Location where the temporary repository will be stored
47
+ [string]
48
+ --details Show details about each commit [boolean]
49
+ --editor Editor to be opened during conflict resolution [string]
50
+ --skipRemoteConfig Use local .backportrc.json config instead of loading from
51
+ Github [boolean]
52
+ --fork Create backports in fork or origin repo [boolean]
53
+ --mainline Parent id of merge commit. Defaults to 1 when supplied
54
+ without arguments [number]
55
+ -n, --maxNumber, --number Number of commits to choose from [number]
56
+ --multiple Select multiple branches/commits [boolean]
57
+ --multipleBranches Backport to multiple branches [boolean]
58
+ --multipleCommits Backport multiple commits [boolean]
59
+ --noCherrypickRef Do not append commit message with \\"(cherry picked from
60
+ commit...)\\" [boolean]
61
+ --noStatusComment Don't publish status comment to Github [boolean]
62
+ --noVerify Bypass the pre-commit and commit-msg hooks [boolean]
63
+ --noFork Create backports in the origin repo [boolean]
64
+ -p, --path Only list commits touching files under the specified path
65
+ [array]
66
+ --prDescription, --description Description to be added to pull request [string]
67
+ --prTitle, --title Title of pull request [string]
68
+ --prFilter Filter source pull requests by a query [string]
69
+ --pullNumber, --pr Pull request to backport [number]
70
+ --resetAuthor Set yourself as commit author [boolean]
71
+ --reviewer Add reviewer to the target PR [array]
72
+ --repoOwner Repository owner [string]
73
+ --repoName Repository name [string]
74
+ --repo Repo owner and name [string]
75
+ --sha, --commit Commit sha to backport [string]
76
+ --sourceBranch Specify a non-default branch (normally \\"master\\") to backport
77
+ from [string]
78
+ --sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
79
+ -b, --targetBranch, --branch Branch(es) to backport to [array]
80
+ --targetBranchChoice List branches to backport to [array]
81
+ -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
82
+ --verbose Show additional debug information [boolean]
83
+ --verify Opposite of no-verify [boolean]
84
+ --help Show help [boolean]
85
+ For bugs, feature requests or questions: https://github.com/sqren/backport/issues
86
+ Or contact me directly: https://twitter.com/sorenlouv"
87
+ `);
88
+ });
89
+ it('should return error when branch is missing', async () => {
90
+ const res = await runBackportAsync([
91
+ '--skip-remote-config',
92
+ '--repo-owner',
93
+ 'backport-org',
94
+ '--repo-name',
95
+ 'backport-e2e',
96
+ '--accessToken',
97
+ devAccessToken,
98
+ ]);
99
+ expect(res).toMatchInlineSnapshot(`
100
+ "Please specify a target branch: \\"--branch 6.1\\".
101
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
102
+ `);
103
+ });
104
+ it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
105
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
106
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
107
+ await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
108
+ await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
109
+ const res = await runBackportAsync(['--accessToken', devAccessToken], {
110
+ cwd: sandboxPath,
111
+ waitForString: 'Select commit',
112
+ });
113
+ expect(res).toMatchInlineSnapshot(`
114
+ "? Select commit (Use arrow keys)
115
+ ❯ 1. Add sheep emoji (#9) 7.8
116
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
117
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
118
+ 4. Add family emoji (#2) 7.x
119
+ 5. Add \`backport\` dep
120
+ 6. Merge pull request #1 from backport-org/add-heart-emoji
121
+ 7. Add ❤️ emoji
122
+ 8. Update .backportrc.json
123
+ 9. Bump to 8.0.0
124
+ 10.Add package.json"
125
+ `);
126
+ });
127
+ it('should return error when access token is invalid', async () => {
128
+ const res = await runBackportAsync([
129
+ '--branch',
130
+ 'foo',
131
+ '--repo-owner',
132
+ 'foo',
133
+ '--repo-name',
134
+ 'bar',
135
+ '--accessToken',
136
+ 'some-token',
137
+ ]);
138
+ expect(res).toContain('Please check your access token and make sure it is valid');
139
+ });
140
+ it(`should return error when repo doesn't exist`, async () => {
141
+ const res = await runBackportAsync([
142
+ '--branch',
143
+ 'foo',
144
+ '--repo-owner',
145
+ 'foo',
146
+ '--repo-name',
147
+ 'bar',
148
+ '--author',
149
+ 'sqren',
150
+ '--accessToken',
151
+ devAccessToken,
152
+ ]);
153
+ expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
154
+ });
155
+ it(`should list commits from master`, async () => {
156
+ jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
157
+ const output = await runBackportAsync([
158
+ '--branch',
159
+ 'foo',
160
+ '--repo-owner',
161
+ 'backport-org',
162
+ '--repo-name',
163
+ 'backport-e2e',
164
+ '--author',
165
+ 'sqren',
166
+ '--accessToken',
167
+ devAccessToken,
168
+ '--max-number',
169
+ '6',
170
+ ], { waitForString: 'Select commit' });
171
+ expect(output).toMatchInlineSnapshot(`
172
+ "? Select commit (Use arrow keys)
173
+ ❯ 1. Add sheep emoji (#9) 7.8
174
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
175
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
176
+ 4. Add family emoji (#2) 7.x
177
+ 5. Add \`backport\` dep
178
+ 6. Merge pull request #1 from backport-org/add-heart-emoji"
179
+ `);
180
+ });
181
+ it(`should limit commits by since and until`, async () => {
182
+ jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
183
+ const output = await runBackportAsync([
184
+ '--branch',
185
+ 'foo',
186
+ '--repo-owner',
187
+ 'backport-org',
188
+ '--repo-name',
189
+ 'backport-e2e',
190
+ '--accessToken',
191
+ devAccessToken,
192
+ '--since',
193
+ '2020-08-15T00:00:00.000Z',
194
+ '--until',
195
+ '2020-08-15T14:00:00.000Z',
196
+ ], { waitForString: 'Select commit' });
197
+ expect(output).toMatchInlineSnapshot(`
198
+ "? Select commit (Use arrow keys)
199
+ ❯ 1. Add 🍏 emoji (#5) 7.x, 7.8
200
+ 2. Add family emoji (#2) 7.x
201
+ 3. Add \`backport\` dep
202
+ 4. Merge pull request #1 from backport-org/add-heart-emoji
203
+ 5. Add ❤️ emoji
204
+ 6. Update .backportrc.json
205
+ 7. Bump to 8.0.0
206
+ 8. Add package.json
207
+ 9. Update .backportrc.json
208
+ 10.Create .backportrc.json"
209
+ `);
210
+ });
211
+ it(`should list commits from 7.x`, async () => {
212
+ const output = await runBackportAsync([
213
+ '--branch',
214
+ 'foo',
215
+ '--repo-owner',
216
+ 'backport-org',
217
+ '--repo-name',
218
+ 'backport-e2e',
219
+ '--author',
220
+ 'sqren',
221
+ '--accessToken',
222
+ devAccessToken,
223
+ '--max-number',
224
+ '6',
225
+ '--source-branch',
226
+ '7.x',
227
+ ], { waitForString: 'Select commit' });
228
+ expect(output).toMatchInlineSnapshot(`
229
+ "? Select commit (Use arrow keys)
230
+ ❯ 1. Add 🍏 emoji (#5) (#6)
231
+ 2. Change Ulysses to Carol
232
+ 3. Add family emoji (#2) (#4)
233
+ 4. Update .backportrc.json
234
+ 5. Branch off: 7.9.0 (7.x)
235
+ 6. Bump to 8.0.0"
236
+ `);
237
+ });
238
+ });
239
+ function runBackportAsync(cliArgs, { waitForString, cwd, } = {}) {
240
+ const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
241
+ const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
242
+ const proc = (0, child_process_1.spawn)(tsNodeBinary, [
243
+ '--transpile-only',
244
+ entrypointFile,
245
+ '--log-file-path',
246
+ '/dev/null',
247
+ ...cliArgs,
248
+ ], { cwd });
249
+ const p = new Promise((resolve, reject) => {
250
+ let data = '';
251
+ // fail if expectations hasn't been found within 10 seconds
252
+ const timeout = setTimeout(() => {
253
+ reject(`Expectation '${waitForString}' not found within ${TIMEOUT_IN_SECONDS} seconds in:
254
+ '${data.toString()}'`);
255
+ }, TIMEOUT_IN_SECONDS * 1000);
256
+ proc.stdout.on('data', (chunk) => {
257
+ data += chunk;
258
+ const output = data.toString();
259
+ if (!waitForString || output.includes(waitForString)) {
260
+ clearTimeout(timeout);
261
+ // remove ansi codes and whitespace
262
+ const strippedOutput = (0, strip_ansi_1.default)(output).replace(/\s+$/gm, '');
263
+ resolve(strippedOutput);
264
+ }
265
+ });
266
+ // for debugging only
267
+ // proc.stderr.on('data', (chunk) => {
268
+ // console.log('stderr', chunk.toString());
269
+ // });
270
+ proc.on('error', (err) => {
271
+ reject(`runBackportAsync failed with: ${err}`);
272
+ });
273
+ });
274
+ // kill child process
275
+ return p.finally(() => {
276
+ proc.kill();
277
+ });
278
+ }
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const entrypoint_module_1 = require("./entrypoint.module");
4
+ const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
5
+ describe('entrypoint.module', () => {
6
+ it('getCommits', async () => {
7
+ const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
8
+ const commits = await (0, entrypoint_module_1.getCommits)({
9
+ accessToken: accessToken,
10
+ repoName: 'backport-e2e',
11
+ repoOwner: 'backport-org',
12
+ pullNumber: 2,
13
+ });
14
+ const expectedCommits = [
15
+ {
16
+ sourceCommit: {
17
+ committedDate: '2020-08-15T10:44:04Z',
18
+ message: 'Add family emoji (#2)',
19
+ sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
20
+ },
21
+ sourcePullRequest: {
22
+ number: 2,
23
+ url: 'https://github.com/backport-org/backport-e2e/pull/2',
24
+ mergeCommit: {
25
+ message: 'Add family emoji (#2)',
26
+ sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
27
+ },
28
+ },
29
+ sourceBranch: 'master',
30
+ expectedTargetPullRequests: [
31
+ {
32
+ branch: '7.x',
33
+ number: 4,
34
+ state: 'MERGED',
35
+ url: 'https://github.com/backport-org/backport-e2e/pull/4',
36
+ mergeCommit: {
37
+ message: 'Add family emoji (#2) (#4)',
38
+ sha: 'f8b4f6ae7ffaf2732fa5e33e98b3ea772bdfff1d',
39
+ },
40
+ },
41
+ ],
42
+ },
43
+ ];
44
+ expect(commits).toEqual(expectedCommits);
45
+ });
46
+ });
@@ -1,4 +1,4 @@
1
- import { Logger } from '../services/logger';
1
+ import winston from 'winston';
2
2
  export interface TargetBranchChoice {
3
3
  name: string;
4
4
  checked?: boolean;
@@ -7,7 +7,7 @@ export declare type TargetBranchChoiceOrString = string | TargetBranchChoice;
7
7
  declare type AutoFixConflictsHandler = ({ files, directory, logger, targetBranch, }: {
8
8
  files: string[];
9
9
  directory: string;
10
- logger: Logger;
10
+ logger: winston.Logger;
11
11
  targetBranch: string;
12
12
  }) => boolean | Promise<boolean>;
13
13
  declare type Options = Partial<{
@@ -52,6 +52,7 @@ declare type Options = Partial<{
52
52
  targetBranchChoices: TargetBranchChoiceOrString[];
53
53
  targetBranches: string[];
54
54
  targetPRLabels: string[];
55
+ username: string;
55
56
  verbose: boolean;
56
57
  }>;
57
58
  export declare type ConfigFileOptions = Options & Partial<{
@@ -35,6 +35,7 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
35
35
  repoOwner?: string | undefined;
36
36
  repoName?: string | undefined;
37
37
  sourceBranch?: string | undefined;
38
+ username?: string | undefined;
38
39
  dateSince?: string | undefined;
39
40
  dateUntil?: string | undefined;
40
41
  commitPaths?: string[] | undefined;
@@ -47,6 +47,12 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
47
47
  description: 'Sets auto-merge method when using --auto-merge. Default: merge',
48
48
  type: 'string',
49
49
  choices: ['merge', 'rebase', 'squash'],
50
+ })
51
+ .option('author', {
52
+ description: 'Show commits by a specific user',
53
+ alias: 'author',
54
+ type: 'string',
55
+ conflicts: 'all',
50
56
  })
51
57
  .option('ci', {
52
58
  description: 'Disable interactive prompts',
@@ -210,10 +216,17 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
210
216
  .option('repoOwner', {
211
217
  description: 'Repository owner',
212
218
  type: 'string',
219
+ conflicts: ['repo'],
213
220
  })
214
221
  .option('repoName', {
215
222
  description: 'Repository name',
216
223
  type: 'string',
224
+ conflicts: ['repo'],
225
+ })
226
+ .option('repo', {
227
+ description: 'Repo owner and name',
228
+ type: 'string',
229
+ conflicts: ['repoName', 'repoOwner'],
217
230
  })
218
231
  .option('sha', {
219
232
  conflicts: ['pullNumber', 'prFilter'],
@@ -248,11 +261,9 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
248
261
  type: 'array',
249
262
  string: true,
250
263
  })
251
- .option('author', {
252
- description: 'Show commits by a specific user',
253
- alias: 'author',
264
+ .option('username', {
265
+ description: 'User repo that branch will be pushed to. Defaults to the authenticated user',
254
266
  type: 'string',
255
- conflicts: 'all',
256
267
  })
257
268
  .option('verbose', {
258
269
  description: 'Show additional debug information',
@@ -283,14 +294,23 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
283
294
  $0, _,
284
295
  /* eslint-enable @typescript-eslint/no-unused-vars */
285
296
  multiple, multipleBranches, multipleCommits, all,
297
+ // repoName and repoOwner
298
+ repo,
286
299
  // filters
287
300
  author, since, until,
288
301
  // negations
289
302
  noCherrypickRef, noFork, noStatusComment, noVerify, verify,
290
303
  // array types (should be renamed to plural form)
291
304
  assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
305
+ const [repoOwner, repoName] = repo?.split('/') ?? [
306
+ restOptions.repoOwner,
307
+ restOptions.repoName,
308
+ ];
292
309
  return (0, excludeUndefined_1.excludeUndefined)({
293
310
  ...restOptions,
311
+ // repoName and repoOwner
312
+ repoOwner,
313
+ repoName,
294
314
  // filters
295
315
  author: all ? null : author,
296
316
  dateSince: since ? new Date(since).toISOString() : undefined,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cliArgs_1 = require("./cliArgs");
4
+ describe('getOptionsFromCliArgs', () => {
5
+ describe('yargs settings', () => {
6
+ it('should accept both camel-case and dashed-case and convert them to camel cased', () => {
7
+ const argv = [
8
+ '--access-token',
9
+ 'my access token',
10
+ '--githubApiBaseUrlV3',
11
+ 'my api hostname',
12
+ ];
13
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
14
+ expect(res.accessToken).toEqual('my access token');
15
+ expect('access-token' in res).toEqual(false);
16
+ expect(res.githubApiBaseUrlV3).toEqual('my api hostname');
17
+ expect('api-hostname' in res).toEqual(false);
18
+ });
19
+ it('strips undefined values from the object', () => {
20
+ const argv = [
21
+ '--access-token',
22
+ 'my access token',
23
+ '--repo-owner',
24
+ 'elastic',
25
+ '--repo-name',
26
+ 'kibana',
27
+ ];
28
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
29
+ expect(res).toEqual({
30
+ accessToken: 'my access token',
31
+ repoOwner: 'elastic',
32
+ repoName: 'kibana',
33
+ });
34
+ });
35
+ });
36
+ describe('sourcePRLabels', () => {
37
+ it('should handle all variations', () => {
38
+ const argv = [
39
+ '--sourcePRLabel',
40
+ 'label a',
41
+ '--sourcePrLabel',
42
+ 'label b',
43
+ '--source-pr-label',
44
+ 'label c',
45
+ ];
46
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
47
+ expect(res.sourcePRLabels).toEqual(['label a', 'label b', 'label c']);
48
+ });
49
+ });
50
+ describe('pullNumber', () => {
51
+ it('should accept `--pr` alias but only return the full representation (`pullNumber`)', () => {
52
+ const argv = ['--pr', '1337'];
53
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
54
+ expect(res.pullNumber).toEqual(1337);
55
+ //@ts-expect-error
56
+ expect(res.pr).toBe(undefined);
57
+ });
58
+ });
59
+ describe('assignees', () => {
60
+ it('--assignee', () => {
61
+ const argv = ['--assignee', 'john'];
62
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
63
+ expect(res.assignees).toEqual(['john']);
64
+ });
65
+ it('--assign', () => {
66
+ const argv = ['--assign', 'john'];
67
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
68
+ expect(res.assignees).toEqual(['john']);
69
+ });
70
+ });
71
+ describe('multipleBranches', () => {
72
+ it('should be undefined by default', () => {
73
+ const argv = [];
74
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
75
+ expect(res.multipleBranches).toBe(undefined);
76
+ });
77
+ it('should set to true', () => {
78
+ const argv = ['--multiple-branches', 'true'];
79
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
80
+ expect(res.multipleBranches).toBe(true);
81
+ });
82
+ it('should set to false', () => {
83
+ const argv = ['--multiple-branches', 'false'];
84
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
85
+ expect(res.multipleBranches).toBe(false);
86
+ });
87
+ it('should respect `multiple` option', () => {
88
+ const argv = ['--multiple'];
89
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
90
+ expect(res.multipleBranches).toBe(true);
91
+ });
92
+ it('should conflict when using both', () => {
93
+ const argv = ['--multiple', '--multiple-branches', 'false'];
94
+ expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrow('Arguments multiple and multipleBranches are mutually exclusive');
95
+ });
96
+ });
97
+ describe('noVerify', () => {
98
+ it('should be undefined by default', () => {
99
+ const argv = [];
100
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
101
+ expect(res.noVerify).toBe(undefined);
102
+ });
103
+ it('should set to false', () => {
104
+ const argv = ['--no-verify', 'false'];
105
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
106
+ expect(res.noVerify).toBe(false);
107
+ });
108
+ it('should set to true', () => {
109
+ const argv = ['--no-verify', 'true'];
110
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
111
+ expect(res.noVerify).toBe(true);
112
+ });
113
+ it('should be enabled by `verify`', () => {
114
+ const argv = ['--verify'];
115
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
116
+ expect(res.noVerify).toBe(true);
117
+ });
118
+ });
119
+ describe('mainline', () => {
120
+ it('should default to 1', () => {
121
+ const argv = ['--mainline'];
122
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
123
+ expect(res.mainline).toEqual(1);
124
+ });
125
+ it('should accept numbers', () => {
126
+ const argv = ['--mainline', '2'];
127
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
128
+ expect(res.mainline).toEqual(2);
129
+ });
130
+ it('should throw on invalid values', () => {
131
+ const argv = ['--mainline', 'foo'];
132
+ expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrowError('--mainline must be an integer. Received: NaN');
133
+ });
134
+ });
135
+ describe('targetBranches', () => {
136
+ it('should not coerce 6.0 to 6', () => {
137
+ const argv = ['-b', '6.0'];
138
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
139
+ expect(res.targetBranches).toEqual(['6.0']);
140
+ });
141
+ });
142
+ describe('since/until', () => {
143
+ it('should always be UTC time (configured globally in jest.config.js)', () => {
144
+ expect(new Date().getTimezoneOffset()).toBe(0);
145
+ });
146
+ it('accepts ISO dates', () => {
147
+ const argv = [
148
+ '--since',
149
+ '2020-08-15T00:00:00.000Z',
150
+ '--until',
151
+ '2020-08-15T14:00:00.000Z',
152
+ ];
153
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
154
+ expect(res.dateSince).toEqual('2020-08-15T00:00:00.000Z');
155
+ expect(res.dateUntil).toEqual('2020-08-15T14:00:00.000Z');
156
+ });
157
+ it('accepts non-ISO dates', () => {
158
+ const argv = ['--since', '2020-08-15', '--until', '2020-08-15 14:00'];
159
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
160
+ expect(res.dateSince).toEqual('2020-08-15T00:00:00.000Z');
161
+ expect(res.dateUntil).toEqual('2020-08-15T14:00:00.000Z');
162
+ });
163
+ it('accepts years', () => {
164
+ const argv = ['--since', '2020', '--until', '2021'];
165
+ const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
166
+ expect(res.dateSince).toEqual('2020-01-01T00:00:00.000Z');
167
+ expect(res.dateUntil).toEqual('2021-01-01T00:00:00.000Z');
168
+ });
169
+ });
170
+ });
@@ -13,13 +13,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
13
13
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
14
14
  files: string[];
15
15
  directory: string;
16
- logger: {
17
- error: (message: string, meta?: unknown) => void;
18
- warn: (message: string, meta?: unknown) => void;
19
- info: (message: string, meta?: unknown) => void;
20
- verbose: (message: string, meta?: unknown) => void;
21
- debug: (message: string, meta?: unknown) => void;
22
- };
16
+ logger: import("winston").Logger;
23
17
  targetBranch: string;
24
18
  }) => boolean | Promise<boolean>) | undefined;
25
19
  autoMerge?: boolean | undefined;
@@ -58,6 +52,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
58
52
  targetBranchChoices?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
59
53
  targetBranches?: string[] | undefined;
60
54
  targetPRLabels?: string[] | undefined;
55
+ username?: string | undefined;
61
56
  verbose?: boolean | undefined;
62
57
  help?: boolean | undefined;
63
58
  version?: boolean | undefined;
@@ -0,0 +1 @@
1
+ export {};