backport 8.3.1 → 8.4.2

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 (225) hide show
  1. package/README.md +11 -178
  2. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +42 -21
  3. package/dist/lib/child-process-promisified.js +2 -2
  4. package/dist/lib/git.d.ts +4 -3
  5. package/dist/lib/git.js +22 -29
  6. package/dist/lib/git.private.test.js +10 -7
  7. package/dist/lib/git.test.js +47 -15
  8. package/dist/lib/github/v4/apiRequestV4.js +14 -8
  9. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
  10. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  11. package/dist/lib/ora.d.ts +1 -0
  12. package/dist/options/ConfigOptions.d.ts +1 -0
  13. package/dist/options/cliArgs.d.ts +1 -0
  14. package/dist/options/cliArgs.js +5 -0
  15. package/dist/options/config/config.d.ts +1 -0
  16. package/dist/options/config/readConfigFile.d.ts +1 -0
  17. package/dist/options/options.d.ts +2 -0
  18. package/dist/options/options.js +3 -2
  19. package/dist/options/options.test.js +5 -4
  20. package/dist/test/e2e/cli/date-filters.private.test.js +1 -0
  21. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +122 -6
  22. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -0
  23. package/dist/test/e2e/cli/error-handling-interactive-mode.private.test.js +27 -13
  24. package/dist/test/e2e/cli/error-handling-non-interactive-mode.private.test.js +3 -2
  25. package/dist/{entrypoint.cli.private.test.d.ts → test/e2e/cli/gracefully-handles-corrupt-repo.private.test.d.ts} +0 -0
  26. package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +52 -0
  27. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +2 -2
  28. package/dist/{lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts → test/e2e/cli/repo-with-programatically-added-commits.mutation.test.d.ts} +0 -0
  29. package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +114 -0
  30. package/dist/test/e2e/cli/runBackportViaCli.d.ts +8 -2
  31. package/dist/test/e2e/cli/runBackportViaCli.js +47 -17
  32. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +7 -1
  33. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +1 -1
  34. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -1
  35. package/dist/test/replaceStringAndLinebreaks.d.ts +5 -0
  36. package/dist/test/replaceStringAndLinebreaks.js +8 -0
  37. package/dist/test/sandbox.js +6 -2
  38. package/dist/utils/packageVersion.d.ts +1 -1
  39. package/dist/utils/packageVersion.js +1 -1
  40. package/package.json +23 -24
  41. package/yarn.lock +841 -950
  42. package/dist/entrypoint.cli.private.test.js +0 -47
  43. package/dist/errors/BackportError.d.ts +0 -19
  44. package/dist/errors/BackportError.js +0 -29
  45. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  46. package/dist/runSequentially.test.d.ts +0 -1
  47. package/dist/runSequentially.test.js +0 -243
  48. package/dist/services/BackportError.d.ts +0 -19
  49. package/dist/services/BackportError.js +0 -29
  50. package/dist/services/HandledBackportError.d.ts +0 -19
  51. package/dist/services/HandledBackportError.js +0 -29
  52. package/dist/services/HandledError.d.ts +0 -19
  53. package/dist/services/HandledError.js +0 -29
  54. package/dist/services/child-process-promisified.d.ts +0 -25
  55. package/dist/services/child-process-promisified.js +0 -58
  56. package/dist/services/env.d.ts +0 -7
  57. package/dist/services/env.js +0 -30
  58. package/dist/services/env.test.d.ts +0 -1
  59. package/dist/services/env.test.js +0 -21
  60. package/dist/services/git.d.ts +0 -77
  61. package/dist/services/git.integration.test.d.ts +0 -1
  62. package/dist/services/git.integration.test.js +0 -616
  63. package/dist/services/git.js +0 -439
  64. package/dist/services/git.private.test.d.ts +0 -1
  65. package/dist/services/git.private.test.js +0 -618
  66. package/dist/services/git.test.d.ts +0 -1
  67. package/dist/services/git.test.js +0 -580
  68. package/dist/services/github/commitFormatters.d.ts +0 -3
  69. package/dist/services/github/commitFormatters.js +0 -17
  70. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  71. package/dist/services/github/commitFormatters.test.js +0 -11
  72. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +0 -2
  73. package/dist/services/github/v3/addAssigneesToPullRequest.js +0 -32
  74. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  75. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  76. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +0 -2
  77. package/dist/services/github/v3/addLabelsToPullRequest.js +0 -30
  78. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +0 -2
  79. package/dist/services/github/v3/addReviewersToPullRequest.js +0 -32
  80. package/dist/services/github/v3/createPullRequest.d.ts +0 -29
  81. package/dist/services/github/v3/createPullRequest.js +0 -91
  82. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  83. package/dist/services/github/v3/createPullRequest.test.js +0 -377
  84. package/dist/services/github/v3/createStatusComment.d.ts +0 -11
  85. package/dist/services/github/v3/createStatusComment.js +0 -131
  86. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  87. package/dist/services/github/v3/createStatusComment.test.js +0 -409
  88. package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +0 -14
  89. package/dist/services/github/v3/getGithubV3ErrorMessage.js +0 -16
  90. package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -2
  91. package/dist/services/github/v4/FetchPullRequestId.js +0 -36
  92. package/dist/services/github/v4/apiRequestV4.d.ts +0 -31
  93. package/dist/services/github/v4/apiRequestV4.js +0 -71
  94. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  95. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  96. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -2
  97. package/dist/services/github/v4/disablePullRequestAutoMerge.js +0 -32
  98. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -2
  99. package/dist/services/github/v4/enablePullRequestAutoMerge.js +0 -50
  100. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  101. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  102. package/dist/services/github/v4/fetchAuthorId.d.ts +0 -10
  103. package/dist/services/github/v4/fetchAuthorId.js +0 -28
  104. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  105. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -25
  106. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  108. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -11
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -58
  110. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  111. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -136
  112. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -11
  113. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +0 -48
  114. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -118
  116. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -29
  117. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +0 -110
  118. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  119. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -196
  120. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  121. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -157
  122. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +0 -3
  123. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +0 -61
  124. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  125. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -107
  126. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +0 -12
  127. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +0 -69
  128. package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -9
  129. package/dist/services/github/v4/fetchExistingPullRequest.js +0 -64
  130. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  131. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -44
  132. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -2
  133. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +0 -39
  134. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +0 -8
  135. package/dist/services/github/v4/fetchRemoteProjectConfig.js +0 -49
  136. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  137. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -49
  138. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -69
  139. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -73
  140. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  141. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -116
  142. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +0 -16
  143. package/dist/services/github/v4/getOptionsFromGithub/query.js +0 -29
  144. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +0 -29
  145. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +0 -61
  146. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  147. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -72
  148. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  149. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -176
  150. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +0 -6
  151. package/dist/services/github/v4/throwOnInvalidAccessToken.js +0 -45
  152. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  153. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  154. package/dist/services/logger.d.ts +0 -9
  155. package/dist/services/logger.js +0 -74
  156. package/dist/services/prompt.test.d.ts +0 -1
  157. package/dist/services/prompt.test.js +0 -139
  158. package/dist/services/prompts.d.ts +0 -17
  159. package/dist/services/prompts.js +0 -132
  160. package/dist/services/remoteConfig.d.ts +0 -20
  161. package/dist/services/remoteConfig.js +0 -52
  162. package/dist/services/sequentially.d.ts +0 -1
  163. package/dist/services/sequentially.js +0 -10
  164. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +0 -16
  165. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +0 -102
  166. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  167. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -467
  168. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +0 -26
  169. package/dist/services/sourceCommit/getMockSourceCommit.js +0 -103
  170. package/dist/services/sourceCommit/parseSourceCommit.d.ts +0 -108
  171. package/dist/services/sourceCommit/parseSourceCommit.js +0 -123
  172. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  173. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -226
  174. package/dist/services/test.d.ts +0 -1
  175. package/dist/services/test.js +0 -23
  176. package/dist/state.d.ts +0 -0
  177. package/dist/state.js +0 -1
  178. package/dist/test/ExecError.d.ts +0 -16
  179. package/dist/test/ExecError.js +0 -15
  180. package/dist/test/e2e/cli/cli.private.test.d.ts +0 -1
  181. package/dist/test/e2e/cli/cli.private.test.js +0 -222
  182. package/dist/test/e2e/cli/date-filters.d.ts +0 -1
  183. package/dist/test/e2e/cli/date-filters.js +0 -43
  184. package/dist/test/e2e/cli/interactive-error-handling.private.test.d.ts +0 -1
  185. package/dist/test/e2e/cli/interactive-error-handling.private.test.js +0 -80
  186. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.d.ts +0 -1
  187. package/dist/test/e2e/cli/non-interactive-error-handling.private.test.js +0 -198
  188. package/dist/test/e2e/cli.e2e.private.test.d.ts +0 -1
  189. package/dist/test/e2e/cli.e2e.private.test.js +0 -433
  190. package/dist/test/e2e/module/module.mutation.test.d.ts +0 -1
  191. package/dist/test/e2e/module/module.mutation.test.js +0 -369
  192. package/dist/test/e2e/module.e2e.mutation.test.d.ts +0 -1
  193. package/dist/test/e2e/module.e2e.mutation.test.js +0 -369
  194. package/dist/test/e2e/module.e2e.private.test.d.ts +0 -1
  195. package/dist/test/e2e/module.e2e.private.test.js +0 -369
  196. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -13
  197. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +0 -243
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  199. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -320
  200. package/dist/ui/getCommits.d.ts +0 -2
  201. package/dist/ui/getCommits.js +0 -75
  202. package/dist/ui/getCommitsWithoutBackports.d.ts +0 -11
  203. package/dist/ui/getCommitsWithoutBackports.js +0 -68
  204. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  205. package/dist/ui/getCommitsWithoutBackports.test.js +0 -335
  206. package/dist/ui/getGitConfigAuthor.d.ts +0 -6
  207. package/dist/ui/getGitConfigAuthor.js +0 -15
  208. package/dist/ui/getTargetBranches.d.ts +0 -5
  209. package/dist/ui/getTargetBranches.js +0 -67
  210. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  211. package/dist/ui/getTargetBranches.test.js +0 -204
  212. package/dist/ui/maybeSetupRepo.d.ts +0 -2
  213. package/dist/ui/maybeSetupRepo.js +0 -53
  214. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  215. package/dist/ui/maybeSetupRepo.test.js +0 -238
  216. package/dist/ui/ora.d.ts +0 -2
  217. package/dist/ui/ora.js +0 -21
  218. package/dist/ui/setupRepo.d.ts +0 -2
  219. package/dist/ui/setupRepo.js +0 -56
  220. package/dist/ui/setupRepo.test.d.ts +0 -1
  221. package/dist/ui/setupRepo.test.js +0 -273
  222. package/dist/utils/filterMissingCommits.d.ts +0 -2
  223. package/dist/utils/filterMissingCommits.js +0 -7
  224. package/dist/utils/redact.d.ts +0 -1
  225. package/dist/utils/redact.js +0 -7
@@ -1,176 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.commitsByAuthorMock = void 0;
4
- exports.commitsByAuthorMock = {
5
- repository: {
6
- ref: {
7
- target: {
8
- history: {
9
- edges: [
10
- {
11
- node: {
12
- author: {
13
- email: 'soren.louv@elastic.co',
14
- name: 'Søren Louv-Jansen',
15
- },
16
- repository: {
17
- name: 'kibana',
18
- owner: { login: 'elastic' },
19
- },
20
- committedDate: '2021-12-24T00:00:00Z',
21
- sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
22
- message: 'Add 👻',
23
- associatedPullRequests: {
24
- edges: [],
25
- },
26
- },
27
- },
28
- {
29
- node: {
30
- author: {
31
- email: 'soren.louv@elastic.co',
32
- name: 'Søren Louv-Jansen',
33
- },
34
- repository: {
35
- name: 'kibana',
36
- owner: { login: 'elastic' },
37
- },
38
- committedDate: '2021-12-23T00:00:00Z',
39
- sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
40
- message: 'Add witch (#85)',
41
- associatedPullRequests: {
42
- edges: [
43
- {
44
- node: {
45
- url: 'https://github.com/elastic/kibana/pull/85',
46
- baseRefName: 'master',
47
- labels: {
48
- nodes: [{ name: 'my-label-b' }],
49
- },
50
- number: 85,
51
- mergeCommit: {
52
- remoteConfigHistory: { edges: [] },
53
- sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
54
- message: 'Add witch (#85)',
55
- },
56
- timelineItems: {
57
- edges: [],
58
- },
59
- },
60
- },
61
- ],
62
- },
63
- },
64
- },
65
- {
66
- node: {
67
- author: {
68
- email: 'soren.louv@elastic.co',
69
- name: 'Søren Louv-Jansen',
70
- },
71
- repository: {
72
- name: 'kibana',
73
- owner: { login: 'elastic' },
74
- },
75
- committedDate: '2021-12-22T00:00:00Z',
76
- sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
77
- message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
78
- associatedPullRequests: {
79
- edges: [
80
- {
81
- node: {
82
- url: 'https://github.com/elastic/kibana/pull/80',
83
- labels: {
84
- nodes: [{ name: 'v6.3.0' }],
85
- },
86
- baseRefName: 'master',
87
- number: 80,
88
- mergeCommit: {
89
- remoteConfigHistory: { edges: [] },
90
- sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
91
- message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
92
- },
93
- timelineItems: {
94
- edges: [
95
- {
96
- node: {
97
- targetPullRequest: {
98
- __typename: 'PullRequest',
99
- targetMergeCommit: {
100
- sha: 'target-merge-commit-sha',
101
- message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
102
- },
103
- repository: {
104
- name: 'kibana',
105
- owner: { login: 'elastic' },
106
- },
107
- url: 'https://github.com/elastic/kibana/pull/99',
108
- title: 'some title',
109
- state: 'MERGED',
110
- number: 99,
111
- baseRefName: '6.3',
112
- commits: {
113
- edges: [
114
- {
115
- node: {
116
- targetCommit: {
117
- sha: 'abc',
118
- message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
119
- },
120
- },
121
- },
122
- ],
123
- },
124
- },
125
- },
126
- },
127
- ],
128
- },
129
- },
130
- },
131
- ],
132
- },
133
- },
134
- },
135
- {
136
- node: {
137
- author: {
138
- email: 'soren.louv@elastic.co',
139
- name: 'Søren Louv-Jansen',
140
- },
141
- repository: {
142
- name: 'kibana',
143
- owner: { login: 'elastic' },
144
- },
145
- committedDate: '2021-12-21T00:00:00Z',
146
- sha: '3827bbbaf39914eda4f02f6940189844375fd097',
147
- message: 'Add backport config',
148
- associatedPullRequests: {
149
- edges: [],
150
- },
151
- },
152
- },
153
- {
154
- node: {
155
- author: {
156
- email: 'soren.louv@elastic.co',
157
- name: 'Søren Louv-Jansen',
158
- },
159
- repository: {
160
- name: 'kibana',
161
- owner: { login: 'elastic' },
162
- },
163
- committedDate: '2021-12-20T00:00:00Z',
164
- sha: '5ea0da550ac191029459289d67f99ad7d310812b',
165
- message: 'Initial commit',
166
- associatedPullRequests: {
167
- edges: [],
168
- },
169
- },
170
- },
171
- ],
172
- },
173
- },
174
- },
175
- },
176
- };
@@ -1,6 +0,0 @@
1
- import { GithubV4Exception } from './apiRequestV4';
2
- export declare function throwOnInvalidAccessToken({ error, repoOwner, repoName, }: {
3
- error: GithubV4Exception<unknown>;
4
- repoOwner: string;
5
- repoName: string;
6
- }): undefined;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwOnInvalidAccessToken = void 0;
4
- const lodash_1 = require("lodash");
5
- const maybe_1 = require("../../../utils/maybe");
6
- const BackportError_1 = require("../../BackportError");
7
- const env_1 = require("../../env");
8
- function throwOnInvalidAccessToken({ error, repoOwner, repoName, }) {
9
- function getSSOAuthUrl(ssoHeader) {
10
- const matches = ssoHeader?.match(/url=(.*)/);
11
- if (matches) {
12
- return matches[1];
13
- }
14
- }
15
- const statusCode = error.githubResponse.status;
16
- switch (statusCode) {
17
- case 200: {
18
- const repoNotFound = error.githubResponse.data.errors?.some((error) => error.type === 'NOT_FOUND' && error.path?.join('.') === 'repository');
19
- const grantedScopes = error.githubResponse.headers['x-oauth-scopes'] || '';
20
- const requiredScopes = error.githubResponse.headers['x-accepted-oauth-scopes'] || '';
21
- const ssoHeader = (0, maybe_1.maybe)(error.githubResponse.headers['x-github-sso']);
22
- if (repoNotFound) {
23
- const hasRequiredScopes = (0, lodash_1.isEmpty)((0, lodash_1.difference)(requiredScopes.split(','), grantedScopes.split(',')));
24
- // user does not have permission to the repo
25
- if (!hasRequiredScopes) {
26
- throw new BackportError_1.BackportError(`You do not have access to the repository "${repoOwner}/${repoName}". Please make sure your access token has the required scopes.\n\nRequired scopes: ${requiredScopes}\nAccess token scopes: ${grantedScopes}`);
27
- }
28
- // repo does not exist
29
- throw new BackportError_1.BackportError(`The repository "${repoOwner}/${repoName}" doesn't exist`);
30
- }
31
- const repoAccessForbidden = error.githubResponse.data.errors?.some((error) => error.type === 'FORBIDDEN');
32
- const ssoAuthUrl = getSSOAuthUrl(ssoHeader);
33
- // user does not have permissions
34
- if (repoAccessForbidden && ssoAuthUrl) {
35
- throw new BackportError_1.BackportError(`Please follow the link to authorize your personal access token with SSO:\n\n${ssoAuthUrl}`);
36
- }
37
- break;
38
- }
39
- case 401:
40
- throw new BackportError_1.BackportError(`Please check your access token and make sure it is valid.\nConfig: ${(0, env_1.getGlobalConfigPath)()}`);
41
- default:
42
- return undefined;
43
- }
44
- }
45
- exports.throwOnInvalidAccessToken = throwOnInvalidAccessToken;
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const throwOnInvalidAccessToken_1 = require("./throwOnInvalidAccessToken");
4
- describe('throwOnInvalidAccessToken', () => {
5
- describe('when status code is', () => {
6
- it('should handle invalid access token', () => {
7
- const error = {
8
- githubResponse: {
9
- status: 401,
10
- headers: {},
11
- },
12
- };
13
- return expect(() => (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
14
- repoOwner: 'elastic',
15
- repoName: 'kibana',
16
- error,
17
- })).toThrowError('Please check your access token and make sure it is valid');
18
- });
19
- it('should handle SSO error', () => {
20
- const error = {
21
- githubResponse: {
22
- status: 200,
23
- headers: { 'x-github-sso': 'required; url=https://ssourl.com' },
24
- data: {
25
- errors: [{ type: 'FORBIDDEN' }],
26
- },
27
- },
28
- };
29
- return expect(() => (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
30
- repoOwner: 'elastic',
31
- repoName: 'kibana',
32
- error,
33
- })).toThrowErrorMatchingSnapshot();
34
- });
35
- it('should handle non-existing repo', () => {
36
- const error = {
37
- githubResponse: {
38
- status: 200,
39
- headers: {
40
- 'x-oauth-scopes': 'a,b,c',
41
- 'x-accepted-oauth-scopes': 'a,b,c',
42
- },
43
- data: {
44
- errors: [{ type: 'NOT_FOUND', path: ['repository'] }],
45
- },
46
- },
47
- };
48
- return expect(() => (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
49
- repoOwner: 'elastic',
50
- repoName: 'kibana',
51
- error,
52
- })).toThrowError(`The repository "elastic/kibana" doesn't exist`);
53
- });
54
- it('should handle insufficient permissions (oauth scopes)', () => {
55
- const error = {
56
- githubResponse: {
57
- status: 200,
58
- headers: {
59
- 'x-oauth-scopes': 'a,b',
60
- 'x-accepted-oauth-scopes': 'a,b,c',
61
- },
62
- data: {
63
- errors: [{ type: 'NOT_FOUND', path: ['repository'] }],
64
- },
65
- },
66
- };
67
- return expect(() => (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
68
- repoOwner: 'elastic',
69
- repoName: 'kibana',
70
- error,
71
- })).toThrowErrorMatchingSnapshot();
72
- });
73
- it('should not handle unknown cases', () => {
74
- const error = {
75
- githubResponse: {
76
- status: 500,
77
- headers: {},
78
- },
79
- };
80
- return expect((0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
81
- repoOwner: 'elastic',
82
- repoName: 'kibana',
83
- error,
84
- })).toBe(undefined);
85
- });
86
- });
87
- });
@@ -1,9 +0,0 @@
1
- import winston from 'winston';
2
- export declare let logger: winston.Logger;
3
- export declare function initLogger({ ci, accessToken, logFilePath, }: {
4
- ci: boolean | undefined;
5
- accessToken?: string;
6
- logFilePath?: string;
7
- }): winston.Logger;
8
- export declare function consoleLog(message: string): void;
9
- export declare function setAccessToken(accessToken: string): void;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.setAccessToken = exports.consoleLog = exports.initLogger = exports.logger = void 0;
27
- const winston_1 = __importStar(require("winston"));
28
- const redact_1 = require("../utils/redact");
29
- const env_1 = require("./env");
30
- let _accessToken;
31
- let _ci;
32
- function initLogger({ ci, accessToken, logFilePath, }) {
33
- _accessToken = accessToken;
34
- _ci = ci;
35
- exports.logger = winston_1.default.createLogger({
36
- format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
37
- // Format the metadata object
38
- winston_1.format.metadata({
39
- fillExcept: ['message', 'level', 'timestamp', 'label'],
40
- })),
41
- transports: new winston_1.default.transports.File({
42
- filename: (0, env_1.getLogfilePath)({ logFilePath }),
43
- level: 'debug',
44
- format: winston_1.format.combine(winston_1.format.json()),
45
- }),
46
- });
47
- return exports.logger;
48
- }
49
- exports.initLogger = initLogger;
50
- // wrapper around console.log
51
- function consoleLog(message) {
52
- if (!_ci) {
53
- // eslint-disable-next-line no-console
54
- console.log(redactAccessToken(message));
55
- }
56
- }
57
- exports.consoleLog = consoleLog;
58
- function setAccessToken(accessToken) {
59
- _accessToken = accessToken;
60
- }
61
- exports.setAccessToken = setAccessToken;
62
- function redactAccessToken(str) {
63
- // `redactAccessToken` might be called before access token is set
64
- if (_accessToken) {
65
- return (0, redact_1.redact)(_accessToken, str);
66
- }
67
- return str;
68
- }
69
- // log levels:
70
- // - error
71
- // - warn
72
- // - info
73
- // - verbose
74
- // - debug
@@ -1 +0,0 @@
1
- export {};
@@ -1,139 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const strip_ansi_1 = __importDefault(require("strip-ansi"));
7
- const prompts_1 = require("./prompts");
8
- describe('prompt', () => {
9
- describe('getChoicesForCommitPrompt', () => {
10
- it('should display status badges via `expectedTargetPullRequests`', () => {
11
- const commits = [
12
- {
13
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
14
- sourceBranch: 'master',
15
- sourceCommit: {
16
- committedDate: '1',
17
- sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
18
- message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
19
- },
20
- sourcePullRequest: {
21
- number: 119700,
22
- url: 'foo',
23
- mergeCommit: {
24
- sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
25
- message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
26
- },
27
- },
28
- expectedTargetPullRequests: [
29
- { number: 120178, branch: '8.0', state: 'MERGED' },
30
- { number: 120179, branch: '7.16', state: 'MERGED' },
31
- { number: 120179, branch: '7.15', state: 'NOT_CREATED' },
32
- ],
33
- },
34
- ];
35
- const choices = (0, prompts_1.getChoicesForCommitPrompt)(commits, false).map(({ name, short }) => ({ name: (0, strip_ansi_1.default)(name), short }));
36
- expect(choices).toEqual([
37
- {
38
- name: '1. [APM] Remove log-log descriptions from correlation charts (#119700) 8.0, 7.16, 7.15',
39
- short: '#119700 (ae9d51b7)',
40
- },
41
- ]);
42
- });
43
- it('should list choices', () => {
44
- const commits = [
45
- {
46
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
47
- sourceBranch: 'master',
48
- sourceCommit: {
49
- committedDate: '',
50
- sha: 'b1b491959dab47aeb83c88ee2accb2db46d23793',
51
- message: '[APM] Prefer service.name for logs correlation (#120694)',
52
- },
53
- sourcePullRequest: {
54
- number: 120694,
55
- url: 'foo',
56
- mergeCommit: {
57
- sha: 'b1b491959dab47aeb83c88ee2accb2db46d23793',
58
- message: '[APM] Prefer service.name for logs correlation (#120694)',
59
- },
60
- },
61
- expectedTargetPullRequests: [],
62
- },
63
- {
64
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
65
- sourceBranch: 'master',
66
- sourceCommit: {
67
- committedDate: '',
68
- sha: 'b1bb4a93959f19a653b9cfb207a5c6acb6559482',
69
- message: '[APM] Disable telemetry in agent config endpoint (#120106)',
70
- },
71
- sourcePullRequest: {
72
- number: 120106,
73
- url: 'foo',
74
- mergeCommit: {
75
- sha: 'b1bb4a93959f19a653b9cfb207a5c6acb6559482',
76
- message: '[APM] Disable telemetry in agent config endpoint (#120106)',
77
- },
78
- },
79
- expectedTargetPullRequests: [],
80
- },
81
- {
82
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
83
- sourceBranch: 'master',
84
- sourceCommit: {
85
- committedDate: '',
86
- sha: '434f6e6a88faf24dc1ea41f9f726db78e46355a7',
87
- message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
88
- },
89
- sourcePullRequest: {
90
- number: 119915,
91
- url: 'foo',
92
- mergeCommit: {
93
- sha: '434f6e6a88faf24dc1ea41f9f726db78e46355a7',
94
- message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
95
- },
96
- },
97
- expectedTargetPullRequests: [],
98
- },
99
- {
100
- author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
101
- sourceBranch: 'master',
102
- sourceCommit: {
103
- committedDate: '',
104
- sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
105
- message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
106
- },
107
- sourcePullRequest: {
108
- number: 119700,
109
- url: 'foo',
110
- mergeCommit: {
111
- sha: 'ae9d51b7fe3ee6f30d0d196c782e0dcabb7ac5ff',
112
- message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
113
- },
114
- },
115
- expectedTargetPullRequests: [],
116
- },
117
- ];
118
- const choices = (0, prompts_1.getChoicesForCommitPrompt)(commits, false).map(({ name, short }) => ({ name: (0, strip_ansi_1.default)(name), short }));
119
- expect(choices).toEqual([
120
- {
121
- name: '1. [APM] Prefer service.name for logs correlation (#120694) ',
122
- short: '#120694 (b1b49195)',
123
- },
124
- {
125
- name: '2. [APM] Disable telemetry in agent config endpoint (#120106) ',
126
- short: '#120106 (b1bb4a93)',
127
- },
128
- {
129
- name: '3. [APM] Remove index_pattern.json and add custom field formatters (#119915) ',
130
- short: '#119915 (434f6e6a)',
131
- },
132
- {
133
- name: '4. [APM] Remove log-log descriptions from correlation charts (#119700) ',
134
- short: '#119700 (ae9d51b7)',
135
- },
136
- ]);
137
- });
138
- });
139
- });
@@ -1,17 +0,0 @@
1
- import { TargetBranchChoice } from '../options/ConfigOptions';
2
- import { Commit } from './sourceCommit/parseSourceCommit';
3
- export declare function getChoicesForCommitPrompt(commits: Commit[], showDetails: boolean): {
4
- name: string;
5
- short: string;
6
- value: Commit;
7
- }[];
8
- export declare function promptForCommits({ commitChoices, isMultipleChoice, showDetails, }: {
9
- commitChoices: Commit[];
10
- isMultipleChoice: boolean;
11
- showDetails: boolean;
12
- }): Promise<Commit[]>;
13
- export declare function promptForTargetBranches({ targetBranchChoices, isMultipleChoice, }: {
14
- targetBranchChoices: TargetBranchChoice[];
15
- isMultipleChoice: boolean;
16
- }): Promise<string[]>;
17
- export declare function confirmPrompt(message: string): Promise<boolean>;