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 @@
1
+ export {};
@@ -0,0 +1,277 @@
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(async () => {
17
+ devAccessToken = await (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
+ --sha, --commit Commit sha to backport [string]
75
+ --sourceBranch Specify a non-default branch (normally \\"master\\") to backport
76
+ from [string]
77
+ --sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
78
+ -b, --targetBranch, --branch Branch(es) to backport to [array]
79
+ --targetBranchChoice List branches to backport to [array]
80
+ -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
81
+ --verbose Show additional debug information [boolean]
82
+ --verify Opposite of no-verify [boolean]
83
+ --help Show help [boolean]
84
+ For bugs, feature requests or questions: https://github.com/sqren/backport/issues
85
+ Or contact me directly: https://twitter.com/sorenlouv"
86
+ `);
87
+ });
88
+ it('should return error when branch is missing', async () => {
89
+ const res = await runBackportAsync([
90
+ '--skip-remote-config',
91
+ '--repo-owner',
92
+ 'backport-org',
93
+ '--repo-name',
94
+ 'backport-e2e',
95
+ '--accessToken',
96
+ devAccessToken,
97
+ ]);
98
+ expect(res).toMatchInlineSnapshot(`
99
+ "Please specify a target branch: \\"--branch 6.1\\".
100
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
101
+ `);
102
+ });
103
+ it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
104
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
105
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
106
+ await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
107
+ await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
108
+ const res = await runBackportAsync(['--accessToken', devAccessToken], {
109
+ cwd: sandboxPath,
110
+ waitForString: 'Select commit',
111
+ });
112
+ expect(res).toMatchInlineSnapshot(`
113
+ "? Select commit (Use arrow keys)
114
+ ❯ 1. Add sheep emoji (#9) 7.8
115
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
116
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
117
+ 4. Add family emoji (#2) 7.x
118
+ 5. Add \`backport\` dep
119
+ 6. Merge pull request #1 from backport-org/add-heart-emoji
120
+ 7. Add ❤️ emoji
121
+ 8. Update .backportrc.json
122
+ 9. Bump to 8.0.0
123
+ 10.Add package.json"
124
+ `);
125
+ });
126
+ it('should return error when access token is invalid', async () => {
127
+ const res = await runBackportAsync([
128
+ '--branch',
129
+ 'foo',
130
+ '--repo-owner',
131
+ 'foo',
132
+ '--repo-name',
133
+ 'bar',
134
+ '--accessToken',
135
+ 'some-token',
136
+ ]);
137
+ expect(res).toContain('Please check your access token and make sure it is valid');
138
+ });
139
+ it(`should return error when repo doesn't exist`, async () => {
140
+ const res = await runBackportAsync([
141
+ '--branch',
142
+ 'foo',
143
+ '--repo-owner',
144
+ 'foo',
145
+ '--repo-name',
146
+ 'bar',
147
+ '--author',
148
+ 'sqren',
149
+ '--accessToken',
150
+ devAccessToken,
151
+ ]);
152
+ expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
153
+ });
154
+ it(`should list commits from master`, async () => {
155
+ jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
156
+ const output = await runBackportAsync([
157
+ '--branch',
158
+ 'foo',
159
+ '--repo-owner',
160
+ 'backport-org',
161
+ '--repo-name',
162
+ 'backport-e2e',
163
+ '--author',
164
+ 'sqren',
165
+ '--accessToken',
166
+ devAccessToken,
167
+ '--max-number',
168
+ '6',
169
+ ], { waitForString: 'Select commit' });
170
+ expect(output).toMatchInlineSnapshot(`
171
+ "? Select commit (Use arrow keys)
172
+ ❯ 1. Add sheep emoji (#9) 7.8
173
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
174
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
175
+ 4. Add family emoji (#2) 7.x
176
+ 5. Add \`backport\` dep
177
+ 6. Merge pull request #1 from backport-org/add-heart-emoji"
178
+ `);
179
+ });
180
+ it(`should limit commits by since and until`, async () => {
181
+ jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
182
+ const output = await runBackportAsync([
183
+ '--branch',
184
+ 'foo',
185
+ '--repo-owner',
186
+ 'backport-org',
187
+ '--repo-name',
188
+ 'backport-e2e',
189
+ '--accessToken',
190
+ devAccessToken,
191
+ '--since',
192
+ '2020-08-15T00:00:00.000Z',
193
+ '--until',
194
+ '2020-08-15T14:00:00.000Z',
195
+ ], { waitForString: 'Select commit' });
196
+ expect(output).toMatchInlineSnapshot(`
197
+ "? Select commit (Use arrow keys)
198
+ ❯ 1. Add 🍏 emoji (#5) 7.x, 7.8
199
+ 2. Add family emoji (#2) 7.x
200
+ 3. Add \`backport\` dep
201
+ 4. Merge pull request #1 from backport-org/add-heart-emoji
202
+ 5. Add ❤️ emoji
203
+ 6. Update .backportrc.json
204
+ 7. Bump to 8.0.0
205
+ 8. Add package.json
206
+ 9. Update .backportrc.json
207
+ 10.Create .backportrc.json"
208
+ `);
209
+ });
210
+ it(`should list commits from 7.x`, async () => {
211
+ const output = await runBackportAsync([
212
+ '--branch',
213
+ 'foo',
214
+ '--repo-owner',
215
+ 'backport-org',
216
+ '--repo-name',
217
+ 'backport-e2e',
218
+ '--author',
219
+ 'sqren',
220
+ '--accessToken',
221
+ devAccessToken,
222
+ '--max-number',
223
+ '6',
224
+ '--source-branch',
225
+ '7.x',
226
+ ], { waitForString: 'Select commit' });
227
+ expect(output).toMatchInlineSnapshot(`
228
+ "? Select commit (Use arrow keys)
229
+ ❯ 1. Add 🍏 emoji (#5) (#6)
230
+ 2. Change Ulysses to Carol
231
+ 3. Add family emoji (#2) (#4)
232
+ 4. Update .backportrc.json
233
+ 5. Branch off: 7.9.0 (7.x)
234
+ 6. Bump to 8.0.0"
235
+ `);
236
+ });
237
+ });
238
+ function runBackportAsync(cliArgs, { waitForString, cwd, } = {}) {
239
+ const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
240
+ const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
241
+ const proc = (0, child_process_1.spawn)(tsNodeBinary, [
242
+ '--transpile-only',
243
+ entrypointFile,
244
+ '--log-file-path',
245
+ '/dev/null',
246
+ ...cliArgs,
247
+ ], { cwd });
248
+ const p = new Promise((resolve, reject) => {
249
+ let data = '';
250
+ // fail if expectations hasn't been found within 10 seconds
251
+ const timeout = setTimeout(() => {
252
+ reject(`Expectation '${waitForString}' not found within ${TIMEOUT_IN_SECONDS} seconds in:
253
+ '${data.toString()}'`);
254
+ }, TIMEOUT_IN_SECONDS * 1000);
255
+ proc.stdout.on('data', (chunk) => {
256
+ data += chunk;
257
+ const output = data.toString();
258
+ if (!waitForString || output.includes(waitForString)) {
259
+ clearTimeout(timeout);
260
+ // remove ansi codes and whitespace
261
+ const strippedOutput = (0, strip_ansi_1.default)(output).replace(/\s+$/gm, '');
262
+ resolve(strippedOutput);
263
+ }
264
+ });
265
+ // for debugging only
266
+ // proc.stderr.on('data', (chunk) => {
267
+ // console.log('stderr', chunk.toString());
268
+ // });
269
+ proc.on('error', (err) => {
270
+ reject(`runBackportAsync failed with: ${err}`);
271
+ });
272
+ });
273
+ // kill child process
274
+ return p.finally(() => {
275
+ proc.kill();
276
+ });
277
+ }
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
+ });
@@ -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
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
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 promises_1 = __importDefault(require("fs/promises"));
7
+ const mockConfigFiles_1 = require("../../test/mockConfigFiles");
8
+ const config_1 = require("./config");
9
+ describe('getOptionsFromConfigFiles', () => {
10
+ let res;
11
+ beforeEach(async () => {
12
+ jest.spyOn(promises_1.default, 'writeFile').mockResolvedValueOnce(undefined);
13
+ jest.spyOn(promises_1.default, 'chmod').mockResolvedValue();
14
+ (0, mockConfigFiles_1.mockConfigFiles)({
15
+ globalConfig: { accessToken: 'abc', editor: 'vim' },
16
+ projectConfig: { repoName: 'kibana', repoOwner: 'elastic' },
17
+ });
18
+ res = await (0, config_1.getOptionsFromConfigFiles)({
19
+ optionsFromCliArgs: {},
20
+ optionsFromModule: {},
21
+ defaultConfigOptions: { ci: false },
22
+ });
23
+ });
24
+ it('should return values from config files', () => {
25
+ expect(res).toEqual({
26
+ accessToken: 'abc',
27
+ editor: 'vim',
28
+ repoName: 'kibana',
29
+ repoOwner: 'elastic',
30
+ });
31
+ });
32
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
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 promises_1 = __importDefault(require("fs/promises"));
7
+ const os_1 = __importDefault(require("os"));
8
+ const make_dir_1 = __importDefault(require("make-dir"));
9
+ const globalConfig_1 = require("./globalConfig");
10
+ describe('config', () => {
11
+ afterEach(() => jest.clearAllMocks());
12
+ beforeEach(() => {
13
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
14
+ });
15
+ describe('getGlobalConfig', () => {
16
+ let res;
17
+ beforeEach(async () => {
18
+ jest.spyOn(promises_1.default, 'chmod').mockResolvedValueOnce();
19
+ jest.spyOn(promises_1.default, 'writeFile').mockResolvedValueOnce();
20
+ jest.spyOn(promises_1.default, 'readFile').mockResolvedValueOnce(JSON.stringify({
21
+ accessToken: 'myAccessToken',
22
+ }));
23
+ res = await (0, globalConfig_1.getGlobalConfig)();
24
+ });
25
+ it("should create config if it doesn't exist", () => {
26
+ expect(promises_1.default.writeFile).toHaveBeenCalledWith('/myHomeDir/.backport/config.json', expect.any(String), { flag: 'wx', mode: 384 });
27
+ });
28
+ it("should create .backport folder if it doesn't exist", () => {
29
+ expect(make_dir_1.default).toHaveBeenCalledWith('/myHomeDir/.backport');
30
+ });
31
+ it('should load config', () => {
32
+ expect(promises_1.default.readFile).toHaveBeenCalledWith('/myHomeDir/.backport/config.json', 'utf8');
33
+ });
34
+ it('should return config', () => {
35
+ expect(res).toEqual({
36
+ accessToken: 'myAccessToken',
37
+ });
38
+ });
39
+ });
40
+ describe('createGlobalConfigIfNotExist', () => {
41
+ it("should create config if it does't exist", async () => {
42
+ jest.spyOn(promises_1.default, 'writeFile').mockResolvedValueOnce(undefined);
43
+ const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/globalConfig', 'myConfigTemplate');
44
+ expect(didCreate).toEqual(true);
45
+ expect(promises_1.default.writeFile).toHaveBeenCalledWith('/path/to/globalConfig', expect.stringContaining('myConfigTemplate'), { flag: 'wx', mode: 384 });
46
+ });
47
+ it('should not fail if config already exists', async () => {
48
+ const err = new Error();
49
+ err.code = 'EEXIST';
50
+ jest.spyOn(promises_1.default, 'writeFile').mockRejectedValueOnce(err);
51
+ const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/global/config.json', 'myConfigTemplate');
52
+ expect(didCreate).toEqual(false);
53
+ });
54
+ it("should fail gracefully if .backport folder doesn't exist", async () => {
55
+ const err = new Error();
56
+ err.code = 'ENOENT';
57
+ jest.spyOn(promises_1.default, 'writeFile').mockRejectedValueOnce(err);
58
+ await expect(() => (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/global/config.json', 'myConfigTemplate')).rejects.toThrowError('The .backport folder (/path/to/global/config.json) does not exist.');
59
+ });
60
+ });
61
+ });
@@ -0,0 +1 @@
1
+ export {};