backport 6.0.0 → 6.1.3

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 (106) hide show
  1. package/README.md +179 -52
  2. package/dist/entrypoint.cli.js +2 -0
  3. package/dist/entrypoint.module.d.ts +16 -4
  4. package/dist/entrypoint.module.js +41 -13
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +34 -0
  7. package/dist/main.js +1 -2
  8. package/dist/options/ConfigOptions.d.ts +16 -6
  9. package/dist/options/cliArgs.d.ts +36 -37
  10. package/dist/options/cliArgs.js +25 -24
  11. package/dist/options/cliArgs.test.js +6 -10
  12. package/dist/options/config/config.d.ts +28 -52
  13. package/dist/options/config/config.js +2 -36
  14. package/dist/options/config/config.test.js +10 -27
  15. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  16. package/dist/options/config/getOptionsFromGit.js +1 -3
  17. package/dist/options/config/globalConfig.js +2 -5
  18. package/dist/options/config/globalConfig.test.js +0 -2
  19. package/dist/options/config/projectConfig.test.js +51 -14
  20. package/dist/options/config/readConfigFile.d.ts +52 -0
  21. package/dist/options/config/readConfigFile.js +28 -2
  22. package/dist/options/options.d.ts +55 -32
  23. package/dist/options/options.js +101 -7
  24. package/dist/options/options.test.js +248 -97
  25. package/dist/options/parseRequiredOptions.d.ts +3 -3
  26. package/dist/options/parseRequiredOptions.js +2 -4
  27. package/dist/options/parseRequiredOptions.test.js +6 -11
  28. package/dist/runSequentially.test.js +40 -78
  29. package/dist/services/git.d.ts +5 -2
  30. package/dist/services/git.js +11 -10
  31. package/dist/services/git.test.js +12 -9
  32. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  33. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
  34. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
  35. package/dist/services/github/v3/createPullRequest.js +10 -13
  36. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  37. package/dist/services/github/v3/createPullRequest.test.js +110 -0
  38. package/dist/services/github/v3/createStatusComment.js +12 -14
  39. package/dist/services/github/v3/createStatusComment.test.js +58 -29
  40. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  41. package/dist/services/github/v4/apiRequestV4.js +1 -1
  42. package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
  43. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
  44. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  45. package/dist/services/github/v4/fetchAuthorId.js +5 -6
  46. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
  47. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
  48. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  49. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
  50. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
  51. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
  52. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
  53. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
  54. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
  55. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
  56. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
  57. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  58. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  59. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
  60. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
  61. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
  62. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  63. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  64. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  65. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  66. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  67. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  68. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
  69. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  70. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  71. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  72. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
  73. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
  74. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
  75. package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
  76. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +32 -15
  77. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
  78. package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
  79. package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
  80. package/dist/test/inquirer.private.test.js +33 -36
  81. package/dist/test/integration/integration.private.test.js +114 -95
  82. package/dist/test/mockConfigFiles.d.ts +5 -0
  83. package/dist/test/mockConfigFiles.js +37 -0
  84. package/dist/test/nockHelpers.d.ts +1 -1
  85. package/dist/test/nockHelpers.js +4 -4
  86. package/dist/test/private/getDevAccessToken.js +1 -1
  87. package/dist/test/setupFiles/automatic-mocks.js +1 -29
  88. package/dist/ui/cherrypickAndCreatePullRequest.test.js +80 -28
  89. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
  90. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +13 -48
  91. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +222 -260
  92. package/dist/ui/getCommits.d.ts +1 -1
  93. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  94. package/dist/ui/getCommitsWithoutBackports.js +53 -0
  95. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  96. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  97. package/dist/ui/getTargetBranches.d.ts +2 -1
  98. package/dist/ui/getTargetBranches.js +17 -1
  99. package/dist/ui/maybeSetupRepo.js +4 -3
  100. package/dist/ui/maybeSetupRepo.test.js +49 -3
  101. package/dist/utils/excludeUndefined.d.ts +6 -0
  102. package/dist/utils/excludeUndefined.js +7 -0
  103. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  104. package/dist/utils/excludeUndefined.test.js +24 -0
  105. package/package.json +9 -8
  106. package/yarn.lock +98 -77
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
 
@@ -19,7 +25,7 @@ A simple CLI tool that automates the process of backporting commits on a GitHub
19
25
  npm install -g backport
20
26
  ```
21
27
 
22
- After installation you should update the [global config](https://github.com/sqren/backport/blob/master/docs/configuration.md#global-config-backportconfigjson) in `~/.backport/config.json` with your Github username and a Github access token. See the [documentation](https://github.com/sqren/backport/blob/master/docs/configuration.md#accesstoken-required) for how the access token is generated.
28
+ After installation you should add an access token to the [global config](https://github.com/sqren/backport/blob/master/docs/configuration.md#global-config-backportconfigjson) in `~/.backport/config.json`. See the [documentation](https://github.com/sqren/backport/blob/master/docs/configuration.md#accesstoken-required) for how the access token is generated.
23
29
 
24
30
  ## Quick start
25
31
 
@@ -28,11 +34,15 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
28
34
  ```js
29
35
  // .backportrc.json
30
36
  {
31
- "upstream": "elastic/kibana",
37
+ "repoOwner": "elastic",
38
+ "repoName": "kibana",
39
+
40
+ // the branches available to backport to
32
41
  "targetBranchChoices": ["main", "6.3", "6.2", "6.1", "6.0"],
42
+
43
+ // Optional: Automatically detect which branches a pull request should be backported to based on the pull request labels.
33
44
  "branchLabelMapping": {
34
- "^v6.4.0$": "main",
35
- "^v(\\d+).(\\d+).\\d+$": "$1.$2"
45
+ "^backport-to-(.+)$": "$1"
36
46
  }
37
47
  }
38
48
  ```
@@ -57,47 +67,159 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
57
67
 
58
68
  ### CLI options
59
69
 
60
- Please note that dashes between the words are optional, for instance you can type `--targetBranch` or `--target-branch` both are valid options.
61
-
62
- | Option | Shorthand notation | Description | Default | Type |
63
- | ------------------- | ------------------ | ------------------------------------------------------------- | -------------- | --------- |
64
- | --access-token | | Github access token | | `string` |
65
- | --all | -a | Show commits from other than yourself | false | `boolean` |
66
- | --author | | Filter commits by Github username | _Current user_ | `string` |
67
- | --assignee | --assign | Assign users to the target PR | | `string` |
68
- | --auto-assign | | Assign current user to the target PR | false | `boolean` |
69
- | --branch | -b | Target branch to backport to | | `string` |
70
- | --ci | | Disable interactive prompts | false | `boolean` |
71
- | --dry-run | | Perform backport without pushing to Github | false | `string` |
72
- | --editor | | Editor (eg. `code`) to open and resolve conflicts | nano | `string` |
73
- | --fork | | Create backports in fork repo | true | `boolean` |
74
- | --git-hostname | | Hostname for Git | github.com | `string` |
75
- | --no-cherrypick-ref | | Do not append "(cherry picked from commit...)". [Git Docs][1] | false | `boolean` |
76
- | --no-verify | | Bypass the pre-commit and commit-msg hooks | false | `boolean` |
77
- | --mainline | | Parent id of merge commit | 1 | `number` |
78
- | --max-number | --number, -n | Number of commits to choose from | 10 | `number` |
79
- | --multiple | | Multi-select for commits and branches | false | `boolean` |
80
- | --multiple-branches | | Multi-select for branches | true | `boolean` |
81
- | --multiple-commits | | Multi-select for commits | false | `boolean` |
82
- | --path | -p | Filter commits by path | | `string` |
83
- | --pull-number | --pr | Backport pull request by number | | `number` |
84
- | --pr-description | --description | Pull request description suffix | | `string` |
85
- | --pr-filter | | Find PRs using [Github's search syntax][2] | | `string` |
86
- | --pr-title | --title | Title of pull request | | `string` |
87
- | --reset-author | | Set yourself as commit author | | `boolean` |
88
- | --reviewer | | Add reviewer to the target PR | | `boolean` |
89
- | --sha | | Sha of commit to backport | | `string` |
90
- | --source-branch | | Specify a non-default branch to backport from | | `string` |
91
- | --source-pr-label | | Labels added to the source PR | | `string` |
92
- | --target-pr-label | --label, -l | Labels added to the target PR | | `string` |
93
- | --target-branch | -b | Target branch(es) to backport to | | `string` |
94
- | --upstream | --up | Name of organization and repository | | `string` |
95
- | --username | | Github username | | `string` |
96
- | --help | | Show help | | |
97
- | -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
+ | --dry-run | | Perform backport without pushing to Github | false |
80
+ | --editor | | Editor (eg. `code`) to open and resolve conflicts | nano |
81
+ | --fork | | Create backports in fork repo | true |
82
+ | --git-hostname | | Hostname for Git | github.com |
83
+ | --mainline | | Parent id of merge commit | 1 |
84
+ | --max-number | --number, -n | Number of commits to choose from | 10 |
85
+ | --multiple | | Multi-select for commits and branches | false |
86
+ | --multiple-branches | | Multi-select for branches | true |
87
+ | --multiple-commits | | Multi-select for commits | false |
88
+ | --no-cherrypick-ref | | Do not append "(cherry picked from commit...)". [Git Docs][1] | false |
89
+ | --no-verify | | Bypass the pre-commit and commit-msg hooks | false |
90
+ | --path | -p | Filter commits by path | |
91
+ | --pr-description | --description | Pull request description suffix | |
92
+ | --pr-filter | | Find PRs using [Github's search syntax][2] | |
93
+ | --pr-title | --title | Title of pull request | |
94
+ | --pull-number | --pr | Backport pull request by number | |
95
+ | --repo-name | | Name of repository | |
96
+ | --repo-owner | | Owner of repository | |
97
+ | --reset-author | | Set yourself as commit author | |
98
+ | --reviewer | | Add reviewer to the target PR | |
99
+ | --sha | | Sha of commit to backport | |
100
+ | --source-branch | | Specify a non-default branch to backport from | |
101
+ | --source-pr-label | | Labels added to the source PR | |
102
+ | --target-branch | -b | Target branch(es) to backport to | |
103
+ | --target-pr-label | --label, -l | Labels added to the target PR | |
104
+ | --help | | Show help | |
105
+ | -v, --version | | Show version number | |
98
106
 
99
107
  The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/master/docs/configuration.md).
100
108
 
109
+ ## Backport Module API
110
+
111
+ `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)
112
+
113
+ ### `backportRun`
114
+
115
+ Backport a commit programatically. Commits can be selected via `pullNumber` or `sha`.
116
+
117
+ #### Arguments:
118
+
119
+ 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:
120
+
121
+ `accessToken` _string_ **(Required)**<br/>
122
+ Github access token to authenticate the request
123
+
124
+ `repoName` _string_ **(Required)**<br/>
125
+ Name of repository
126
+
127
+ `repoOwner` _string_ **(Required)**<br/>
128
+ Owner of repository (organisation or username)
129
+
130
+ `pullNumber` _number_<br/>
131
+ Filter commits by pull request number
132
+
133
+ `sha` _string_<br/>
134
+ Filter commits by commit sha
135
+
136
+ `ci` _boolean_<br/>
137
+ Enabling this will disable the interactive prompts
138
+
139
+ #### Example
140
+
141
+ ```ts
142
+ import { backportRun } from 'backport';
143
+
144
+ const result = await backportRun({
145
+ accessToken: 'abc',
146
+ repoName: 'kibana',
147
+ repoOwner: 'elastic',
148
+ pullNumber: 121633,
149
+ ci: true,
150
+ targetPRLabels: ['backport'],
151
+ autoMerge: true,
152
+ autoMergeMethod: 'squash',
153
+ });
154
+
155
+ console.log(result);
156
+ ```
157
+
158
+ ### `getCommits`
159
+
160
+ Retrieve information about commits and whether they are backported
161
+
162
+ #### Arguments:
163
+
164
+ `accessToken` _string_ **(Required)**<br/>
165
+ Github access token to authenticate the request
166
+
167
+ `repoName` _string_ **(Required)**<br/>
168
+ Name of repository
169
+
170
+ `repoOwner` _string_ **(Required)**<br/>
171
+ Owner of repository (organisation or username)
172
+
173
+ `author` _string_<br/>
174
+ Filter commits by Github user
175
+
176
+ `pullNumber` _number_<br/>
177
+ Filter commits by pull request number
178
+
179
+ `sha` _string_<br/>
180
+ Filter commits by commit sha
181
+
182
+ `sourceBranch` _string_<br/>
183
+ The branch to display commits from. Defaults to the default branch (normally "main" or "master")
184
+
185
+ #### Example
186
+
187
+ ```ts
188
+ import { getCommits } from 'backport';
189
+
190
+ const commits = await getCommits({
191
+ accessToken: 'abc',
192
+ repoName: 'kibana',
193
+ repoOwner: 'elastic',
194
+ pullNumber: 121633,
195
+ });
196
+
197
+ console.log(commits);
198
+
199
+ /*
200
+ [{
201
+ committedDate: '2021-12-20T14:20:16Z',
202
+ sourceBranch: 'main',
203
+ sha: 'd421ddcf6157150596581c7885afa3690cec6339',
204
+ originalMessage: '[APM] Add note about synthtrace to APM docs (#121633)',
205
+ pullNumber: 121633,
206
+ pullUrl: 'https://github.com/elastic/kibana/pull/121633',
207
+ expectedTargetPullRequests: [
208
+ {
209
+ url: 'https://github.com/elastic/kibana/pull/121643',
210
+ number: 121643,
211
+ branch: '8.0',
212
+ state: 'MERGED'
213
+ }
214
+ ]
215
+ }]
216
+ */
217
+ ```
218
+
219
+ ## The Backport Tool as a Github Action
220
+
221
+ 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.
222
+
101
223
  ## What is backporting?
102
224
 
103
225
  > 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.
@@ -108,20 +230,21 @@ Source: [https://en.wikipedia.org/wiki/Backporting](https://en.wikipedia.org/wik
108
230
 
109
231
  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.
110
232
 
111
- `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.
233
+ `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.
112
234
 
113
235
  **Features:**
114
236
 
115
237
  - interactively backport one or more commits to one or more branches with an intuitive UI
116
- - will never run `git reset --hard` or other git commands in your working directory - all git operations are handled in a separate directory
238
+ - ability to see which commits have been backported and to which branches
239
+ - ability to customize the title, description and labels of the created backport PRs
240
+ - all git operations are handled in a separate directory to not interfere with unstaged files
241
+ - Conflicts are handled gracefully, and hints are provided to help the user understand the source of the conflict
117
242
  - backport a commit by specifying a PR: `backport --pr 1337`
118
243
  - list and backport commits by a particular user: `backport --author john`
119
244
  - list and backport commits by a particular path: `backport --path src/plugins/chatbot`
120
245
  - list PRs filtered by a query: `backport --pr-filter label:backport-v2` (will list commits from PRs with the label "backport-v2")
121
- - forward port commits: `backport --sourceBranch 7.x --branch master` (will forwardport from 7.x to master)
246
+ - forward port commits: `backport --source-branch 7.x --branch master` (will forwardport from 7.x to master)
122
247
  - backport merge commits: `backport --mainline`
123
- - ability to see which commits have been backported and to which branches
124
- - customize the title, description and labels of the created backport PRs
125
248
 
126
249
  ## Contributing
127
250
 
@@ -129,3 +252,7 @@ See [CONTRIBUTING.md](https://github.com/sqren/backport/blob/master/CONTRIBUTING
129
252
 
130
253
  [1]: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x
131
254
  [2]: https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
255
+
256
+ [![Build Status](https://travis-ci.com/sqren/backport.svg?branch=master)](https://app.travis-ci.com/github/sqren/backport)
257
+ [![NPM version](https://img.shields.io/npm/v/backport.svg)](https://www.npmjs.com/package/backport)
258
+ [![Coverage Status](https://coveralls.io/repos/github/sqren/backport/badge.svg?branch=master)](https://coveralls.io/github/sqren/backport?branch=master)
@@ -2,6 +2,8 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const main_1 = require("./main");
5
+ const logger_1 = require("./services/logger");
5
6
  const args = process.argv.slice(2);
7
+ (0, logger_1.initLogger)();
6
8
  // this is the entrypoint when running from command line
7
9
  (0, main_1.main)(args);
@@ -1,7 +1,19 @@
1
1
  import { ConfigFileOptions } from './options/ConfigOptions';
2
- export declare function run(options: ConfigFileOptions, args?: string[]): Promise<import("./main").BackportResponse>;
2
+ import { ValidConfigOptions } from './options/options';
3
3
  export { BackportResponse } from './main';
4
4
  export { ConfigFileOptions } from './options/ConfigOptions';
5
- export { fetchCommitsByAuthor } from './services/github/v4/fetchCommits/fetchCommitsByAuthor';
6
- export { fetchCommitByPullNumber } from './services/github/v4/fetchCommits/fetchCommitByPullNumber';
7
- export { fetchCommitBySha } from './services/github/v4/fetchCommits/fetchCommitBySha';
5
+ export { Commit } from './services/sourceCommit/parseSourceCommit';
6
+ export { fetchProjectConfig } from './services/github/v4/fetchProjectConfig';
7
+ export declare function backportRun(options: ConfigFileOptions, args?: string[]): Promise<import("./main").BackportResponse>;
8
+ export declare function getCommits(options: {
9
+ accessToken: string;
10
+ repoName: string;
11
+ repoOwner: string;
12
+ author?: string;
13
+ branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
14
+ githubApiBaseUrlV4?: string;
15
+ pullNumber?: number;
16
+ sha?: string;
17
+ skipRemoteConfig?: boolean;
18
+ sourceBranch?: string;
19
+ }): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
@@ -1,23 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchCommitBySha = exports.fetchCommitByPullNumber = exports.fetchCommitsByAuthor = exports.run = void 0;
3
+ exports.getCommits = exports.backportRun = exports.fetchProjectConfig = void 0;
4
4
  const main_1 = require("./main");
5
- // this is the entry point when importing backport as module:
6
- function run(options,
7
- // cli args will not automatically be forwarded when consumed as a module (required/imported)
5
+ const fetchCommitByPullNumber_1 = require("./services/github/v4/fetchCommits/fetchCommitByPullNumber");
6
+ const fetchCommitBySha_1 = require("./services/github/v4/fetchCommits/fetchCommitBySha");
7
+ const fetchCommitsByAuthor_1 = require("./services/github/v4/fetchCommits/fetchCommitsByAuthor");
8
+ const getOptionsFromGithub_1 = require("./services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
9
+ const logger_1 = require("./services/logger");
10
+ (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; } });
13
+ function backportRun(options,
14
+ // cli args will not automatically be forwarded when it is consumed as a module
8
15
  // It is simple to forward args manually via `process.argv`:
9
16
  //
10
- // import { run } from `backport
17
+ // import { backportRun } from `backport
11
18
  // const args = process.argv.slice(2);
12
- // run(options, args)
19
+ // backportRun(options, args)
13
20
  //
14
21
  args = []) {
15
22
  return (0, main_1.main)(args, options);
16
23
  }
17
- exports.run = run;
18
- var fetchCommitsByAuthor_1 = require("./services/github/v4/fetchCommits/fetchCommitsByAuthor");
19
- Object.defineProperty(exports, "fetchCommitsByAuthor", { enumerable: true, get: function () { return fetchCommitsByAuthor_1.fetchCommitsByAuthor; } });
20
- var fetchCommitByPullNumber_1 = require("./services/github/v4/fetchCommits/fetchCommitByPullNumber");
21
- Object.defineProperty(exports, "fetchCommitByPullNumber", { enumerable: true, get: function () { return fetchCommitByPullNumber_1.fetchCommitByPullNumber; } });
22
- var fetchCommitBySha_1 = require("./services/github/v4/fetchCommits/fetchCommitBySha");
23
- Object.defineProperty(exports, "fetchCommitBySha", { enumerable: true, get: function () { return fetchCommitBySha_1.fetchCommitBySha; } });
24
+ exports.backportRun = backportRun;
25
+ async function getCommits(options) {
26
+ const optionsFromGithub = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(options);
27
+ if (options.pullNumber) {
28
+ return [
29
+ await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
30
+ ...optionsFromGithub,
31
+ ...options,
32
+ pullNumber: options.pullNumber,
33
+ }),
34
+ ];
35
+ }
36
+ if (options.sha) {
37
+ return [
38
+ await (0, fetchCommitBySha_1.fetchCommitBySha)({
39
+ ...optionsFromGithub,
40
+ ...options,
41
+ sha: options.sha,
42
+ }),
43
+ ];
44
+ }
45
+ return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
46
+ ...optionsFromGithub,
47
+ ...options,
48
+ author: options.author ?? null,
49
+ });
50
+ }
51
+ exports.getCommits = getCommits;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ jest.unmock('./services/logger');
4
+ const entrypoint_module_1 = require("./entrypoint.module");
5
+ const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
6
+ describe('entrypoint.module', () => {
7
+ it('getCommits', async () => {
8
+ const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ const commits = await (0, entrypoint_module_1.getCommits)({
10
+ accessToken: accessToken,
11
+ repoName: 'backport-e2e',
12
+ repoOwner: 'backport-org',
13
+ pullNumber: 2,
14
+ });
15
+ expect(commits).toEqual([
16
+ {
17
+ committedDate: '2020-08-15T10:44:04Z',
18
+ expectedTargetPullRequests: [
19
+ {
20
+ branch: '7.x',
21
+ number: 4,
22
+ state: 'MERGED',
23
+ url: 'https://github.com/backport-org/backport-e2e/pull/4',
24
+ },
25
+ ],
26
+ originalMessage: 'Add family emoji (#2)',
27
+ pullNumber: 2,
28
+ pullUrl: 'https://github.com/backport-org/backport-e2e/pull/2',
29
+ sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
30
+ sourceBranch: 'master',
31
+ },
32
+ ]);
33
+ });
34
+ });
package/dist/main.js CHANGED
@@ -14,7 +14,6 @@ const logger_1 = require("./services/logger");
14
14
  const getCommits_1 = require("./ui/getCommits");
15
15
  const getTargetBranches_1 = require("./ui/getTargetBranches");
16
16
  async function main(argv, optionsFromModule) {
17
- const logger = (0, logger_1.initLogger)();
18
17
  let options = null;
19
18
  let commits = [];
20
19
  try {
@@ -57,7 +56,7 @@ async function main(argv, optionsFromModule) {
57
56
  (0, logger_1.consoleLog)('Please open an issue in https://github.com/sqren/backport/issues or contact me directly on https://twitter.com/sorenlouv');
58
57
  (0, logger_1.consoleLog)(chalk_1.default.italic(`For additional details see the logs: ${(0, env_1.getLogfilePath)()}`));
59
58
  // log file
60
- logger.info('Unknown error:', e);
59
+ logger_1.logger.info('Unknown error:', e);
61
60
  }
62
61
  return backportResponse;
63
62
  }
@@ -12,19 +12,18 @@ declare type AutoFixConflictsHandler = ({ files, directory, logger, targetBranch
12
12
  }) => boolean | Promise<boolean>;
13
13
  declare type Options = Partial<{
14
14
  accessToken: string;
15
- all: boolean;
16
15
  assignees: string[];
17
- author: string;
16
+ author: string | null;
18
17
  autoAssign: boolean;
19
18
  autoFixConflicts: AutoFixConflictsHandler;
20
19
  autoMerge: boolean;
21
20
  autoMergeMethod: string;
22
- ci: boolean;
21
+ backportBinary: string;
23
22
  cherrypickRef: boolean;
23
+ ci: boolean;
24
24
  commitPaths: string[];
25
25
  details: boolean;
26
26
  editor: string;
27
- forceLocalConfig: boolean;
28
27
  fork: boolean;
29
28
  gitHostname: string;
30
29
  githubApiBaseUrlV3: string;
@@ -38,21 +37,32 @@ declare type Options = Partial<{
38
37
  prFilter: string;
39
38
  prTitle: string;
40
39
  pullNumber: number;
40
+ repoName: string;
41
+ repoOwner: string;
41
42
  resetAuthor: boolean;
42
43
  reviewers: string[];
43
44
  sha: string;
45
+ skipRemoteConfig: boolean;
44
46
  sourceBranch: string;
45
47
  sourcePRLabels: string[];
46
48
  targetBranchChoices: TargetBranchChoiceOrString[];
47
49
  targetBranches: string[];
48
50
  targetPRLabels: string[];
49
- upstream: string;
50
- username: string;
51
51
  verbose: boolean;
52
52
  }>;
53
53
  export declare type ConfigFileOptions = Options & Partial<{
54
54
  branchLabelMapping: Record<string, string>;
55
+ /**
56
+ * @deprecated Replaced by `repoOwner` and `repoName`
57
+ */
58
+ upstream: string;
59
+ /**
60
+ * @deprecated Replaced by `targetBranchChoices`
61
+ */
55
62
  branches: TargetBranchChoiceOrString[];
63
+ /**
64
+ * @deprecated Replaced by `targetPRLabels`
65
+ */
56
66
  labels: string[];
57
67
  }>;
58
68
  export {};
@@ -2,41 +2,40 @@ export declare type OptionsFromCliArgs = ReturnType<typeof getOptionsFromCliArgs
2
2
  export declare function getOptionsFromCliArgs(argv: readonly string[], { exitOnError }?: {
3
3
  exitOnError?: boolean;
4
4
  }): {
5
- multipleBranches: boolean | undefined;
6
- multipleCommits: boolean | undefined;
7
- assignees: string[];
8
- commitPaths: string[];
9
- reviewers: string[];
10
- sourcePRLabels: string[] | undefined;
11
- targetBranchChoices: string[] | undefined;
12
- targetBranches: string[] | undefined;
13
- targetPRLabels: string[] | undefined;
14
- cherrypickRef: boolean | undefined;
15
- fork: boolean | undefined;
16
- noVerify: boolean | undefined;
17
- accessToken: string | undefined;
18
- all: boolean | undefined;
19
- author: string | undefined;
20
- autoAssign: boolean | undefined;
21
- autoMerge: boolean | undefined;
22
- autoMergeMethod: string | undefined;
23
- ci: boolean | undefined;
24
- details: boolean | undefined;
25
- editor: string | undefined;
26
- forceLocalConfig: boolean | undefined;
27
- gitHostname: string | undefined;
28
- githubApiBaseUrlV3: string | undefined;
29
- githubApiBaseUrlV4: string | undefined;
30
- mainline: number | undefined;
31
- maxNumber: number | undefined;
32
- prDescription: string | undefined;
33
- prTitle: string | undefined;
34
- prFilter: string | undefined;
35
- pullNumber: number | undefined;
36
- resetAuthor: boolean | undefined;
37
- sha: string | undefined;
38
- sourceBranch: string | undefined;
39
- upstream: string | undefined;
40
- username: string | undefined;
41
- verbose: boolean | undefined;
5
+ fork?: boolean | undefined;
6
+ verbose?: boolean | undefined;
7
+ accessToken?: string | undefined;
8
+ assignees?: string[] | undefined;
9
+ author?: string | null | undefined;
10
+ autoAssign?: boolean | undefined;
11
+ autoMerge?: boolean | undefined;
12
+ autoMergeMethod?: string | undefined;
13
+ cherrypickRef?: boolean | undefined;
14
+ ci?: boolean | undefined;
15
+ commitPaths?: string[] | undefined;
16
+ details?: boolean | undefined;
17
+ editor?: string | undefined;
18
+ gitHostname?: string | undefined;
19
+ githubApiBaseUrlV3?: string | undefined;
20
+ githubApiBaseUrlV4?: string | undefined;
21
+ maxNumber?: number | undefined;
22
+ multipleBranches?: boolean | undefined;
23
+ multipleCommits?: boolean | undefined;
24
+ noVerify?: boolean | undefined;
25
+ prDescription?: string | undefined;
26
+ prFilter?: string | undefined;
27
+ prTitle?: string | undefined;
28
+ pullNumber?: number | undefined;
29
+ repoName?: string | undefined;
30
+ repoOwner?: string | undefined;
31
+ resetAuthor?: boolean | undefined;
32
+ reviewers?: string[] | undefined;
33
+ sha?: string | undefined;
34
+ skipRemoteConfig?: boolean | undefined;
35
+ sourceBranch?: string | undefined;
36
+ sourcePRLabels?: string[] | undefined;
37
+ targetBranchChoices?: string[] | undefined;
38
+ targetBranches?: string[] | undefined;
39
+ targetPRLabels?: string[] | undefined;
40
+ mainline?: number | undefined;
42
41
  };