backport 8.4.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/lib/cherrypickAndCreateTargetPullRequest.js +30 -20
- package/dist/lib/git.d.ts +1 -1
- package/dist/lib/git.js +5 -27
- package/dist/lib/git.private.test.js +7 -7
- package/dist/lib/git.test.js +5 -15
- package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
- package/dist/lib/ora.d.ts +1 -0
- package/dist/options/options.js +2 -2
- package/dist/options/options.test.js +4 -4
- package/dist/test/e2e/cli/date-filters.private.test.js +1 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +120 -4
- 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 +14 -14
- package/yarn.lock +115 -119
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)
|
|
@@ -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));
|
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");
|
|
@@ -180,7 +180,7 @@ async function getIsMergeCommit(options, sha) {
|
|
|
180
180
|
return res.stdout !== '';
|
|
181
181
|
}
|
|
182
182
|
exports.getIsMergeCommit = getIsMergeCommit;
|
|
183
|
-
async function
|
|
183
|
+
async function getShasInMergeCommit(options, sha) {
|
|
184
184
|
try {
|
|
185
185
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
186
186
|
const res = await (0, child_process_promisified_1.spawnPromise)('git', ['--no-pager', 'log', `${sha}^1..${sha}^2`, '--pretty=format:%H'], cwd);
|
|
@@ -195,30 +195,8 @@ async function getCommitsInMergeCommit(options, sha) {
|
|
|
195
195
|
throw e;
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
-
exports.
|
|
199
|
-
async function getShaOrRange(options, sha) {
|
|
200
|
-
if (!options.mainline) {
|
|
201
|
-
try {
|
|
202
|
-
const isMergeCommit = await getIsMergeCommit(options, sha);
|
|
203
|
-
if (isMergeCommit) {
|
|
204
|
-
const shas = await getCommitsInMergeCommit(options, sha);
|
|
205
|
-
return `${(0, lodash_1.last)(shas)}^..${(0, lodash_1.first)(shas)}`;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch (e) {
|
|
209
|
-
const isSpawnError = e instanceof child_process_promisified_1.SpawnError;
|
|
210
|
-
// swallow error if it's a 128 exit code
|
|
211
|
-
// exit 128 happens when the cherrypicked commit is empty which is handled below
|
|
212
|
-
// (128 also applies to many other types of errors)
|
|
213
|
-
if (!isSpawnError || e.context.code !== 128) {
|
|
214
|
-
throw e;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return sha;
|
|
219
|
-
}
|
|
198
|
+
exports.getShasInMergeCommit = getShasInMergeCommit;
|
|
220
199
|
async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor, }) {
|
|
221
|
-
const shaOrRange = await getShaOrRange(options, sha);
|
|
222
200
|
const cmdArgs = [
|
|
223
201
|
'-c',
|
|
224
202
|
`user.name="${commitAuthor.name}"`,
|
|
@@ -230,7 +208,7 @@ async function cherrypick({ options, sha, mergedTargetPullRequest, commitAuthor,
|
|
|
230
208
|
: []),
|
|
231
209
|
...(options.cherrypickRef === false ? [] : ['-x']),
|
|
232
210
|
...(options.signoff ? ['--signoff'] : []),
|
|
233
|
-
|
|
211
|
+
sha,
|
|
234
212
|
];
|
|
235
213
|
try {
|
|
236
214
|
const cwd = (0, env_1.getRepoPath)(options);
|
|
@@ -421,7 +399,7 @@ async function pushBackportBranch({ options, backportBranch, }) {
|
|
|
421
399
|
spinner.fail();
|
|
422
400
|
if (e instanceof child_process_promisified_1.SpawnError &&
|
|
423
401
|
e.context.stderr.toLowerCase().includes(`repository not found`)) {
|
|
424
|
-
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`);
|
|
425
403
|
}
|
|
426
404
|
if (e instanceof child_process_promisified_1.SpawnError &&
|
|
427
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
|
});
|
package/dist/lib/git.test.js
CHANGED
|
@@ -301,8 +301,7 @@ describe('cherrypick', () => {
|
|
|
301
301
|
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
302
302
|
jest
|
|
303
303
|
.spyOn(childProcess, 'spawnPromise')
|
|
304
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock
|
|
305
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
304
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock `git cherrypick`
|
|
306
305
|
expect(await (0, git_1.cherrypick)({
|
|
307
306
|
options,
|
|
308
307
|
sha: 'abcd',
|
|
@@ -316,8 +315,7 @@ describe('cherrypick', () => {
|
|
|
316
315
|
it('should use mainline option when specified', async () => {
|
|
317
316
|
const spawnSpy = jest
|
|
318
317
|
.spyOn(childProcess, 'spawnPromise')
|
|
319
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock
|
|
320
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
318
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock `git cherrypick`
|
|
321
319
|
await (0, git_1.cherrypick)({
|
|
322
320
|
options: { ...options, mainline: 1 },
|
|
323
321
|
sha: 'abcd',
|
|
@@ -343,14 +341,13 @@ describe('cherrypick', () => {
|
|
|
343
341
|
it('should use signoff option when specified', async () => {
|
|
344
342
|
const spawnSpy = jest
|
|
345
343
|
.spyOn(childProcess, 'spawnPromise')
|
|
346
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock
|
|
347
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock cherrypick(...)
|
|
344
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }); // mock `git cherrypick`
|
|
348
345
|
await (0, git_1.cherrypick)({
|
|
349
346
|
options: { ...options, signoff: true },
|
|
350
347
|
sha: 'abcd',
|
|
351
348
|
commitAuthor,
|
|
352
349
|
});
|
|
353
|
-
const args = spawnSpy.mock.calls[
|
|
350
|
+
const args = spawnSpy.mock.calls[0];
|
|
354
351
|
expect(args).toEqual([
|
|
355
352
|
'git',
|
|
356
353
|
[
|
|
@@ -369,7 +366,6 @@ describe('cherrypick', () => {
|
|
|
369
366
|
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
370
367
|
jest
|
|
371
368
|
.spyOn(childProcess, 'spawnPromise')
|
|
372
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] }) // mock getIsMergeCommit(...)
|
|
373
369
|
// mock `git cherrypick`
|
|
374
370
|
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
375
371
|
code: 128,
|
|
@@ -404,8 +400,6 @@ describe('cherrypick', () => {
|
|
|
404
400
|
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
405
401
|
jest
|
|
406
402
|
.spyOn(childProcess, 'spawnPromise')
|
|
407
|
-
// mock getIsMergeCommit(...)
|
|
408
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
409
403
|
// mock cherry pick command
|
|
410
404
|
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
411
405
|
code: 128,
|
|
@@ -431,8 +425,6 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
431
425
|
it('should gracefully handle empty commits', async () => {
|
|
432
426
|
jest
|
|
433
427
|
.spyOn(childProcess, 'spawnPromise')
|
|
434
|
-
// mock getIsMergeCommit(...)
|
|
435
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
436
428
|
// mock cherry pick command
|
|
437
429
|
.mockRejectedValueOnce(new childProcess.SpawnError({
|
|
438
430
|
code: 1,
|
|
@@ -449,8 +441,6 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
449
441
|
it('should re-throw non-cherrypick errors', async () => {
|
|
450
442
|
jest
|
|
451
443
|
.spyOn(childProcess, 'spawnPromise')
|
|
452
|
-
// mock getIsMergeCommit(...)
|
|
453
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '', code: 0, cmdArgs: [] })
|
|
454
444
|
// mock cherry pick command
|
|
455
445
|
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
456
446
|
// getConflictingFiles
|
|
@@ -600,7 +590,7 @@ describe('pushBackportBranch', () => {
|
|
|
600
590
|
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects
|
|
601
591
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
602
592
|
"Error pushing to https://github.com/the_fork_owner/kibana. Repository does not exist. Either fork the repository (https://github.com/elastic/kibana) or disable fork mode via \\"--no-fork\\".
|
|
603
|
-
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/
|
|
593
|
+
Read more about fork mode in the docs: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#fork"
|
|
604
594
|
`);
|
|
605
595
|
});
|
|
606
596
|
});
|
|
@@ -6,6 +6,7 @@ const fetchCommitBySha_1 = require("./fetchCommitBySha");
|
|
|
6
6
|
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
7
7
|
const fetchPullRequestsBySearchQuery_1 = require("./fetchPullRequestsBySearchQuery");
|
|
8
8
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
jest.setTimeout(15000);
|
|
9
10
|
describe('allFetchers', () => {
|
|
10
11
|
let commitByAuthor;
|
|
11
12
|
beforeEach(async () => {
|
package/dist/lib/ora.d.ts
CHANGED
package/dist/options/options.js
CHANGED
|
@@ -8,8 +8,8 @@ const getOptionsFromGithub_1 = require("../lib/github/v4/getOptionsFromGithub/ge
|
|
|
8
8
|
const getRepoOwnerAndNameFromGitRemotes_1 = require("../lib/github/v4/getRepoOwnerAndNameFromGitRemotes");
|
|
9
9
|
const logger_1 = require("../lib/logger");
|
|
10
10
|
const config_1 = require("./config/config");
|
|
11
|
-
const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/
|
|
12
|
-
const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/
|
|
11
|
+
const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson';
|
|
12
|
+
const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/config-file-options.md#global-config-backportconfigjson';
|
|
13
13
|
exports.defaultConfigOptions = {
|
|
14
14
|
assignees: [],
|
|
15
15
|
autoAssign: false,
|
|
@@ -71,7 +71,7 @@ describe('getOptions', () => {
|
|
|
71
71
|
"Please update your config file: \\"/myHomeDir/.backport/config.json\\".
|
|
72
72
|
It must contain a valid \\"accessToken\\".
|
|
73
73
|
|
|
74
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
74
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#global-config-backportconfigjson"
|
|
75
75
|
`);
|
|
76
76
|
});
|
|
77
77
|
it('when `targetBranches`, `targetBranchChoices` and `branchLabelMapping` are all empty', async () => {
|
|
@@ -83,7 +83,7 @@ describe('getOptions', () => {
|
|
|
83
83
|
await expect(() => (0, options_1.getOptions)({ optionsFromCliArgs: {}, optionsFromModule: {} })).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
84
84
|
"Please specify a target branch: \\"--branch 6.1\\".
|
|
85
85
|
|
|
86
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
86
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson"
|
|
87
87
|
`);
|
|
88
88
|
});
|
|
89
89
|
describe('whe option is an empty string', () => {
|
|
@@ -107,7 +107,7 @@ describe('getOptions', () => {
|
|
|
107
107
|
"Please update your config file: \\"/myHomeDir/.backport/config.json\\".
|
|
108
108
|
It must contain a valid \\"accessToken\\".
|
|
109
109
|
|
|
110
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
110
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#global-config-backportconfigjson"
|
|
111
111
|
`);
|
|
112
112
|
});
|
|
113
113
|
});
|
|
@@ -120,7 +120,7 @@ describe('getOptions', () => {
|
|
|
120
120
|
await expect(() => (0, options_1.getOptions)({ optionsFromCliArgs: {}, optionsFromModule: {} })).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
121
121
|
"Please specify a repository: \\"--repo elastic/kibana\\".
|
|
122
122
|
|
|
123
|
-
Read more: https://github.com/sqren/backport/blob/main/docs/
|
|
123
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/config-file-options.md#project-config-backportrcjson"
|
|
124
124
|
`);
|
|
125
125
|
});
|
|
126
126
|
it('should get repoName from the remote', async () => {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const getDevAccessToken_1 = require("../../private/getDevAccessToken");
|
|
4
4
|
const runBackportViaCli_1 = require("./runBackportViaCli");
|
|
5
5
|
const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
6
|
+
jest.setTimeout(15000);
|
|
6
7
|
describe('date filters (dateSince, dateUntil)', () => {
|
|
7
8
|
it(`filters commits by "since" and "until"`, async () => {
|
|
8
9
|
const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
|