backport 5.6.5 → 6.1.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.
Files changed (238) hide show
  1. package/README.md +166 -41
  2. package/dist/entrypoint.cli.js +3 -1
  3. package/dist/entrypoint.module.d.ts +18 -5
  4. package/dist/entrypoint.module.js +42 -12
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +34 -0
  7. package/dist/ink.d.ts +1 -0
  8. package/dist/ink.js +49 -0
  9. package/dist/main.d.ts +11 -6
  10. package/dist/main.js +40 -25
  11. package/dist/options/ConfigOptions.d.ts +28 -12
  12. package/dist/options/cliArgs.d.ts +36 -35
  13. package/dist/options/cliArgs.js +91 -52
  14. package/dist/options/cliArgs.test.js +41 -42
  15. package/dist/options/config/config.d.ts +34 -57
  16. package/dist/options/config/config.js +5 -39
  17. package/dist/options/config/config.test.js +11 -25
  18. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  19. package/dist/options/config/getOptionsFromGit.js +1 -3
  20. package/dist/options/config/globalConfig.d.ts +2 -49
  21. package/dist/options/config/globalConfig.js +9 -12
  22. package/dist/options/config/globalConfig.test.js +7 -5
  23. package/dist/options/config/projectConfig.d.ts +2 -49
  24. package/dist/options/config/projectConfig.js +2 -2
  25. package/dist/options/config/projectConfig.test.js +53 -16
  26. package/dist/options/config/readConfigFile.d.ts +43 -39
  27. package/dist/options/config/readConfigFile.js +30 -4
  28. package/dist/options/options.d.ts +57 -31
  29. package/dist/options/options.js +102 -10
  30. package/dist/options/options.test.js +263 -61
  31. package/dist/options/parseRequiredOptions.d.ts +19 -14
  32. package/dist/options/parseRequiredOptions.js +9 -15
  33. package/dist/options/parseRequiredOptions.test.js +30 -26
  34. package/dist/runSequentially.d.ts +20 -0
  35. package/dist/runSequentially.js +41 -0
  36. package/dist/runSequentially.test.d.ts +1 -0
  37. package/dist/runSequentially.test.js +196 -0
  38. package/dist/runWithOptions.js +7 -14
  39. package/dist/runWithOptions.test.js +140 -17
  40. package/dist/scripts/generate-gql.d.ts +1 -0
  41. package/dist/scripts/generate-gql.js +15 -0
  42. package/dist/scripts/postinstall.js +4 -4
  43. package/dist/scripts/postinstall.test.js +9 -2
  44. package/dist/scripts/runPostinstall.js +1 -1
  45. package/dist/services/HandledError.d.ts +11 -1
  46. package/dist/services/HandledError.js +2 -1
  47. package/dist/services/child-process-promisified.d.ts +1 -1
  48. package/dist/services/child-process-promisified.js +1 -1
  49. package/dist/services/env.js +5 -5
  50. package/dist/services/env.test.js +11 -4
  51. package/dist/services/fs-promisified.js +4 -4
  52. package/dist/services/getExpectedTarget.d.ts +9 -0
  53. package/dist/services/getExpectedTarget.js +77 -0
  54. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  55. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  56. package/dist/services/git.d.ts +20 -6
  57. package/dist/services/git.integration.test.d.ts +1 -0
  58. package/dist/services/git.integration.test.js +168 -0
  59. package/dist/services/git.js +93 -67
  60. package/dist/services/git.test.js +68 -68
  61. package/dist/services/github/commitFormatters.d.ts +3 -7
  62. package/dist/services/github/commitFormatters.js +10 -19
  63. package/dist/services/github/commitFormatters.test.js +2 -24
  64. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  66. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  67. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  68. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  69. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  70. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  71. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  72. package/dist/services/github/v3/createPullRequest.js +31 -29
  73. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  74. package/dist/services/github/v3/createPullRequest.test.js +110 -0
  75. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  76. package/dist/services/github/v3/createStatusComment.js +97 -0
  77. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  78. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  79. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  80. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  81. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  82. package/dist/services/github/v4/apiRequestV4.js +8 -10
  83. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  84. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +1 -8
  85. package/dist/services/github/v4/disablePullRequestAutoMerge.js +6 -32
  86. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +1 -8
  87. package/dist/services/github/v4/enablePullRequestAutoMerge.js +31 -40
  88. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  89. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  90. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  91. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  92. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  93. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  94. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  95. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  96. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  97. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  110. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  113. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  114. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  115. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  119. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  120. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  121. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  122. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  123. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  124. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  125. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  126. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  127. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  128. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  129. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  130. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  131. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  132. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  133. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  134. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  135. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  136. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  137. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  138. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  139. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  140. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  141. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  142. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  143. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  144. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  145. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  146. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  147. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  148. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -9
  149. package/dist/services/github/v4/getOptionsFromGithub/index.js +59 -19
  150. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +119 -32
  151. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
  152. package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -15
  153. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  154. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  155. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  156. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  157. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  158. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  159. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  160. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  161. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  162. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  163. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  164. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  165. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  166. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  167. package/dist/services/logger.d.ts +3 -3
  168. package/dist/services/logger.js +16 -15
  169. package/dist/services/prompt.test.d.ts +1 -0
  170. package/dist/services/prompt.test.js +87 -0
  171. package/dist/services/prompts.d.ts +10 -4
  172. package/dist/services/prompts.js +85 -22
  173. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  174. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  175. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  176. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +413 -0
  177. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  178. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  179. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  180. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  181. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  182. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  183. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  184. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  185. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  186. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  187. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  188. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  189. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  190. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  191. package/dist/services/sourceCommit.d.ts +78 -0
  192. package/dist/services/sourceCommit.js +86 -0
  193. package/dist/services/sourceCommit.test.d.ts +1 -0
  194. package/dist/services/sourceCommit.test.js +280 -0
  195. package/dist/test/inquirer.private.test.js +64 -49
  196. package/dist/test/integration/createSpies.js +6 -6
  197. package/dist/test/integration/envConstants.js +5 -6
  198. package/dist/test/integration/helpers.js +1 -1
  199. package/dist/test/integration/integration.private.test.d.ts +1 -0
  200. package/dist/test/integration/integration.private.test.js +327 -0
  201. package/dist/test/integration/integration.test.js +28 -29
  202. package/dist/test/mockConfigFiles.d.ts +5 -0
  203. package/dist/test/mockConfigFiles.js +37 -0
  204. package/dist/test/nockHelpers.d.ts +1 -1
  205. package/dist/test/nockHelpers.js +7 -11
  206. package/dist/test/private/getDevAccessToken.js +1 -1
  207. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  208. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  209. package/dist/types/Commit.d.ts +85 -0
  210. package/dist/types/Commit.js +139 -0
  211. package/dist/types/commitNode.d.ts +89 -0
  212. package/dist/types/commitNode.js +139 -0
  213. package/dist/types/commitNode.test.d.ts +1 -0
  214. package/dist/types/commitNode.test.js +255 -0
  215. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  216. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  217. package/dist/ui/cherrypickAndCreatePullRequest.test.js +346 -76
  218. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  219. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
  220. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  221. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  222. package/dist/ui/getCommits.d.ts +1 -1
  223. package/dist/ui/getCommits.js +55 -25
  224. package/dist/ui/getTargetBranches.d.ts +3 -2
  225. package/dist/ui/getTargetBranches.js +33 -18
  226. package/dist/ui/getTargetBranches.test.js +75 -99
  227. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  228. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  229. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  230. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  231. package/dist/ui/maybeSetupRepo.js +11 -10
  232. package/dist/ui/maybeSetupRepo.test.js +54 -4
  233. package/dist/utils/excludeUndefined.d.ts +6 -0
  234. package/dist/utils/excludeUndefined.js +7 -0
  235. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  236. package/dist/utils/excludeUndefined.test.js +24 -0
  237. package/package.json +37 -51
  238. package/yarn.lock +2414 -2993
package/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # backport
2
2
 
3
- [![Build Status](https://travis-ci.org/sqren/backport.svg?branch=master)](https://travis-ci.org/sqren/backport)
3
+ [![Build Status](https://travis-ci.com/sqren/backport.svg?branch=master)](https://app.travis-ci.com/github/sqren/backport)
4
4
  [![NPM version](https://img.shields.io/npm/v/backport.svg)](https://www.npmjs.com/package/backport)
5
- [![dependencies Status](https://david-dm.org/sqren/backport/status.svg)](https://david-dm.org/sqren/backport)
6
5
  [![Coverage Status](https://coveralls.io/repos/github/sqren/backport/badge.svg?branch=master)](https://coveralls.io/github/sqren/backport?branch=master)
7
6
 
8
7
  A simple CLI tool that automates the process of backporting commits on a GitHub repo.
@@ -11,7 +10,7 @@ A simple CLI tool that automates the process of backporting commits on a GitHub
11
10
 
12
11
  ## Requirements
13
12
 
14
- - Node 10 or higher
13
+ - Node 16 or higher
15
14
  - git
16
15
 
17
16
  ## Install
@@ -20,7 +19,7 @@ A simple CLI tool that automates the process of backporting commits on a GitHub
20
19
  npm install -g backport
21
20
  ```
22
21
 
23
- 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.
22
+ 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.
24
23
 
25
24
  ## Quick start
26
25
 
@@ -29,8 +28,16 @@ Add a [project config](https://github.com/sqren/backport/blob/master/docs/config
29
28
  ```js
30
29
  // .backportrc.json
31
30
  {
32
- "upstream": "elastic/kibana",
33
- "targetBranchChoices": [{ "name": "6.x", "checked": true }, "6.3", "6.2", "6.1", "6.0"],
31
+ "repoOwner": "elastic",
32
+ "repoName": "kibana",
33
+
34
+ // the branches available to backport to
35
+ "targetBranchChoices": ["main", "6.3", "6.2", "6.1", "6.0"],
36
+
37
+ // Automatically detect which branches a pull request should be backported to based on the pull request labels.
38
+ "branchLabelMapping": {
39
+ "^backport-to-(.+)$": "$1"
40
+ }
34
41
  }
35
42
  ```
36
43
 
@@ -54,44 +61,159 @@ See [configuration.md](https://github.com/sqren/backport/blob/master/docs/config
54
61
 
55
62
  ### CLI options
56
63
 
57
- Please note that dashes between the words are optional,for instance you can type `--targetBranchor` `--target-branch` both are valid options.
58
-
59
- | Option | Shorthand notation | Description | Default | Type |
60
- | ------------------- | -------------------- | ------------------------------------------------------ | -------------- | --------------- |
61
- | --access-token | --accesstoken | Github access token | | `string` |
62
- | --all | -a | Show commits from other than me | false | `boolean` |
63
- | --author | | Filter commits by author | _Current user_ | `string` |
64
- | --assignees | --assignee, --assign | Assign users to target pull request | | `Array<string>` |
65
- | --auto-assign | | Assign current user to target pull request | false | `boolean` |
66
- | --branch | --b | Target branch to backport to | | `string` |
67
- | --ci | | Disable interactive prompts | false | `boolean` |
68
- | --dry-run | | Perform backport without pushing to Github | false | `string` |
69
- | --editor | | Editor (eg. `code`) to open and solve conflicts | nano | `string` |
70
- | --fork | | Create backports in fork (true) or origin repo (false) | true | `boolean` |
71
- | --git-hostname | | Hostname for Git | github.com | `string` |
72
- | --mainline | | Parent id of merge commit | 1 | `number` |
73
- | --max-number | --number, --n | Number of commits to choose from | 10 | `number` |
74
- | --multiple | | Select multiple commits/branches | false | `boolean` |
75
- | --multiple-branches | | Backport to multiple branches | true | `boolean` |
76
- | --multiple-commits | | Backport multiple commits | false | `boolean` |
77
- | --path | -p | Only list commits touching files under a specific path | | `string` |
78
- | --pull-number | --pr | Pull request to backport | | `number` |
79
- | --pr-description | --description | Pull request description suffix | | `string` |
80
- | --pr-filter | | List commits from PRs filtered by a given query | | `string` |
81
- | --pr-title | --title | Title of pull request | | `string` |
82
- | --reset-author | | Set yourself as commit author | | `boolean` |
83
- | --sha | | Sha of commit to backport | | `string` |
84
- | --source-branch | | Specify a non-default branch to backport from | | `string` |
85
- | --source-pr-labels | --sourcePRLabel | Labels added to the source PR | | `array<string>` |
86
- | --target-pr-Labels | --labels, --label | Labels added to the target PR | | `array<string>` |
87
- | --target-branches | --b, --targetBranch | Target branch(es) to backport to | | `array<string>` |
88
- | --upstream | --up | Name of organization and repository | | `string` |
89
- | --username | | Github username | | `string` |
90
- | --help | | Show help | | |
91
- | -v, --version | | Show version number | | |
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 | |
92
100
 
93
101
  The CLI options will override the [configuration options](https://github.com/sqren/backport/blob/master/docs/configuration.md).
94
102
 
103
+ ### Node module
104
+
105
+ `backport` can be imported as a Node module and interacted with programatically.
106
+
107
+ #### `backportRun`
108
+
109
+ Backport a commit programatically. Commits can be selected via `pullNumber` or `sha`.
110
+
111
+ ##### Arguments:
112
+
113
+ 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
+
115
+ `accessToken` _string_ **(Required)**
116
+ Github access token to authenticate the request
117
+
118
+ `repoName` _string_ **(Required)**
119
+ Name of repository
120
+
121
+ `repoOwner` _string_ **(Required)**
122
+ Owner of repository (organisation or username)
123
+
124
+ `pullNumber` _number_
125
+ Filter commits by pull request number
126
+
127
+ `sha` _string_
128
+ Filter commits by commit sha
129
+
130
+ `ci` _boolean_
131
+ Enabling this will disable the interactive prompts
132
+
133
+ ##### Example
134
+
135
+ ```ts
136
+ import { backportRun } from 'backport';
137
+
138
+ const result = await backportRun({
139
+ accessToken: 'abc',
140
+ repoName: 'kibana',
141
+ repoOwner: 'elastic',
142
+ pullNumber: 121633,
143
+ ci: true,
144
+ targetPRLabels: ['backport'],
145
+ autoMerge: true,
146
+ autoMergeMethod: 'squash',
147
+ });
148
+
149
+ console.log(result);
150
+ ```
151
+
152
+ #### `getCommits`
153
+
154
+ Retrieve information about commits and whether they are backported
155
+
156
+ ##### Arguments:
157
+
158
+ `accessToken` _string_ **(Required)**
159
+ Github access token to authenticate the request
160
+
161
+ `repoName` _string_ **(Required)**
162
+ Name of repository
163
+
164
+ `repoOwner` _string_ **(Required)**
165
+ Owner of repository (organisation or username)
166
+
167
+ `author` _string_
168
+ Filter commits by Github user
169
+
170
+ `pullNumber` _number_
171
+ Filter commits by pull request number
172
+
173
+ `sha` _string_
174
+ Filter commits by commit sha
175
+
176
+ `sourceBranch` _string_
177
+ The branch to display commits from. Defaults to the default branch (normally "main" or "master")
178
+
179
+ ##### Example
180
+
181
+ ```ts
182
+ import { getCommits } from 'backport';
183
+
184
+ const commits = await getCommits({
185
+ accessToken: 'abc',
186
+ repoName: 'kibana',
187
+ repoOwner: 'elastic',
188
+ pullNumber: 121633,
189
+ });
190
+
191
+ console.log(commits);
192
+
193
+ /*
194
+ [{
195
+ committedDate: '2021-12-20T14:20:16Z',
196
+ sourceBranch: 'main',
197
+ sha: 'd421ddcf6157150596581c7885afa3690cec6339',
198
+ originalMessage: '[APM] Add note about synthtrace to APM docs (#121633)',
199
+ pullNumber: 121633,
200
+ pullUrl: 'https://github.com/elastic/kibana/pull/121633',
201
+ expectedTargetPullRequests: [
202
+ {
203
+ url: 'https://github.com/elastic/kibana/pull/121643',
204
+ number: 121643,
205
+ branch: '8.0',
206
+ state: 'MERGED'
207
+ }
208
+ ]
209
+ }]
210
+ */
211
+ ```
212
+
213
+ ## Github Action (beta)
214
+
215
+ A [Github Action](https://github.com/elastic/kibana-github-actions/tree/main/backport) for automatically backporting pull requests.
216
+
95
217
  ## What is backporting?
96
218
 
97
219
  > 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.
@@ -120,3 +242,6 @@ This tools is for anybody who is working on a codebase where they have to mainta
120
242
  ## Contributing
121
243
 
122
244
  See [CONTRIBUTING.md](https://github.com/sqren/backport/blob/master/CONTRIBUTING.md)
245
+
246
+ [1]: https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x
247
+ [2]: https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
@@ -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
- main_1.main(args);
9
+ (0, main_1.main)(args);
@@ -1,6 +1,19 @@
1
- import { ConfigOptions } from './options/ConfigOptions';
2
- export declare function run(options: ConfigOptions, args?: string[]): Promise<import("./main").BackportResponse>;
1
+ import { ConfigFileOptions } from './options/ConfigOptions';
2
+ import { ValidConfigOptions } from './options/options';
3
3
  export { BackportResponse } from './main';
4
- export { ConfigOptions } from './options/ConfigOptions';
5
- export { getTargetBranchForLabel } from './services/github/v4/getTargetBranchesFromLabels';
6
- export { fetchMergedPullRequests } from './services/github/v4/fetchMergedPullRequests';
4
+ export { ConfigFileOptions } from './options/ConfigOptions';
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,21 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchMergedPullRequests = exports.getTargetBranchForLabel = 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
- return main_1.main(args, options);
22
+ return (0, main_1.main)(args, options);
16
23
  }
17
- exports.run = run;
18
- var getTargetBranchesFromLabels_1 = require("./services/github/v4/getTargetBranchesFromLabels");
19
- Object.defineProperty(exports, "getTargetBranchForLabel", { enumerable: true, get: function () { return getTargetBranchesFromLabels_1.getTargetBranchForLabel; } });
20
- var fetchMergedPullRequests_1 = require("./services/github/v4/fetchMergedPullRequests");
21
- Object.defineProperty(exports, "fetchMergedPullRequests", { enumerable: true, get: function () { return fetchMergedPullRequests_1.fetchMergedPullRequests; } });
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/ink.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function renderInk(): void;
package/dist/ink.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.renderInk = void 0;
26
+ const ink_1 = require("ink");
27
+ const ink_spinner_1 = __importDefault(require("ink-spinner"));
28
+ const react_1 = __importStar(require("react"));
29
+ const Example = () => {
30
+ const [message, setMessage] = (0, react_1.useState)();
31
+ (0, react_1.useEffect)(() => {
32
+ setTimeout(() => {
33
+ setMessage('Received message');
34
+ }, 5000);
35
+ });
36
+ if (!message) {
37
+ return (react_1.default.createElement(react_1.default.Fragment, null,
38
+ react_1.default.createElement(ink_1.Box, null,
39
+ react_1.default.createElement(ink_1.Box, { marginRight: 1 },
40
+ react_1.default.createElement(ink_1.Text, { color: 'cyan' },
41
+ react_1.default.createElement(ink_spinner_1.default, { type: "dots" }))),
42
+ react_1.default.createElement(ink_1.Text, null, "Loading via ink!!"))));
43
+ }
44
+ return react_1.default.createElement(ink_1.Text, null, message);
45
+ };
46
+ function renderInk() {
47
+ (0, ink_1.render)(react_1.default.createElement(Example, null));
48
+ }
49
+ exports.renderInk = renderInk;
package/dist/main.d.ts CHANGED
@@ -1,9 +1,14 @@
1
- import { ConfigOptions } from './options/ConfigOptions';
2
- import { Result } from './runWithOptions';
1
+ import { ConfigFileOptions } from './options/ConfigOptions';
2
+ import { Result } from './runSequentially';
3
+ import { Commit } from './services/sourceCommit/parseSourceCommit';
3
4
  export declare type BackportResponse = {
4
- success: boolean;
5
+ status: 'success';
6
+ commits: Commit[];
5
7
  results: Result[];
6
- errorMessage?: string;
7
- error?: Error;
8
+ } | {
9
+ status: 'failure';
10
+ commits: Commit[];
11
+ errorMessage: string;
12
+ error: Error;
8
13
  };
9
- export declare function main(argv: string[], optionsFromModule?: ConfigOptions): Promise<BackportResponse>;
14
+ export declare function main(argv: string[], optionsFromModule?: ConfigFileOptions): Promise<BackportResponse>;
package/dist/main.js CHANGED
@@ -6,44 +6,59 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.main = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const options_1 = require("./options/options");
9
- const runWithOptions_1 = require("./runWithOptions");
9
+ const runSequentially_1 = require("./runSequentially");
10
10
  const HandledError_1 = require("./services/HandledError");
11
11
  const env_1 = require("./services/env");
12
+ const createStatusComment_1 = require("./services/github/v3/createStatusComment");
12
13
  const logger_1 = require("./services/logger");
14
+ const getCommits_1 = require("./ui/getCommits");
15
+ const getTargetBranches_1 = require("./ui/getTargetBranches");
13
16
  async function main(argv, optionsFromModule) {
14
- const logger = logger_1.initLogger();
17
+ let options = null;
18
+ let commits = [];
15
19
  try {
16
- const options = await options_1.getOptions(argv, optionsFromModule);
17
- const results = await runWithOptions_1.runWithOptions(options);
18
- return {
19
- success: results.every((res) => res.success),
20
+ options = await (0, options_1.getOptions)(argv, optionsFromModule);
21
+ commits = await (0, getCommits_1.getCommits)(options);
22
+ const targetBranches = await (0, getTargetBranches_1.getTargetBranches)(options, commits);
23
+ const results = await (0, runSequentially_1.runSequentially)({ options, commits, targetBranches });
24
+ const backportResponse = {
25
+ status: 'success',
26
+ commits,
20
27
  results,
21
28
  };
29
+ await (0, createStatusComment_1.createStatusComment)({
30
+ options,
31
+ backportResponse,
32
+ });
33
+ return backportResponse;
22
34
  }
23
35
  catch (e) {
24
- const isHandledError = e instanceof HandledError_1.HandledError;
25
- if (isHandledError) {
26
- logger_1.consoleLog(e.message);
36
+ const backportResponse = {
37
+ status: 'failure',
38
+ commits,
39
+ errorMessage: e.message,
40
+ error: e,
41
+ };
42
+ if (options?.ci) {
43
+ await (0, createStatusComment_1.createStatusComment)({
44
+ options,
45
+ backportResponse,
46
+ });
47
+ }
48
+ if (e instanceof HandledError_1.HandledError) {
49
+ (0, logger_1.consoleLog)(e.message);
27
50
  }
28
- else {
51
+ else if (e instanceof Error) {
29
52
  // output
30
- logger_1.consoleLog('\n');
31
- logger_1.consoleLog(chalk_1.default.bold('⚠️ Ouch! An unknown error occured 😿'));
32
- logger_1.consoleLog(`Error message: ${e.message}`);
33
- logger_1.consoleLog('Please open an issue in https://github.com/sqren/backport/issues or contact me directly on https://twitter.com/sorenlouv');
34
- logger_1.consoleLog(chalk_1.default.italic(`For additional details see the logs: ${env_1.getLogfilePath()}`));
53
+ (0, logger_1.consoleLog)('\n');
54
+ (0, logger_1.consoleLog)(chalk_1.default.bold('⚠️ Ouch! An unhandled error occured 😿'));
55
+ (0, logger_1.consoleLog)(`Error message: ${e.message}`);
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');
57
+ (0, logger_1.consoleLog)(chalk_1.default.italic(`For additional details see the logs: ${(0, env_1.getLogfilePath)()}`));
35
58
  // log file
36
- logger.info('Unknown error:', e);
59
+ logger_1.logger.info('Unknown error:', e);
37
60
  }
38
- const errorMessage = logger_1.redact(e.message);
39
- return {
40
- success: false,
41
- results: [],
42
- errorMessage: isHandledError
43
- ? errorMessage
44
- : `An unhandled error occurred: ${errorMessage}`,
45
- error: e,
46
- };
61
+ return backportResponse;
47
62
  }
48
63
  }
49
64
  exports.main = main;
@@ -1,26 +1,28 @@
1
1
  import { Logger } from '../services/logger';
2
- export interface BranchChoice {
2
+ export interface TargetBranchChoice {
3
3
  name: string;
4
4
  checked?: boolean;
5
5
  }
6
- export declare type BranchChoiceRaw = string | BranchChoice;
6
+ export declare type TargetBranchChoiceOrString = string | TargetBranchChoice;
7
7
  declare type AutoFixConflictsHandler = ({ files, directory, logger, targetBranch, }: {
8
8
  files: string[];
9
9
  directory: string;
10
10
  logger: Logger;
11
11
  targetBranch: string;
12
12
  }) => boolean | Promise<boolean>;
13
- export declare type ConfigOptions = Partial<{
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
- branchLabelMapping: Record<string, string>;
19
+ autoMerge: boolean;
20
+ autoMergeMethod: string;
21
+ cherrypickRef: boolean;
21
22
  ci: boolean;
23
+ commitPaths: string[];
24
+ details: boolean;
22
25
  editor: string;
23
- forceLocalConfig: boolean;
24
26
  fork: boolean;
25
27
  gitHostname: string;
26
28
  githubApiBaseUrlV3: string;
@@ -30,22 +32,36 @@ export declare type ConfigOptions = Partial<{
30
32
  multipleBranches: boolean;
31
33
  multipleCommits: boolean;
32
34
  noVerify: boolean;
33
- path: string;
34
35
  prDescription: string;
35
36
  prFilter: string;
36
37
  prTitle: string;
37
38
  pullNumber: number;
39
+ repoName: string;
40
+ repoOwner: string;
38
41
  resetAuthor: boolean;
42
+ reviewers: string[];
39
43
  sha: string;
44
+ skipRemoteConfig: boolean;
40
45
  sourceBranch: string;
41
46
  sourcePRLabels: string[];
42
- targetBranchChoices: BranchChoiceRaw[];
47
+ targetBranchChoices: TargetBranchChoiceOrString[];
43
48
  targetBranches: string[];
44
49
  targetPRLabels: string[];
45
- upstream: string;
46
- username: string;
47
50
  verbose: boolean;
48
- branches: BranchChoiceRaw[];
51
+ }>;
52
+ export declare type ConfigFileOptions = Options & Partial<{
53
+ branchLabelMapping: Record<string, string>;
54
+ /**
55
+ * @deprecated Replaced by `repoOwner` and `repoName`
56
+ */
57
+ upstream: string;
58
+ /**
59
+ * @deprecated Replaced by `targetBranchChoices`
60
+ */
61
+ branches: TargetBranchChoiceOrString[];
62
+ /**
63
+ * @deprecated Replaced by `targetPRLabels`
64
+ */
49
65
  labels: string[];
50
66
  }>;
51
67
  export {};