backport 8.3.1 → 8.4.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.
- package/README.md +11 -178
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +42 -21
- package/dist/lib/child-process-promisified.js +2 -2
- package/dist/lib/git.d.ts +4 -3
- package/dist/lib/git.js +22 -29
- package/dist/lib/git.private.test.js +10 -7
- package/dist/lib/git.test.js +47 -15
- package/dist/lib/github/v4/apiRequestV4.js +14 -8
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
- package/dist/lib/ora.d.ts +1 -0
- package/dist/options/ConfigOptions.d.ts +1 -0
- package/dist/options/cliArgs.d.ts +1 -0
- package/dist/options/cliArgs.js +5 -0
- package/dist/options/config/config.d.ts +1 -0
- package/dist/options/config/readConfigFile.d.ts +1 -0
- package/dist/options/options.d.ts +2 -0
- package/dist/options/options.js +3 -2
- package/dist/options/options.test.js +5 -4
- package/dist/test/e2e/cli/date-filters.private.test.js +1 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +122 -6
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -0
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +27 -13
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
- package/dist/{entrypoint.cli.private.test.d.ts → test/e2e/cli/gracefully-handles-corrupt-repo.private.test.d.ts} +0 -0
- package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +52 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
- package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/repo-with-programatically-added-commits.mutation.test.d.ts} +0 -0
- package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +114 -0
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +8 -2
- package/dist/test/e2e/cli/runBackportViaCli.js +47 -17
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +7 -1
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
- package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
- package/dist/test/replaceStringAndLinebreaks.d.ts +5 -0
- package/dist/test/replaceStringAndLinebreaks.js +8 -0
- package/dist/test/sandbox.js +6 -2
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +23 -24
- package/yarn.lock +841 -950
- package/dist/entrypoint.cli.private.test.js +0 -47
- package/dist/errors/BackportError.d.ts +0 -19
- package/dist/errors/BackportError.js +0 -29
- package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
- package/dist/runSequentially.test.d.ts +0 -1
- package/dist/runSequentially.test.js +0 -243
- package/dist/services/BackportError.d.ts +0 -19
- package/dist/services/BackportError.js +0 -29
- package/dist/services/HandledBackportError.d.ts +0 -19
- package/dist/services/HandledBackportError.js +0 -29
- package/dist/services/HandledError.d.ts +0 -19
- package/dist/services/HandledError.js +0 -29
- package/dist/services/child-process-promisified.d.ts +0 -25
- package/dist/services/child-process-promisified.js +0 -58
- package/dist/services/env.d.ts +0 -7
- package/dist/services/env.js +0 -30
- package/dist/services/env.test.d.ts +0 -1
- package/dist/services/env.test.js +0 -21
- package/dist/services/git.d.ts +0 -77
- package/dist/services/git.integration.test.d.ts +0 -1
- package/dist/services/git.integration.test.js +0 -616
- package/dist/services/git.js +0 -439
- package/dist/services/git.private.test.d.ts +0 -1
- package/dist/services/git.private.test.js +0 -618
- package/dist/services/git.test.d.ts +0 -1
- package/dist/services/git.test.js +0 -580
- package/dist/services/github/commitFormatters.d.ts +0 -3
- package/dist/services/github/commitFormatters.js +0 -17
- package/dist/services/github/commitFormatters.test.d.ts +0 -1
- package/dist/services/github/commitFormatters.test.js +0 -11
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
- package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
- package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
- package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
- package/dist/services/github/v3/createPullRequest.d.ts +0 -29
- package/dist/services/github/v3/createPullRequest.js +0 -91
- package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
- package/dist/services/github/v3/createPullRequest.test.js +0 -377
- package/dist/services/github/v3/createStatusComment.d.ts +0 -11
- package/dist/services/github/v3/createStatusComment.js +0 -131
- package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
- package/dist/services/github/v3/createStatusComment.test.js +0 -409
- package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
- package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
- package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
- package/dist/services/github/v4/FetchPullRequestId.js +0 -36
- package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
- package/dist/services/github/v4/apiRequestV4.js +0 -71
- package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
- package/dist/services/github/v4/apiRequestV4.test.js +0 -109
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
- package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
- package/dist/services/github/v4/fetchAuthorId.js +0 -28
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
- package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
- package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
- package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
- package/dist/services/logger.d.ts +0 -9
- package/dist/services/logger.js +0 -74
- package/dist/services/prompt.test.d.ts +0 -1
- package/dist/services/prompt.test.js +0 -139
- package/dist/services/prompts.d.ts +0 -17
- package/dist/services/prompts.js +0 -132
- package/dist/services/remoteConfig.d.ts +0 -20
- package/dist/services/remoteConfig.js +0 -52
- package/dist/services/sequentially.d.ts +0 -1
- package/dist/services/sequentially.js +0 -10
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
- package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
- package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
- package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
- package/dist/services/test.d.ts +0 -1
- package/dist/services/test.js +0 -23
- package/dist/state.d.ts +0 -0
- package/dist/state.js +0 -1
- package/dist/test/ExecError.d.ts +0 -16
- package/dist/test/ExecError.js +0 -15
- package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
- package/dist/test/e2e/cli/cli.private.test.js +0 -222
- package/dist/test/e2e/cli/date-filters.d.ts +0 -1
- package/dist/test/e2e/cli/date-filters.js +0 -43
- package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
- package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
- package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
- package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
- package/dist/test/e2e/cli.e2e.private.test.js +0 -433
- package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
- package/dist/test/e2e/module/module.mutation.test.js +0 -369
- package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
- package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
- package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
- package/dist/test/e2e/module.e2e.private.test.js +0 -369
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
- package/dist/ui/getCommits.d.ts +0 -2
- package/dist/ui/getCommits.js +0 -75
- package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
- package/dist/ui/getCommitsWithoutBackports.js +0 -68
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
- package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
- package/dist/ui/getGitConfigAuthor.d.ts +0 -6
- package/dist/ui/getGitConfigAuthor.js +0 -15
- package/dist/ui/getTargetBranches.d.ts +0 -5
- package/dist/ui/getTargetBranches.js +0 -67
- package/dist/ui/getTargetBranches.test.d.ts +0 -1
- package/dist/ui/getTargetBranches.test.js +0 -204
- package/dist/ui/maybeSetupRepo.d.ts +0 -2
- package/dist/ui/maybeSetupRepo.js +0 -53
- package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
- package/dist/ui/maybeSetupRepo.test.js +0 -238
- package/dist/ui/ora.d.ts +0 -2
- package/dist/ui/ora.js +0 -21
- package/dist/ui/setupRepo.d.ts +0 -2
- package/dist/ui/setupRepo.js +0 -56
- package/dist/ui/setupRepo.test.d.ts +0 -1
- package/dist/ui/setupRepo.test.js +0 -273
- package/dist/utils/filterMissingCommits.d.ts +0 -2
- package/dist/utils/filterMissingCommits.js +0 -7
- package/dist/utils/redact.d.ts +0 -1
- package/dist/utils/redact.js +0 -7
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const child_process_promisified_1 = require("../../../lib/child-process-promisified");
|
|
4
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
5
|
+
const sandbox_1 = require("../../sandbox");
|
|
6
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
7
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
8
|
+
jest.setTimeout(15000);
|
|
9
|
+
describe('gracefully handle corrupted repo', () => {
|
|
10
|
+
it('backports correctly', async () => {
|
|
11
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
12
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
13
|
+
// first run: backport should clone the repo
|
|
14
|
+
await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
15
|
+
'--repo=backport-org/integration-test',
|
|
16
|
+
'--sha=16cfd987b82f49a79ebc663506f5d215b7a81c5c',
|
|
17
|
+
'--branch=7.x',
|
|
18
|
+
`--accessToken=${accessToken}`,
|
|
19
|
+
`--dir=${sandboxPath}`,
|
|
20
|
+
'--dry-run',
|
|
21
|
+
], {
|
|
22
|
+
showOra: true,
|
|
23
|
+
timeoutSeconds: 10,
|
|
24
|
+
});
|
|
25
|
+
// remove all git objects and references
|
|
26
|
+
await (0, child_process_promisified_1.exec)('rm -rf .git', { cwd: sandboxPath });
|
|
27
|
+
await (0, child_process_promisified_1.exec)('git init', { cwd: sandboxPath });
|
|
28
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
29
|
+
'--repo=backport-org/integration-test',
|
|
30
|
+
'--sha=16cfd987b82f49a79ebc663506f5d215b7a81c5c',
|
|
31
|
+
'--branch=7.x',
|
|
32
|
+
`--accessToken=${accessToken}`,
|
|
33
|
+
`--dir=${sandboxPath}`,
|
|
34
|
+
'--dry-run',
|
|
35
|
+
], {
|
|
36
|
+
showOra: true,
|
|
37
|
+
timeoutSeconds: 10,
|
|
38
|
+
});
|
|
39
|
+
// second run: backport should re-create remotes and branches correctly
|
|
40
|
+
expect(output).toMatchInlineSnapshot(`
|
|
41
|
+
"- Initializing...
|
|
42
|
+
? Select commit Bump to 8.0.0
|
|
43
|
+
|
|
44
|
+
Backporting to 7.x:
|
|
45
|
+
- Pulling latest changes
|
|
46
|
+
✔ Pulling latest changes
|
|
47
|
+
- Cherry-picking: Bump to 8.0.0
|
|
48
|
+
✔ Cherry-picking: Bump to 8.0.0
|
|
49
|
+
✔ Dry run complete"
|
|
50
|
+
`);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -9,7 +9,7 @@ describe('repo-with-backportrc-removed (missing .backportrc.json config file)',
|
|
|
9
9
|
'--branch=production',
|
|
10
10
|
'--repo=backport-org/repo-with-backportrc-removed',
|
|
11
11
|
`--accessToken=${accessToken}`,
|
|
12
|
-
], { waitForString: 'Select commit' });
|
|
12
|
+
], { waitForString: 'Select commit', timeoutSeconds: 4 });
|
|
13
13
|
expect(output).toMatchInlineSnapshot(`
|
|
14
14
|
"? Select commit (Use arrow keys)
|
|
15
15
|
❯ 1. Rename README.me to README.md
|
|
@@ -31,7 +31,7 @@ describe('repo-with-backportrc-removed (missing .backportrc.json config file)',
|
|
|
31
31
|
], {
|
|
32
32
|
showOra: true,
|
|
33
33
|
});
|
|
34
|
-
expect(output).toContain('Cherry-picking:
|
|
34
|
+
expect(output).toContain('Cherry-picking: Create README.me');
|
|
35
35
|
});
|
|
36
36
|
it('backport by commit sha', async () => {
|
|
37
37
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
File without changes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
const rest_1 = require("@octokit/rest");
|
|
5
|
+
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
6
|
+
const sandbox_1 = require("../../sandbox");
|
|
7
|
+
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
8
|
+
jest.setTimeout(15000);
|
|
9
|
+
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
10
|
+
const octokit = new rest_1.Octokit({ auth: accessToken });
|
|
11
|
+
describe('Programatically add new commits', () => {
|
|
12
|
+
it('should backport commits added after the first run', async () => {
|
|
13
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
14
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
15
|
+
// first run: backport should clone the repo
|
|
16
|
+
await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
17
|
+
'--repo=backport-org/repo-with-programatically-added-commits',
|
|
18
|
+
'--pr=1',
|
|
19
|
+
'--branch=7.x',
|
|
20
|
+
`--accessToken=${accessToken}`,
|
|
21
|
+
`--dir=${sandboxPath}`,
|
|
22
|
+
'--dry-run',
|
|
23
|
+
], { showOra: true });
|
|
24
|
+
const formattedDate = new Date().toLocaleString('da-DK');
|
|
25
|
+
const commitMessage = `Automatically added at ${formattedDate}`;
|
|
26
|
+
const sha = await createAndCommitFile({
|
|
27
|
+
commitMessage,
|
|
28
|
+
files: [
|
|
29
|
+
{
|
|
30
|
+
path: `files/${formattedDate}.md`,
|
|
31
|
+
sha: await createBlob(`# Hello\nSome content added @ ${formattedDate}`),
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
// second run: backport should find and backport the new commit
|
|
36
|
+
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
37
|
+
'--repo=backport-org/repo-with-programatically-added-commits',
|
|
38
|
+
`--sha=${sha}`,
|
|
39
|
+
'--branch=7.x',
|
|
40
|
+
`--accessToken=${accessToken}`,
|
|
41
|
+
`--dir=${sandboxPath}`,
|
|
42
|
+
'--dry-run',
|
|
43
|
+
], { showOra: true });
|
|
44
|
+
expect(output).toContain(commitMessage);
|
|
45
|
+
expect(output).toContain('Dry run complete');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
async function createAndCommitFile({ commitMessage, files, }) {
|
|
49
|
+
const latestCommitSha = await getLatestCommitSha();
|
|
50
|
+
const treeSha = await createTree(files);
|
|
51
|
+
const commitSha = await createCommit({
|
|
52
|
+
latestCommitSha,
|
|
53
|
+
commitMessage,
|
|
54
|
+
treeSha,
|
|
55
|
+
});
|
|
56
|
+
await updateRef(commitSha);
|
|
57
|
+
return commitSha;
|
|
58
|
+
}
|
|
59
|
+
async function updateRef(sha) {
|
|
60
|
+
try {
|
|
61
|
+
const res = await octokit.rest.git.updateRef({
|
|
62
|
+
owner: 'backport-org',
|
|
63
|
+
repo: 'repo-with-programatically-added-commits',
|
|
64
|
+
ref: 'heads/main',
|
|
65
|
+
sha,
|
|
66
|
+
});
|
|
67
|
+
return res.data;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
console.log(e);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function createCommit({ latestCommitSha, commitMessage, treeSha, }) {
|
|
74
|
+
const res = await octokit.rest.git.createCommit({
|
|
75
|
+
owner: 'backport-org',
|
|
76
|
+
repo: 'repo-with-programatically-added-commits',
|
|
77
|
+
message: commitMessage,
|
|
78
|
+
parents: [latestCommitSha],
|
|
79
|
+
tree: treeSha,
|
|
80
|
+
});
|
|
81
|
+
return res.data.sha;
|
|
82
|
+
}
|
|
83
|
+
async function createTree(files) {
|
|
84
|
+
const res = await octokit.git.createTree({
|
|
85
|
+
owner: 'backport-org',
|
|
86
|
+
repo: 'repo-with-programatically-added-commits',
|
|
87
|
+
tree: files.map((f) => {
|
|
88
|
+
return {
|
|
89
|
+
path: f.path,
|
|
90
|
+
sha: f.sha,
|
|
91
|
+
mode: '100644',
|
|
92
|
+
type: 'blob',
|
|
93
|
+
};
|
|
94
|
+
}),
|
|
95
|
+
});
|
|
96
|
+
return res.data.sha;
|
|
97
|
+
}
|
|
98
|
+
async function createBlob(content) {
|
|
99
|
+
const res = await octokit.rest.git.createBlob({
|
|
100
|
+
owner: 'backport-org',
|
|
101
|
+
repo: 'repo-with-programatically-added-commits',
|
|
102
|
+
content: content,
|
|
103
|
+
encoding: 'utf-8',
|
|
104
|
+
});
|
|
105
|
+
return res.data.sha;
|
|
106
|
+
}
|
|
107
|
+
async function getLatestCommitSha() {
|
|
108
|
+
const res = await octokit.repos.getBranch({
|
|
109
|
+
owner: 'backport-org',
|
|
110
|
+
repo: 'repo-with-programatically-added-commits',
|
|
111
|
+
branch: 'main',
|
|
112
|
+
});
|
|
113
|
+
return res.data.commit.sha;
|
|
114
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
declare type RunBackportOptions = {
|
|
2
2
|
timeoutSeconds?: number;
|
|
3
3
|
showOra?: boolean;
|
|
4
4
|
waitForString?: string;
|
|
5
5
|
cwd?: string;
|
|
6
|
-
|
|
6
|
+
keepAlive?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function runBackportViaCli(backportArgs: string[], runBackportOptions?: RunBackportOptions): Promise<{
|
|
7
9
|
output: string;
|
|
8
10
|
code: number | null;
|
|
11
|
+
keypress: (keyCode: "up" | "down" | "enter", runBackportOptions?: RunBackportOptions | undefined) => Promise<{
|
|
12
|
+
output: string;
|
|
13
|
+
}>;
|
|
9
14
|
}>;
|
|
15
|
+
export {};
|
|
@@ -9,10 +9,11 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
10
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
11
11
|
const sandbox_1 = require("../../sandbox");
|
|
12
|
+
const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
|
|
13
|
+
const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
|
|
12
14
|
jest.setTimeout(15000);
|
|
13
|
-
function runBackportViaCli(backportArgs,
|
|
14
|
-
const
|
|
15
|
-
const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
|
|
15
|
+
function runBackportViaCli(backportArgs, runBackportOptions = {}) {
|
|
16
|
+
const chunks = '';
|
|
16
17
|
const randomString = Math.random().toString(36).slice(2);
|
|
17
18
|
const sandboxPath = (0, sandbox_1.getSandboxPath)({
|
|
18
19
|
filename: __filename,
|
|
@@ -28,30 +29,52 @@ function runBackportViaCli(backportArgs, { timeoutSeconds = 3, showOra, waitForS
|
|
|
28
29
|
: [`--dir=${sandboxPath}`]),
|
|
29
30
|
...backportArgs,
|
|
30
31
|
];
|
|
31
|
-
const proc = (0, child_process_1.spawn)(tsNodeBinary, cmdArgs, { cwd });
|
|
32
|
+
const proc = (0, child_process_1.spawn)(tsNodeBinary, cmdArgs, { cwd: runBackportOptions.cwd });
|
|
33
|
+
return getPromise(proc, runBackportOptions, cmdArgs, chunks);
|
|
34
|
+
}
|
|
35
|
+
exports.runBackportViaCli = runBackportViaCli;
|
|
36
|
+
const keyCodeMap = {
|
|
37
|
+
down: '\x1B\x5B\x42',
|
|
38
|
+
up: '\x1B\x5B\x41',
|
|
39
|
+
enter: '\x0D',
|
|
40
|
+
};
|
|
41
|
+
function getPromise(proc, runBackportOptions, cmdArgs, chunks) {
|
|
42
|
+
if (proc.killed) {
|
|
43
|
+
throw new Error('Process is already killed. Did you forget `keepAlive: true`?');
|
|
44
|
+
}
|
|
45
|
+
const { timeoutSeconds = 3, waitForString, showOra, keepAlive, } = runBackportOptions;
|
|
32
46
|
return new Promise((resolve, reject) => {
|
|
33
|
-
let data = '';
|
|
34
47
|
const postponeTimeout = (0, lodash_1.debounce)(() => {
|
|
35
|
-
const
|
|
48
|
+
const formattedChunks = formatChunk(chunks);
|
|
36
49
|
const cmd = [tsNodeBinary, ...cmdArgs].join(' ');
|
|
37
50
|
reject(waitForString
|
|
38
|
-
? `Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${
|
|
39
|
-
: `
|
|
40
|
-
}, timeoutSeconds * 1000, { maxWait:
|
|
41
|
-
function
|
|
51
|
+
? `Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${formattedChunks}\n\nCommand: ${cmd}`
|
|
52
|
+
: `Process did not complete within ${timeoutSeconds} seconds. Received:\n${formattedChunks}\n\nCommand: ${cmd}`);
|
|
53
|
+
}, timeoutSeconds * 1000, { maxWait: 10000 });
|
|
54
|
+
function formatChunk(data) {
|
|
42
55
|
return (0, strip_ansi_1.default)(data.toString()).trim();
|
|
43
56
|
}
|
|
57
|
+
function keypress(keyCode, runBackportOptions = {}) {
|
|
58
|
+
const p = getPromise(proc, runBackportOptions, cmdArgs, chunks);
|
|
59
|
+
proc.stdin.write(keyCodeMap[keyCode]);
|
|
60
|
+
return p;
|
|
61
|
+
}
|
|
44
62
|
const onChunk = (chunk) => {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
if (waitForString &&
|
|
63
|
+
chunks += chunk;
|
|
64
|
+
const formattedChunk = formatChunk(chunk);
|
|
65
|
+
if (waitForString && formattedChunk.includes(waitForString)) {
|
|
48
66
|
postponeTimeout.cancel();
|
|
49
|
-
resolve({ output, code: null });
|
|
67
|
+
resolve({ output: formatChunk(chunks), code: null, keypress });
|
|
50
68
|
}
|
|
51
69
|
};
|
|
52
70
|
proc.on('exit', (code) => {
|
|
53
71
|
postponeTimeout.cancel();
|
|
54
|
-
|
|
72
|
+
if (waitForString) {
|
|
73
|
+
reject(`runBackportViaCli exited before finding: ${waitForString}. Output: ${formatChunk(chunks)}`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
resolve({ output: formatChunk(chunks), code, keypress });
|
|
77
|
+
}
|
|
55
78
|
});
|
|
56
79
|
proc.stdout.on('data', (chunk) => {
|
|
57
80
|
postponeTimeout();
|
|
@@ -68,7 +91,14 @@ function runBackportViaCli(backportArgs, { timeoutSeconds = 3, showOra, waitForS
|
|
|
68
91
|
reject(`runBackportViaCli failed with: ${err}`);
|
|
69
92
|
});
|
|
70
93
|
}).finally(() => {
|
|
71
|
-
|
|
94
|
+
if (!keepAlive) {
|
|
95
|
+
proc.kill();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
proc.removeAllListeners('exit');
|
|
99
|
+
proc.stdout.removeAllListeners('data');
|
|
100
|
+
proc.stderr.removeAllListeners('data');
|
|
101
|
+
proc.removeAllListeners('errors');
|
|
102
|
+
}
|
|
72
103
|
});
|
|
73
104
|
}
|
|
74
|
-
exports.runBackportViaCli = runBackportViaCli;
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const child_process_promisified_1 = require("../../../lib/child-process-promisified");
|
|
4
4
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
5
|
+
const replaceStringAndLinebreaks_1 = require("../../replaceStringAndLinebreaks");
|
|
5
6
|
const sandbox_1 = require("../../sandbox");
|
|
6
7
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
7
8
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
jest.setTimeout(15000);
|
|
8
10
|
describe('test-that-repo-can-be-cloned', () => {
|
|
9
11
|
describe('when local repo does not exist', () => {
|
|
10
12
|
let sandboxPath;
|
|
@@ -75,7 +77,11 @@ describe('test-that-repo-can-be-cloned', () => {
|
|
|
75
77
|
}
|
|
76
78
|
it('clones using the local repo', async () => {
|
|
77
79
|
const { output } = await run();
|
|
78
|
-
expect(
|
|
80
|
+
expect((0, replaceStringAndLinebreaks_1.replaceStringAndLinebreaks)({
|
|
81
|
+
haystack: output,
|
|
82
|
+
stringBefore: sourceRepo,
|
|
83
|
+
stringAfter: '<SOURCE_REPO>',
|
|
84
|
+
})).toContain('✔ 100% Cloning repository from <SOURCE_REPO> (one-time operation)');
|
|
79
85
|
});
|
|
80
86
|
});
|
|
81
87
|
});
|
|
@@ -8,7 +8,7 @@ const sandbox_1 = require("../../sandbox");
|
|
|
8
8
|
jest.unmock('find-up');
|
|
9
9
|
jest.unmock('del');
|
|
10
10
|
jest.unmock('make-dir');
|
|
11
|
-
jest.setTimeout(
|
|
11
|
+
jest.setTimeout(15000);
|
|
12
12
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
13
13
|
const octokit = new rest_1.Octokit({ auth: accessToken });
|
|
14
14
|
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
@@ -5,7 +5,7 @@ const getDevAccessToken_1 = require("./private/getDevAccessToken");
|
|
|
5
5
|
const sandbox_1 = require("./sandbox");
|
|
6
6
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
7
7
|
jest.unmock('find-up');
|
|
8
|
-
jest.setTimeout(
|
|
8
|
+
jest.setTimeout(20000);
|
|
9
9
|
describe('Handle unbackported pull requests', () => {
|
|
10
10
|
it('shows missing backports for PR number 8', async () => {
|
|
11
11
|
const commits = await (0, entrypoint_module_1.getCommits)({
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceStringAndLinebreaks = void 0;
|
|
4
|
+
function replaceStringAndLinebreaks({ haystack, stringBefore, stringAfter, }) {
|
|
5
|
+
const regex = stringBefore.split('').join('\\s?');
|
|
6
|
+
return haystack.replace(new RegExp(regex, 'g'), stringAfter);
|
|
7
|
+
}
|
|
8
|
+
exports.replaceStringAndLinebreaks = replaceStringAndLinebreaks;
|
package/dist/test/sandbox.js
CHANGED
|
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.resetSandbox = exports.getSandboxPath = void 0;
|
|
30
|
+
const os_1 = require("os");
|
|
30
31
|
const path_1 = __importStar(require("path"));
|
|
31
32
|
const del_1 = __importDefault(require("del"));
|
|
32
33
|
const make_dir_1 = __importDefault(require("make-dir"));
|
|
@@ -34,11 +35,14 @@ jest.unmock('make-dir');
|
|
|
34
35
|
jest.unmock('del');
|
|
35
36
|
function getSandboxPath({ filename, specname, }) {
|
|
36
37
|
const baseFilename = getFilenameWithoutExtension(filename);
|
|
37
|
-
return (0, path_1.resolve)(`${
|
|
38
|
+
return (0, path_1.resolve)(`${(0, os_1.homedir)()}/.backport_testing/${baseFilename}${specname ? `/${specname}` : ''}`);
|
|
38
39
|
}
|
|
39
40
|
exports.getSandboxPath = getSandboxPath;
|
|
40
41
|
async function resetSandbox(sandboxPath) {
|
|
41
|
-
|
|
42
|
+
if (sandboxPath.length < 30) {
|
|
43
|
+
throw new Error(`sandboxPath "${sandboxPath}" is too short. Reset aborted`);
|
|
44
|
+
}
|
|
45
|
+
await (0, del_1.default)(sandboxPath, { force: true });
|
|
42
46
|
await (0, make_dir_1.default)(sandboxPath);
|
|
43
47
|
}
|
|
44
48
|
exports.resetSandbox = resetSandbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "8.
|
|
1
|
+
export declare const PACKAGE_VERSION = "8.4.2";
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"branches",
|
|
15
15
|
"branching"
|
|
16
16
|
],
|
|
17
|
-
"version": "8.
|
|
17
|
+
"version": "8.4.2",
|
|
18
18
|
"main": "./dist/entrypoint.module.js",
|
|
19
19
|
"types": "dist/entrypoint.module.d.ts",
|
|
20
20
|
"bin": {
|
|
@@ -25,16 +25,15 @@
|
|
|
25
25
|
"postinstall": "test -f ./dist/scripts/runPostinstall.js && node ./dist/scripts/runPostinstall.js || echo 'Dist folder missing'",
|
|
26
26
|
"version": "echo \"Bumping version\" && yarn extractPackageVersion && git add src/utils/packageVersion.ts && yarn tsc",
|
|
27
27
|
"prepare": "husky install",
|
|
28
|
-
"prepublishOnly": "yarn lint && yarn tsc",
|
|
28
|
+
"prepublishOnly": "rm -rf ./dist/ && yarn lint && yarn tsc",
|
|
29
29
|
"extractPackageVersion": "node -p \"'export const PACKAGE_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" | prettier --parser typescript > src/utils/packageVersion.ts",
|
|
30
30
|
"lint-and-test": "yarn tsc && yarn lint && yarn test-all",
|
|
31
31
|
"lint": "echo \"Running lint\" && eslint './**/*.{ts,js}'",
|
|
32
32
|
"start": "ts-node --transpile-only ./src/entrypoint.cli.ts",
|
|
33
|
-
"test-all": "
|
|
33
|
+
"test-all": "jest --config ./jest.config.all.js",
|
|
34
34
|
"test-mutation": "jest --config ./jest.config.mutation.js",
|
|
35
35
|
"test-private": "jest --config ./jest.config.private.js",
|
|
36
|
-
"test": "jest"
|
|
37
|
-
"docker-run": "./docker/build-and-run-dockerfile.sh"
|
|
36
|
+
"test": "jest"
|
|
38
37
|
},
|
|
39
38
|
"lint-staged": {
|
|
40
39
|
"*.ts": [
|
|
@@ -65,14 +64,14 @@
|
|
|
65
64
|
},
|
|
66
65
|
"dependencies": {
|
|
67
66
|
"@octokit/rest": "^18.12.0",
|
|
68
|
-
"axios": "^0.
|
|
67
|
+
"axios": "^0.27.2",
|
|
69
68
|
"dedent": "^0.7.0",
|
|
70
69
|
"del": "^6.0.0",
|
|
71
|
-
"dotenv": "^16.0.
|
|
70
|
+
"dotenv": "^16.0.1",
|
|
72
71
|
"find-up": "^5.0.0",
|
|
73
|
-
"graphql": "^16.
|
|
72
|
+
"graphql": "^16.5.0",
|
|
74
73
|
"graphql-tag": "^2.12.6",
|
|
75
|
-
"inquirer": "^8.2.
|
|
74
|
+
"inquirer": "^8.2.3",
|
|
76
75
|
"lodash": "^4.17.21",
|
|
77
76
|
"make-dir": "^3.1.0",
|
|
78
77
|
"ora": "^5.4.1",
|
|
@@ -80,36 +79,36 @@
|
|
|
80
79
|
"strip-json-comments": "^3.1.1",
|
|
81
80
|
"terminal-link": "^2.1.1",
|
|
82
81
|
"utility-types": "^3.10.0",
|
|
83
|
-
"winston": "^3.
|
|
84
|
-
"yargs": "^17.
|
|
82
|
+
"winston": "^3.7.2",
|
|
83
|
+
"yargs": "^17.5.1",
|
|
85
84
|
"yargs-parser": "^21.0.1"
|
|
86
85
|
},
|
|
87
86
|
"devDependencies": {
|
|
88
87
|
"@types/core-js": "^2.5.5",
|
|
89
88
|
"@types/dedent": "^0.7.0",
|
|
90
89
|
"@types/inquirer": "^8.2.1",
|
|
91
|
-
"@types/jest": "^27.
|
|
92
|
-
"@types/lodash": "^4.14.
|
|
93
|
-
"@types/node": "^17.0.
|
|
90
|
+
"@types/jest": "^27.5.1",
|
|
91
|
+
"@types/lodash": "^4.14.182",
|
|
92
|
+
"@types/node": "^17.0.34",
|
|
94
93
|
"@types/safe-json-stringify": "^1.1.2",
|
|
95
94
|
"@types/yargs": "^17.0.10",
|
|
96
95
|
"@types/yargs-parser": "^21.0.0",
|
|
97
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
98
|
-
"@typescript-eslint/parser": "^5.
|
|
99
|
-
"eslint": "^8.
|
|
96
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
97
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
98
|
+
"eslint": "^8.15.0",
|
|
100
99
|
"eslint-config-prettier": "^8.5.0",
|
|
101
|
-
"eslint-plugin-import": "^2.
|
|
102
|
-
"eslint-plugin-jest": "^26.
|
|
100
|
+
"eslint-plugin-import": "^2.26.0",
|
|
101
|
+
"eslint-plugin-jest": "^26.2.2",
|
|
103
102
|
"eslint-plugin-prettier": "^4.0.0",
|
|
104
|
-
"graphql-config": "^4.
|
|
105
|
-
"husky": "^
|
|
106
|
-
"jest": "^
|
|
103
|
+
"graphql-config": "^4.3.0",
|
|
104
|
+
"husky": "^8.0.1",
|
|
105
|
+
"jest": "^28.1.0",
|
|
107
106
|
"jest-snapshot-serializer-ansi": "^1.0.0",
|
|
108
|
-
"lint-staged": "^12.
|
|
107
|
+
"lint-staged": "^12.4.1",
|
|
109
108
|
"nock": "^13.2.4",
|
|
110
109
|
"prettier": "^2.6.2",
|
|
111
110
|
"strip-ansi": "^6.0.1",
|
|
112
|
-
"ts-jest": "^
|
|
111
|
+
"ts-jest": "^28.0.2",
|
|
113
112
|
"ts-node": "^10.7.0",
|
|
114
113
|
"typescript": "^4.6.3"
|
|
115
114
|
}
|