backport 6.1.1 → 6.1.5

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.
Files changed (81) hide show
  1. package/README.md +83 -70
  2. package/dist/entrypoint.module.d.ts +4 -1
  3. package/dist/entrypoint.module.js +10 -4
  4. package/dist/entrypoint.module.private.test.js +4 -1
  5. package/dist/main.js +5 -1
  6. package/dist/options/ConfigOptions.d.ts +3 -0
  7. package/dist/options/cliArgs.d.ts +5 -1
  8. package/dist/options/cliArgs.js +24 -2
  9. package/dist/options/cliArgs.test.js +0 -7
  10. package/dist/options/config/config.d.ts +7 -1
  11. package/dist/options/config/config.js +2 -2
  12. package/dist/options/config/config.test.js +1 -1
  13. package/dist/options/config/globalConfig.d.ts +1 -1
  14. package/dist/options/config/globalConfig.js +4 -8
  15. package/dist/options/config/readConfigFile.d.ts +4 -1
  16. package/dist/options/options.d.ts +10 -1
  17. package/dist/options/options.js +10 -2
  18. package/dist/options/options.test.js +113 -123
  19. package/dist/runSequentially.test.js +8 -5
  20. package/dist/services/HandledError.d.ts +1 -1
  21. package/dist/services/env.d.ts +2 -3
  22. package/dist/services/env.js +9 -10
  23. package/dist/services/env.test.js +0 -6
  24. package/dist/services/git.d.ts +2 -1
  25. package/dist/services/git.js +5 -3
  26. package/dist/services/github/v3/createPullRequest.js +1 -1
  27. package/dist/services/github/v3/createPullRequest.test.js +3 -3
  28. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  29. package/dist/services/github/v3/createStatusComment.js +50 -27
  30. package/dist/services/github/v3/createStatusComment.test.js +155 -73
  31. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  32. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  33. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  34. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  35. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  36. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  37. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  38. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  39. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  40. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  41. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  42. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  43. package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
  44. package/dist/services/github/v4/fetchProjectConfig.js +3 -3
  45. package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
  46. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  47. package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
  48. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  49. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  50. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +3 -0
  51. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
  52. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  53. package/dist/services/logger.d.ts +0 -1
  54. package/dist/services/logger.js +3 -3
  55. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  56. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  57. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  58. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  59. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  60. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  61. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  62. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  63. package/dist/test/inquirer.private.test.js +4 -15
  64. package/dist/test/integration/integration.private.test.js +2 -2
  65. package/dist/test/nockHelpers.js +1 -3
  66. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  67. package/dist/todo-delete.d.ts +1 -0
  68. package/dist/todo-delete.js +17 -0
  69. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
  70. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -48
  71. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
  72. package/dist/ui/getCommits.js +1 -1
  73. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  74. package/dist/ui/getCommitsWithoutBackports.js +68 -0
  75. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  76. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  77. package/dist/ui/maybeSetupRepo.js +0 -6
  78. package/dist/utils/redact.d.ts +1 -0
  79. package/dist/utils/redact.js +7 -0
  80. package/package.json +3 -3
  81. package/yarn.lock +462 -284
package/README.md CHANGED
@@ -1,10 +1,16 @@
1
- # backport
1
+ <div align="center">
2
+ <img src="https://user-images.githubusercontent.com/209966/148229483-9f867a20-da7d-4cff-8c52-fcb27d482b89.png" height="200">
3
+ <p>
4
+ <b>A CLI tool that automates the process of backporting commits.</b>
5
+ </p>
6
+ <br>
7
+ </div>
2
8
 
3
- [![Build Status](https://travis-ci.com/sqren/backport.svg?branch=master)](https://app.travis-ci.com/github/sqren/backport)
4
- [![NPM version](https://img.shields.io/npm/v/backport.svg)](https://www.npmjs.com/package/backport)
5
- [![Coverage Status](https://coveralls.io/repos/github/sqren/backport/badge.svg?branch=master)](https://coveralls.io/github/sqren/backport?branch=master)
9
+ ## How it works
6
10
 
7
- A simple CLI tool that automates the process of backporting commits on a GitHub repo.
11
+ 1. Select a commit to backport
12
+ 2. Select a branch to backport to
13
+ 3. The commit will be cherrypicked, pushed and a pull request created.
8
14
 
9
15
  ![backport-demo](https://user-images.githubusercontent.com/209966/80993576-95766380-8e3b-11ea-9efd-b35eb2e6a9ec.gif)
10
16
 
@@ -34,7 +40,7 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
34
40
  // the branches available to backport to
35
41
  "targetBranchChoices": ["main", "6.3", "6.2", "6.1", "6.0"],
36
42
 
37
- // Automatically detect which branches a pull request should be backported to based on the pull request labels.
43
+ // Optional: Automatically detect which branches a pull request should be backported to based on the pull request labels.
38
44
  "branchLabelMapping": {
39
45
  "^backport-to-(.+)$": "$1"
40
46
  }
@@ -61,76 +67,78 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
61
67
 
62
68
  ### CLI options
63
69
 
64
- | Option | Shorthand notation | Description | Default |
65
- | ------------------- | ------------------ | ------------------------------------------------------------- | -------------- |
66
- | --access-token | | Github access token | |
67
- | --all | -a | Show commits from any author | false |
68
- | --assignee | --assign | Assign users to the target PR | |
69
- | --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
70
- | --auto-assign | | Assign current user to the target PR | false |
71
- | --branch | -b | Target branch to backport to | |
72
- | --ci | | Disable interactive prompts | false |
73
- | --dry-run | | Perform backport without pushing to Github | false |
74
- | --editor | | Editor (eg. `code`) to open and resolve conflicts | nano |
75
- | --fork | | Create backports in fork repo | true |
76
- | --git-hostname | | Hostname for Git | github.com |
77
- | --mainline | | Parent id of merge commit | 1 |
78
- | --max-number | --number, -n | Number of commits to choose from | 10 |
79
- | --multiple | | Multi-select for commits and branches | false |
80
- | --multiple-branches | | Multi-select for branches | true |
81
- | --multiple-commits | | Multi-select for commits | false |
82
- | --no-cherrypick-ref | | Do not append "(cherry picked from commit...)". [Git Docs][1] | false |
83
- | --no-verify | | Bypass the pre-commit and commit-msg hooks | false |
84
- | --path | -p | Filter commits by path | |
85
- | --pr-description | --description | Pull request description suffix | |
86
- | --pr-filter | | Find PRs using [Github's search syntax][2] | |
87
- | --pr-title | --title | Title of pull request | |
88
- | --pull-number | --pr | Backport pull request by number | |
89
- | --repo-name | | Name of repository | |
90
- | --repo-owner | | Owner of repository | |
91
- | --reset-author | | Set yourself as commit author | |
92
- | --reviewer | | Add reviewer to the target PR | |
93
- | --sha | | Sha of commit to backport | |
94
- | --source-branch | | Specify a non-default branch to backport from | |
95
- | --source-pr-label | | Labels added to the source PR | |
96
- | --target-branch | -b | Target branch(es) to backport to | |
97
- | --target-pr-label | --label, -l | Labels added to the target PR | |
98
- | --help | | Show help | |
99
- | -v, --version | | Show version number | |
70
+ | Option | Shorthand notation | Description | Default |
71
+ | ------------------- | ------------------ | -------------------------------------------------------------------------- | ------------------------- |
72
+ | --access-token | | Github access token | |
73
+ | --all | -a | Show commits from any author | false |
74
+ | --assignee | --assign | Assign users to the target PR | |
75
+ | --author | | Filter commits by Github username. Opposite of `--all` | _Current user_ |
76
+ | --auto-assign | | Assign current user to the target PR | false |
77
+ | --branch | -b | Target branch to backport to | |
78
+ | --ci | | Disable interactive prompts | false |
79
+ | --dir | | Clone repository into custom directory | ~/.backport/repositories/ |
80
+ | --dry-run | | Perform backport without pushing to Github | false |
81
+ | --editor | | Editor (eg. `code`) to open and resolve conflicts | nano |
82
+ | --fork | | Create backports in fork repo | true |
83
+ | --git-hostname | | Hostname for Git | github.com |
84
+ | --mainline | | Parent id of merge commit | 1 |
85
+ | --max-number | --number, -n | Number of commits to choose from | 10 |
86
+ | --multiple | | Multi-select for commits and branches | false |
87
+ | --multiple-branches | | Multi-select for branches | true |
88
+ | --multiple-commits | | Multi-select for commits | false |
89
+ | --no-cherrypick-ref | | Do not append "(cherry picked from commit...)". [Git Docs][1] | false |
90
+ | --no-status-comment | | Do not publish a status comment to Github with the results of the backport | false |
91
+ | --no-verify | | Bypass the pre-commit and commit-msg hooks | false |
92
+ | --path | -p | Filter commits by path | |
93
+ | --pr-description | --description | Pull request description suffix | |
94
+ | --pr-filter | | Find PRs using [Github's search syntax][2] | |
95
+ | --pr-title | --title | Title of pull request | |
96
+ | --pull-number | --pr | Backport pull request by number | |
97
+ | --repo-name | | Name of repository | |
98
+ | --repo-owner | | Owner of repository | |
99
+ | --reset-author | | Set yourself as commit author | |
100
+ | --reviewer | | Add reviewer to the target PR | |
101
+ | --sha | | Sha of commit to backport | |
102
+ | --source-branch | | Specify a non-default branch to backport from | |
103
+ | --source-pr-label | | Labels added to the source PR | |
104
+ | --target-branch | -b | Target branch(es) to backport to | |
105
+ | --target-pr-label | --label, -l | Labels added to the target PR | |
106
+ | --help | | Show help | |
107
+ | -v, --version | | Show version number | |
100
108
 
101
109
  The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/master/docs/configuration.md).
102
110
 
103
- ### Node module
111
+ ## Backport Module API
104
112
 
105
- `backport` can be imported as a Node module and interacted with programatically.
113
+ `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/elastic/kibana-github-actions/blob/f5c58195840b8b0cf6036cfeba6e0b497306fb39/backport/index.ts)
106
114
 
107
- #### `backportRun`
115
+ ### `backportRun`
108
116
 
109
117
  Backport a commit programatically. Commits can be selected via `pullNumber` or `sha`.
110
118
 
111
- ##### Arguments:
119
+ #### Arguments:
112
120
 
113
121
  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:
114
122
 
115
- `accessToken` _string_ **(Required)**
123
+ `accessToken` _string_ **(Required)**<br/>
116
124
  Github access token to authenticate the request
117
125
 
118
- `repoName` _string_ **(Required)**
126
+ `repoName` _string_ **(Required)**<br/>
119
127
  Name of repository
120
128
 
121
- `repoOwner` _string_ **(Required)**
129
+ `repoOwner` _string_ **(Required)**<br/>
122
130
  Owner of repository (organisation or username)
123
131
 
124
- `pullNumber` _number_
132
+ `pullNumber` _number_<br/>
125
133
  Filter commits by pull request number
126
134
 
127
- `sha` _string_
135
+ `sha` _string_<br/>
128
136
  Filter commits by commit sha
129
137
 
130
- `ci` _boolean_
138
+ `ci` _boolean_<br/>
131
139
  Enabling this will disable the interactive prompts
132
140
 
133
- ##### Example
141
+ #### Example
134
142
 
135
143
  ```ts
136
144
  import { backportRun } from 'backport';
@@ -149,34 +157,34 @@ const result = await backportRun({
149
157
  console.log(result);
150
158
  ```
151
159
 
152
- #### `getCommits`
160
+ ### `getCommits`
153
161
 
154
162
  Retrieve information about commits and whether they are backported
155
163
 
156
- ##### Arguments:
164
+ #### Arguments:
157
165
 
158
- `accessToken` _string_ **(Required)**
166
+ `accessToken` _string_ **(Required)**<br/>
159
167
  Github access token to authenticate the request
160
168
 
161
- `repoName` _string_ **(Required)**
169
+ `repoName` _string_ **(Required)**<br/>
162
170
  Name of repository
163
171
 
164
- `repoOwner` _string_ **(Required)**
172
+ `repoOwner` _string_ **(Required)**<br/>
165
173
  Owner of repository (organisation or username)
166
174
 
167
- `author` _string_
175
+ `author` _string_<br/>
168
176
  Filter commits by Github user
169
177
 
170
- `pullNumber` _number_
178
+ `pullNumber` _number_<br/>
171
179
  Filter commits by pull request number
172
180
 
173
- `sha` _string_
181
+ `sha` _string_<br/>
174
182
  Filter commits by commit sha
175
183
 
176
- `sourceBranch` _string_
184
+ `sourceBranch` _string_<br/>
177
185
  The branch to display commits from. Defaults to the default branch (normally "main" or "master")
178
186
 
179
- ##### Example
187
+ #### Example
180
188
 
181
189
  ```ts
182
190
  import { getCommits } from 'backport';
@@ -210,9 +218,9 @@ console.log(commits);
210
218
  */
211
219
  ```
212
220
 
213
- ## Github Action (beta)
221
+ ## The Backport Tool as a Github Action
214
222
 
215
- A [Github Action](https://github.com/elastic/kibana-github-actions/tree/main/backport) for automatically backporting pull requests.
223
+ A [Github Action](https://github.com/elastic/kibana-github-actions/tree/main/backport) around The Backport Tool for automatically creating backports when pull requests are merged.
216
224
 
217
225
  ## What is backporting?
218
226
 
@@ -224,20 +232,21 @@ Source: [https://en.wikipedia.org/wiki/Backporting](https://en.wikipedia.org/wik
224
232
 
225
233
  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.
226
234
 
227
- `backport` is a CLI tool that will let you backport commit(s) interactively and then cherry-pick and create pull requests automatically. `backport` will always perform the git operation in a temporary folder (`~/.backport/repositories/`) separate from your working directory, thereby never interfering with any unstages changes your might have.
235
+ `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.
228
236
 
229
237
  **Features:**
230
238
 
231
239
  - interactively backport one or more commits to one or more branches with an intuitive UI
232
- - will never run `git reset --hard` or other git commands in your working directory - all git operations are handled in a separate directory
240
+ - ability to see which commits have been backported and to which branches
241
+ - ability to customize the title, description and labels of the created backport PRs
242
+ - all git operations are handled in a separate directory to not interfere with unstaged files
243
+ - Conflicts are handled gracefully, and hints are provided to help the user understand the source of the conflict
233
244
  - backport a commit by specifying a PR: `backport --pr 1337`
234
245
  - list and backport commits by a particular user: `backport --author john`
235
246
  - list and backport commits by a particular path: `backport --path src/plugins/chatbot`
236
247
  - list PRs filtered by a query: `backport --pr-filter label:backport-v2` (will list commits from PRs with the label "backport-v2")
237
- - forward port commits: `backport --sourceBranch 7.x --branch master` (will forwardport from 7.x to master)
248
+ - forward port commits: `backport --source-branch 7.x --branch master` (will forwardport from 7.x to master)
238
249
  - backport merge commits: `backport --mainline`
239
- - ability to see which commits have been backported and to which branches
240
- - customize the title, description and labels of the created backport PRs
241
250
 
242
251
  ## Contributing
243
252
 
@@ -245,3 +254,7 @@ See [CONTRIBUTING.md](https://github.com/sqren/backport/blob/master/CONTRIBUTING
245
254
 
246
255
  [1]: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x
247
256
  [2]: https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
257
+
258
+ [![Build Status](https://travis-ci.com/sqren/backport.svg?branch=master)](https://app.travis-ci.com/github/sqren/backport)
259
+ [![NPM version](https://img.shields.io/npm/v/backport.svg)](https://www.npmjs.com/package/backport)
260
+ [![Coverage Status](https://coveralls.io/repos/github/sqren/backport/badge.svg?branch=master)](https://coveralls.io/github/sqren/backport?branch=master)
@@ -3,7 +3,8 @@ import { ValidConfigOptions } from './options/options';
3
3
  export { BackportResponse } from './main';
4
4
  export { ConfigFileOptions } from './options/ConfigOptions';
5
5
  export { Commit } from './services/sourceCommit/parseSourceCommit';
6
- export { fetchProjectConfig } from './services/github/v4/fetchProjectConfig';
6
+ export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './services/github/v4/fetchRemoteProjectConfig';
7
+ export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
7
8
  export declare function backportRun(options: ConfigFileOptions, args?: string[]): Promise<import("./main").BackportResponse>;
8
9
  export declare function getCommits(options: {
9
10
  accessToken: string;
@@ -16,4 +17,6 @@ export declare function getCommits(options: {
16
17
  sha?: string;
17
18
  skipRemoteConfig?: boolean;
18
19
  sourceBranch?: string;
20
+ dateUntil?: string;
21
+ dateSince?: string;
19
22
  }): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
@@ -1,15 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommits = exports.backportRun = exports.fetchProjectConfig = void 0;
3
+ exports.getCommits = exports.backportRun = exports.getLocalGlobalConfig = exports.getRemoteProjectConfig = void 0;
4
4
  const main_1 = require("./main");
5
5
  const fetchCommitByPullNumber_1 = require("./services/github/v4/fetchCommits/fetchCommitByPullNumber");
6
6
  const fetchCommitBySha_1 = require("./services/github/v4/fetchCommits/fetchCommitBySha");
7
7
  const fetchCommitsByAuthor_1 = require("./services/github/v4/fetchCommits/fetchCommitsByAuthor");
8
8
  const getOptionsFromGithub_1 = require("./services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
9
9
  const logger_1 = require("./services/logger");
10
+ const excludeUndefined_1 = require("./utils/excludeUndefined");
10
11
  (0, logger_1.initLogger)();
11
- var fetchProjectConfig_1 = require("./services/github/v4/fetchProjectConfig");
12
- Object.defineProperty(exports, "fetchProjectConfig", { enumerable: true, get: function () { return fetchProjectConfig_1.fetchProjectConfig; } });
12
+ var fetchRemoteProjectConfig_1 = require("./services/github/v4/fetchRemoteProjectConfig");
13
+ Object.defineProperty(exports, "getRemoteProjectConfig", { enumerable: true, get: function () { return fetchRemoteProjectConfig_1.fetchRemoteProjectConfig; } });
14
+ var globalConfig_1 = require("./options/config/globalConfig");
15
+ Object.defineProperty(exports, "getLocalGlobalConfig", { enumerable: true, get: function () { return globalConfig_1.getGlobalConfig; } });
13
16
  function backportRun(options,
14
17
  // cli args will not automatically be forwarded when it is consumed as a module
15
18
  // It is simple to forward args manually via `process.argv`:
@@ -19,7 +22,7 @@ function backportRun(options,
19
22
  // backportRun(options, args)
20
23
  //
21
24
  args = []) {
22
- return (0, main_1.main)(args, options);
25
+ return (0, main_1.main)(args, (0, excludeUndefined_1.excludeUndefined)(options));
23
26
  }
24
27
  exports.backportRun = backportRun;
25
28
  async function getCommits(options) {
@@ -45,7 +48,10 @@ async function getCommits(options) {
45
48
  return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
46
49
  ...optionsFromGithub,
47
50
  ...options,
51
+ // filters
48
52
  author: options.author ?? null,
53
+ dateSince: options.dateSince ?? null,
54
+ dateUntil: options.dateUntil ?? null,
49
55
  });
50
56
  }
51
57
  exports.getCommits = getCommits;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- jest.unmock('./services/logger');
4
3
  const entrypoint_module_1 = require("./entrypoint.module");
5
4
  const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
6
5
  describe('entrypoint.module', () => {
@@ -21,6 +20,10 @@ describe('entrypoint.module', () => {
21
20
  number: 4,
22
21
  state: 'MERGED',
23
22
  url: 'https://github.com/backport-org/backport-e2e/pull/4',
23
+ mergeCommit: {
24
+ message: 'Add family emoji (#2) (#4)',
25
+ sha: 'f8b4f6ae7ffaf2732fa5e33e98b3ea772bdfff1d',
26
+ },
24
27
  },
25
28
  ],
26
29
  originalMessage: 'Add family emoji (#2)',
package/dist/main.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.main = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
+ const ora_1 = __importDefault(require("ora"));
8
9
  const options_1 = require("./options/options");
9
10
  const runSequentially_1 = require("./runSequentially");
10
11
  const HandledError_1 = require("./services/HandledError");
@@ -14,10 +15,12 @@ const logger_1 = require("./services/logger");
14
15
  const getCommits_1 = require("./ui/getCommits");
15
16
  const getTargetBranches_1 = require("./ui/getTargetBranches");
16
17
  async function main(argv, optionsFromModule) {
18
+ const spinner = (0, ora_1.default)().start('Initializing...');
17
19
  let options = null;
18
20
  let commits = [];
19
21
  try {
20
22
  options = await (0, options_1.getOptions)(argv, optionsFromModule);
23
+ spinner.stop();
21
24
  commits = await (0, getCommits_1.getCommits)(options);
22
25
  const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
23
26
  const results = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
@@ -33,13 +36,14 @@ async function main(argv, optionsFromModule) {
33
36
  return backportResponse;
34
37
  }
35
38
  catch (e) {
39
+ spinner.stop();
36
40
  const backportResponse = {
37
41
  status: 'failure',
38
42
  commits,
39
43
  errorMessage: e.message,
40
44
  error: e,
41
45
  };
42
- if (options?.ci) {
46
+ if (options) {
43
47
  await (0, createStatusComment_1.createStatusComment)({
44
48
  options,
45
49
  backportResponse,
@@ -18,9 +18,11 @@ declare type Options = Partial<{
18
18
  autoFixConflicts: AutoFixConflictsHandler;
19
19
  autoMerge: boolean;
20
20
  autoMergeMethod: string;
21
+ backportBinary: string;
21
22
  cherrypickRef: boolean;
22
23
  ci: boolean;
23
24
  commitPaths: string[];
25
+ dir: string;
24
26
  details: boolean;
25
27
  editor: string;
26
28
  fork: boolean;
@@ -35,6 +37,7 @@ declare type Options = Partial<{
35
37
  prDescription: string;
36
38
  prFilter: string;
37
39
  prTitle: string;
40
+ publishStatusComment: boolean;
38
41
  pullNumber: number;
39
42
  repoName: string;
40
43
  repoOwner: string;
@@ -3,7 +3,9 @@ export declare function getOptionsFromCliArgs(argv: readonly string[], { exitOnE
3
3
  exitOnError?: boolean;
4
4
  }): {
5
5
  fork?: boolean | undefined;
6
+ dir?: string | undefined;
6
7
  verbose?: boolean | undefined;
8
+ ci?: boolean | undefined;
7
9
  accessToken?: string | undefined;
8
10
  assignees?: string[] | undefined;
9
11
  author?: string | null | undefined;
@@ -11,7 +13,6 @@ export declare function getOptionsFromCliArgs(argv: readonly string[], { exitOnE
11
13
  autoMerge?: boolean | undefined;
12
14
  autoMergeMethod?: string | undefined;
13
15
  cherrypickRef?: boolean | undefined;
14
- ci?: boolean | undefined;
15
16
  commitPaths?: string[] | undefined;
16
17
  details?: boolean | undefined;
17
18
  editor?: string | undefined;
@@ -25,6 +26,7 @@ export declare function getOptionsFromCliArgs(argv: readonly string[], { exitOnE
25
26
  prDescription?: string | undefined;
26
27
  prFilter?: string | undefined;
27
28
  prTitle?: string | undefined;
29
+ publishStatusComment?: boolean | undefined;
28
30
  pullNumber?: number | undefined;
29
31
  repoName?: string | undefined;
30
32
  repoOwner?: string | undefined;
@@ -38,4 +40,6 @@ export declare function getOptionsFromCliArgs(argv: readonly string[], { exitOnE
38
40
  targetBranches?: string[] | undefined;
39
41
  targetPRLabels?: string[] | undefined;
40
42
  mainline?: number | undefined;
43
+ dateSince?: string | undefined;
44
+ dateUntil?: string | undefined;
41
45
  };
@@ -56,6 +56,18 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
56
56
  description: 'Append commit message with "(cherry picked from commit...)',
57
57
  type: 'boolean',
58
58
  conflicts: ['noCherrypickRef'],
59
+ })
60
+ .option('since', {
61
+ description: 'ISO-8601 date for filtering commits',
62
+ type: 'string',
63
+ })
64
+ .option('until', {
65
+ description: 'ISO-8601 date for filtering commits',
66
+ type: 'string',
67
+ })
68
+ .option('dir', {
69
+ description: 'Location where the temporary repository will be stored',
70
+ type: 'string',
59
71
  })
60
72
  .option('details', {
61
73
  description: 'Show details about each commit',
@@ -135,6 +147,10 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
135
147
  description: 'Do not append commit message with "(cherry picked from commit...)"',
136
148
  type: 'boolean',
137
149
  conflicts: ['cherrypickRef'],
150
+ })
151
+ .option('noStatusComment', {
152
+ description: "Don't publish status comment to Github",
153
+ type: 'boolean',
138
154
  })
139
155
  .option('noVerify', {
140
156
  description: 'Bypass the pre-commit and commit-msg hooks',
@@ -256,14 +272,19 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
256
272
  /* eslint-disable @typescript-eslint/no-unused-vars */
257
273
  $0, _,
258
274
  /* eslint-enable @typescript-eslint/no-unused-vars */
259
- multiple, multipleBranches, multipleCommits, all, author,
275
+ multiple, multipleBranches, multipleCommits, all,
276
+ // filters
277
+ author, since, until,
260
278
  // negations
261
- verify, noVerify, noCherrypickRef, noFork,
279
+ noCherrypickRef, noFork, noStatusComment, noVerify, verify,
262
280
  // array types (should be renamed to plural form)
263
281
  assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
264
282
  return (0, excludeUndefined_1.excludeUndefined)({
265
283
  ...restOptions,
284
+ // filters
266
285
  author: all ? null : author,
286
+ dateSince: since,
287
+ dateUntil: until,
267
288
  // `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
268
289
  multipleBranches: multiple ?? multipleBranches,
269
290
  multipleCommits: multiple ?? multipleCommits,
@@ -279,6 +300,7 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
279
300
  cherrypickRef: noCherrypickRef === true ? false : restOptions.cherrypickRef,
280
301
  fork: noFork === true ? false : restOptions.fork,
281
302
  noVerify: verify ?? noVerify,
303
+ publishStatusComment: noStatusComment === true ? false : undefined,
282
304
  });
283
305
  }
284
306
  exports.getOptionsFromCliArgs = getOptionsFromCliArgs;
@@ -20,8 +20,6 @@ describe('getOptionsFromCliArgs', () => {
20
20
  const argv = [
21
21
  '--access-token',
22
22
  'my access token',
23
- '--author',
24
- 'sqren',
25
23
  '--repo-owner',
26
24
  'elastic',
27
25
  '--repo-name',
@@ -32,11 +30,6 @@ describe('getOptionsFromCliArgs', () => {
32
30
  accessToken: 'my access token',
33
31
  repoOwner: 'elastic',
34
32
  repoName: 'kibana',
35
- author: 'sqren',
36
- mainline: 1,
37
- reviewers: [],
38
- assignees: [],
39
- commitPaths: [],
40
33
  });
41
34
  });
42
35
  });
@@ -1,6 +1,9 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
2
  export declare type OptionsFromConfigFiles = Awaited<ReturnType<typeof getOptionsFromConfigFiles>>;
3
- export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFileOptions): Promise<{
3
+ export declare function getOptionsFromConfigFiles({ optionsFromModule, ci, }: {
4
+ optionsFromModule?: ConfigFileOptions;
5
+ ci: boolean;
6
+ }): Promise<{
4
7
  accessToken?: string | undefined;
5
8
  assignees?: string[] | undefined;
6
9
  author?: string | null | undefined;
@@ -19,9 +22,11 @@ export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFile
19
22
  }) => boolean | Promise<boolean>) | undefined;
20
23
  autoMerge?: boolean | undefined;
21
24
  autoMergeMethod?: string | undefined;
25
+ backportBinary?: string | undefined;
22
26
  cherrypickRef?: boolean | undefined;
23
27
  ci?: boolean | undefined;
24
28
  commitPaths?: string[] | undefined;
29
+ dir?: string | undefined;
25
30
  details?: boolean | undefined;
26
31
  editor?: string | undefined;
27
32
  fork?: boolean | undefined;
@@ -36,6 +41,7 @@ export declare function getOptionsFromConfigFiles(optionsFromModule?: ConfigFile
36
41
  prDescription?: string | undefined;
37
42
  prFilter?: string | undefined;
38
43
  prTitle?: string | undefined;
44
+ publishStatusComment?: boolean | undefined;
39
45
  pullNumber?: number | undefined;
40
46
  repoName?: string | undefined;
41
47
  repoOwner?: string | undefined;
@@ -4,11 +4,11 @@ exports.getOptionsFromConfigFiles = void 0;
4
4
  const getOptionsFromGit_1 = require("./getOptionsFromGit");
5
5
  const globalConfig_1 = require("./globalConfig");
6
6
  const projectConfig_1 = require("./projectConfig");
7
- async function getOptionsFromConfigFiles(optionsFromModule) {
7
+ async function getOptionsFromConfigFiles({ optionsFromModule, ci, }) {
8
8
  const [gitConfig, projectConfig, globalConfig] = await Promise.all([
9
9
  (0, getOptionsFromGit_1.getOptionsFromGit)(),
10
10
  (0, projectConfig_1.getProjectConfig)(),
11
- (0, globalConfig_1.getGlobalConfig)(optionsFromModule?.ci),
11
+ ci ? undefined : (0, globalConfig_1.getGlobalConfig)(),
12
12
  ]);
13
13
  return {
14
14
  ...gitConfig,
@@ -9,7 +9,7 @@ describe('getOptionsFromConfigFiles', () => {
9
9
  globalConfig: { accessToken: 'abc', editor: 'vim' },
10
10
  projectConfig: { repoName: 'kibana', repoOwner: 'elastic' },
11
11
  });
12
- res = await (0, config_1.getOptionsFromConfigFiles)();
12
+ res = await (0, config_1.getOptionsFromConfigFiles)({ ci: false });
13
13
  });
14
14
  it('should return values from config files', () => {
15
15
  expect(res).toEqual({
@@ -1,4 +1,4 @@
1
1
  import { ConfigFileOptions } from '../ConfigOptions';
2
- export declare function getGlobalConfig(ci?: boolean): Promise<ConfigFileOptions | undefined>;
2
+ export declare function getGlobalConfig(): Promise<ConfigFileOptions>;
3
3
  export declare function createGlobalConfigAndFolderIfNotExist(): Promise<boolean>;
4
4
  export declare function createGlobalConfigIfNotExist(globalConfigPath: string, configTemplate: string): Promise<boolean>;
@@ -8,21 +8,17 @@ const make_dir_1 = __importDefault(require("make-dir"));
8
8
  const env_1 = require("../../services/env");
9
9
  const fs_promisified_1 = require("../../services/fs-promisified");
10
10
  const readConfigFile_1 = require("./readConfigFile");
11
- async function getGlobalConfig(ci) {
12
- // don't attempt to fetch global config in ci environment
13
- if (ci) {
14
- return;
15
- }
11
+ async function getGlobalConfig() {
16
12
  await createGlobalConfigAndFolderIfNotExist();
17
13
  const globalConfigPath = (0, env_1.getGlobalConfigPath)();
18
14
  return (0, readConfigFile_1.readConfigFile)(globalConfigPath);
19
15
  }
20
16
  exports.getGlobalConfig = getGlobalConfig;
21
17
  async function createGlobalConfigAndFolderIfNotExist() {
22
- const reposPath = (0, env_1.getReposPath)();
18
+ // create .backport folder
19
+ await (0, make_dir_1.default)((0, env_1.getBackportDirPath)());
23
20
  const globalConfigPath = (0, env_1.getGlobalConfigPath)();
24
21
  const configTemplate = getConfigTemplate();
25
- await (0, make_dir_1.default)(reposPath);
26
22
  const didCreate = await createGlobalConfigIfNotExist(globalConfigPath, configTemplate);
27
23
  await ensureCorrectPermissions(globalConfigPath);
28
24
  return didCreate;
@@ -50,7 +46,7 @@ async function createGlobalConfigIfNotExist(globalConfigPath, configTemplate) {
50
46
  exports.createGlobalConfigIfNotExist = createGlobalConfigIfNotExist;
51
47
  function getConfigTemplate() {
52
48
  return `{
53
- // Github personal access token. Must be created here: https://github.com/settings/tokens/new
49
+ // Create a personal access token here: https://github.com/settings/tokens
54
50
  // Must have "Repo: Full control of private repositories"
55
51
  "accessToken": ""
56
52
  }`;
@@ -2,7 +2,9 @@ import { ConfigFileOptions } from '../ConfigOptions';
2
2
  export declare function readConfigFile(filepath: string): Promise<ConfigFileOptions>;
3
3
  export declare function withConfigMigrations({ upstream, labels, branches, ...config }: ConfigFileOptions): {
4
4
  fork?: boolean | undefined;
5
+ dir?: string | undefined;
5
6
  verbose?: boolean | undefined;
7
+ ci?: boolean | undefined;
6
8
  accessToken?: string | undefined;
7
9
  assignees?: string[] | undefined;
8
10
  author?: string | null | undefined;
@@ -21,8 +23,8 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
21
23
  }) => boolean | Promise<boolean>) | undefined;
22
24
  autoMerge?: boolean | undefined;
23
25
  autoMergeMethod?: string | undefined;
26
+ backportBinary?: string | undefined;
24
27
  cherrypickRef?: boolean | undefined;
25
- ci?: boolean | undefined;
26
28
  commitPaths?: string[] | undefined;
27
29
  details?: boolean | undefined;
28
30
  editor?: string | undefined;
@@ -37,6 +39,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
37
39
  prDescription?: string | undefined;
38
40
  prFilter?: string | undefined;
39
41
  prTitle?: string | undefined;
42
+ publishStatusComment?: boolean | undefined;
40
43
  pullNumber?: number | undefined;
41
44
  repoName?: string | undefined;
42
45
  repoOwner?: string | undefined;