backport 5.6.3 → 6.0.0

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 (230) hide show
  1. package/README.md +48 -39
  2. package/dist/entrypoint.cli.js +1 -1
  3. package/dist/entrypoint.module.d.ts +6 -5
  4. package/dist/entrypoint.module.js +8 -6
  5. package/dist/ink.d.ts +1 -0
  6. package/dist/ink.js +49 -0
  7. package/dist/main.d.ts +11 -6
  8. package/dist/main.js +40 -24
  9. package/dist/options/ConfigOptions.d.ts +47 -39
  10. package/dist/options/cliArgs.d.ts +28 -34
  11. package/dist/options/cliArgs.js +113 -94
  12. package/dist/options/cliArgs.test.js +103 -119
  13. package/dist/options/config/config.d.ts +81 -2
  14. package/dist/options/config/config.js +46 -6
  15. package/dist/options/config/config.test.js +24 -2
  16. package/dist/options/config/getOptionsFromGit.d.ts +3 -0
  17. package/dist/options/config/getOptionsFromGit.js +10 -0
  18. package/dist/options/config/globalConfig.d.ts +2 -1
  19. package/dist/options/config/globalConfig.js +8 -8
  20. package/dist/options/config/globalConfig.test.js +7 -3
  21. package/dist/options/config/projectConfig.d.ts +2 -1
  22. package/dist/options/config/projectConfig.js +3 -3
  23. package/dist/options/config/projectConfig.test.js +4 -4
  24. package/dist/options/config/readConfigFile.d.ts +2 -2
  25. package/dist/options/config/readConfigFile.js +3 -3
  26. package/dist/options/options.d.ts +40 -27
  27. package/dist/options/options.js +8 -16
  28. package/dist/options/options.test.js +66 -26
  29. package/dist/options/parseRequiredOptions.d.ts +71 -0
  30. package/dist/options/parseRequiredOptions.js +70 -0
  31. package/dist/options/parseRequiredOptions.test.d.ts +1 -0
  32. package/dist/options/parseRequiredOptions.test.js +127 -0
  33. package/dist/runSequentially.d.ts +20 -0
  34. package/dist/runSequentially.js +41 -0
  35. package/dist/runSequentially.test.d.ts +1 -0
  36. package/dist/runSequentially.test.js +235 -0
  37. package/dist/runWithOptions.js +7 -14
  38. package/dist/runWithOptions.test.js +142 -16
  39. package/dist/scripts/generate-gql.d.ts +1 -0
  40. package/dist/scripts/generate-gql.js +15 -0
  41. package/dist/scripts/postinstall.js +4 -4
  42. package/dist/scripts/postinstall.test.js +9 -2
  43. package/dist/scripts/runPostinstall.js +1 -1
  44. package/dist/services/HandledError.d.ts +11 -1
  45. package/dist/services/HandledError.js +2 -1
  46. package/dist/services/child-process-promisified.d.ts +1 -1
  47. package/dist/services/child-process-promisified.js +2 -2
  48. package/dist/services/env.js +5 -5
  49. package/dist/services/env.test.js +11 -4
  50. package/dist/services/fs-promisified.js +4 -4
  51. package/dist/services/getExpectedTarget.d.ts +9 -0
  52. package/dist/services/getExpectedTarget.js +77 -0
  53. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  54. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  55. package/dist/services/git.d.ts +19 -4
  56. package/dist/services/git.integration.test.d.ts +1 -0
  57. package/dist/services/git.integration.test.js +168 -0
  58. package/dist/services/git.js +129 -57
  59. package/dist/services/git.test.js +155 -51
  60. package/dist/services/github/commitFormatters.d.ts +3 -7
  61. package/dist/services/github/commitFormatters.js +10 -19
  62. package/dist/services/github/commitFormatters.test.js +2 -24
  63. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  64. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
  65. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
  66. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  67. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  68. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  69. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  70. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  71. package/dist/services/github/v3/createPullRequest.js +33 -24
  72. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  73. package/dist/services/github/v3/createStatusComment.js +97 -0
  74. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  75. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  76. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  77. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  78. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  79. package/dist/services/github/v4/apiRequestV4.js +8 -10
  80. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  81. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +9 -0
  82. package/dist/services/github/v4/disablePullRequestAutoMerge.js +28 -0
  83. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +9 -0
  84. package/dist/services/github/v4/enablePullRequestAutoMerge.js +51 -0
  85. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  86. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +113 -0
  87. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -0
  88. package/dist/services/github/v4/fetchAuthorId.js +1 -1
  89. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
  90. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  91. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +6 -6
  92. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  93. package/dist/services/github/v4/fetchCommitBySha.private.test.js +7 -5
  94. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  110. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  111. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  112. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  113. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
  114. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  115. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  116. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +3 -2
  117. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  118. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +81 -8
  119. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  120. package/dist/services/github/v4/fetchDefaultBranch.d.ts +1 -1
  121. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  122. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +4 -0
  123. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +52 -0
  124. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +1 -0
  125. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +32 -0
  126. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +4 -0
  127. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +72 -0
  128. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +1 -0
  129. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +34 -0
  130. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +40 -0
  131. package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +72 -0
  132. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  133. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
  134. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +19 -20
  135. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -68
  136. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  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.d.ts +1 -1
  140. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  141. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +8 -6
  142. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  143. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  144. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  145. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +61 -0
  146. package/dist/services/github/v4/getOptionsFromGithub/index.js +139 -0
  147. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +1 -0
  148. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +126 -0
  149. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +34 -0
  150. package/dist/services/github/v4/getOptionsFromGithub/query.js +44 -0
  151. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  152. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  153. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  154. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  155. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  156. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +2 -2
  157. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  158. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +2 -2
  159. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +4 -1
  160. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  161. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  162. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  163. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  164. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  165. package/dist/services/logger.d.ts +3 -3
  166. package/dist/services/logger.js +24 -24
  167. package/dist/services/prompt.test.d.ts +1 -0
  168. package/dist/services/prompt.test.js +87 -0
  169. package/dist/services/prompts.d.ts +10 -4
  170. package/dist/services/prompts.js +85 -22
  171. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  172. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  173. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  174. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  175. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  176. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  177. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  178. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  179. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  180. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  181. package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
  182. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  183. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  184. package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
  185. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  186. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  187. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  188. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  189. package/dist/services/sourceCommit.d.ts +78 -0
  190. package/dist/services/sourceCommit.js +86 -0
  191. package/dist/services/sourceCommit.test.d.ts +1 -0
  192. package/dist/services/sourceCommit.test.js +280 -0
  193. package/dist/test/inquirer.private.test.js +81 -45
  194. package/dist/test/integration/createSpies.d.ts +1 -1
  195. package/dist/test/integration/createSpies.js +21 -9
  196. package/dist/test/integration/envConstants.js +5 -6
  197. package/dist/test/integration/helpers.js +1 -1
  198. package/dist/test/integration/integration.private.test.d.ts +1 -0
  199. package/dist/test/integration/integration.private.test.js +308 -0
  200. package/dist/test/integration/integration.test.js +30 -31
  201. package/dist/test/nockHelpers.d.ts +2 -2
  202. package/dist/test/nockHelpers.js +3 -7
  203. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  204. package/dist/test/setupFiles/automatic-mocks.js +0 -22
  205. package/dist/types/Commit.d.ts +85 -0
  206. package/dist/types/Commit.js +139 -0
  207. package/dist/types/commitNode.d.ts +89 -0
  208. package/dist/types/commitNode.js +139 -0
  209. package/dist/types/commitNode.test.d.ts +1 -0
  210. package/dist/types/commitNode.test.js +255 -0
  211. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  212. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  213. package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
  214. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  215. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +135 -67
  216. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  217. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  218. package/dist/ui/getCommits.d.ts +1 -1
  219. package/dist/ui/getCommits.js +55 -25
  220. package/dist/ui/getTargetBranches.d.ts +2 -2
  221. package/dist/ui/getTargetBranches.js +16 -17
  222. package/dist/ui/getTargetBranches.test.js +75 -99
  223. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  224. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  225. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  226. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  227. package/dist/ui/maybeSetupRepo.js +9 -9
  228. package/dist/ui/maybeSetupRepo.test.js +5 -1
  229. package/package.json +36 -51
  230. package/yarn.lock +2387 -2979
@@ -0,0 +1,252 @@
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 nock_1 = __importDefault(require("nock"));
7
+ const nockHelpers_1 = require("../../../../test/nockHelpers");
8
+ const fetchPullRequestBySearchQueryMock_1 = require("../mocks/fetchPullRequestBySearchQueryMock");
9
+ const fetchPullRequestBySearchQuery_1 = require("./fetchPullRequestBySearchQuery");
10
+ describe('fetchPullRequestBySearchQuery', () => {
11
+ let res;
12
+ let mockCalls;
13
+ beforeEach(async () => {
14
+ mockCalls = (0, nockHelpers_1.mockGqlRequest)({
15
+ name: 'PullRequestBySearchQuery',
16
+ statusCode: 200,
17
+ body: { data: fetchPullRequestBySearchQueryMock_1.fetchPullRequestBySearchQueryMock },
18
+ });
19
+ res = await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)({
20
+ accessToken: 'myAccessToken',
21
+ all: false,
22
+ author: 'sqren',
23
+ githubApiBaseUrlV4: 'http://localhost/graphql',
24
+ maxNumber: 10,
25
+ repoName: 'kibana',
26
+ repoOwner: 'elastic',
27
+ sourceBranch: 'master',
28
+ prFilter: 'label:Team:apm',
29
+ });
30
+ });
31
+ afterEach(() => {
32
+ nock_1.default.cleanAll();
33
+ });
34
+ it('should make request with correct variables', () => {
35
+ expect(mockCalls.length).toBe(1);
36
+ expect(mockCalls[0].variables).toEqual({
37
+ maxNumber: 10,
38
+ query: 'type:pr is:merged sort:updated-desc repo:elastic/kibana author:sqren label:Team:apm base:master',
39
+ });
40
+ });
41
+ it('should return correct response', async () => {
42
+ expect(res).toMatchInlineSnapshot(`
43
+ Array [
44
+ Object {
45
+ "committedDate": "2021-01-01T00:00:00",
46
+ "existingTargetPullRequests": Array [
47
+ Object {
48
+ "branch": "7.x",
49
+ "number": 99,
50
+ "state": "MERGED",
51
+ },
52
+ ],
53
+ "formattedMessage": "[APM] @ts-error -> @ts-expect-error (#76492)",
54
+ "originalMessage": "[APM] @ts-error -> @ts-expect-error (#76492)
55
+
56
+ Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>",
57
+ "pullNumber": 76492,
58
+ "sha": "e0f4775b780aada005bdd1774edcceac0ffee006",
59
+ "sourceBranch": "master",
60
+ "targetBranchesFromLabels": Array [],
61
+ },
62
+ Object {
63
+ "committedDate": "2021-01-01T00:00:00",
64
+ "existingTargetPullRequests": Array [
65
+ Object {
66
+ "branch": "7.x",
67
+ "number": 99,
68
+ "state": "MERGED",
69
+ },
70
+ ],
71
+ "formattedMessage": "[APM] Avoid negative offset for error marker on timeline (#76638)",
72
+ "originalMessage": "[APM] Avoid negative offset for error marker on timeline (#76638)
73
+
74
+ Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>",
75
+ "pullNumber": 76638,
76
+ "sha": "fae1e02e0f7a475bf92da05be52a817aa2a84959",
77
+ "sourceBranch": "master",
78
+ "targetBranchesFromLabels": Array [],
79
+ },
80
+ Object {
81
+ "committedDate": "2021-01-01T00:00:00",
82
+ "existingTargetPullRequests": Array [
83
+ Object {
84
+ "branch": "7.x",
85
+ "number": 99,
86
+ "state": "MERGED",
87
+ },
88
+ Object {
89
+ "branch": "7.9",
90
+ "number": 99,
91
+ "state": "MERGED",
92
+ },
93
+ ],
94
+ "formattedMessage": "[APM] Add anomaly detection API tests + fixes (#73120)",
95
+ "originalMessage": "[APM] Add anomaly detection API tests + fixes (#73120)
96
+
97
+ Co-authored-by: Nathan L Smith <nathan.smith@elastic.co>",
98
+ "pullNumber": 73120,
99
+ "sha": "aa68e3b63a4b513294dc58eaf4422e66a0beffb1",
100
+ "sourceBranch": "master",
101
+ "targetBranchesFromLabels": Array [],
102
+ },
103
+ Object {
104
+ "committedDate": "2021-01-01T00:00:00",
105
+ "existingTargetPullRequests": Array [],
106
+ "formattedMessage": "[APM] Update script with new roles/users (#72599)",
107
+ "originalMessage": "[APM] Update script with new roles/users (#72599)
108
+
109
+ * [APM] Update script with new roles/users
110
+
111
+ * add log
112
+
113
+ * Add validation for http prefix",
114
+ "pullNumber": 72599,
115
+ "sha": "2fc7112ec27a9f8ded0e2f9e097613721f1179dd",
116
+ "sourceBranch": "master",
117
+ "targetBranchesFromLabels": Array [],
118
+ },
119
+ Object {
120
+ "committedDate": "2021-01-01T00:00:00",
121
+ "existingTargetPullRequests": Array [
122
+ Object {
123
+ "branch": "7.x",
124
+ "number": 99,
125
+ "state": "MERGED",
126
+ },
127
+ Object {
128
+ "branch": "7.9",
129
+ "number": 99,
130
+ "state": "MERGED",
131
+ },
132
+ ],
133
+ "formattedMessage": "Update jobs_list.tsx (#72797)",
134
+ "originalMessage": "Update jobs_list.tsx (#72797)",
135
+ "pullNumber": 72797,
136
+ "sha": "7e126bfab6a3bfc44f9fa50feecfe22b4634e1a0",
137
+ "sourceBranch": "master",
138
+ "targetBranchesFromLabels": Array [],
139
+ },
140
+ Object {
141
+ "committedDate": "2021-01-01T00:00:00",
142
+ "existingTargetPullRequests": Array [
143
+ Object {
144
+ "branch": "7.x",
145
+ "number": 99,
146
+ "state": "MERGED",
147
+ },
148
+ ],
149
+ "formattedMessage": "[APM] Fix confusing request/minute viz (#69143)",
150
+ "originalMessage": "[APM] Fix confusing request/minute viz (#69143)",
151
+ "pullNumber": 69143,
152
+ "sha": "d12208c7ea9513529ea1aff42d154db89e3573ff",
153
+ "sourceBranch": "master",
154
+ "targetBranchesFromLabels": Array [],
155
+ },
156
+ Object {
157
+ "committedDate": "2021-01-01T00:00:00",
158
+ "existingTargetPullRequests": Array [
159
+ Object {
160
+ "branch": "7.x",
161
+ "number": 99,
162
+ "state": "MERGED",
163
+ },
164
+ ],
165
+ "formattedMessage": "[APM] Remove watcher integration (#71655)",
166
+ "originalMessage": "[APM] Remove watcher integration (#71655)",
167
+ "pullNumber": 71655,
168
+ "sha": "f760d8513b0216a73e9a476661f0fb8fb0887a61",
169
+ "sourceBranch": "master",
170
+ "targetBranchesFromLabels": Array [],
171
+ },
172
+ Object {
173
+ "committedDate": "2021-01-01T00:00:00",
174
+ "existingTargetPullRequests": Array [
175
+ Object {
176
+ "branch": "7.x",
177
+ "number": 99,
178
+ "state": "MERGED",
179
+ },
180
+ Object {
181
+ "branch": "7.9",
182
+ "number": 99,
183
+ "state": "MERGED",
184
+ },
185
+ ],
186
+ "formattedMessage": "[APM] Disable flaky rum e2e’s (#72614)",
187
+ "originalMessage": "[APM] Disable flaky rum e2e’s (#72614)",
188
+ "pullNumber": 72614,
189
+ "sha": "05ee3da80db34ccf93e7424aa2704c098a1b49fa",
190
+ "sourceBranch": "master",
191
+ "targetBranchesFromLabels": Array [],
192
+ },
193
+ Object {
194
+ "committedDate": "2021-01-01T00:00:00",
195
+ "existingTargetPullRequests": Array [
196
+ Object {
197
+ "branch": "7.x",
198
+ "number": 99,
199
+ "state": "MERGED",
200
+ },
201
+ Object {
202
+ "branch": "7.9",
203
+ "number": 99,
204
+ "state": "MERGED",
205
+ },
206
+ ],
207
+ "formattedMessage": "[APM] Increase \`xpack.apm.ui.transactionGroupBucketSize\` (#71661)",
208
+ "originalMessage": "[APM] Increase \`xpack.apm.ui.transactionGroupBucketSize\` (#71661)",
209
+ "pullNumber": 71661,
210
+ "sha": "51a862988c344b34bd9da57dd57008df12e1b5e5",
211
+ "sourceBranch": "master",
212
+ "targetBranchesFromLabels": Array [],
213
+ },
214
+ Object {
215
+ "committedDate": "2021-01-01T00:00:00",
216
+ "existingTargetPullRequests": Array [
217
+ Object {
218
+ "branch": "7.9",
219
+ "number": 99,
220
+ "state": "MERGED",
221
+ },
222
+ Object {
223
+ "branch": "7.x",
224
+ "number": 99,
225
+ "state": "MERGED",
226
+ },
227
+ ],
228
+ "formattedMessage": "[APM] Handle ML errors (#72316)",
229
+ "originalMessage": "[APM] Handle ML errors (#72316)
230
+
231
+ * [APM] Handle ML errors
232
+
233
+ * Add capability check
234
+
235
+ * Improve test
236
+
237
+ * Address Caue’s feedback
238
+
239
+ * Move getSeverity
240
+
241
+ * Fix tsc
242
+
243
+ * Fix copy",
244
+ "pullNumber": 72316,
245
+ "sha": "511e4543a7828cf0cdb157b88b01352947e0384f",
246
+ "sourceBranch": "master",
247
+ "targetBranchesFromLabels": Array [],
248
+ },
249
+ ]
250
+ `);
251
+ });
252
+ });
@@ -2,11 +2,11 @@ import { ValidConfigOptions } from '../../../options/options';
2
2
  import { Commit } from '../../../types/Commit';
3
3
  import { PullRequestNode } from './getExistingTargetPullRequests';
4
4
  export declare function fetchCommitsByAuthor(options: ValidConfigOptions): Promise<Commit[]>;
5
- export interface DataResponse {
5
+ export interface CommitByAuthorResponse {
6
6
  repository: {
7
7
  ref: {
8
8
  target: {
9
- history: {
9
+ [commitPath: string]: {
10
10
  edges: HistoryEdge[];
11
11
  };
12
12
  };
@@ -17,6 +17,7 @@ interface HistoryEdge {
17
17
  node: {
18
18
  oid: string;
19
19
  message: string;
20
+ committedDate: string;
20
21
  associatedPullRequests: {
21
22
  edges: {
22
23
  node: PullRequestNode;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fetchCommitsByAuthor = void 0;
7
- const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
7
+ const lodash_1 = require("lodash");
8
8
  const ora_1 = __importDefault(require("ora"));
9
9
  const HandledError_1 = require("../../HandledError");
10
10
  const commitFormatters_1 = require("../commitFormatters");
@@ -12,8 +12,34 @@ const apiRequestV4_1 = require("./apiRequestV4");
12
12
  const fetchAuthorId_1 = require("./fetchAuthorId");
13
13
  const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
14
14
  const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
15
+ function getCommitHistoryFragment(commitPath, index = 0) {
16
+ return /* GraphQL */ `
17
+ _${index}: history(
18
+ first: $maxNumber
19
+ author: { id: $authorId }
20
+ ${commitPath ? `path: "${commitPath}"` : ''}
21
+ ) {
22
+ edges {
23
+ node {
24
+ oid
25
+ message
26
+ committedDate
27
+ associatedPullRequests(first: 1) {
28
+ edges {
29
+ node {
30
+ ...${getExistingTargetPullRequests_1.pullRequestFragment.name}
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }`;
37
+ }
15
38
  async function fetchCommitsByAuthor(options) {
16
- const { accessToken, githubApiBaseUrlV4, maxNumber, path, repoName, repoOwner, sourceBranch, } = options;
39
+ const { accessToken, githubApiBaseUrlV4, maxNumber, commitPaths, repoName, repoOwner, sourceBranch, } = options;
40
+ const commitHistoryFragment = commitPaths.length > 0
41
+ ? commitPaths.map(getCommitHistoryFragment).join('\n')
42
+ : getCommitHistoryFragment(null);
17
43
  const query = /* GraphQL */ `
18
44
  query CommitsByAuthor(
19
45
  $repoOwner: String!
@@ -21,44 +47,25 @@ async function fetchCommitsByAuthor(options) {
21
47
  $maxNumber: Int!
22
48
  $sourceBranch: String!
23
49
  $authorId: ID
24
- $historyPath: String
25
50
  ) {
26
51
  repository(owner: $repoOwner, name: $repoName) {
27
52
  ref(qualifiedName: $sourceBranch) {
28
53
  target {
29
54
  ... on Commit {
30
- history(
31
- first: $maxNumber
32
- author: { id: $authorId }
33
- path: $historyPath
34
- ) {
35
- edges {
36
- node {
37
- oid
38
- message
39
- associatedPullRequests(first: 1) {
40
- edges {
41
- node {
42
- ...${getExistingTargetPullRequests_1.pullRequestFragmentName}
43
- }
44
- }
45
- }
46
- }
47
- }
48
- }
55
+ ${commitHistoryFragment}
49
56
  }
50
57
  }
51
58
  }
52
59
  }
53
60
  }
54
61
 
55
- ${getExistingTargetPullRequests_1.pullRequestFragment}
62
+ ${getExistingTargetPullRequests_1.pullRequestFragment.source}
56
63
  `;
57
- const spinner = ora_1.default(`Loading commits from branch "${sourceBranch}"...`).start();
64
+ const spinner = (0, ora_1.default)(`Loading commits from branch "${sourceBranch}"...`).start();
58
65
  let res;
59
66
  try {
60
- const authorId = await fetchAuthorId_1.fetchAuthorId(options);
61
- res = await apiRequestV4_1.apiRequestV4({
67
+ const authorId = await (0, fetchAuthorId_1.fetchAuthorId)(options);
68
+ res = await (0, apiRequestV4_1.apiRequestV4)({
62
69
  githubApiBaseUrlV4,
63
70
  accessToken,
64
71
  query,
@@ -68,7 +75,6 @@ async function fetchCommitsByAuthor(options) {
68
75
  sourceBranch,
69
76
  maxNumber,
70
77
  authorId,
71
- historyPath: path || null,
72
78
  },
73
79
  });
74
80
  spinner.stop();
@@ -80,71 +86,76 @@ async function fetchCommitsByAuthor(options) {
80
86
  if (res.repository.ref === null) {
81
87
  throw new HandledError_1.HandledError(`The upstream branch "${sourceBranch}" does not exist. Try specifying a different branch with "--source-branch <your-branch>"`);
82
88
  }
83
- const commits = res.repository.ref.target.history.edges.map((edge) => {
84
- var _a;
85
- const commitMessage = edge.node.message;
86
- const sha = edge.node.oid;
87
- // it is assumed that there can only be a single PR associated with a commit
88
- // that assumption might not hold true forever but for now it works out
89
- const pullRequestNode = (_a = edge.node.associatedPullRequests.edges[0]) === null || _a === void 0 ? void 0 : _a.node;
90
- // the source pull request for the commit cannot be retrieved
91
- // This happens if the commits was pushed directly to a branch (not merging via a PR)
92
- if (!isSourcePullRequest({ pullRequestNode, options, sha })) {
93
- const pullNumber = commitFormatters_1.getPullNumberFromMessage(commitMessage);
94
- const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
89
+ const commits = Object.values(res.repository.ref.target).flatMap((historyResponse) => {
90
+ return historyResponse.edges.map((edge) => {
91
+ const commitMessage = edge.node.message;
92
+ const sha = edge.node.oid;
93
+ const committedDate = edge.node.committedDate;
94
+ // it is assumed that there can only be a single PR associated with a commit
95
+ // that assumption might not hold true forever but for now it works out
96
+ const pullRequestNode = edge.node.associatedPullRequests.edges[0]?.node;
97
+ // the source pull request for the commit cannot be retrieved
98
+ // This happens if the commits was pushed directly to a branch (not merging via a PR)
99
+ if (!isSourcePullRequest({ pullRequestNode, options, sha })) {
100
+ const pullNumber = (0, commitFormatters_1.getPullNumberFromMessage)(commitMessage);
101
+ const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
102
+ message: commitMessage,
103
+ pullNumber,
104
+ sha,
105
+ });
106
+ return {
107
+ committedDate,
108
+ sourceBranch,
109
+ targetBranchesFromLabels: [],
110
+ sha,
111
+ formattedMessage,
112
+ originalMessage: commitMessage,
113
+ pullNumber,
114
+ existingTargetPullRequests: [],
115
+ };
116
+ }
117
+ const pullNumber = pullRequestNode.number;
118
+ const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
95
119
  message: commitMessage,
96
120
  pullNumber,
97
121
  sha,
98
122
  });
123
+ const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
124
+ const targetBranchesFromLabels = (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
125
+ sourceBranch: pullRequestNode.baseRefName,
126
+ existingTargetPullRequests,
127
+ branchLabelMapping: options.branchLabelMapping,
128
+ labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
129
+ });
99
130
  return {
131
+ committedDate,
100
132
  sourceBranch,
101
- targetBranchesFromLabels: [],
133
+ targetBranchesFromLabels,
102
134
  sha,
103
135
  formattedMessage,
104
136
  originalMessage: commitMessage,
105
137
  pullNumber,
106
- existingTargetPullRequests: [],
138
+ existingTargetPullRequests,
107
139
  };
108
- }
109
- const pullNumber = pullRequestNode.number;
110
- const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
111
- message: commitMessage,
112
- pullNumber,
113
- sha,
114
- });
115
- const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
116
- const targetBranchesFromLabels = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
117
- sourceBranch: pullRequestNode.baseRefName,
118
- existingTargetPullRequests,
119
- branchLabelMapping: options.branchLabelMapping,
120
- labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
121
140
  });
122
- return {
123
- sourceBranch,
124
- targetBranchesFromLabels,
125
- sha,
126
- formattedMessage,
127
- originalMessage: commitMessage,
128
- pullNumber,
129
- existingTargetPullRequests,
130
- };
131
141
  });
132
142
  // terminate if not commits were found
133
- if (lodash_isempty_1.default(commits)) {
134
- const pathText = options.path
135
- ? ` touching files in path: "${options.path}"`
143
+ if ((0, lodash_1.isEmpty)(commits)) {
144
+ const pathText = options.commitPaths.length > 0
145
+ ? ` touching files in path: "${options.commitPaths}"`
136
146
  : '';
137
147
  const errorText = options.all
138
148
  ? `There are no commits in this repository${pathText}`
139
149
  : `There are no commits by "${options.author}" in this repository${pathText}. Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`;
140
150
  throw new HandledError_1.HandledError(errorText);
141
151
  }
142
- return commits;
152
+ const commitsUnique = (0, lodash_1.uniqBy)(commits, 'sha');
153
+ const commitsSorted = (0, lodash_1.orderBy)(commitsUnique, 'committedDate', 'desc');
154
+ return commitsSorted;
143
155
  }
144
156
  exports.fetchCommitsByAuthor = fetchCommitsByAuthor;
145
157
  function isSourcePullRequest({ pullRequestNode, options, sha, }) {
146
- var _a;
147
- return ((pullRequestNode === null || pullRequestNode === void 0 ? void 0 : pullRequestNode.repository.name) === options.repoName &&
158
+ return (pullRequestNode?.repository.name === options.repoName &&
148
159
  pullRequestNode.repository.owner.login === options.repoOwner &&
149
- ((_a = pullRequestNode.mergeCommit) === null || _a === void 0 ? void 0 : _a.oid) === sha);
160
+ pullRequestNode.mergeCommit?.oid === sha);
150
161
  }
@@ -5,12 +5,84 @@ const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
5
5
  describe('fetchCommitsByAuthor', () => {
6
6
  let devAccessToken;
7
7
  beforeAll(async () => {
8
- devAccessToken = await getDevAccessToken_1.getDevAccessToken();
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ describe('commitPaths', () => {
11
+ const getOptions = () => ({
12
+ repoOwner: 'backport-org',
13
+ repoName: 'repo-with-different-commit-paths',
14
+ sourceBranch: 'main',
15
+ accessToken: devAccessToken,
16
+ username: 'sqren',
17
+ author: 'sqren',
18
+ maxNumber: 10,
19
+ githubApiBaseUrlV4: 'https://api.github.com/graphql',
20
+ });
21
+ const getCommitMessages = (commits) => {
22
+ return commits.map((c) => c.originalMessage.replace(/(\r\n|\n|\r)/gm, ''));
23
+ };
24
+ it('returns all commits', async () => {
25
+ const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
26
+ ...getOptions(),
27
+ commitPaths: [],
28
+ });
29
+ const commitMessages = getCommitMessages(commits);
30
+ expect(commitMessages).toEqual([
31
+ 'Edit all lyrics',
32
+ 'Update .backportrc.json',
33
+ 'Edit "Take on me"',
34
+ 'Add backportrc.json',
35
+ 'Add "Bohemian Rhapsody""',
36
+ 'Add "99 Luftballons"',
37
+ 'Add "Take on me"',
38
+ ]);
39
+ });
40
+ it('only returns commits related to "99-luftballons.txt"', async () => {
41
+ const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
42
+ ...getOptions(),
43
+ commitPaths: ['lyrics/99-luftballons.txt'],
44
+ });
45
+ const commitMessages = getCommitMessages(commits);
46
+ expect(commitMessages).toEqual([
47
+ 'Edit all lyrics',
48
+ 'Add "99 Luftballons"',
49
+ ]);
50
+ });
51
+ it('only returns commits related to "take-on-me.txt"', async () => {
52
+ const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
53
+ ...getOptions(),
54
+ commitPaths: ['lyrics/take-on-me.txt'],
55
+ });
56
+ const commitMessages = getCommitMessages(commits);
57
+ expect(commitMessages).toEqual([
58
+ 'Edit all lyrics',
59
+ 'Edit "Take on me"',
60
+ 'Add "Take on me"',
61
+ ]);
62
+ });
63
+ it('removes duplicates and order by `committedDate`', async () => {
64
+ const commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
65
+ ...getOptions(),
66
+ commitPaths: [
67
+ 'lyrics/99-luftballons.txt',
68
+ 'lyrics/take-on-me.txt',
69
+ 'lyrics/bohemian-rhapsody.txt',
70
+ ],
71
+ });
72
+ const commitMessages = getCommitMessages(commits);
73
+ expect(commitMessages).toEqual([
74
+ 'Edit all lyrics',
75
+ 'Edit "Take on me"',
76
+ 'Add "Bohemian Rhapsody""',
77
+ 'Add "99 Luftballons"',
78
+ 'Add "Take on me"',
79
+ ]);
80
+ });
9
81
  });
10
82
  describe('existingTargetPullRequests', () => {
11
83
  let res;
12
84
  beforeEach(async () => {
13
- res = await fetchCommitsByAuthor_1.fetchCommitsByAuthor({
85
+ res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
14
86
  repoOwner: 'backport-org',
15
87
  repoName: 'backport-e2e',
16
88
  sourceBranch: 'master',
@@ -19,24 +91,25 @@ describe('fetchCommitsByAuthor', () => {
19
91
  author: 'sqren',
20
92
  maxNumber: 10,
21
93
  githubApiBaseUrlV4: 'https://api.github.com/graphql',
94
+ commitPaths: [],
22
95
  });
23
96
  });
24
97
  it('returns related OPEN PRs', async () => {
25
98
  const commitWithOpenPR = res.find((commit) => commit.pullNumber === 9);
26
- expect(commitWithOpenPR === null || commitWithOpenPR === void 0 ? void 0 : commitWithOpenPR.existingTargetPullRequests).toEqual([
27
- { branch: '7.8', state: 'OPEN' },
99
+ expect(commitWithOpenPR?.existingTargetPullRequests).toEqual([
100
+ { branch: '7.8', state: 'OPEN', number: 10 },
28
101
  ]);
29
102
  });
30
103
  it('returns related MERGED PRs', async () => {
31
104
  const commitWithMergedPRs = res.find((commit) => commit.pullNumber === 5);
32
- expect(commitWithMergedPRs === null || commitWithMergedPRs === void 0 ? void 0 : commitWithMergedPRs.existingTargetPullRequests).toEqual([
33
- { branch: '7.x', state: 'MERGED' },
34
- { branch: '7.8', state: 'MERGED' },
105
+ expect(commitWithMergedPRs?.existingTargetPullRequests).toEqual([
106
+ { branch: '7.x', state: 'MERGED', number: 6 },
107
+ { branch: '7.8', state: 'MERGED', number: 7 },
35
108
  ]);
36
109
  });
37
110
  it('returns empty if there are no related PRs', async () => {
38
111
  const commitWithoutPRs = res.find((commit) => commit.pullNumber === 8);
39
- expect(commitWithoutPRs === null || commitWithoutPRs === void 0 ? void 0 : commitWithoutPRs.existingTargetPullRequests).toEqual([]);
112
+ expect(commitWithoutPRs?.existingTargetPullRequests).toEqual([]);
40
113
  });
41
114
  });
42
115
  });