backport 8.3.0 → 8.4.1
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/backportRun.js +1 -1
- package/dist/entrypoint.module.d.ts +2 -2
- package/dist/entrypoint.module.js +2 -0
- package/dist/entrypoint.module.private.test.js +11 -10
- package/dist/lib/cherrypickAndCreateTargetPullRequest.js +30 -20
- package/dist/lib/child-process-promisified.js +2 -2
- package/dist/lib/getCommits.js +1 -1
- package/dist/lib/git.d.ts +1 -1
- package/dist/lib/git.js +8 -28
- package/dist/lib/git.private.test.js +7 -7
- package/dist/lib/git.test.js +28 -12
- package/dist/lib/github/v3/createStatusComment.js +3 -2
- package/dist/lib/github/v3/createStatusComment.test.js +61 -0
- package/dist/lib/github/v4/apiRequestV4.js +1 -1
- package/dist/lib/github/v4/enablePullRequestAutoMerge.js +2 -1
- package/dist/{entrypoint.cli.private.test.d.ts → lib/github/v4/enablePullRequestAutoMerge.mutation.test.d.ts} +0 -0
- package/dist/lib/github/v4/{enablePullRequestAutoMerge.private.test.js → enablePullRequestAutoMerge.mutation.test.js} +34 -8
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +6 -3
- package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +0 -1
- package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +5 -6
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +7 -3
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +2 -0
- package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +23 -7
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +2 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +1 -0
- package/dist/lib/github/v4/getOptionsFromGithub/query.js +1 -0
- package/dist/lib/ora.d.ts +1 -0
- package/dist/lib/remoteConfig.d.ts +1 -1
- package/dist/lib/remoteConfig.js +4 -0
- package/dist/options/ConfigOptions.d.ts +1 -0
- package/dist/options/cliArgs.d.ts +3 -2
- package/dist/options/cliArgs.js +21 -6
- package/dist/options/config/config.d.ts +1 -0
- package/dist/options/config/readConfigFile.d.ts +1 -0
- package/dist/options/options.d.ts +5 -2
- package/dist/options/options.js +3 -3
- package/dist/options/options.test.js +7 -4
- package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/date-filters.private.test.d.ts} +0 -0
- package/dist/test/e2e/cli/date-filters.private.test.js +48 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +120 -4
- package/dist/test/e2e/cli/entrypoint.cli.private.test.js +4 -18
- package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +2 -1
- package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
- 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 +1 -0
- package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
- package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +20 -21
- package/yarn.lock +210 -220
- 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/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/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
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const rest_1 = require("@octokit/rest");
|
|
4
|
-
const entrypoint_module_1 = require("../../entrypoint.module");
|
|
5
|
-
const commitFormatters_1 = require("../../services/github/commitFormatters");
|
|
6
|
-
const getDevAccessToken_1 = require("../private/getDevAccessToken");
|
|
7
|
-
const sandbox_1 = require("../sandbox");
|
|
8
|
-
jest.unmock('find-up');
|
|
9
|
-
jest.unmock('del');
|
|
10
|
-
jest.unmock('make-dir');
|
|
11
|
-
jest.setTimeout(15000);
|
|
12
|
-
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
13
|
-
const octokit = new rest_1.Octokit({ auth: accessToken });
|
|
14
|
-
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
15
|
-
// repo
|
|
16
|
-
const REPO_OWNER = 'backport-org';
|
|
17
|
-
const REPO_NAME = 'integration-test';
|
|
18
|
-
const AUTHOR = 'sqren';
|
|
19
|
-
// commit 1
|
|
20
|
-
const COMMIT_SHA_1 = '5bf29b7d847ea3dbde9280448f0f62ad0f22d3ad';
|
|
21
|
-
const BRANCH_WITH_ONE_COMMIT = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}`;
|
|
22
|
-
// commit 2
|
|
23
|
-
const COMMIT_SHA_2 = '59d6ff1ca90a4ce210c0a4f0e159214875c19d60';
|
|
24
|
-
const BRANCH_WITH_TWO_COMMITS = `backport/7.x/commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_1)}_commit-${(0, commitFormatters_1.getShortSha)(COMMIT_SHA_2)}`;
|
|
25
|
-
describe('backport e2e', () => {
|
|
26
|
-
describe('when a single commit is backported', () => {
|
|
27
|
-
let res;
|
|
28
|
-
let pullRequestResponse;
|
|
29
|
-
beforeAll(async () => {
|
|
30
|
-
await resetState(accessToken);
|
|
31
|
-
res = await (0, entrypoint_module_1.backportRun)({
|
|
32
|
-
dir: sandboxPath,
|
|
33
|
-
accessToken,
|
|
34
|
-
repoOwner: 'backport-org',
|
|
35
|
-
repoName: 'integration-test',
|
|
36
|
-
sha: COMMIT_SHA_1,
|
|
37
|
-
targetBranches: ['7.x'],
|
|
38
|
-
});
|
|
39
|
-
// @ts-expect-error
|
|
40
|
-
const pullRequestNumber = res.results[0].pullRequestNumber;
|
|
41
|
-
pullRequestResponse = await octokit.pulls.get({
|
|
42
|
-
owner: REPO_OWNER,
|
|
43
|
-
repo: REPO_NAME,
|
|
44
|
-
pull_number: pullRequestNumber,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
it('returns the backport result', () => {
|
|
48
|
-
expect(res).toEqual({
|
|
49
|
-
commits: [
|
|
50
|
-
{
|
|
51
|
-
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
52
|
-
expectedTargetPullRequests: [],
|
|
53
|
-
sourceBranch: 'master',
|
|
54
|
-
sourceCommit: {
|
|
55
|
-
committedDate: '2020-08-15T10:37:41Z',
|
|
56
|
-
message: 'Add ❤️ emoji',
|
|
57
|
-
sha: COMMIT_SHA_1,
|
|
58
|
-
},
|
|
59
|
-
sourcePullRequest: undefined,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
results: [
|
|
63
|
-
{
|
|
64
|
-
didUpdate: false,
|
|
65
|
-
pullRequestNumber: expect.any(Number),
|
|
66
|
-
pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
|
|
67
|
-
status: 'success',
|
|
68
|
-
targetBranch: '7.x',
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
status: 'success',
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
it('pull request: status code', async () => {
|
|
75
|
-
expect(pullRequestResponse.status).toEqual(200);
|
|
76
|
-
});
|
|
77
|
-
it('pull request: title', async () => {
|
|
78
|
-
expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
|
|
79
|
-
});
|
|
80
|
-
it('pull request: body', async () => {
|
|
81
|
-
expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
|
|
82
|
-
"# Backport
|
|
83
|
-
|
|
84
|
-
This will backport the following commits from \`master\` to \`7.x\`:
|
|
85
|
-
- Add ❤️ emoji (5bf29b7d)
|
|
86
|
-
|
|
87
|
-
<!--- Backport version: 1.2.3-mocked -->
|
|
88
|
-
|
|
89
|
-
### Questions ?
|
|
90
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
91
|
-
`);
|
|
92
|
-
});
|
|
93
|
-
it('pull request: head branch is in fork repo', async () => {
|
|
94
|
-
expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_ONE_COMMIT}`);
|
|
95
|
-
});
|
|
96
|
-
it('pull request: base branch', async () => {
|
|
97
|
-
expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
|
|
98
|
-
});
|
|
99
|
-
it('does not create any new branches in origin (backport-org/integration-test)', async () => {
|
|
100
|
-
const branches = await getBranchesOnGithub({
|
|
101
|
-
accessToken,
|
|
102
|
-
repoOwner: REPO_OWNER,
|
|
103
|
-
repoName: REPO_NAME,
|
|
104
|
-
});
|
|
105
|
-
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
106
|
-
});
|
|
107
|
-
it('creates a branch in the fork (sqren/integration-test)', async () => {
|
|
108
|
-
const branches = await getBranchesOnGithub({
|
|
109
|
-
accessToken,
|
|
110
|
-
repoOwner: AUTHOR,
|
|
111
|
-
repoName: REPO_NAME,
|
|
112
|
-
});
|
|
113
|
-
expect(branches.map((b) => b.name)).toEqual([
|
|
114
|
-
'7.x',
|
|
115
|
-
BRANCH_WITH_ONE_COMMIT,
|
|
116
|
-
'master',
|
|
117
|
-
]);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
describe('when two commits are backported', () => {
|
|
121
|
-
let res;
|
|
122
|
-
let pullRequestResponse;
|
|
123
|
-
beforeAll(async () => {
|
|
124
|
-
await resetState(accessToken);
|
|
125
|
-
res = await (0, entrypoint_module_1.backportRun)({
|
|
126
|
-
dir: sandboxPath,
|
|
127
|
-
accessToken,
|
|
128
|
-
repoOwner: 'backport-org',
|
|
129
|
-
repoName: 'integration-test',
|
|
130
|
-
sha: [COMMIT_SHA_1, COMMIT_SHA_2],
|
|
131
|
-
targetBranches: ['7.x'],
|
|
132
|
-
});
|
|
133
|
-
// @ts-expect-error
|
|
134
|
-
const pullRequestNumber = res.results[0].pullRequestNumber;
|
|
135
|
-
pullRequestResponse = await octokit.pulls.get({
|
|
136
|
-
owner: REPO_OWNER,
|
|
137
|
-
repo: REPO_NAME,
|
|
138
|
-
pull_number: pullRequestNumber,
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
it('returns the backport result containing both commits', () => {
|
|
142
|
-
expect(res).toEqual({
|
|
143
|
-
commits: [
|
|
144
|
-
{
|
|
145
|
-
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
146
|
-
expectedTargetPullRequests: [],
|
|
147
|
-
sourceBranch: 'master',
|
|
148
|
-
sourceCommit: {
|
|
149
|
-
committedDate: '2020-08-15T10:37:41Z',
|
|
150
|
-
message: 'Add ❤️ emoji',
|
|
151
|
-
sha: COMMIT_SHA_1,
|
|
152
|
-
},
|
|
153
|
-
sourcePullRequest: undefined,
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
157
|
-
expectedTargetPullRequests: [],
|
|
158
|
-
sourceBranch: 'master',
|
|
159
|
-
sourceCommit: {
|
|
160
|
-
committedDate: '2020-08-15T10:44:04Z',
|
|
161
|
-
message: 'Add family emoji (#2)',
|
|
162
|
-
sha: COMMIT_SHA_2,
|
|
163
|
-
},
|
|
164
|
-
sourcePullRequest: undefined,
|
|
165
|
-
},
|
|
166
|
-
],
|
|
167
|
-
results: [
|
|
168
|
-
{
|
|
169
|
-
didUpdate: false,
|
|
170
|
-
pullRequestNumber: expect.any(Number),
|
|
171
|
-
pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
|
|
172
|
-
status: 'success',
|
|
173
|
-
targetBranch: '7.x',
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
status: 'success',
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
it('pull request: status code', async () => {
|
|
180
|
-
expect(pullRequestResponse.status).toEqual(200);
|
|
181
|
-
});
|
|
182
|
-
it('pull request: title', async () => {
|
|
183
|
-
expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji | Add family emoji (#2)');
|
|
184
|
-
});
|
|
185
|
-
it('pull request: body', async () => {
|
|
186
|
-
expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
|
|
187
|
-
"# Backport
|
|
188
|
-
|
|
189
|
-
This will backport the following commits from \`master\` to \`7.x\`:
|
|
190
|
-
- Add ❤️ emoji (5bf29b7d)
|
|
191
|
-
- Add family emoji (#2) (59d6ff1c)
|
|
192
|
-
|
|
193
|
-
<!--- Backport version: 1.2.3-mocked -->
|
|
194
|
-
|
|
195
|
-
### Questions ?
|
|
196
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
197
|
-
`);
|
|
198
|
-
});
|
|
199
|
-
it('pull request: head branch contains both commits in name', async () => {
|
|
200
|
-
expect(pullRequestResponse.data.head.label).toEqual(`sqren:${BRANCH_WITH_TWO_COMMITS}`);
|
|
201
|
-
});
|
|
202
|
-
it('pull request: base branch', async () => {
|
|
203
|
-
expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
describe('when disabling fork mode', () => {
|
|
207
|
-
let res;
|
|
208
|
-
let pullRequestResponse;
|
|
209
|
-
beforeAll(async () => {
|
|
210
|
-
await resetState(accessToken);
|
|
211
|
-
res = await (0, entrypoint_module_1.backportRun)({
|
|
212
|
-
fork: false,
|
|
213
|
-
dir: sandboxPath,
|
|
214
|
-
accessToken,
|
|
215
|
-
repoOwner: 'backport-org',
|
|
216
|
-
repoName: 'integration-test',
|
|
217
|
-
sha: COMMIT_SHA_1,
|
|
218
|
-
targetBranches: ['7.x'],
|
|
219
|
-
});
|
|
220
|
-
// @ts-expect-error
|
|
221
|
-
const pullRequestNumber = res.results[0].pullRequestNumber;
|
|
222
|
-
pullRequestResponse = await octokit.pulls.get({
|
|
223
|
-
owner: REPO_OWNER,
|
|
224
|
-
repo: REPO_NAME,
|
|
225
|
-
pull_number: pullRequestNumber,
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
it('pull request: title', async () => {
|
|
229
|
-
expect(pullRequestResponse.data.title).toEqual('[7.x] Add ❤️ emoji');
|
|
230
|
-
});
|
|
231
|
-
it('pull request: body', async () => {
|
|
232
|
-
expect(pullRequestResponse.data.body).toMatchInlineSnapshot(`
|
|
233
|
-
"# Backport
|
|
234
|
-
|
|
235
|
-
This will backport the following commits from \`master\` to \`7.x\`:
|
|
236
|
-
- Add ❤️ emoji (5bf29b7d)
|
|
237
|
-
|
|
238
|
-
<!--- Backport version: 1.2.3-mocked -->
|
|
239
|
-
|
|
240
|
-
### Questions ?
|
|
241
|
-
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
242
|
-
`);
|
|
243
|
-
});
|
|
244
|
-
it('pull request: head branch is in origin (non-fork) repo', async () => {
|
|
245
|
-
expect(pullRequestResponse.data.head.label).toEqual(`backport-org:${BRANCH_WITH_ONE_COMMIT}`);
|
|
246
|
-
});
|
|
247
|
-
it('pull request: base branch', async () => {
|
|
248
|
-
expect(pullRequestResponse.data.base.label).toEqual('backport-org:7.x');
|
|
249
|
-
});
|
|
250
|
-
it('returns pull request', () => {
|
|
251
|
-
expect(res).toEqual({
|
|
252
|
-
commits: [
|
|
253
|
-
{
|
|
254
|
-
author: { email: 'sorenlouv@gmail.com', name: 'Søren Louv-Jansen' },
|
|
255
|
-
expectedTargetPullRequests: [],
|
|
256
|
-
sourceBranch: 'master',
|
|
257
|
-
sourceCommit: {
|
|
258
|
-
committedDate: '2020-08-15T10:37:41Z',
|
|
259
|
-
message: 'Add ❤️ emoji',
|
|
260
|
-
sha: COMMIT_SHA_1,
|
|
261
|
-
},
|
|
262
|
-
sourcePullRequest: undefined,
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
results: [
|
|
266
|
-
{
|
|
267
|
-
didUpdate: false,
|
|
268
|
-
pullRequestNumber: expect.any(Number),
|
|
269
|
-
pullRequestUrl: expect.stringContaining('https://github.com/backport-org/integration-test/pull/'),
|
|
270
|
-
status: 'success',
|
|
271
|
-
targetBranch: '7.x',
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
status: 'success',
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
it('creates a new branch in origin (backport-org/integration-test)', async () => {
|
|
278
|
-
const branches = await getBranchesOnGithub({
|
|
279
|
-
accessToken,
|
|
280
|
-
repoOwner: REPO_OWNER,
|
|
281
|
-
repoName: REPO_NAME,
|
|
282
|
-
});
|
|
283
|
-
expect(branches.map((b) => b.name)).toEqual([
|
|
284
|
-
'7.x',
|
|
285
|
-
BRANCH_WITH_ONE_COMMIT,
|
|
286
|
-
'master',
|
|
287
|
-
]);
|
|
288
|
-
});
|
|
289
|
-
it('does not create branches in the fork (sqren/integration-test)', async () => {
|
|
290
|
-
const branches = await getBranchesOnGithub({
|
|
291
|
-
accessToken,
|
|
292
|
-
repoOwner: AUTHOR,
|
|
293
|
-
repoName: REPO_NAME,
|
|
294
|
-
});
|
|
295
|
-
expect(branches.map((b) => b.name)).toEqual(['7.x', 'master']);
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
async function getBranchesOnGithub({ accessToken, repoOwner, repoName, }) {
|
|
300
|
-
// console.log(`fetch branches for ${repoOwner}`);
|
|
301
|
-
const octokit = new rest_1.Octokit({
|
|
302
|
-
auth: accessToken,
|
|
303
|
-
});
|
|
304
|
-
const res = await octokit.repos.listBranches({
|
|
305
|
-
owner: repoOwner,
|
|
306
|
-
repo: repoName,
|
|
307
|
-
});
|
|
308
|
-
return res.data;
|
|
309
|
-
}
|
|
310
|
-
async function deleteBranchOnGithub({ accessToken, repoOwner, repoName, branchName, }) {
|
|
311
|
-
try {
|
|
312
|
-
const octokit = new rest_1.Octokit({
|
|
313
|
-
auth: accessToken,
|
|
314
|
-
});
|
|
315
|
-
// console.log({ accessToken });
|
|
316
|
-
const opts = {
|
|
317
|
-
owner: repoOwner,
|
|
318
|
-
repo: repoName,
|
|
319
|
-
ref: `heads/${branchName}`,
|
|
320
|
-
};
|
|
321
|
-
const res = await octokit.git.deleteRef(opts);
|
|
322
|
-
// console.log(`Deleted ${repoOwner}:heads/${branchName}`);
|
|
323
|
-
return res.data;
|
|
324
|
-
}
|
|
325
|
-
catch (e) {
|
|
326
|
-
// console.log(
|
|
327
|
-
// `Could not delete ${repoOwner}:heads/${branchName} (${e.message})`
|
|
328
|
-
// );
|
|
329
|
-
if (e.message === 'Reference does not exist') {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
throw e;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
async function resetState(accessToken) {
|
|
336
|
-
const ownerBranches = await getBranchesOnGithub({
|
|
337
|
-
accessToken,
|
|
338
|
-
repoOwner: REPO_OWNER,
|
|
339
|
-
repoName: REPO_NAME,
|
|
340
|
-
});
|
|
341
|
-
// delete all branches except master and 7.x
|
|
342
|
-
await Promise.all(ownerBranches
|
|
343
|
-
.filter((b) => b.name !== 'master' && b.name !== '7.x')
|
|
344
|
-
.map((b) => {
|
|
345
|
-
return deleteBranchOnGithub({
|
|
346
|
-
accessToken,
|
|
347
|
-
repoOwner: REPO_OWNER,
|
|
348
|
-
repoName: REPO_NAME,
|
|
349
|
-
branchName: b.name,
|
|
350
|
-
});
|
|
351
|
-
}));
|
|
352
|
-
const forkBranches = await getBranchesOnGithub({
|
|
353
|
-
accessToken,
|
|
354
|
-
repoOwner: AUTHOR,
|
|
355
|
-
repoName: REPO_NAME,
|
|
356
|
-
});
|
|
357
|
-
// delete all branches except master and 7.x
|
|
358
|
-
await Promise.all(forkBranches
|
|
359
|
-
.filter((b) => b.name !== 'master' && b.name !== '7.x')
|
|
360
|
-
.map((b) => {
|
|
361
|
-
return deleteBranchOnGithub({
|
|
362
|
-
accessToken,
|
|
363
|
-
repoOwner: AUTHOR,
|
|
364
|
-
repoName: REPO_NAME,
|
|
365
|
-
branchName: b.name,
|
|
366
|
-
});
|
|
367
|
-
}));
|
|
368
|
-
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
369
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ValidConfigOptions } from '../options/options';
|
|
2
|
-
import { Commit } from '../services/sourceCommit/parseSourceCommit';
|
|
3
|
-
import { GitConfigAuthor } from './getGitConfigAuthor';
|
|
4
|
-
export declare function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, gitConfigAuthor, }: {
|
|
5
|
-
options: ValidConfigOptions;
|
|
6
|
-
commits: Commit[];
|
|
7
|
-
targetBranch: string;
|
|
8
|
-
gitConfigAuthor?: GitConfigAuthor;
|
|
9
|
-
}): Promise<{
|
|
10
|
-
url: string;
|
|
11
|
-
number: number;
|
|
12
|
-
didUpdate: boolean;
|
|
13
|
-
}>;
|
|
@@ -1,243 +0,0 @@
|
|
|
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
|
-
exports.cherrypickAndCreateTargetPullRequest = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const lodash_1 = require("lodash");
|
|
9
|
-
const BackportError_1 = require("../services/BackportError");
|
|
10
|
-
const child_process_promisified_1 = require("../services/child-process-promisified");
|
|
11
|
-
const env_1 = require("../services/env");
|
|
12
|
-
const git_1 = require("../services/git");
|
|
13
|
-
const commitFormatters_1 = require("../services/github/commitFormatters");
|
|
14
|
-
const addAssigneesToPullRequest_1 = require("../services/github/v3/addAssigneesToPullRequest");
|
|
15
|
-
const addLabelsToPullRequest_1 = require("../services/github/v3/addLabelsToPullRequest");
|
|
16
|
-
const addReviewersToPullRequest_1 = require("../services/github/v3/addReviewersToPullRequest");
|
|
17
|
-
const createPullRequest_1 = require("../services/github/v3/createPullRequest");
|
|
18
|
-
const enablePullRequestAutoMerge_1 = require("../services/github/v4/enablePullRequestAutoMerge");
|
|
19
|
-
const logger_1 = require("../services/logger");
|
|
20
|
-
const prompts_1 = require("../services/prompts");
|
|
21
|
-
const sequentially_1 = require("../services/sequentially");
|
|
22
|
-
const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
|
|
23
|
-
const ora_1 = require("./ora");
|
|
24
|
-
async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBranch, gitConfigAuthor, }) {
|
|
25
|
-
const backportBranch = getBackportBranchName(targetBranch, commits);
|
|
26
|
-
const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
|
|
27
|
-
(0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
|
|
28
|
-
await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
|
|
29
|
-
await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch, gitConfigAuthor));
|
|
30
|
-
if (options.dryRun) {
|
|
31
|
-
(0, ora_1.ora)(options.ci).succeed('Dry run complete');
|
|
32
|
-
return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
|
|
33
|
-
}
|
|
34
|
-
await (0, git_1.pushBackportBranch)({ options, backportBranch });
|
|
35
|
-
await (0, git_1.deleteBackportBranch)({ options, backportBranch });
|
|
36
|
-
const prPayload = {
|
|
37
|
-
owner: options.repoOwner,
|
|
38
|
-
repo: options.repoName,
|
|
39
|
-
title: (0, createPullRequest_1.getTitle)({ options, commits, targetBranch }),
|
|
40
|
-
body: (0, createPullRequest_1.getPullRequestBody)({ options, commits, targetBranch }),
|
|
41
|
-
head: `${repoForkOwner}:${backportBranch}`,
|
|
42
|
-
base: targetBranch, // eg. 7.x
|
|
43
|
-
};
|
|
44
|
-
const targetPullRequest = await (0, createPullRequest_1.createPullRequest)({ options, prPayload });
|
|
45
|
-
// add assignees to target pull request
|
|
46
|
-
const assignees = options.autoAssign
|
|
47
|
-
? [options.authenticatedUsername]
|
|
48
|
-
: options.assignees;
|
|
49
|
-
if (options.assignees.length > 0) {
|
|
50
|
-
await (0, addAssigneesToPullRequest_1.addAssigneesToPullRequest)(options, targetPullRequest.number, assignees);
|
|
51
|
-
}
|
|
52
|
-
// add reviewers to target pull request
|
|
53
|
-
if (options.reviewers.length > 0) {
|
|
54
|
-
await (0, addReviewersToPullRequest_1.addReviewersToPullRequest)(options, targetPullRequest.number, options.reviewers);
|
|
55
|
-
}
|
|
56
|
-
// add labels to target pull request
|
|
57
|
-
if (options.targetPRLabels.length > 0) {
|
|
58
|
-
await (0, addLabelsToPullRequest_1.addLabelsToPullRequest)(options, targetPullRequest.number, options.targetPRLabels);
|
|
59
|
-
}
|
|
60
|
-
// make PR auto mergable
|
|
61
|
-
if (options.autoMerge) {
|
|
62
|
-
await (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)(options, targetPullRequest.number);
|
|
63
|
-
}
|
|
64
|
-
// add labels to source pull requests
|
|
65
|
-
if (options.sourcePRLabels.length > 0) {
|
|
66
|
-
const promises = commits.map((commit) => {
|
|
67
|
-
if (commit.sourcePullRequest) {
|
|
68
|
-
return (0, addLabelsToPullRequest_1.addLabelsToPullRequest)(options, commit.sourcePullRequest.number, options.sourcePRLabels);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
await Promise.all(promises);
|
|
72
|
-
}
|
|
73
|
-
(0, logger_1.consoleLog)(`View pull request: ${targetPullRequest.url}`);
|
|
74
|
-
return targetPullRequest;
|
|
75
|
-
}
|
|
76
|
-
exports.cherrypickAndCreateTargetPullRequest = cherrypickAndCreateTargetPullRequest;
|
|
77
|
-
/*
|
|
78
|
-
* Returns the name of the backport branch without remote name
|
|
79
|
-
*
|
|
80
|
-
* Examples:
|
|
81
|
-
* For a single PR: `backport/7.x/pr-1234`
|
|
82
|
-
* For a single commit: `backport/7.x/commit-abcdef`
|
|
83
|
-
* For multiple: `backport/7.x/pr-1234_commit-abcdef`
|
|
84
|
-
*/
|
|
85
|
-
function getBackportBranchName(targetBranch, commits) {
|
|
86
|
-
const refValues = commits
|
|
87
|
-
.map((commit) => commit.sourcePullRequest
|
|
88
|
-
? `pr-${commit.sourcePullRequest.number}`
|
|
89
|
-
: `commit-${(0, commitFormatters_1.getShortSha)(commit.sourceCommit.sha)}`)
|
|
90
|
-
.join('_')
|
|
91
|
-
.slice(0, 200);
|
|
92
|
-
return `backport/${targetBranch}/${refValues}`;
|
|
93
|
-
}
|
|
94
|
-
async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor) {
|
|
95
|
-
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
|
|
96
|
-
const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
97
|
-
const cherrypickSpinner = (0, ora_1.ora)(options.ci, spinnerText).start();
|
|
98
|
-
let conflictingFiles;
|
|
99
|
-
let unstagedFiles;
|
|
100
|
-
let needsResolving;
|
|
101
|
-
const commitAuthor = getCommitAuthor({
|
|
102
|
-
options,
|
|
103
|
-
gitConfigAuthor,
|
|
104
|
-
commit,
|
|
105
|
-
});
|
|
106
|
-
try {
|
|
107
|
-
await (0, git_1.fetchBranch)(options, commit.sourceBranch);
|
|
108
|
-
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)({
|
|
109
|
-
options,
|
|
110
|
-
sha: commit.sourceCommit.sha,
|
|
111
|
-
mergedTargetPullRequest,
|
|
112
|
-
commitAuthor,
|
|
113
|
-
}));
|
|
114
|
-
// no conflicts encountered
|
|
115
|
-
if (!needsResolving) {
|
|
116
|
-
cherrypickSpinner.succeed();
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
// cherrypick failed due to conflicts
|
|
120
|
-
cherrypickSpinner.fail();
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
cherrypickSpinner.fail();
|
|
124
|
-
throw e;
|
|
125
|
-
}
|
|
126
|
-
const repoPath = (0, env_1.getRepoPath)(options);
|
|
127
|
-
// resolve conflicts automatically
|
|
128
|
-
if (options.autoFixConflicts) {
|
|
129
|
-
const autoResolveSpinner = (0, ora_1.ora)(options.ci, 'Attempting to resolve conflicts automatically').start();
|
|
130
|
-
const didAutoFix = await options.autoFixConflicts({
|
|
131
|
-
files: conflictingFiles.map((f) => f.absolute),
|
|
132
|
-
directory: repoPath,
|
|
133
|
-
logger: logger_1.logger,
|
|
134
|
-
targetBranch,
|
|
135
|
-
});
|
|
136
|
-
// conflicts were automatically resolved
|
|
137
|
-
if (didAutoFix) {
|
|
138
|
-
autoResolveSpinner.succeed();
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
autoResolveSpinner.fail();
|
|
142
|
-
}
|
|
143
|
-
const conflictingFilesRelative = conflictingFiles
|
|
144
|
-
.map((f) => f.relative)
|
|
145
|
-
.slice(0, 50);
|
|
146
|
-
const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
|
|
147
|
-
options,
|
|
148
|
-
commit,
|
|
149
|
-
targetBranch,
|
|
150
|
-
conflictingFiles: conflictingFilesRelative,
|
|
151
|
-
});
|
|
152
|
-
if (options.ci) {
|
|
153
|
-
throw new BackportError_1.BackportError({
|
|
154
|
-
code: 'merge-conflict-exception',
|
|
155
|
-
commitsWithoutBackports,
|
|
156
|
-
conflictingFiles: conflictingFilesRelative,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
(0, logger_1.consoleLog)(chalk_1.default.bold('\nThe commit could not be backported due to conflicts\n'));
|
|
160
|
-
(0, logger_1.consoleLog)(`Please fix the conflicts in ${repoPath}`);
|
|
161
|
-
if (commitsWithoutBackports.length > 0) {
|
|
162
|
-
(0, logger_1.consoleLog)(chalk_1.default.italic(`Hint: Before fixing the conflicts manually you should consider backporting the following pull requests to "${targetBranch}":`));
|
|
163
|
-
(0, logger_1.consoleLog)(`${commitsWithoutBackports.map((c) => c.formatted).join('\n')}\n\n`);
|
|
164
|
-
}
|
|
165
|
-
/*
|
|
166
|
-
* Commit could not be cleanly cherrypicked: Initiating conflict resolution
|
|
167
|
-
*/
|
|
168
|
-
if (options.editor) {
|
|
169
|
-
await (0, child_process_promisified_1.spawnPromise)(options.editor, [repoPath], options.cwd);
|
|
170
|
-
}
|
|
171
|
-
// list files with conflict markers + unstaged files and require user to resolve them
|
|
172
|
-
await listConflictingAndUnstagedFiles({
|
|
173
|
-
retries: 0,
|
|
174
|
-
options,
|
|
175
|
-
conflictingFiles: conflictingFiles.map((f) => f.absolute),
|
|
176
|
-
unstagedFiles,
|
|
177
|
-
});
|
|
178
|
-
// Conflicts should be resolved and files staged at this point
|
|
179
|
-
const stagingSpinner = (0, ora_1.ora)(options.ci, `Finalizing cherrypick`).start();
|
|
180
|
-
try {
|
|
181
|
-
// Run `git commit`
|
|
182
|
-
await (0, git_1.commitChanges)(commit, options);
|
|
183
|
-
stagingSpinner.succeed();
|
|
184
|
-
}
|
|
185
|
-
catch (e) {
|
|
186
|
-
stagingSpinner.fail();
|
|
187
|
-
throw e;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
async function listConflictingAndUnstagedFiles({ retries, options, conflictingFiles, unstagedFiles, }) {
|
|
191
|
-
const hasUnstagedFiles = !(0, lodash_1.isEmpty)((0, lodash_1.difference)(unstagedFiles, conflictingFiles));
|
|
192
|
-
const hasConflictingFiles = !(0, lodash_1.isEmpty)(conflictingFiles);
|
|
193
|
-
if (!hasConflictingFiles && !hasUnstagedFiles) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
// add divider between prompts
|
|
197
|
-
if (retries > 0) {
|
|
198
|
-
(0, logger_1.consoleLog)('\n----------------------------------------\n');
|
|
199
|
-
}
|
|
200
|
-
const header = chalk_1.default.reset(`Fix the following conflicts manually:`);
|
|
201
|
-
// show conflict section if there are conflicting files
|
|
202
|
-
const conflictSection = hasConflictingFiles
|
|
203
|
-
? `Conflicting files:\n${chalk_1.default.reset(conflictingFiles.map((file) => ` - ${file}`).join('\n'))}`
|
|
204
|
-
: '';
|
|
205
|
-
const unstagedSection = hasUnstagedFiles
|
|
206
|
-
? `Unstaged files:\n${chalk_1.default.reset(unstagedFiles.map((file) => ` - ${file}`).join('\n'))}`
|
|
207
|
-
: '';
|
|
208
|
-
const didConfirm = await (0, prompts_1.confirmPrompt)(`${header}
|
|
209
|
-
|
|
210
|
-
${conflictSection}
|
|
211
|
-
${unstagedSection}
|
|
212
|
-
|
|
213
|
-
Press ENTER when the conflicts are resolved and files are staged`);
|
|
214
|
-
if (!didConfirm) {
|
|
215
|
-
throw new BackportError_1.BackportError({ code: 'abort-exception' });
|
|
216
|
-
}
|
|
217
|
-
const MAX_RETRIES = 100;
|
|
218
|
-
if (retries++ > MAX_RETRIES) {
|
|
219
|
-
throw new Error(`Maximum number of retries (${MAX_RETRIES}) exceeded`);
|
|
220
|
-
}
|
|
221
|
-
const [_conflictingFiles, _unstagedFiles] = await Promise.all([
|
|
222
|
-
(0, git_1.getConflictingFiles)(options),
|
|
223
|
-
(0, git_1.getUnstagedFiles)(options),
|
|
224
|
-
]);
|
|
225
|
-
await listConflictingAndUnstagedFiles({
|
|
226
|
-
retries,
|
|
227
|
-
options,
|
|
228
|
-
conflictingFiles: _conflictingFiles.map((file) => file.absolute),
|
|
229
|
-
unstagedFiles: _unstagedFiles,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
function getCommitAuthor({ options, gitConfigAuthor, commit, }) {
|
|
233
|
-
if (options.resetAuthor) {
|
|
234
|
-
return {
|
|
235
|
-
name: options.authenticatedUsername,
|
|
236
|
-
email: `<${options.authenticatedUsername}@users.noreply.github.com>`,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
name: options.gitAuthorName ?? gitConfigAuthor?.name ?? commit.author.name,
|
|
241
|
-
email: options.gitAuthorEmail ?? gitConfigAuthor?.email ?? commit.author.email,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|