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
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<br>
|
|
7
7
|
</div>
|
|
8
8
|
|
|
9
|
-
## 🎉 New
|
|
9
|
+
## 🎉 New: The Backport Tool as a Github Action 🎉
|
|
10
10
|
|
|
11
11
|
A [Github Action](https://github.com/sqren/backport-github-action) around The Backport Tool now exists. It makes it a breeze to get automatic backports when pull requests are merged.
|
|
12
12
|
|
|
@@ -33,7 +33,7 @@ The remaining documentation focuses on the Backport CLI tool (not the Github Act
|
|
|
33
33
|
npm install -g backport
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
After installation you should add an access token to the [global config](
|
|
36
|
+
After installation you should add an access token to the [global config](/docs/config-file-options.md#global-config-backportconfigjson) in `~/.backport/config.json`. See the [documentation](/docs/config-file-options.md#accesstoken-required) for how the access token is generated.
|
|
37
37
|
|
|
38
38
|
## Quick start
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ After installation you should add an access token to the [global config](https:/
|
|
|
41
41
|
npm install backport
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
Add a [project config](
|
|
44
|
+
Add a [project config](/docs/config-file-options.md#project-config-backportrcjson) to the root of your repository:
|
|
45
45
|
|
|
46
46
|
```js
|
|
47
47
|
// .backportrc.json
|
|
@@ -60,7 +60,7 @@ Add a [project config](https://github.com/sqren/backport/blob/main/docs/configur
|
|
|
60
60
|
}
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
Add personal access token to [global config](
|
|
63
|
+
Add personal access token to [global config](/docs/config-file-options.md#global-config-backportconfigjson):
|
|
64
64
|
|
|
65
65
|
```js
|
|
66
66
|
// ~/.backport/config.json
|
|
@@ -77,185 +77,24 @@ npx backport
|
|
|
77
77
|
|
|
78
78
|
_This will start an interactive prompt. You can use your keyboards arrow keys to choose options, `<space>` to select checkboxes and `<enter>` to proceed._
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
### CLI options
|
|
85
|
-
|
|
86
|
-
| Option | Shorthand notation | Description | Default |
|
|
87
|
-
| ------------------- | ------------------ | -------------------------------------------------------------------------- | ------------------------- |
|
|
88
|
-
| --access-token | | Github access token | |
|
|
89
|
-
| --all | -a | Show commits from any author. Opposite of `--author` | false |
|
|
90
|
-
| --assignee | --assign | Assign users to the target PR | |
|
|
91
|
-
| --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
|
|
92
|
-
| --auto-assign | | Assign current user to the target PR | false |
|
|
93
|
-
| --branch | -b | Target branch to backport to | |
|
|
94
|
-
| --config-file | | Custom path to project config file (.backportrc.json) | |
|
|
95
|
-
| --dir | | Clone repository into custom directory | ~/.backport/repositories/ |
|
|
96
|
-
| --dry-run | | Perform backport without pushing to Github | false |
|
|
97
|
-
| --editor | | Editor (eg. `code`) to open and resolve conflicts | nano |
|
|
98
|
-
| --fork | | Create backports in fork repo | true |
|
|
99
|
-
| --git-hostname | | Hostname for Git | github.com |
|
|
100
|
-
| --interactive | | Enable interactive prompts | true |
|
|
101
|
-
| --mainline | | Parent id of merge commit | 1 |
|
|
102
|
-
| --max-number | --number, -n | Number of commits to choose from | 10 |
|
|
103
|
-
| --multiple | | Multi-select for commits and branches | false |
|
|
104
|
-
| --multiple-branches | | Multi-select for branches | true |
|
|
105
|
-
| --multiple-commits | | Multi-select for commits | false |
|
|
106
|
-
| --no-cherrypick-ref | | Do not append "(cherry picked from commit...)". [Git Docs][1] | false |
|
|
107
|
-
| --no-status-comment | | Do not publish a status comment to Github with the results of the backport | false |
|
|
108
|
-
| --no-verify | | Bypass the pre-commit and commit-msg hooks | false |
|
|
109
|
-
| --path | -p | Filter commits by path | |
|
|
110
|
-
| --pr-description | --description | Description for pull request | |
|
|
111
|
-
| --pr-filter | | Find PRs using [Github's search syntax][2] | |
|
|
112
|
-
| --pr-title | --title | Title of pull request | |
|
|
113
|
-
| --pull-number | --pr | Backport pull request by number | |
|
|
114
|
-
| --repo-fork-owner | | The owner of the fork where the backport branch is pushed. | _Current user_ |
|
|
115
|
-
| --repo-name | | Name of repository | |
|
|
116
|
-
| --repo-owner | | Owner of repository | |
|
|
117
|
-
| --reset-author | | Set yourself as commit author | |
|
|
118
|
-
| --reviewer | | Add reviewer to the target PR | |
|
|
119
|
-
| --sha | | Sha of commit to backport | |
|
|
120
|
-
| --source-branch | | Specify a non-default branch to backport from | |
|
|
121
|
-
| --source-pr-label | | Labels added to the source PR | |
|
|
122
|
-
| --target-branch | -b | Target branch(es) to backport to | |
|
|
123
|
-
| --target-pr-label | --label, -l | Labels added to the target PR | |
|
|
124
|
-
| --help | | Show help | |
|
|
125
|
-
| -v, --version | | Show version number | |
|
|
126
|
-
|
|
127
|
-
The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/main/docs/configuration.md).
|
|
128
|
-
|
|
129
|
-
## Backport Module API
|
|
130
|
-
|
|
131
|
-
`backport` can be imported as a Node module and interacted with programatically. This can be useful when creating automation around the Backport tool. See for example the [Backport Github Action](https://github.com/sqren/backport-github-action)
|
|
132
|
-
|
|
133
|
-
### `backportRun`
|
|
134
|
-
|
|
135
|
-
Backport a commit programatically. Commits can be selected via `pullNumber` or `sha`.
|
|
136
|
-
|
|
137
|
-
#### Arguments:
|
|
138
|
-
|
|
139
|
-
All of the options listed on [configuration.md](https://github.com/sqren/backport/blob/main/docs/configuration.md) are valid. The most common options are:
|
|
140
|
-
|
|
141
|
-
`accessToken` _string_ **(Required)**<br/>
|
|
142
|
-
Github access token to authenticate the request
|
|
143
|
-
|
|
144
|
-
`repoName` _string_ **(Required)**<br/>
|
|
145
|
-
Name of repository
|
|
146
|
-
|
|
147
|
-
`repoOwner` _string_ **(Required)**<br/>
|
|
148
|
-
Owner of repository (organisation or username)
|
|
149
|
-
|
|
150
|
-
`pullNumber` _number_<br/>
|
|
151
|
-
Filter commits by pull request number
|
|
152
|
-
|
|
153
|
-
`sha` _string_<br/>
|
|
154
|
-
Filter commits by commit sha
|
|
155
|
-
|
|
156
|
-
`interactive` _boolean_<br/>
|
|
157
|
-
Enable interactive prompts
|
|
158
|
-
|
|
159
|
-
#### Example
|
|
160
|
-
|
|
161
|
-
```ts
|
|
162
|
-
import { backportRun } from 'backport';
|
|
163
|
-
|
|
164
|
-
const result = await backportRun({
|
|
165
|
-
options: {
|
|
166
|
-
accessToken: 'very secret',
|
|
167
|
-
repoName: 'kibana',
|
|
168
|
-
repoOwner: 'elastic',
|
|
169
|
-
pullNumber: 121633,
|
|
170
|
-
interactive: false,
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
console.log(result);
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### `getCommits`
|
|
178
|
-
|
|
179
|
-
Retrieve information about commits and whether they are backported
|
|
180
|
-
|
|
181
|
-
#### Arguments:
|
|
182
|
-
|
|
183
|
-
`accessToken` _string_ **(Required)**<br/>
|
|
184
|
-
Github access token to authenticate the request
|
|
185
|
-
|
|
186
|
-
`repoName` _string_ **(Required)**<br/>
|
|
187
|
-
Name of repository
|
|
188
|
-
|
|
189
|
-
`repoOwner` _string_ **(Required)**<br/>
|
|
190
|
-
Owner of repository (organisation or username)
|
|
191
|
-
|
|
192
|
-
`author` _string_<br/>
|
|
193
|
-
Filter commits by Github user
|
|
194
|
-
|
|
195
|
-
`pullNumber` _number_<br/>
|
|
196
|
-
Filter commits by pull request number
|
|
197
|
-
|
|
198
|
-
`sha` _string_<br/>
|
|
199
|
-
Filter commits by commit sha
|
|
200
|
-
|
|
201
|
-
`sourceBranch` _string_<br/>
|
|
202
|
-
The branch to display commits from. Defaults to the default branch (normally "main" or "master")
|
|
203
|
-
|
|
204
|
-
#### Example
|
|
205
|
-
|
|
206
|
-
```ts
|
|
207
|
-
import { getCommits } from 'backport';
|
|
208
|
-
|
|
209
|
-
const commits = await getCommits({
|
|
210
|
-
accessToken: 'abc',
|
|
211
|
-
repoName: 'kibana',
|
|
212
|
-
repoOwner: 'elastic',
|
|
213
|
-
pullNumber: 121633,
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
console.log(commits);
|
|
217
|
-
|
|
218
|
-
/*
|
|
219
|
-
[{
|
|
220
|
-
soureCommit: {
|
|
221
|
-
committedDate: '2021-12-20T14:20:16Z',
|
|
222
|
-
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
|
|
223
|
-
message: '[APM] Add note about synthtrace to APM docs (#121633)',
|
|
224
|
-
},
|
|
225
|
-
sourcePullRequest: {
|
|
226
|
-
number: 121633,
|
|
227
|
-
url: 'https://github.com/elastic/kibana/pull/121633'
|
|
228
|
-
mergeCommit: {
|
|
229
|
-
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
|
|
230
|
-
message: '[APM] Add note about synthtrace to APM docs (#121633)',
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
sourceBranch: 'main',
|
|
234
|
-
expectedTargetPullRequests: [
|
|
235
|
-
{
|
|
236
|
-
url: 'https://github.com/elastic/kibana/pull/121643',
|
|
237
|
-
number: 121643,
|
|
238
|
-
branch: '8.0',
|
|
239
|
-
state: 'MERGED'
|
|
240
|
-
}
|
|
241
|
-
]
|
|
242
|
-
}]
|
|
243
|
-
*/
|
|
244
|
-
```
|
|
80
|
+
## Documentation
|
|
81
|
+
- [Config file options](/docs/config-file-options.md)
|
|
82
|
+
- [CLI options](/docs/cli-options.md)
|
|
83
|
+
- [Module API](/docs/api.md)
|
|
245
84
|
|
|
246
|
-
|
|
85
|
+
### What is backporting?
|
|
247
86
|
|
|
248
87
|
> Backporting is the action of taking parts from a newer version of a software system [..] and porting them to an older version of the same software. It forms part of the maintenance step in a software development process, and it is commonly used for fixing security issues in older versions of the software and also for providing new features to older versions.
|
|
249
88
|
|
|
250
89
|
Source: [https://en.wikipedia.org/wiki/Backporting](https://en.wikipedia.org/wiki/Backporting)
|
|
251
90
|
|
|
252
|
-
|
|
91
|
+
### Who is this tool for?
|
|
253
92
|
|
|
254
93
|
This tools is for anybody who is working on a codebase where they have to maintain multiple versions. If you manually cherry-pick commits from master and apply them to one or more branches, this tool might save you a lot of time.
|
|
255
94
|
|
|
256
95
|
`backport` is a CLI tool that will let you backport commit(s) interactively and then cherry-pick and create pull requests automatically. `backport` will perform all git operations in a temporary folder (`~/.backport/repositories/`) separate from your working directory, thereby never interfering with any unstages changes your might have.
|
|
257
96
|
|
|
258
|
-
|
|
97
|
+
### Features:
|
|
259
98
|
|
|
260
99
|
- interactively backport one or more commits to one or more branches with an intuitive UI
|
|
261
100
|
- ability to see which commits have been backported and to which branches
|
|
@@ -272,9 +111,3 @@ This tools is for anybody who is working on a codebase where they have to mainta
|
|
|
272
111
|
## Contributing
|
|
273
112
|
|
|
274
113
|
See [CONTRIBUTING.md](https://github.com/sqren/backport/blob/master/CONTRIBUTING.md)
|
|
275
|
-
|
|
276
|
-
[1]: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x
|
|
277
|
-
[2]: https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
|
|
278
|
-
|
|
279
|
-
[](https://www.npmjs.com/package/backport)
|
|
280
|
-
[](https://coveralls.io/github/sqren/backport?branch=master)
|
package/dist/backportRun.js
CHANGED
|
@@ -102,7 +102,7 @@ async function backportRun({ processArgs, optionsFromModule = {}, exitCodeOnFail
|
|
|
102
102
|
if (exitCodeOnFailure && backportResponse.status === 'failure') {
|
|
103
103
|
process.exitCode = 1;
|
|
104
104
|
}
|
|
105
|
-
logger.error('Unhandled exception', e);
|
|
105
|
+
logger.error('Unhandled exception:', e);
|
|
106
106
|
return backportResponse;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
@@ -20,6 +20,8 @@ export declare function getCommits(options: {
|
|
|
20
20
|
repoOwner: string;
|
|
21
21
|
author?: string;
|
|
22
22
|
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
23
|
+
dateSince?: string;
|
|
24
|
+
dateUntil?: string;
|
|
23
25
|
githubApiBaseUrlV4?: string;
|
|
24
26
|
maxNumber?: number;
|
|
25
27
|
onlyMissing?: boolean;
|
|
@@ -28,6 +30,4 @@ export declare function getCommits(options: {
|
|
|
28
30
|
sha?: string | string[];
|
|
29
31
|
skipRemoteConfig?: boolean;
|
|
30
32
|
sourceBranch?: string;
|
|
31
|
-
dateUntil?: string;
|
|
32
|
-
dateSince?: string;
|
|
33
33
|
}): Promise<Commit[]>;
|
|
@@ -243,7 +243,8 @@ describe('entrypoint.module', () => {
|
|
|
243
243
|
accessToken: accessToken,
|
|
244
244
|
repoName: 'kibana',
|
|
245
245
|
repoOwner: 'elastic',
|
|
246
|
-
|
|
246
|
+
dateUntil: '2021-06-02',
|
|
247
|
+
prFilter: 'label:Team:apm base:master',
|
|
247
248
|
maxNumber: 3,
|
|
248
249
|
});
|
|
249
250
|
const commitMessage = commits.map((commit) => {
|
|
@@ -255,19 +256,19 @@ describe('entrypoint.module', () => {
|
|
|
255
256
|
expect(commitMessage).toMatchInlineSnapshot(`
|
|
256
257
|
Array [
|
|
257
258
|
Object {
|
|
258
|
-
"committedDate": "2021-
|
|
259
|
-
"message": "
|
|
260
|
-
"sha": "
|
|
259
|
+
"committedDate": "2021-05-28T12:41:42Z",
|
|
260
|
+
"message": "[Observability] Fix typo in readme for new navigation (#100861)",
|
|
261
|
+
"sha": "79945fe0275b2ec9c93747e26154110133ec51fb",
|
|
261
262
|
},
|
|
262
263
|
Object {
|
|
263
|
-
"committedDate": "2021-
|
|
264
|
-
"message": "
|
|
265
|
-
"sha": "
|
|
264
|
+
"committedDate": "2021-05-28T19:43:30Z",
|
|
265
|
+
"message": "[APM] Move APM tutorial from apm_oss to x-pack/apm (#100780)",
|
|
266
|
+
"sha": "0bcd78b0e999feb95057f5e6eafdb572b9b2fe39",
|
|
266
267
|
},
|
|
267
268
|
Object {
|
|
268
|
-
"committedDate": "2021-
|
|
269
|
-
"message": "
|
|
270
|
-
"sha": "
|
|
269
|
+
"committedDate": "2021-05-18T10:33:16Z",
|
|
270
|
+
"message": "Migrate from Joi to @kbn/config-schema in \\"home\\" and \\"features\\" plugins (#100201)",
|
|
271
|
+
"sha": "574f6595ad2e5452fa90e6a3111220a599e473c0",
|
|
271
272
|
},
|
|
272
273
|
]
|
|
273
274
|
`);
|
|
@@ -18,6 +18,7 @@ const addLabelsToPullRequest_1 = require("./github/v3/addLabelsToPullRequest");
|
|
|
18
18
|
const addReviewersToPullRequest_1 = require("./github/v3/addReviewersToPullRequest");
|
|
19
19
|
const createPullRequest_1 = require("./github/v3/createPullRequest");
|
|
20
20
|
const enablePullRequestAutoMerge_1 = require("./github/v4/enablePullRequestAutoMerge");
|
|
21
|
+
const fetchCommitBySha_1 = require("./github/v4/fetchCommits/fetchCommitBySha");
|
|
21
22
|
const logger_1 = require("./logger");
|
|
22
23
|
const ora_1 = require("./ora");
|
|
23
24
|
const prompts_1 = require("./prompts");
|
|
@@ -30,7 +31,8 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
|
|
|
30
31
|
(0, getGitConfigAuthor_1.getGitConfigAuthor)(options),
|
|
31
32
|
(0, git_1.createBackportBranch)({ options, targetBranch, backportBranch }),
|
|
32
33
|
]);
|
|
33
|
-
|
|
34
|
+
const commitsFlattened = (0, lodash_1.flatten)(await Promise.all(commits.map((c) => getMergeCommits(options, c))));
|
|
35
|
+
await (0, sequentially_1.sequentially)(commitsFlattened, (commit) => waitForCherrypick(options, commit, targetBranch, gitConfigAuthor));
|
|
34
36
|
if (options.dryRun) {
|
|
35
37
|
(0, ora_1.ora)(options.interactive).succeed('Dry run complete');
|
|
36
38
|
return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
|
|
@@ -78,6 +80,17 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
|
|
|
78
80
|
return targetPullRequest;
|
|
79
81
|
}
|
|
80
82
|
exports.cherrypickAndCreateTargetPullRequest = cherrypickAndCreateTargetPullRequest;
|
|
83
|
+
async function getMergeCommits(options, commit) {
|
|
84
|
+
const { sha } = commit.sourceCommit;
|
|
85
|
+
if (!options.mainline) {
|
|
86
|
+
const isMergeCommit = await (0, git_1.getIsMergeCommit)(options, sha);
|
|
87
|
+
if (isMergeCommit) {
|
|
88
|
+
const shas = await (0, git_1.getShasInMergeCommit)(options, sha);
|
|
89
|
+
return Promise.all(shas.reverse().map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [commit];
|
|
93
|
+
}
|
|
81
94
|
/*
|
|
82
95
|
* Returns the name of the backport branch without remote name
|
|
83
96
|
*
|
|
@@ -97,18 +110,27 @@ function getBackportBranchName(targetBranch, commits) {
|
|
|
97
110
|
}
|
|
98
111
|
async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor) {
|
|
99
112
|
const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
|
|
100
|
-
const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
101
113
|
const cherrypickSpinner = (0, ora_1.ora)(options.interactive, spinnerText).start();
|
|
114
|
+
await (0, git_1.fetchBranch)(options, commit.sourceBranch);
|
|
115
|
+
await cherrypickAndHandleConflicts(options, commit, targetBranch, cherrypickSpinner, gitConfigAuthor);
|
|
116
|
+
// Conflicts should be resolved and files staged at this point
|
|
117
|
+
try {
|
|
118
|
+
// Run `git commit`
|
|
119
|
+
await (0, git_1.commitChanges)(commit, options);
|
|
120
|
+
cherrypickSpinner.succeed();
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
cherrypickSpinner.fail();
|
|
124
|
+
throw e;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function cherrypickAndHandleConflicts(options, commit, targetBranch, cherrypickSpinner, gitConfigAuthor) {
|
|
128
|
+
const mergedTargetPullRequest = commit.expectedTargetPullRequests.find((pr) => pr.state === 'MERGED' && pr.branch === targetBranch);
|
|
129
|
+
const commitAuthor = getCommitAuthor({ options, gitConfigAuthor, commit });
|
|
102
130
|
let conflictingFiles;
|
|
103
131
|
let unstagedFiles;
|
|
104
132
|
let needsResolving;
|
|
105
|
-
const commitAuthor = getCommitAuthor({
|
|
106
|
-
options,
|
|
107
|
-
gitConfigAuthor,
|
|
108
|
-
commit,
|
|
109
|
-
});
|
|
110
133
|
try {
|
|
111
|
-
await (0, git_1.fetchBranch)(options, commit.sourceBranch);
|
|
112
134
|
({ conflictingFiles, unstagedFiles, needsResolving } = await (0, git_1.cherrypick)({
|
|
113
135
|
options,
|
|
114
136
|
sha: commit.sourceCommit.sha,
|
|
@@ -117,7 +139,6 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
|
|
|
117
139
|
}));
|
|
118
140
|
// no conflicts encountered
|
|
119
141
|
if (!needsResolving) {
|
|
120
|
-
cherrypickSpinner.succeed();
|
|
121
142
|
return;
|
|
122
143
|
}
|
|
123
144
|
// cherrypick failed due to conflicts
|
|
@@ -179,17 +200,6 @@ async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor)
|
|
|
179
200
|
conflictingFiles: conflictingFiles.map((f) => f.absolute),
|
|
180
201
|
unstagedFiles,
|
|
181
202
|
});
|
|
182
|
-
// Conflicts should be resolved and files staged at this point
|
|
183
|
-
const stagingSpinner = (0, ora_1.ora)(options.interactive, `Finalizing cherrypick`).start();
|
|
184
|
-
try {
|
|
185
|
-
// Run `git commit`
|
|
186
|
-
await (0, git_1.commitChanges)(commit, options);
|
|
187
|
-
stagingSpinner.succeed();
|
|
188
|
-
}
|
|
189
|
-
catch (e) {
|
|
190
|
-
stagingSpinner.fail();
|
|
191
|
-
throw e;
|
|
192
|
-
}
|
|
193
203
|
}
|
|
194
204
|
async function listConflictingAndUnstagedFiles({ retries, options, conflictingFiles, unstagedFiles, }) {
|
|
195
205
|
const hasUnstagedFiles = !(0, lodash_1.isEmpty)((0, lodash_1.difference)(unstagedFiles, conflictingFiles));
|
|
@@ -17,6 +17,8 @@ async function exec(cmd, options) {
|
|
|
17
17
|
}
|
|
18
18
|
exports.exec = exec;
|
|
19
19
|
async function spawnPromise(cmd, cmdArgs, cwd) {
|
|
20
|
+
const fullCmd = `${cmd} ${cmdArgs.join(' ')}`;
|
|
21
|
+
logger_1.logger.info(`Running command: "${fullCmd}"`);
|
|
20
22
|
return new Promise(function (resolve, reject) {
|
|
21
23
|
const subprocess = child_process_1.default.spawn(cmd, cmdArgs, { cwd });
|
|
22
24
|
let stderr = '';
|
|
@@ -28,8 +30,6 @@ async function spawnPromise(cmd, cmdArgs, cwd) {
|
|
|
28
30
|
stderr += data;
|
|
29
31
|
});
|
|
30
32
|
subprocess.on('close', (code) => {
|
|
31
|
-
const fullCmd = `${cmd} ${cmdArgs.join(' ')}`;
|
|
32
|
-
logger_1.logger.info(`Running command: "${fullCmd}"`);
|
|
33
33
|
if (code === 0 || code === null) {
|
|
34
34
|
resolve({ cmdArgs, code, stderr, stdout });
|
|
35
35
|
}
|
package/dist/lib/getCommits.js
CHANGED
|
@@ -46,7 +46,7 @@ async function getCommits(options) {
|
|
|
46
46
|
spinner.text = options.prFilter
|
|
47
47
|
? 'Loading pull requests...'
|
|
48
48
|
: `Loading commits from branch "${options.sourceBranch}"...`;
|
|
49
|
-
const commitChoices = options.prFilter
|
|
49
|
+
const commitChoices = options.prFilter !== undefined
|
|
50
50
|
? await (0, fetchPullRequestsBySearchQuery_1.fetchPullRequestsBySearchQuery)({
|
|
51
51
|
...options,
|
|
52
52
|
prFilter: options.prFilter,
|
package/dist/lib/git.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare function deleteRemote(options: ValidConfigOptions, remoteName: st
|
|
|
27
27
|
export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
28
28
|
export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
|
|
29
29
|
export declare function getIsMergeCommit(options: ValidConfigOptions, sha: string): Promise<boolean>;
|
|
30
|
-
export declare function
|
|
30
|
+
export declare function getShasInMergeCommit(options: ValidConfigOptions, sha: string): Promise<string[]>;
|
|
31
31
|
export declare function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }: {
|
|
32
32
|
options: ValidConfigOptions;
|
|
33
33
|
sha: string;
|
package/dist/lib/git.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLocalSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getGitConfig = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.
|
|
3
|
+
exports.getLocalSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getGitConfig = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getShasInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRootPath = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
6
|
const ora_1 = require("../lib/ora");
|
|
@@ -15,6 +15,7 @@ function getRemoteUrl({ repoName, accessToken, gitHostname = 'github.com' }, rep
|
|
|
15
15
|
}
|
|
16
16
|
exports.getRemoteUrl = getRemoteUrl;
|
|
17
17
|
async function cloneRepo({ sourcePath, targetPath }, onProgress) {
|
|
18
|
+
logger_1.logger.info(`Cloning repo from ${sourcePath} to ${targetPath}`);
|
|
18
19
|
return new Promise((resolve, reject) => {
|
|
19
20
|
const subprocess = (0, child_process_promisified_1.spawnOriginal)('git', [
|
|
20
21
|
'clone',
|
|
@@ -28,7 +29,7 @@ async function cloneRepo({ sourcePath, targetPath }, onProgress) {
|
|
|
28
29
|
};
|
|
29
30
|
subprocess.on('error', (err) => reject(err));
|
|
30
31
|
subprocess.stderr.on('data', (data) => {
|
|
31
|
-
logger_1.logger.verbose(
|
|
32
|
+
logger_1.logger.verbose(data.toString());
|
|
32
33
|
const [, objectReceiveProgress] = data.toString().match(/^Receiving objects:\s+(\d+)%/) || [];
|
|
33
34
|
if (objectReceiveProgress) {
|
|
34
35
|
progress.objectReceive = parseInt(objectReceiveProgress, 10);
|
|
@@ -179,7 +180,7 @@ async function getIsMergeCommit(options, sha) {
|
|
|
179
180
|
return res.stdout !== '';
|
|
180
181
|
}
|
|
181
182
|
exports.getIsMergeCommit = getIsMergeCommit;
|
|
182
|
-
async function
|
|
183
|
+
async function getShasInMergeCommit(options, sha) {
|
|
183
184
|
try {
|
|
184
185
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
185
186
|
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'log', `${sha}^1..${sha}^2`, '--pretty=format:%H'], cwd);
|
|
@@ -194,30 +195,8 @@ async function getCommitsInMergeCommit(options, sha) {
|
|
|
194
195
|
throw e;
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
|
-
exports.
|
|
198
|
-
async function getShaOrRange(options, sha) {
|
|
199
|
-
if (!options.mainline) {
|
|
200
|
-
try {
|
|
201
|
-
const isMergeCommit = await getIsMergeCommit(options, sha);
|
|
202
|
-
if (isMergeCommit) {
|
|
203
|
-
const shas = await getCommitsInMergeCommit(options, sha);
|
|
204
|
-
return `${(0, lodash_1.last)(shas)}^..${(0, lodash_1.first)(shas)}`;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
catch (e) {
|
|
208
|
-
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
209
|
-
// swallow error if it's a 128 exit code
|
|
210
|
-
// exit 128 happens when the cherrypicked commit is empty which is handled below
|
|
211
|
-
// (128 also applies to many other types of errors)
|
|
212
|
-
if (!isSpawnError || e.context.code !== 128) {
|
|
213
|
-
throw e;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return sha;
|
|
218
|
-
}
|
|
198
|
+
exports.getShasInMergeCommit = getShasInMergeCommit;
|
|
219
199
|
async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }) {
|
|
220
|
-
const shaOrRange = await getShaOrRange(options, sha);
|
|
221
200
|
const cmdArgs = [
|
|
222
201
|
'-c',
|
|
223
202
|
`user.name="${commitAuthor.name}"`,
|
|
@@ -228,7 +207,8 @@ async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor,
|
|
|
228
207
|
? ['--mainline', `${options.mainline}`]
|
|
229
208
|
: []),
|
|
230
209
|
...(options.cherrypickRef === false ? [] : ['-x']),
|
|
231
|
-
|
|
210
|
+
...(options.signoff ? ['--signoff'] : []),
|
|
211
|
+
sha,
|
|
232
212
|
];
|
|
233
213
|
try {
|
|
234
214
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
@@ -419,7 +399,7 @@ async function pushBackportBranch({ options, backportBranch, }) {
|
|
|
419
399
|
spinner.fail();
|
|
420
400
|
if (e instanceof child_process_promisified_1.SpawnError &&
|
|
421
401
|
e.context.stderr.toLowerCase().includes(`repository not found`)) {
|
|
422
|
-
throw new BackportError_1.BackportError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode via "--no-fork".\nRead more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/
|
|
402
|
+
throw new BackportError_1.BackportError(`Error pushing to https://github.com/${repoForkOwner}/${options.repoName}. Repository does not exist. Either fork the repository (https://github.com/${options.repoOwner}/${options.repoName}) or disable fork mode via "--no-fork".\nRead more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#fork`);
|
|
423
403
|
}
|
|
424
404
|
if (e instanceof child_process_promisified_1.SpawnError &&
|
|
425
405
|
e.context.stderr.includes(`could not read Username for`)) {
|
|
@@ -169,7 +169,7 @@ describe('git.integration', () => {
|
|
|
169
169
|
});
|
|
170
170
|
}).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
171
171
|
"Error pushing to https://github.com/sqren/repo-with-conflicts. Repository does not exist. Either fork the repository (https://github.com/sqren/repo-with-conflicts) or disable fork mode via \\"--no-fork\\".
|
|
172
|
-
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/
|
|
172
|
+
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#fork"
|
|
173
173
|
`);
|
|
174
174
|
});
|
|
175
175
|
});
|
|
@@ -535,11 +535,11 @@ describe('git.integration', () => {
|
|
|
535
535
|
expect(res).toBe(false);
|
|
536
536
|
});
|
|
537
537
|
});
|
|
538
|
-
describe('
|
|
538
|
+
describe('getShasInMergeCommit', () => {
|
|
539
539
|
it('returns a list of commit hashes - excluding the merge hash itself', async () => {
|
|
540
|
-
const
|
|
541
|
-
expect(
|
|
542
|
-
expect(
|
|
540
|
+
const shas = await (0, git_1.getShasInMergeCommit)({ dir: cwd }, MERGE_COMMIT_HASH_1);
|
|
541
|
+
expect(shas).not.toContain(MERGE_COMMIT_HASH_1);
|
|
542
|
+
expect(shas).toEqual([
|
|
543
543
|
'f9a760e0d9eb3ebcc64f8cb75ce885714b836496',
|
|
544
544
|
'7b92e29e88266004485ce0fae0260605b01df887',
|
|
545
545
|
'a1facf8c006fb815d6a6ecd1b2907e6e64f29576',
|
|
@@ -551,8 +551,8 @@ describe('git.integration', () => {
|
|
|
551
551
|
]);
|
|
552
552
|
});
|
|
553
553
|
it('returns empty for squash commits', async () => {
|
|
554
|
-
const
|
|
555
|
-
expect(
|
|
554
|
+
const shas = await (0, git_1.getShasInMergeCommit)({ dir: cwd }, SQUASH_COMMIT_HASH);
|
|
555
|
+
expect(shas).toEqual([]);
|
|
556
556
|
});
|
|
557
557
|
});
|
|
558
558
|
});
|