backport 5.6.6 → 6.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.
- package/README.md +48 -39
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +6 -5
- package/dist/entrypoint.module.js +8 -6
- package/dist/ink.d.ts +1 -0
- package/dist/ink.js +49 -0
- package/dist/main.d.ts +11 -6
- package/dist/main.js +40 -24
- package/dist/options/ConfigOptions.d.ts +13 -8
- package/dist/options/cliArgs.d.ts +11 -9
- package/dist/options/cliArgs.js +74 -36
- package/dist/options/cliArgs.test.js +33 -37
- package/dist/options/config/config.d.ts +17 -15
- package/dist/options/config/config.js +8 -8
- package/dist/options/config/config.test.js +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -1
- package/dist/options/config/globalConfig.d.ts +2 -51
- package/dist/options/config/globalConfig.js +8 -8
- package/dist/options/config/globalConfig.test.js +7 -3
- package/dist/options/config/projectConfig.d.ts +2 -51
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/projectConfig.test.js +3 -3
- package/dist/options/config/readConfigFile.d.ts +2 -51
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +19 -14
- package/dist/options/options.js +5 -6
- package/dist/options/options.test.js +48 -11
- package/dist/options/parseRequiredOptions.d.ts +18 -13
- package/dist/options/parseRequiredOptions.js +8 -12
- package/dist/options/parseRequiredOptions.test.js +25 -16
- package/dist/runSequentially.d.ts +20 -0
- package/dist/runSequentially.js +41 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +235 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +138 -17
- package/dist/scripts/generate-gql.d.ts +1 -0
- package/dist/scripts/generate-gql.js +15 -0
- package/dist/scripts/postinstall.js +4 -4
- package/dist/scripts/postinstall.test.js +9 -2
- package/dist/scripts/runPostinstall.js +1 -1
- package/dist/services/HandledError.d.ts +11 -1
- package/dist/services/HandledError.js +2 -1
- package/dist/services/child-process-promisified.d.ts +1 -1
- package/dist/services/child-process-promisified.js +1 -1
- package/dist/services/env.js +5 -5
- package/dist/services/env.test.js +11 -4
- package/dist/services/fs-promisified.js +4 -4
- package/dist/services/getExpectedTarget.d.ts +9 -0
- package/dist/services/getExpectedTarget.js +77 -0
- package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/getExpectedTargetPullRequests.js +77 -0
- package/dist/services/git.d.ts +15 -4
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +86 -61
- package/dist/services/git.test.js +61 -64
- package/dist/services/github/commitFormatters.d.ts +3 -7
- package/dist/services/github/commitFormatters.js +10 -19
- package/dist/services/github/commitFormatters.test.js +2 -24
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
- package/dist/services/github/v3/createPullRequest.d.ts +3 -2
- package/dist/services/github/v3/createPullRequest.js +32 -23
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +97 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +209 -0
- package/dist/services/github/v4/FetchPullRequestId.js +1 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +5 -7
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +8 -7
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +94 -33
- package/dist/services/github/v4/fetchAuthorId.js +1 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
- package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +16 -10
- package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +25 -7
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +13 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +13 -15
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.js +16 -15
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +87 -0
- package/dist/services/prompts.d.ts +10 -4
- package/dist/services/prompts.js +85 -22
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
- package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/sourceCommit.js +86 -0
- package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
- package/dist/services/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit.js +86 -0
- package/dist/services/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit.test.js +280 -0
- package/dist/test/inquirer.private.test.js +22 -15
- package/dist/test/integration/createSpies.js +6 -6
- package/dist/test/integration/envConstants.js +5 -6
- package/dist/test/integration/helpers.js +1 -1
- package/dist/test/integration/integration.private.test.d.ts +1 -0
- package/dist/test/integration/integration.private.test.js +308 -0
- package/dist/test/integration/integration.test.js +28 -29
- package/dist/test/nockHelpers.js +3 -7
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +0 -22
- package/dist/types/Commit.d.ts +85 -0
- package/dist/types/Commit.js +139 -0
- package/dist/types/commitNode.d.ts +89 -0
- package/dist/types/commitNode.js +139 -0
- package/dist/types/commitNode.test.d.ts +1 -0
- package/dist/types/commitNode.test.js +255 -0
- package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
- package/dist/types/commitWithAssociatedPullRequests.js +145 -0
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +131 -68
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommits.js +55 -25
- package/dist/ui/getTargetBranches.d.ts +2 -2
- package/dist/ui/getTargetBranches.js +16 -17
- package/dist/ui/getTargetBranches.test.js +75 -99
- package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
- package/dist/ui/getTargetBranchesFromLabels.js +40 -0
- package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
- package/dist/ui/maybeSetupRepo.js +9 -9
- package/dist/ui/maybeSetupRepo.test.js +5 -1
- package/package.json +36 -51
- package/yarn.lock +2387 -2987
package/dist/options/cliArgs.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getOptionsFromCliArgs = void 0;
|
|
7
7
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
8
|
function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
9
|
-
const yargsInstance = yargs_1.default(argv)
|
|
9
|
+
const yargsInstance = (0, yargs_1.default)(argv)
|
|
10
10
|
.parserConfiguration({
|
|
11
11
|
'strip-dashed': true,
|
|
12
12
|
'strip-aliased': true,
|
|
@@ -25,16 +25,16 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
25
25
|
alias: 'a',
|
|
26
26
|
type: 'boolean',
|
|
27
27
|
})
|
|
28
|
-
.option('
|
|
29
|
-
description: 'Show commits by specific author',
|
|
30
|
-
type: 'string',
|
|
31
|
-
})
|
|
32
|
-
.option('assignees', {
|
|
28
|
+
.option('assignee', {
|
|
33
29
|
description: 'Add assignees to the target pull request',
|
|
34
|
-
alias:
|
|
30
|
+
alias: 'assign',
|
|
35
31
|
type: 'array',
|
|
36
32
|
string: true,
|
|
37
33
|
conflicts: ['autoAssign'],
|
|
34
|
+
})
|
|
35
|
+
.option('author', {
|
|
36
|
+
description: 'Show commits by specific author',
|
|
37
|
+
type: 'string',
|
|
38
38
|
})
|
|
39
39
|
.option('autoAssign', {
|
|
40
40
|
description: 'Auto assign the target pull request to yourself',
|
|
@@ -54,8 +54,13 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
54
54
|
description: 'Disable interactive prompts',
|
|
55
55
|
type: 'boolean',
|
|
56
56
|
})
|
|
57
|
-
.option('
|
|
58
|
-
description: '
|
|
57
|
+
.option('cherrypickRef', {
|
|
58
|
+
description: 'Append commit message with "(cherry picked from commit...)',
|
|
59
|
+
type: 'boolean',
|
|
60
|
+
conflicts: ['noCherrypickRef'],
|
|
61
|
+
})
|
|
62
|
+
.option('details', {
|
|
63
|
+
description: 'Show details about each commit',
|
|
59
64
|
type: 'boolean',
|
|
60
65
|
})
|
|
61
66
|
.option('editor', {
|
|
@@ -70,6 +75,7 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
70
75
|
.option('fork', {
|
|
71
76
|
description: 'Create backports in fork or origin repo',
|
|
72
77
|
type: 'boolean',
|
|
78
|
+
conflicts: ['noFork'],
|
|
73
79
|
})
|
|
74
80
|
.option('gitHostname', {
|
|
75
81
|
hidden: true,
|
|
@@ -125,25 +131,36 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
125
131
|
description: 'Backport multiple commits',
|
|
126
132
|
type: 'boolean',
|
|
127
133
|
conflicts: ['multiple'],
|
|
134
|
+
})
|
|
135
|
+
.option('noCherrypickRef', {
|
|
136
|
+
description: 'Do not append commit message with "(cherry picked from commit...)"',
|
|
137
|
+
type: 'boolean',
|
|
138
|
+
conflicts: ['cherrypickRef'],
|
|
128
139
|
})
|
|
129
140
|
.option('noVerify', {
|
|
130
|
-
description: '
|
|
141
|
+
description: 'Bypass the pre-commit and commit-msg hooks',
|
|
131
142
|
type: 'boolean',
|
|
143
|
+
})
|
|
144
|
+
.option('noFork', {
|
|
145
|
+
description: 'Create backports in the origin repo',
|
|
146
|
+
type: 'boolean',
|
|
147
|
+
conflicts: ['fork'],
|
|
132
148
|
})
|
|
133
149
|
.option('path', {
|
|
134
150
|
description: 'Only list commits touching files under the specified path',
|
|
135
151
|
alias: 'p',
|
|
152
|
+
type: 'array',
|
|
153
|
+
string: true,
|
|
154
|
+
})
|
|
155
|
+
.option('prDescription', {
|
|
156
|
+
description: 'Description to be added to pull request',
|
|
157
|
+
alias: 'description',
|
|
136
158
|
type: 'string',
|
|
137
159
|
})
|
|
138
160
|
.option('prTitle', {
|
|
139
161
|
description: 'Title of pull request',
|
|
140
162
|
alias: 'title',
|
|
141
163
|
type: 'string',
|
|
142
|
-
})
|
|
143
|
-
.option('prDescription', {
|
|
144
|
-
description: 'Description to be added to pull request',
|
|
145
|
-
alias: 'description',
|
|
146
|
-
type: 'string',
|
|
147
164
|
})
|
|
148
165
|
.option('prFilter', {
|
|
149
166
|
conflicts: ['pullNumber', 'sha'],
|
|
@@ -159,6 +176,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
159
176
|
.option('resetAuthor', {
|
|
160
177
|
description: 'Set yourself as commit author',
|
|
161
178
|
type: 'boolean',
|
|
179
|
+
})
|
|
180
|
+
.option('reviewer', {
|
|
181
|
+
description: 'Add reviewer to the target PR',
|
|
182
|
+
type: 'array',
|
|
183
|
+
string: true,
|
|
162
184
|
})
|
|
163
185
|
.option('sha', {
|
|
164
186
|
conflicts: ['pullNumber', 'prFilter'],
|
|
@@ -170,34 +192,28 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
170
192
|
description: `Specify a non-default branch (normally "master") to backport from`,
|
|
171
193
|
type: 'string',
|
|
172
194
|
})
|
|
173
|
-
.option('
|
|
195
|
+
.option('sourcePRLabel', {
|
|
174
196
|
description: 'Add labels to the source (original) PR',
|
|
175
|
-
alias:
|
|
197
|
+
alias: 'sourcePrLabel',
|
|
176
198
|
type: 'array',
|
|
177
199
|
string: true,
|
|
178
200
|
})
|
|
179
|
-
.option('
|
|
201
|
+
.option('targetBranch', {
|
|
180
202
|
description: 'Branch(es) to backport to',
|
|
181
|
-
alias: ['
|
|
203
|
+
alias: ['branch', 'b'],
|
|
182
204
|
type: 'array',
|
|
183
|
-
string: true,
|
|
205
|
+
string: true, // ensure `6.0` is not coerced to `6`
|
|
184
206
|
})
|
|
185
|
-
.option('
|
|
207
|
+
.option('targetBranchChoice', {
|
|
186
208
|
description: 'List branches to backport to',
|
|
187
|
-
alias: 'targetBranchChoice',
|
|
188
209
|
type: 'array',
|
|
189
210
|
string: true,
|
|
190
211
|
})
|
|
191
|
-
.option('
|
|
212
|
+
.option('targetPRLabel', {
|
|
192
213
|
description: 'Add labels to the target (backport) PR',
|
|
193
|
-
alias: ['
|
|
214
|
+
alias: ['label', 'l'],
|
|
194
215
|
type: 'array',
|
|
195
216
|
string: true,
|
|
196
|
-
})
|
|
197
|
-
// cli-only
|
|
198
|
-
.option('verify', {
|
|
199
|
-
description: `Opposite of no-verify`,
|
|
200
|
-
type: 'boolean',
|
|
201
217
|
})
|
|
202
218
|
.option('upstream', {
|
|
203
219
|
description: 'Name of repository',
|
|
@@ -211,6 +227,11 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
211
227
|
.option('verbose', {
|
|
212
228
|
description: 'Show additional debug information',
|
|
213
229
|
type: 'boolean',
|
|
230
|
+
})
|
|
231
|
+
// cli-only
|
|
232
|
+
.option('verify', {
|
|
233
|
+
description: `Opposite of no-verify`,
|
|
234
|
+
type: 'boolean',
|
|
214
235
|
})
|
|
215
236
|
.alias('version', 'v')
|
|
216
237
|
.alias('version', 'V')
|
|
@@ -227,15 +248,32 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
|
|
|
227
248
|
throw new Error(msg);
|
|
228
249
|
});
|
|
229
250
|
}
|
|
230
|
-
|
|
231
|
-
|
|
251
|
+
const {
|
|
252
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
253
|
+
$0, _,
|
|
254
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
255
|
+
multiple, multipleBranches, multipleCommits,
|
|
256
|
+
// negations
|
|
257
|
+
verify, noVerify, noCherrypickRef, noFork,
|
|
258
|
+
// array types (should be renamed to plural form)
|
|
259
|
+
assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
|
|
232
260
|
return excludeUndefined({
|
|
233
|
-
...
|
|
261
|
+
...restOptions,
|
|
234
262
|
// `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
|
|
235
|
-
multipleBranches: multiple
|
|
236
|
-
multipleCommits: multiple
|
|
237
|
-
//
|
|
238
|
-
|
|
263
|
+
multipleBranches: multiple ?? multipleBranches,
|
|
264
|
+
multipleCommits: multiple ?? multipleCommits,
|
|
265
|
+
// rename array types to plural
|
|
266
|
+
assignees: assignee ?? [],
|
|
267
|
+
commitPaths: path ?? [],
|
|
268
|
+
reviewers: reviewer ?? [],
|
|
269
|
+
sourcePRLabels: sourcePRLabel,
|
|
270
|
+
targetBranchChoices: targetBranchChoice,
|
|
271
|
+
targetBranches: targetBranch,
|
|
272
|
+
targetPRLabels: targetPRLabel,
|
|
273
|
+
// negations (cli-only flags)
|
|
274
|
+
cherrypickRef: noCherrypickRef === true ? false : restOptions.cherrypickRef,
|
|
275
|
+
fork: noFork === true ? false : restOptions.fork,
|
|
276
|
+
noVerify: verify ?? noVerify,
|
|
239
277
|
});
|
|
240
278
|
}
|
|
241
279
|
exports.getOptionsFromCliArgs = getOptionsFromCliArgs;
|
|
@@ -10,7 +10,7 @@ describe('getOptionsFromCliArgs', () => {
|
|
|
10
10
|
'--githubApiBaseUrlV3',
|
|
11
11
|
'my api hostname',
|
|
12
12
|
];
|
|
13
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
13
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
14
14
|
expect(res.accessToken).toEqual('my access token');
|
|
15
15
|
expect('access-token' in res).toEqual(false);
|
|
16
16
|
expect(res.githubApiBaseUrlV3).toEqual('my api hostname');
|
|
@@ -25,11 +25,15 @@ describe('getOptionsFromCliArgs', () => {
|
|
|
25
25
|
'--upstream',
|
|
26
26
|
'elastic/kibana',
|
|
27
27
|
];
|
|
28
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
28
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
29
29
|
expect(res).toEqual({
|
|
30
30
|
accessToken: 'my access token',
|
|
31
31
|
upstream: 'elastic/kibana',
|
|
32
32
|
username: 'sqren',
|
|
33
|
+
mainline: 1,
|
|
34
|
+
reviewers: [],
|
|
35
|
+
assignees: [],
|
|
36
|
+
commitPaths: [],
|
|
33
37
|
});
|
|
34
38
|
});
|
|
35
39
|
});
|
|
@@ -46,114 +50,106 @@ describe('getOptionsFromCliArgs', () => {
|
|
|
46
50
|
describe('sourcePRLabels', () => {
|
|
47
51
|
it('should handle all variations', () => {
|
|
48
52
|
const argv = [
|
|
49
|
-
'--sourcePRLabels',
|
|
50
|
-
'label a',
|
|
51
|
-
'--sourcePrLabels',
|
|
52
|
-
'label b',
|
|
53
|
-
'--source-pr-labels',
|
|
54
|
-
'label c',
|
|
55
53
|
'--sourcePRLabel',
|
|
56
|
-
'label d',
|
|
57
|
-
'--sourcePrLabel',
|
|
58
|
-
'label e',
|
|
59
|
-
'--source-pr-label',
|
|
60
|
-
'label f',
|
|
61
|
-
];
|
|
62
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
63
|
-
expect(res.sourcePRLabels).toEqual([
|
|
64
54
|
'label a',
|
|
55
|
+
'--sourcePrLabel',
|
|
65
56
|
'label b',
|
|
57
|
+
'--source-pr-label',
|
|
66
58
|
'label c',
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
]);
|
|
59
|
+
];
|
|
60
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
61
|
+
expect(res.sourcePRLabels).toEqual(['label a', 'label b', 'label c']);
|
|
71
62
|
});
|
|
72
63
|
});
|
|
73
64
|
describe('pullNumber', () => {
|
|
74
65
|
it('should accept `--pr` alias but only return the full representation (`pullNumber`)', () => {
|
|
75
66
|
const argv = ['--pr', '1337'];
|
|
76
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
67
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
77
68
|
expect(res.pullNumber).toEqual(1337);
|
|
78
69
|
//@ts-expect-error
|
|
79
70
|
expect(res.pr).toBe(undefined);
|
|
80
71
|
});
|
|
81
72
|
});
|
|
82
73
|
describe('assignees', () => {
|
|
83
|
-
it('
|
|
84
|
-
const argv = ['--
|
|
85
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
74
|
+
it('--assignee', () => {
|
|
75
|
+
const argv = ['--assignee', 'john'];
|
|
76
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
77
|
+
expect(res.assignees).toEqual(['john']);
|
|
78
|
+
});
|
|
79
|
+
it('--assign', () => {
|
|
80
|
+
const argv = ['--assign', 'john'];
|
|
81
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
86
82
|
expect(res.assignees).toEqual(['john']);
|
|
87
83
|
});
|
|
88
84
|
});
|
|
89
85
|
describe('multipleBranches', () => {
|
|
90
86
|
it('should be undefined by default', () => {
|
|
91
87
|
const argv = [];
|
|
92
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
88
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
93
89
|
expect(res.multipleBranches).toBe(undefined);
|
|
94
90
|
});
|
|
95
91
|
it('should set to true', () => {
|
|
96
92
|
const argv = ['--multiple-branches', 'true'];
|
|
97
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
93
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
98
94
|
expect(res.multipleBranches).toBe(true);
|
|
99
95
|
});
|
|
100
96
|
it('should set to false', () => {
|
|
101
97
|
const argv = ['--multiple-branches', 'false'];
|
|
102
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
98
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
103
99
|
expect(res.multipleBranches).toBe(false);
|
|
104
100
|
});
|
|
105
101
|
it('should respect `multiple` option', () => {
|
|
106
102
|
const argv = ['--multiple'];
|
|
107
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
103
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
108
104
|
expect(res.multipleBranches).toBe(true);
|
|
109
105
|
});
|
|
110
106
|
it('should conflict when using both', () => {
|
|
111
107
|
const argv = ['--multiple', '--multiple-branches', 'false'];
|
|
112
|
-
expect(() => cliArgs_1.getOptionsFromCliArgs(argv, { exitOnError: false })).toThrow('Arguments multiple and multipleBranches are mutually exclusive');
|
|
108
|
+
expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrow('Arguments multiple and multipleBranches are mutually exclusive');
|
|
113
109
|
});
|
|
114
110
|
});
|
|
115
111
|
describe('noVerify', () => {
|
|
116
112
|
it('should be undefined by default', () => {
|
|
117
113
|
const argv = [];
|
|
118
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
114
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
119
115
|
expect(res.noVerify).toBe(undefined);
|
|
120
116
|
});
|
|
121
117
|
it('should set to false', () => {
|
|
122
118
|
const argv = ['--no-verify', 'false'];
|
|
123
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
119
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
124
120
|
expect(res.noVerify).toBe(false);
|
|
125
121
|
});
|
|
126
122
|
it('should set to true', () => {
|
|
127
123
|
const argv = ['--no-verify', 'true'];
|
|
128
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
124
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
129
125
|
expect(res.noVerify).toBe(true);
|
|
130
126
|
});
|
|
131
127
|
it('should be enabled by `verify`', () => {
|
|
132
128
|
const argv = ['--verify'];
|
|
133
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
129
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
134
130
|
expect(res.noVerify).toBe(true);
|
|
135
131
|
});
|
|
136
132
|
});
|
|
137
133
|
describe('mainline', () => {
|
|
138
134
|
it('should default to 1', () => {
|
|
139
135
|
const argv = ['--mainline'];
|
|
140
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
136
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
141
137
|
expect(res.mainline).toEqual(1);
|
|
142
138
|
});
|
|
143
139
|
it('should accept numbers', () => {
|
|
144
140
|
const argv = ['--mainline', '2'];
|
|
145
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
141
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
146
142
|
expect(res.mainline).toEqual(2);
|
|
147
143
|
});
|
|
148
144
|
it('should throw on invalid values', () => {
|
|
149
145
|
const argv = ['--mainline', 'foo'];
|
|
150
|
-
expect(() => cliArgs_1.getOptionsFromCliArgs(argv, { exitOnError: false })).toThrowError('--mainline must be an integer. Received: NaN');
|
|
146
|
+
expect(() => (0, cliArgs_1.getOptionsFromCliArgs)(argv, { exitOnError: false })).toThrowError('--mainline must be an integer. Received: NaN');
|
|
151
147
|
});
|
|
152
148
|
});
|
|
153
149
|
describe('targetBranches', () => {
|
|
154
150
|
it('should not coerce 6.0 to 6', () => {
|
|
155
151
|
const argv = ['-b', '6.0'];
|
|
156
|
-
const res = cliArgs_1.getOptionsFromCliArgs(argv);
|
|
152
|
+
const res = (0, cliArgs_1.getOptionsFromCliArgs)(argv);
|
|
157
153
|
expect(res.targetBranches).toEqual(['6.0']);
|
|
158
154
|
});
|
|
159
155
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ConfigOptions } from '../ConfigOptions';
|
|
1
|
+
import { ConfigFileOptions } from '../ConfigOptions';
|
|
3
2
|
export declare const defaultConfigOptions: {
|
|
4
3
|
all: boolean;
|
|
5
|
-
assignees:
|
|
4
|
+
assignees: string[];
|
|
6
5
|
autoAssign: boolean;
|
|
7
6
|
autoMerge: boolean;
|
|
8
7
|
autoMergeMethod: string;
|
|
9
8
|
ci: boolean;
|
|
10
|
-
|
|
9
|
+
cherrypickRef: boolean;
|
|
10
|
+
details: boolean;
|
|
11
11
|
fork: boolean;
|
|
12
12
|
gitHostname: string;
|
|
13
13
|
githubApiBaseUrlV3: string;
|
|
@@ -19,22 +19,20 @@ export declare const defaultConfigOptions: {
|
|
|
19
19
|
prTitle: string;
|
|
20
20
|
resetAuthor: boolean;
|
|
21
21
|
sourcePRLabels: never[];
|
|
22
|
-
targetBranches: never[];
|
|
23
22
|
targetBranchChoices: never[];
|
|
23
|
+
targetBranches: never[];
|
|
24
24
|
targetPRLabels: never[];
|
|
25
25
|
verbose: boolean;
|
|
26
26
|
};
|
|
27
|
-
export declare type OptionsFromConfigFiles =
|
|
28
|
-
export declare function getOptionsFromConfigFiles(optionsFromModule?:
|
|
27
|
+
export declare type OptionsFromConfigFiles = Awaited<ReturnType<typeof getOptionsFromConfigFiles>>;
|
|
28
|
+
export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFileOptions): Promise<{
|
|
29
29
|
targetPRLabels: string[];
|
|
30
|
-
targetBranchChoices: import("../ConfigOptions").
|
|
30
|
+
targetBranchChoices: import("../ConfigOptions").TargetBranchChoiceOrString[];
|
|
31
31
|
accessToken?: string | undefined;
|
|
32
32
|
all: boolean;
|
|
33
|
-
assignees: string[]
|
|
33
|
+
assignees: string[];
|
|
34
34
|
author?: string | undefined;
|
|
35
35
|
autoAssign: boolean;
|
|
36
|
-
autoMerge: boolean;
|
|
37
|
-
autoMergeMethod: string;
|
|
38
36
|
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
39
37
|
files: string[];
|
|
40
38
|
directory: string;
|
|
@@ -47,8 +45,12 @@ export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigOpti
|
|
|
47
45
|
};
|
|
48
46
|
targetBranch: string;
|
|
49
47
|
}) => boolean | Promise<boolean>) | undefined;
|
|
50
|
-
|
|
48
|
+
autoMerge: boolean;
|
|
49
|
+
autoMergeMethod: string;
|
|
51
50
|
ci: boolean;
|
|
51
|
+
cherrypickRef: boolean;
|
|
52
|
+
commitPaths?: string[] | undefined;
|
|
53
|
+
details: boolean;
|
|
52
54
|
editor?: string | undefined;
|
|
53
55
|
forceLocalConfig?: boolean | undefined;
|
|
54
56
|
fork: boolean;
|
|
@@ -60,12 +62,12 @@ export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigOpti
|
|
|
60
62
|
multipleBranches: boolean;
|
|
61
63
|
multipleCommits: boolean;
|
|
62
64
|
noVerify: boolean;
|
|
63
|
-
path?: string | undefined;
|
|
64
65
|
prDescription?: string | undefined;
|
|
65
66
|
prFilter?: string | undefined;
|
|
66
67
|
prTitle: string;
|
|
67
68
|
pullNumber?: number | undefined;
|
|
68
69
|
resetAuthor: boolean;
|
|
70
|
+
reviewers?: string[] | undefined;
|
|
69
71
|
sha?: string | undefined;
|
|
70
72
|
sourceBranch?: string | undefined;
|
|
71
73
|
sourcePRLabels: string[] | never[];
|
|
@@ -73,7 +75,7 @@ export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigOpti
|
|
|
73
75
|
upstream: string | undefined;
|
|
74
76
|
username?: string | undefined;
|
|
75
77
|
verbose: boolean;
|
|
76
|
-
|
|
78
|
+
branchLabelMapping?: Record<string, string> | undefined;
|
|
79
|
+
branches?: import("../ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
77
80
|
labels?: string[] | undefined;
|
|
78
|
-
dryRun: boolean;
|
|
79
81
|
}>;
|
|
@@ -11,7 +11,8 @@ exports.defaultConfigOptions = {
|
|
|
11
11
|
autoMerge: false,
|
|
12
12
|
autoMergeMethod: 'merge',
|
|
13
13
|
ci: false,
|
|
14
|
-
|
|
14
|
+
cherrypickRef: true,
|
|
15
|
+
details: false,
|
|
15
16
|
fork: true,
|
|
16
17
|
gitHostname: 'github.com',
|
|
17
18
|
githubApiBaseUrlV3: 'https://api.github.com',
|
|
@@ -23,17 +24,16 @@ exports.defaultConfigOptions = {
|
|
|
23
24
|
prTitle: '[{targetBranch}] {commitMessages}',
|
|
24
25
|
resetAuthor: false,
|
|
25
26
|
sourcePRLabels: [],
|
|
26
|
-
targetBranches: [],
|
|
27
27
|
targetBranchChoices: [],
|
|
28
|
+
targetBranches: [],
|
|
28
29
|
targetPRLabels: [],
|
|
29
30
|
verbose: false,
|
|
30
31
|
};
|
|
31
32
|
async function getOptionsFromConfigFiles(optionsFromModule) {
|
|
32
|
-
var _a, _b, _c, _d;
|
|
33
33
|
const [gitConfig, projectConfig, globalConfig] = await Promise.all([
|
|
34
|
-
getOptionsFromGit_1.getOptionsFromGit(),
|
|
35
|
-
projectConfig_1.getProjectConfig(),
|
|
36
|
-
globalConfig_1.getGlobalConfig(optionsFromModule
|
|
34
|
+
(0, getOptionsFromGit_1.getOptionsFromGit)(),
|
|
35
|
+
(0, projectConfig_1.getProjectConfig)(),
|
|
36
|
+
(0, globalConfig_1.getGlobalConfig)(optionsFromModule?.ci),
|
|
37
37
|
]);
|
|
38
38
|
// global and project config combined
|
|
39
39
|
const combinedConfig = {
|
|
@@ -46,9 +46,9 @@ async function getOptionsFromConfigFiles(optionsFromModule) {
|
|
|
46
46
|
...exports.defaultConfigOptions,
|
|
47
47
|
...combinedConfig,
|
|
48
48
|
// backwards-compatability: `labels` was renamed `targetPRLabels`
|
|
49
|
-
targetPRLabels:
|
|
49
|
+
targetPRLabels: combinedConfig.targetPRLabels ?? combinedConfig.labels ?? [],
|
|
50
50
|
// backwards-compatability: `branches` was renamed `targetBranchChoices`
|
|
51
|
-
targetBranchChoices:
|
|
51
|
+
targetBranchChoices: combinedConfig.targetBranchChoices ?? combinedConfig.branches ?? [],
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
exports.getOptionsFromConfigFiles = getOptionsFromConfigFiles;
|
|
@@ -4,7 +4,7 @@ const config_1 = require("./config");
|
|
|
4
4
|
describe('getOptionsFromConfigFiles', () => {
|
|
5
5
|
let res;
|
|
6
6
|
beforeEach(async () => {
|
|
7
|
-
res = await config_1.getOptionsFromConfigFiles();
|
|
7
|
+
res = await (0, config_1.getOptionsFromConfigFiles)();
|
|
8
8
|
});
|
|
9
9
|
it('should return values from (mock) config files incl. default values', () => {
|
|
10
10
|
expect(res).toEqual({
|
|
@@ -15,7 +15,8 @@ describe('getOptionsFromConfigFiles', () => {
|
|
|
15
15
|
autoMerge: false,
|
|
16
16
|
autoMergeMethod: 'merge',
|
|
17
17
|
ci: false,
|
|
18
|
-
|
|
18
|
+
cherrypickRef: true,
|
|
19
|
+
details: false,
|
|
19
20
|
fork: true,
|
|
20
21
|
gitHostname: 'github.com',
|
|
21
22
|
githubApiBaseUrlV3: 'https://api.github.com',
|
|
@@ -4,7 +4,7 @@ exports.getOptionsFromGit = void 0;
|
|
|
4
4
|
const git_1 = require("../../services/git");
|
|
5
5
|
async function getOptionsFromGit() {
|
|
6
6
|
return {
|
|
7
|
-
upstream: await git_1.getUpstreamFromGitRemote(),
|
|
7
|
+
upstream: await (0, git_1.getUpstreamFromGitRemote)(),
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
exports.getOptionsFromGit = getOptionsFromGit;
|
|
@@ -1,53 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
all: boolean;
|
|
4
|
-
assignees: string[];
|
|
5
|
-
author: string;
|
|
6
|
-
autoAssign: boolean;
|
|
7
|
-
autoMerge: boolean;
|
|
8
|
-
autoMergeMethod: string;
|
|
9
|
-
autoFixConflicts: ({ files, directory, logger, targetBranch, }: {
|
|
10
|
-
files: string[];
|
|
11
|
-
directory: string;
|
|
12
|
-
logger: {
|
|
13
|
-
error: (message: string, meta?: unknown) => void;
|
|
14
|
-
warn: (message: string, meta?: unknown) => void;
|
|
15
|
-
info: (message: string, meta?: unknown) => void;
|
|
16
|
-
verbose: (message: string, meta?: unknown) => void;
|
|
17
|
-
debug: (message: string, meta?: unknown) => void;
|
|
18
|
-
};
|
|
19
|
-
targetBranch: string;
|
|
20
|
-
}) => boolean | Promise<boolean>;
|
|
21
|
-
branchLabelMapping: Record<string, string>;
|
|
22
|
-
ci: boolean;
|
|
23
|
-
editor: string;
|
|
24
|
-
forceLocalConfig: boolean;
|
|
25
|
-
fork: boolean;
|
|
26
|
-
gitHostname: string;
|
|
27
|
-
githubApiBaseUrlV3: string;
|
|
28
|
-
githubApiBaseUrlV4: string;
|
|
29
|
-
maxNumber: number;
|
|
30
|
-
multiple: boolean;
|
|
31
|
-
multipleBranches: boolean;
|
|
32
|
-
multipleCommits: boolean;
|
|
33
|
-
noVerify: boolean;
|
|
34
|
-
path: string;
|
|
35
|
-
prDescription: string;
|
|
36
|
-
prFilter: string;
|
|
37
|
-
prTitle: string;
|
|
38
|
-
pullNumber: number;
|
|
39
|
-
resetAuthor: boolean;
|
|
40
|
-
sha: string;
|
|
41
|
-
sourceBranch: string;
|
|
42
|
-
sourcePRLabels: string[];
|
|
43
|
-
targetBranchChoices: import("../ConfigOptions").BranchChoiceRaw[];
|
|
44
|
-
targetBranches: string[];
|
|
45
|
-
targetPRLabels: string[];
|
|
46
|
-
upstream: string;
|
|
47
|
-
username: string;
|
|
48
|
-
verbose: boolean;
|
|
49
|
-
branches: import("../ConfigOptions").BranchChoiceRaw[];
|
|
50
|
-
labels: string[];
|
|
51
|
-
}> | undefined>;
|
|
1
|
+
import { ConfigFileOptions } from '../ConfigOptions';
|
|
2
|
+
export declare function getGlobalConfig(ci?: boolean): Promise<ConfigFileOptions | undefined>;
|
|
52
3
|
export declare function createGlobalConfigAndFolderIfNotExist(): Promise<boolean>;
|
|
53
4
|
export declare function createGlobalConfigIfNotExist(globalConfigPath: string, configTemplate: string): Promise<boolean>;
|
|
@@ -14,28 +14,28 @@ async function getGlobalConfig(ci) {
|
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
await createGlobalConfigAndFolderIfNotExist();
|
|
17
|
-
const globalConfigPath = env_1.getGlobalConfigPath();
|
|
18
|
-
return readConfigFile_1.readConfigFile(globalConfigPath);
|
|
17
|
+
const globalConfigPath = (0, env_1.getGlobalConfigPath)();
|
|
18
|
+
return (0, readConfigFile_1.readConfigFile)(globalConfigPath);
|
|
19
19
|
}
|
|
20
20
|
exports.getGlobalConfig = getGlobalConfig;
|
|
21
21
|
async function createGlobalConfigAndFolderIfNotExist() {
|
|
22
|
-
const reposPath = env_1.getReposPath();
|
|
23
|
-
const globalConfigPath = env_1.getGlobalConfigPath();
|
|
22
|
+
const reposPath = (0, env_1.getReposPath)();
|
|
23
|
+
const globalConfigPath = (0, env_1.getGlobalConfigPath)();
|
|
24
24
|
const configTemplate = getConfigTemplate();
|
|
25
|
-
await make_dir_1.default(reposPath);
|
|
25
|
+
await (0, make_dir_1.default)(reposPath);
|
|
26
26
|
const didCreate = await createGlobalConfigIfNotExist(globalConfigPath, configTemplate);
|
|
27
27
|
await ensureCorrectPermissions(globalConfigPath);
|
|
28
28
|
return didCreate;
|
|
29
29
|
}
|
|
30
30
|
exports.createGlobalConfigAndFolderIfNotExist = createGlobalConfigAndFolderIfNotExist;
|
|
31
31
|
function ensureCorrectPermissions(globalConfigPath) {
|
|
32
|
-
return fs_promisified_1.chmod(globalConfigPath, '600');
|
|
32
|
+
return (0, fs_promisified_1.chmod)(globalConfigPath, '600');
|
|
33
33
|
}
|
|
34
34
|
async function createGlobalConfigIfNotExist(globalConfigPath, configTemplate) {
|
|
35
35
|
try {
|
|
36
|
-
await fs_promisified_1.writeFile(globalConfigPath, configTemplate, {
|
|
36
|
+
await (0, fs_promisified_1.writeFile)(globalConfigPath, configTemplate, {
|
|
37
37
|
flag: 'wx',
|
|
38
|
-
mode: 0o600,
|
|
38
|
+
mode: 0o600, // give the owner read-write privleges, no access for others
|
|
39
39
|
});
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
@@ -22,11 +22,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
25
26
|
const make_dir_1 = __importDefault(require("make-dir"));
|
|
26
27
|
const fs = __importStar(require("../../services/fs-promisified"));
|
|
27
28
|
const globalConfig_1 = require("./globalConfig");
|
|
28
29
|
describe('config', () => {
|
|
29
30
|
afterEach(() => jest.clearAllMocks());
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
33
|
+
});
|
|
30
34
|
describe('getGlobalConfig', () => {
|
|
31
35
|
let res;
|
|
32
36
|
beforeEach(async () => {
|
|
@@ -36,7 +40,7 @@ describe('config', () => {
|
|
|
36
40
|
accessToken: 'myAccessToken',
|
|
37
41
|
username: 'sqren',
|
|
38
42
|
}));
|
|
39
|
-
res = await globalConfig_1.getGlobalConfig();
|
|
43
|
+
res = await (0, globalConfig_1.getGlobalConfig)();
|
|
40
44
|
});
|
|
41
45
|
it("should create config if it doesn't exist", () => {
|
|
42
46
|
expect(fs.writeFile).toHaveBeenCalledWith('/myHomeDir/.backport/config.json', expect.any(String), { flag: 'wx', mode: 384 });
|
|
@@ -57,7 +61,7 @@ describe('config', () => {
|
|
|
57
61
|
describe('createGlobalConfigIfNotExist', () => {
|
|
58
62
|
it('should create config and succeed', async () => {
|
|
59
63
|
jest.spyOn(fs, 'writeFile').mockResolvedValueOnce(undefined);
|
|
60
|
-
const didCreate = await globalConfig_1.createGlobalConfigIfNotExist('/path/to/globalConfig', 'myConfigTemplate');
|
|
64
|
+
const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('/path/to/globalConfig', 'myConfigTemplate');
|
|
61
65
|
expect(didCreate).toEqual(true);
|
|
62
66
|
expect(fs.writeFile).toHaveBeenCalledWith('/path/to/globalConfig', expect.stringContaining('myConfigTemplate'), { flag: 'wx', mode: 384 });
|
|
63
67
|
});
|
|
@@ -65,7 +69,7 @@ describe('config', () => {
|
|
|
65
69
|
const err = new Error();
|
|
66
70
|
err.code = 'EEXIST';
|
|
67
71
|
jest.spyOn(fs, 'writeFile').mockRejectedValueOnce(err);
|
|
68
|
-
const didCreate = await globalConfig_1.createGlobalConfigIfNotExist('myPath', 'myConfigTemplate');
|
|
72
|
+
const didCreate = await (0, globalConfig_1.createGlobalConfigIfNotExist)('myPath', 'myConfigTemplate');
|
|
69
73
|
expect(didCreate).toEqual(false);
|
|
70
74
|
});
|
|
71
75
|
});
|