backport 5.6.6 → 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 (206) 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 +13 -8
  10. package/dist/options/cliArgs.d.ts +11 -9
  11. package/dist/options/cliArgs.js +74 -36
  12. package/dist/options/cliArgs.test.js +33 -37
  13. package/dist/options/config/config.d.ts +17 -15
  14. package/dist/options/config/config.js +8 -8
  15. package/dist/options/config/config.test.js +3 -2
  16. package/dist/options/config/getOptionsFromGit.js +1 -1
  17. package/dist/options/config/globalConfig.d.ts +2 -51
  18. package/dist/options/config/globalConfig.js +8 -8
  19. package/dist/options/config/globalConfig.test.js +7 -3
  20. package/dist/options/config/projectConfig.d.ts +2 -51
  21. package/dist/options/config/projectConfig.js +2 -2
  22. package/dist/options/config/projectConfig.test.js +3 -3
  23. package/dist/options/config/readConfigFile.d.ts +2 -51
  24. package/dist/options/config/readConfigFile.js +2 -2
  25. package/dist/options/options.d.ts +19 -14
  26. package/dist/options/options.js +5 -6
  27. package/dist/options/options.test.js +48 -11
  28. package/dist/options/parseRequiredOptions.d.ts +18 -13
  29. package/dist/options/parseRequiredOptions.js +8 -12
  30. package/dist/options/parseRequiredOptions.test.js +25 -16
  31. package/dist/runSequentially.d.ts +20 -0
  32. package/dist/runSequentially.js +41 -0
  33. package/dist/runSequentially.test.d.ts +1 -0
  34. package/dist/runSequentially.test.js +235 -0
  35. package/dist/runWithOptions.js +7 -14
  36. package/dist/runWithOptions.test.js +138 -17
  37. package/dist/scripts/generate-gql.d.ts +1 -0
  38. package/dist/scripts/generate-gql.js +15 -0
  39. package/dist/scripts/postinstall.js +4 -4
  40. package/dist/scripts/postinstall.test.js +9 -2
  41. package/dist/scripts/runPostinstall.js +1 -1
  42. package/dist/services/HandledError.d.ts +11 -1
  43. package/dist/services/HandledError.js +2 -1
  44. package/dist/services/child-process-promisified.d.ts +1 -1
  45. package/dist/services/child-process-promisified.js +1 -1
  46. package/dist/services/env.js +5 -5
  47. package/dist/services/env.test.js +11 -4
  48. package/dist/services/fs-promisified.js +4 -4
  49. package/dist/services/getExpectedTarget.d.ts +9 -0
  50. package/dist/services/getExpectedTarget.js +77 -0
  51. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  52. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  53. package/dist/services/git.d.ts +15 -4
  54. package/dist/services/git.integration.test.d.ts +1 -0
  55. package/dist/services/git.integration.test.js +168 -0
  56. package/dist/services/git.js +86 -61
  57. package/dist/services/git.test.js +61 -64
  58. package/dist/services/github/commitFormatters.d.ts +3 -7
  59. package/dist/services/github/commitFormatters.js +10 -19
  60. package/dist/services/github/commitFormatters.test.js +2 -24
  61. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  62. package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
  63. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
  64. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  66. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  67. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  68. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  69. package/dist/services/github/v3/createPullRequest.js +32 -23
  70. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  71. package/dist/services/github/v3/createStatusComment.js +97 -0
  72. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  73. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  74. package/dist/services/github/v4/FetchPullRequestId.js +1 -1
  75. package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
  76. package/dist/services/github/v4/apiRequestV4.js +5 -7
  77. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  78. package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
  79. package/dist/services/github/v4/enablePullRequestAutoMerge.js +8 -7
  80. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +94 -33
  81. package/dist/services/github/v4/fetchAuthorId.js +1 -1
  82. package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
  83. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  84. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  85. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  86. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  87. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
  88. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  89. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  90. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
  91. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
  92. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  93. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  94. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  103. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  104. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  105. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  106. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
  107. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  109. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  110. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  111. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  112. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  113. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  114. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  115. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
  116. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  117. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  118. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  119. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
  120. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  121. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  122. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  123. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  124. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  125. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +16 -10
  126. package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
  127. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +25 -7
  128. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +13 -16
  129. package/dist/services/github/v4/getOptionsFromGithub/query.js +13 -15
  130. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  131. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  132. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  133. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  134. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  135. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  136. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  137. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  138. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  139. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  140. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  141. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  142. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  143. package/dist/services/logger.d.ts +3 -3
  144. package/dist/services/logger.js +16 -15
  145. package/dist/services/prompt.test.d.ts +1 -0
  146. package/dist/services/prompt.test.js +87 -0
  147. package/dist/services/prompts.d.ts +10 -4
  148. package/dist/services/prompts.js +85 -22
  149. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  150. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  151. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  152. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
  153. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  154. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  155. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  156. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  157. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  158. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  159. package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
  160. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  161. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  162. package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
  163. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  164. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  165. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  166. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  167. package/dist/services/sourceCommit.d.ts +78 -0
  168. package/dist/services/sourceCommit.js +86 -0
  169. package/dist/services/sourceCommit.test.d.ts +1 -0
  170. package/dist/services/sourceCommit.test.js +280 -0
  171. package/dist/test/inquirer.private.test.js +22 -15
  172. package/dist/test/integration/createSpies.js +6 -6
  173. package/dist/test/integration/envConstants.js +5 -6
  174. package/dist/test/integration/helpers.js +1 -1
  175. package/dist/test/integration/integration.private.test.d.ts +1 -0
  176. package/dist/test/integration/integration.private.test.js +308 -0
  177. package/dist/test/integration/integration.test.js +28 -29
  178. package/dist/test/nockHelpers.js +3 -7
  179. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  180. package/dist/test/setupFiles/automatic-mocks.js +0 -22
  181. package/dist/types/Commit.d.ts +85 -0
  182. package/dist/types/Commit.js +139 -0
  183. package/dist/types/commitNode.d.ts +89 -0
  184. package/dist/types/commitNode.js +139 -0
  185. package/dist/types/commitNode.test.d.ts +1 -0
  186. package/dist/types/commitNode.test.js +255 -0
  187. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  188. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  189. package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
  190. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  191. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +131 -68
  192. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  193. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  194. package/dist/ui/getCommits.d.ts +1 -1
  195. package/dist/ui/getCommits.js +55 -25
  196. package/dist/ui/getTargetBranches.d.ts +2 -2
  197. package/dist/ui/getTargetBranches.js +16 -17
  198. package/dist/ui/getTargetBranches.test.js +75 -99
  199. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  200. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  201. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  202. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  203. package/dist/ui/maybeSetupRepo.js +9 -9
  204. package/dist/ui/maybeSetupRepo.test.js +5 -1
  205. package/package.json +36 -51
  206. package/yarn.lock +2387 -2987
@@ -20,6 +20,7 @@ const defaultOptions = {
20
20
  maxNumber: 10,
21
21
  githubApiBaseUrlV3: 'https://api.github.com',
22
22
  githubApiBaseUrlV4: 'http://localhost/graphql',
23
+ commitPaths: [],
23
24
  };
24
25
  const authorIdMockData = { user: { id: 'myUserId' } };
25
26
  describe('fetchCommitsByAuthor', () => {
@@ -34,21 +35,22 @@ describe('fetchCommitsByAuthor', () => {
34
35
  let authorIdCalls;
35
36
  let commitsByAuthorCalls;
36
37
  beforeEach(async () => {
37
- authorIdCalls = nockHelpers_1.mockGqlRequest({
38
+ authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
38
39
  name: 'AuthorId',
39
40
  statusCode: 200,
40
41
  body: { data: authorIdMockData },
41
42
  });
42
- commitsByAuthorCalls = nockHelpers_1.mockGqlRequest({
43
+ commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
43
44
  name: 'CommitsByAuthor',
44
45
  statusCode: 200,
45
46
  body: { data: commitsByAuthorMock_1.commitsWithPullRequestsMock },
46
47
  });
47
- res = await fetchCommitsByAuthor_1.fetchCommitsByAuthor(defaultOptions);
48
+ res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(defaultOptions);
48
49
  });
49
- it('Should return a list of commits with pullNumber and existing backports', () => {
50
+ it('should return a list of commits with pullNumber and existing backports', () => {
50
51
  const expectedCommits = [
51
52
  {
53
+ committedDate: '2021-12-24T00:00:00Z',
52
54
  sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
53
55
  formattedMessage: 'Add 👻 (2e63475c)',
54
56
  originalMessage: 'Add 👻',
@@ -57,6 +59,7 @@ describe('fetchCommitsByAuthor', () => {
57
59
  sourceBranch: 'master',
58
60
  },
59
61
  {
62
+ committedDate: '2021-12-23T00:00:00Z',
60
63
  sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
61
64
  formattedMessage: 'Add witch (#85)',
62
65
  originalMessage: 'Add witch (#85)',
@@ -66,6 +69,7 @@ describe('fetchCommitsByAuthor', () => {
66
69
  sourceBranch: 'master',
67
70
  },
68
71
  {
72
+ committedDate: '2021-12-22T00:00:00Z',
69
73
  sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
70
74
  formattedMessage: 'Add SF mention (#80)',
71
75
  originalMessage: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
@@ -77,6 +81,7 @@ describe('fetchCommitsByAuthor', () => {
77
81
  sourceBranch: 'master',
78
82
  },
79
83
  {
84
+ committedDate: '2021-12-21T00:00:00Z',
80
85
  sha: '3827bbbaf39914eda4f02f6940189844375fd097',
81
86
  formattedMessage: 'Add backport config (3827bbba)',
82
87
  originalMessage: 'Add backport config',
@@ -85,6 +90,7 @@ describe('fetchCommitsByAuthor', () => {
85
90
  sourceBranch: 'master',
86
91
  },
87
92
  {
93
+ committedDate: '2021-12-20T00:00:00Z',
88
94
  sha: '5ea0da550ac191029459289d67f99ad7d310812b',
89
95
  formattedMessage: 'Initial commit (5ea0da55)',
90
96
  originalMessage: 'Initial commit',
@@ -107,6 +113,7 @@ describe('fetchCommitsByAuthor', () => {
107
113
  const res = await getExistingBackportsByRepoName('kibana', 'kibana');
108
114
  const expectedCommits = [
109
115
  {
116
+ committedDate: '2021-12-13T22:46:29Z',
110
117
  existingTargetPullRequests: [
111
118
  { branch: '6.3', state: 'MERGED', number: 99 },
112
119
  ],
@@ -124,6 +131,7 @@ describe('fetchCommitsByAuthor', () => {
124
131
  const res = await getExistingBackportsByRepoName('kibana', 'kibana2');
125
132
  const expectedCommits = [
126
133
  {
134
+ committedDate: '2021-12-13T22:46:29Z',
127
135
  existingTargetPullRequests: [],
128
136
  formattedMessage: 'Add SF mention (#80)',
129
137
  originalMessage: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
@@ -138,19 +146,19 @@ describe('fetchCommitsByAuthor', () => {
138
146
  });
139
147
  describe('when a custom github api hostname is supplied', () => {
140
148
  it('should be used in gql requests', async () => {
141
- const authorIdCalls = nockHelpers_1.mockGqlRequest({
149
+ const authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
142
150
  name: 'AuthorId',
143
151
  statusCode: 200,
144
152
  body: { data: authorIdMockData },
145
153
  apiBaseUrl: 'http://localhost/my-custom-api',
146
154
  });
147
- const commitsByAuthorCalls = nockHelpers_1.mockGqlRequest({
155
+ const commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
148
156
  name: 'CommitsByAuthor',
149
157
  statusCode: 200,
150
158
  body: { data: commitsByAuthorMock_1.commitsWithPullRequestsMock },
151
159
  apiBaseUrl: 'http://localhost/my-custom-api',
152
160
  });
153
- await fetchCommitsByAuthor_1.fetchCommitsByAuthor({
161
+ await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
154
162
  ...defaultOptions,
155
163
  githubApiBaseUrlV4: 'http://localhost/my-custom-api',
156
164
  });
@@ -164,7 +172,7 @@ describe('getExistingTargetPullRequests', () => {
164
172
  nock_1.default.cleanAll();
165
173
  });
166
174
  it('should return a result when commit messages match', () => {
167
- const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
175
+ const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
168
176
  sourcePullRequest: {
169
177
  number: 1234,
170
178
  commitMessage: 'my message (#1234)',
@@ -175,13 +183,13 @@ describe('getExistingTargetPullRequests', () => {
175
183
  commitMessages: ['my message (#1234)'],
176
184
  },
177
185
  });
178
- const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
186
+ const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
179
187
  expect(existingPRs).toEqual([
180
188
  { branch: '7.x', state: 'MERGED', number: 10 },
181
189
  ]);
182
190
  });
183
191
  it('should not return a result when commit messages do not match', () => {
184
- const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
192
+ const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
185
193
  sourcePullRequest: {
186
194
  number: 1234,
187
195
  commitMessage: 'the initial message',
@@ -192,11 +200,11 @@ describe('getExistingTargetPullRequests', () => {
192
200
  commitMessages: ['my changed message (#1234)'],
193
201
  },
194
202
  });
195
- const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
203
+ const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
196
204
  expect(existingPRs).toEqual([]);
197
205
  });
198
206
  it('should return a result when commit message matches pull request title and number', () => {
199
- const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
207
+ const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
200
208
  sourcePullRequest: {
201
209
  number: 1234,
202
210
  commitMessage: 'the initial message',
@@ -207,13 +215,13 @@ describe('getExistingTargetPullRequests', () => {
207
215
  commitMessages: ['the actual message'],
208
216
  },
209
217
  });
210
- const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
218
+ const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
211
219
  expect(existingPRs).toEqual([
212
220
  { branch: '7.x', state: 'MERGED', number: 40 },
213
221
  ]);
214
222
  });
215
223
  it('should not return a result when only pull request title (but not pull number) matches', () => {
216
- const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
224
+ const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
217
225
  sourcePullRequest: {
218
226
  number: 1234,
219
227
  commitMessage: 'my message',
@@ -224,11 +232,11 @@ describe('getExistingTargetPullRequests', () => {
224
232
  commitMessages: ['the actual message'],
225
233
  },
226
234
  });
227
- const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
235
+ const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
228
236
  expect(existingPRs).toEqual([]);
229
237
  });
230
238
  it('should return a result when first line of a multiline commit message matches', () => {
231
- const pullRequestNode = getPullRequestNodeMock_1.getPullRequestNodeMock({
239
+ const pullRequestNode = (0, getPullRequestNodeMock_1.getPullRequestNodeMock)({
232
240
  sourcePullRequest: {
233
241
  number: 1234,
234
242
  commitMessage: 'my message (#1234)',
@@ -239,25 +247,25 @@ describe('getExistingTargetPullRequests', () => {
239
247
  commitMessages: ['my message (#1234)\n\nsomething else'],
240
248
  },
241
249
  });
242
- const existingPRs = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
250
+ const existingPRs = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
243
251
  expect(existingPRs).toEqual([
244
252
  { branch: '7.x', state: 'MERGED', number: 20 },
245
253
  ]);
246
254
  });
247
255
  });
248
256
  async function getExistingBackportsByRepoName(repoName1, repoName2) {
249
- const commitsMock = getCommitsByAuthorMock_1.getCommitsByAuthorMock(repoName1);
250
- nockHelpers_1.mockGqlRequest({
257
+ const commitsMock = (0, getCommitsByAuthorMock_1.getCommitsByAuthorMock)(repoName1);
258
+ (0, nockHelpers_1.mockGqlRequest)({
251
259
  name: 'AuthorId',
252
260
  statusCode: 200,
253
261
  body: { data: authorIdMockData },
254
262
  });
255
- nockHelpers_1.mockGqlRequest({
263
+ (0, nockHelpers_1.mockGqlRequest)({
256
264
  name: 'CommitsByAuthor',
257
265
  statusCode: 200,
258
266
  body: { data: commitsMock },
259
267
  });
260
- return fetchCommitsByAuthor_1.fetchCommitsByAuthor({
268
+ return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
261
269
  ...defaultOptions,
262
270
  repoName: repoName2,
263
271
  });
@@ -13,7 +13,7 @@ async function fetchDefaultBranch(options) {
13
13
  }
14
14
  }
15
15
  `;
16
- const res = await apiRequestV4_1.apiRequestV4({
16
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
17
17
  githubApiBaseUrlV4,
18
18
  accessToken,
19
19
  query,
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.splitHead = exports.fetchExistingPullRequest = void 0;
4
4
  const apiRequestV4_1 = require("./apiRequestV4");
5
5
  async function fetchExistingPullRequest({ options, prPayload, }) {
6
- var _a;
7
6
  const { githubApiBaseUrlV4, accessToken } = options;
8
7
  const query = /* GraphQL */ `
9
8
  query ExistingPullRequest(
@@ -34,7 +33,7 @@ async function fetchExistingPullRequest({ options, prPayload, }) {
34
33
  }
35
34
  `;
36
35
  const { repoForkOwner, head } = splitHead(prPayload);
37
- const res = await apiRequestV4_1.apiRequestV4({
36
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
38
37
  githubApiBaseUrlV4,
39
38
  accessToken,
40
39
  query,
@@ -45,7 +44,7 @@ async function fetchExistingPullRequest({ options, prPayload, }) {
45
44
  head: head,
46
45
  },
47
46
  });
48
- const existingPullRequest = (_a = res.repository.ref) === null || _a === void 0 ? void 0 : _a.associatedPullRequests.edges[0];
47
+ const existingPullRequest = res.repository.ref?.associatedPullRequests.edges[0];
49
48
  if (!existingPullRequest) {
50
49
  return;
51
50
  }
@@ -5,7 +5,7 @@ const fetchExistingPullRequest_1 = require("./fetchExistingPullRequest");
5
5
  describe('fetchExistingPullRequest', () => {
6
6
  let devAccessToken;
7
7
  beforeAll(async () => {
8
- devAccessToken = await getDevAccessToken_1.getDevAccessToken();
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
9
  });
10
10
  describe('when PR does not exist', () => {
11
11
  it('returns undefined', async () => {
@@ -21,7 +21,7 @@ describe('fetchExistingPullRequest', () => {
21
21
  head: 'sqren:backport/7.8/pr-foo',
22
22
  base: '7.8',
23
23
  };
24
- const res = await fetchExistingPullRequest_1.fetchExistingPullRequest({ options, prPayload });
24
+ const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
25
25
  expect(res).toBe(undefined);
26
26
  });
27
27
  });
@@ -39,7 +39,7 @@ describe('fetchExistingPullRequest', () => {
39
39
  head: 'sqren:backport/7.8/pr-9',
40
40
  base: '7.8',
41
41
  };
42
- const res = await fetchExistingPullRequest_1.fetchExistingPullRequest({ options, prPayload });
42
+ const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
43
43
  expect(res).toEqual({
44
44
  url: 'https://github.com/backport-org/backport-e2e/pull/10',
45
45
  number: 10,
@@ -1,10 +1,19 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- import { PullRequestNode } from './getExistingTargetPullRequests';
3
- export declare function fetchMergedPullRequests(options: ValidConfigOptions, dateRange: {
4
- since: string;
5
- until: string;
2
+ import { CommitNode } from '../../../types/commitNode';
3
+ export declare function fetchMergedPullRequests({ accessToken, branchLabelMapping, commitsCount, dateRange, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch, }: {
4
+ accessToken: string;
5
+ branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
6
+ commitsCount?: number;
7
+ dateRange: {
8
+ since: string;
9
+ until: string;
10
+ };
11
+ githubApiBaseUrlV4?: string;
12
+ repoName: string;
13
+ repoOwner: string;
14
+ sourceBranch: string;
6
15
  }): Promise<{
7
- sourcePullNumber: number;
16
+ sourcePullNumber: number | undefined;
8
17
  existingTargetPullRequests: {
9
18
  number: number;
10
19
  branch: string;
@@ -12,27 +21,17 @@ export declare function fetchMergedPullRequests(options: ValidConfigOptions, dat
12
21
  }[];
13
22
  expectedTargetBranches: string[];
14
23
  remainingTargetBranches: string[];
15
- }[] | undefined>;
24
+ }[]>;
16
25
  export interface CommitsSinceDateResponse {
17
26
  repository: {
18
27
  ref: {
19
28
  target: {
20
29
  history: {
21
- edges: HistoryEdge[];
30
+ edges: Array<{
31
+ node: CommitNode;
32
+ }>;
22
33
  };
23
34
  };
24
35
  } | null;
25
36
  };
26
37
  }
27
- interface HistoryEdge {
28
- node: {
29
- oid: string;
30
- message: string;
31
- associatedPullRequests: {
32
- edges: {
33
- node: PullRequestNode;
34
- }[];
35
- };
36
- };
37
- }
38
- export {};
@@ -1,83 +1,36 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchMergedPullRequests = void 0;
7
- const lodash_difference_1 = __importDefault(require("lodash.difference"));
8
- const apiRequestV4_1 = require("./apiRequestV4");
9
- const fetchDefaultBranch_1 = require("./fetchDefaultBranch");
10
- const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
11
- const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
12
- async function fetchMergedPullRequests(options, dateRange) {
13
- var _a;
14
- const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
15
- const query = /* GraphQL */ `
16
- query CommitsSinceDate($repoOwner: String!, $repoName: String!, $commitsCount: Int!, $sourceBranch: String!, $since: GitTimestamp!, $until: GitTimestamp!) {
17
- repository(owner: $repoOwner, name: $repoName) {
18
- id
19
- ref(qualifiedName: $sourceBranch) {
20
- target {
21
- ... on Commit {
22
- history(first: $commitsCount, since: $since, until: $until) {
23
- totalCount
24
- edges {
25
- node {
26
- oid
27
- message
28
- associatedPullRequests(first: 1) {
29
- edges {
30
- node {
31
- ...${getExistingTargetPullRequests_1.pullRequestFragmentName}
32
- }
33
- }
34
- }
35
- }
36
- }
37
- }
38
- }
39
- }
40
- }
41
- }
42
- }
43
-
44
- ${getExistingTargetPullRequests_1.pullRequestFragment}
45
- `;
46
- // TODO: It should be possible to delete this since defaultBranch is already fetched during startup
47
- const defaultBranch = await fetchDefaultBranch_1.fetchDefaultBranch(options);
48
- const res = await apiRequestV4_1.apiRequestV4({
49
- githubApiBaseUrlV4,
4
+ const lodash_1 = require("lodash");
5
+ const fetchCommitsInDateRange_1 = require("./fetchCommits/fetchCommitsInDateRange");
6
+ async function fetchMergedPullRequests({ accessToken, branchLabelMapping, commitsCount = 50, dateRange, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sourceBranch, }) {
7
+ const commits = await (0, fetchCommitsInDateRange_1.fetchCommitsInDateRange)({
50
8
  accessToken,
51
- query,
52
- variables: {
53
- repoOwner,
54
- repoName,
55
- commitsCount: 50,
56
- sourceBranch: defaultBranch,
57
- since: dateRange.since,
58
- until: dateRange.until,
59
- },
9
+ branchLabelMapping,
10
+ commitsCount,
11
+ dateRange,
12
+ githubApiBaseUrlV4,
13
+ repoName,
14
+ repoOwner,
15
+ sourceBranch,
60
16
  });
61
- return (_a = res.repository.ref) === null || _a === void 0 ? void 0 : _a.target.history.edges.filter((commitEdge) => { var _a; return !!((_a = commitEdge.node.associatedPullRequests.edges[0]) === null || _a === void 0 ? void 0 : _a.node); }).map((commitEdge) => {
62
- const pullRequestNode = commitEdge.node.associatedPullRequests.edges[0].node;
63
- const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
64
- const expectedTargetBranches = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
65
- sourceBranch: pullRequestNode.baseRefName,
66
- existingTargetPullRequests: [],
67
- branchLabelMapping: options.branchLabelMapping,
68
- labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
69
- });
70
- const mergedTargetBranches = existingTargetPullRequests
17
+ return (commits ?? [])
18
+ .filter((commit) => !!commit.pullNumber)
19
+ .map((commit) => {
20
+ const mergedTargetBranches = commit.existingTargetPullRequests
71
21
  .filter((pr) => pr.state === 'MERGED')
72
22
  .map((pr) => pr.branch);
73
- const remainingTargetBranches = lodash_difference_1.default(expectedTargetBranches, mergedTargetBranches);
23
+ const expectedTargetBranches = commit.targetBranchesFromLabels;
24
+ // missing and unmerged pull requests
25
+ const remainingTargetBranches = (0, lodash_1.difference)(expectedTargetBranches, mergedTargetBranches);
74
26
  return {
75
- sourcePullNumber: pullRequestNode.number,
76
- existingTargetPullRequests,
27
+ sourcePullNumber: commit.pullNumber,
28
+ existingTargetPullRequests: commit.existingTargetPullRequests,
77
29
  expectedTargetBranches,
78
30
  remainingTargetBranches,
79
31
  };
80
- }).filter((res) => {
32
+ })
33
+ .filter((res) => {
81
34
  return res.remainingTargetBranches.length > 0;
82
35
  });
83
36
  }
@@ -5,26 +5,25 @@ const fetchMergedPullRequests_1 = require("./fetchMergedPullRequests");
5
5
  describe('fetchMergedPullRequests', () => {
6
6
  let devAccessToken;
7
7
  beforeAll(async () => {
8
- devAccessToken = await getDevAccessToken_1.getDevAccessToken();
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
9
  });
10
10
  describe('fetchMergedPullRequests', () => {
11
11
  it('returns the unbackported PRs', async () => {
12
- const options = {
12
+ const res = await (0, fetchMergedPullRequests_1.fetchMergedPullRequests)({
13
13
  repoOwner: 'backport-org',
14
14
  repoName: 'backport-e2e',
15
+ sourceBranch: 'master',
15
16
  accessToken: devAccessToken,
16
- githubApiBaseUrlV4: 'https://api.github.com/graphql',
17
17
  branchLabelMapping: {
18
18
  '^v8.0.0$': 'master',
19
19
  '^v7.9.0$': '7.x',
20
20
  '^v(\\d+).(\\d+).\\d+$': '$1.$2',
21
21
  },
22
- };
23
- const dateRange = {
24
- since: new Date('2020-01-01').toISOString(),
25
- until: new Date('2020-09-01').toISOString(),
26
- };
27
- const res = await fetchMergedPullRequests_1.fetchMergedPullRequests(options, dateRange);
22
+ dateRange: {
23
+ since: new Date('2020-01-01').toISOString(),
24
+ until: new Date('2020-09-01').toISOString(),
25
+ },
26
+ });
28
27
  expect(res).toMatchInlineSnapshot(`
29
28
  Array [
30
29
  Object {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchPullRequestAutoMergeMethod = void 0;
4
4
  const apiRequestV4_1 = require("./apiRequestV4");
5
5
  async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
6
- var _a, _b;
7
6
  const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
8
7
  const query = /* GraphQL */ `
9
8
  query PullRequestAutoMergeMethod(
@@ -21,7 +20,7 @@ async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
21
20
  }
22
21
  }
23
22
  `;
24
- const res = await apiRequestV4_1.apiRequestV4({
23
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
25
24
  githubApiBaseUrlV4,
26
25
  accessToken,
27
26
  query,
@@ -31,6 +30,6 @@ async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
31
30
  pullNumber,
32
31
  },
33
32
  });
34
- return (_b = (_a = res.repository.pullRequest) === null || _a === void 0 ? void 0 : _a.autoMergeRequest) === null || _b === void 0 ? void 0 : _b.mergeMethod;
33
+ return res.repository.pullRequest?.autoMergeRequest?.mergeMethod;
35
34
  }
36
35
  exports.fetchPullRequestAutoMergeMethod = fetchPullRequestAutoMergeMethod;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fetchPullRequestBySearchQuery = 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");
@@ -18,20 +18,20 @@ async function fetchPullRequestBySearchQuery(options) {
18
18
  search(query: $query, type: ISSUE, first: $maxNumber) {
19
19
  nodes {
20
20
  ... on PullRequest {
21
- ...${getExistingTargetPullRequests_1.pullRequestFragmentName}
21
+ ...${getExistingTargetPullRequests_1.pullRequestFragment.name}
22
22
  }
23
23
  }
24
24
  }
25
25
  }
26
26
 
27
- ${getExistingTargetPullRequests_1.pullRequestFragment}
27
+ ${getExistingTargetPullRequests_1.pullRequestFragment.source}
28
28
  `;
29
29
  const authorFilter = all ? '' : `author:${author}`;
30
30
  const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName} ${authorFilter} ${prFilter} base:${sourceBranch}`;
31
- const spinner = ora_1.default('Loading pull requests...').start();
31
+ const spinner = (0, ora_1.default)('Loading pull requests...').start();
32
32
  let res;
33
33
  try {
34
- res = await apiRequestV4_1.apiRequestV4({
34
+ res = await (0, apiRequestV4_1.apiRequestV4)({
35
35
  githubApiBaseUrlV4,
36
36
  accessToken,
37
37
  query,
@@ -52,22 +52,24 @@ async function fetchPullRequestBySearchQuery(options) {
52
52
  if (pullRequestNode.mergeCommit == null) {
53
53
  throw new Error('Pull Request is not merged');
54
54
  }
55
+ const committedDate = pullRequestNode.mergeCommit.committedDate;
55
56
  const sha = pullRequestNode.mergeCommit.oid;
56
57
  const pullNumber = pullRequestNode.number;
57
58
  const commitMessage = pullRequestNode.mergeCommit.message;
58
- const formattedMessage = commitFormatters_1.getFormattedCommitMessage({
59
+ const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
59
60
  message: commitMessage,
60
61
  sha,
61
62
  pullNumber,
62
63
  });
63
- const existingTargetPullRequests = getExistingTargetPullRequests_1.getExistingTargetPullRequests(pullRequestNode);
64
- const targetBranchesFromLabels = getTargetBranchesFromLabels_1.getTargetBranchesFromLabels({
64
+ const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
65
+ const targetBranchesFromLabels = (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
65
66
  sourceBranch: pullRequestNode.baseRefName,
66
67
  existingTargetPullRequests,
67
68
  branchLabelMapping: options.branchLabelMapping,
68
- labels: getExistingTargetPullRequests_1.getPullRequestLabels(pullRequestNode),
69
+ labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
69
70
  });
70
71
  const choice = {
72
+ committedDate,
71
73
  sourceBranch,
72
74
  targetBranchesFromLabels,
73
75
  sha,
@@ -79,7 +81,7 @@ async function fetchPullRequestBySearchQuery(options) {
79
81
  return choice;
80
82
  });
81
83
  // terminate if not commits were found
82
- if (lodash_isempty_1.default(commits)) {
84
+ if ((0, lodash_1.isEmpty)(commits)) {
83
85
  const errorText = options.all
84
86
  ? `There are no pull requests matching the filter "${prFilter}"`
85
87
  : `There are no commits by "${options.author}" matching the filter "${prFilter}". Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`;
@@ -5,7 +5,7 @@ const fetchPullRequestBySearchQuery_1 = require("./fetchPullRequestBySearchQuery
5
5
  describe('fetchPullRequestBySearchQuery', () => {
6
6
  let devAccessToken;
7
7
  beforeAll(async () => {
8
- devAccessToken = await getDevAccessToken_1.getDevAccessToken();
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
9
  });
10
10
  describe('when filter does not match any PRs', () => {
11
11
  it('throws an error', async () => {
@@ -20,7 +20,7 @@ describe('fetchPullRequestBySearchQuery', () => {
20
20
  repoOwner: 'backport-org',
21
21
  sourceBranch: 'master',
22
22
  };
23
- await expect(fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery(options)).rejects.toThrowError('There are no commits by "sqren" matching the filter "label:non-existing". Try with `--all` for commits by all users or `--author=<username>` for commits from a specific user');
23
+ await expect((0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).rejects.toThrowError('There are no commits by "sqren" matching the filter "label:non-existing". Try with `--all` for commits by all users or `--author=<username>` for commits from a specific user');
24
24
  });
25
25
  });
26
26
  describe('when filter matches PRs', () => {
@@ -36,7 +36,7 @@ describe('fetchPullRequestBySearchQuery', () => {
36
36
  repoOwner: 'backport-org',
37
37
  sourceBranch: 'master',
38
38
  };
39
- expect(await fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery(options)).toEqual([
39
+ expect(await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).toEqual([
40
40
  {
41
41
  existingTargetPullRequests: [
42
42
  { branch: '7.8', state: 'OPEN', number: 10 },
@@ -11,12 +11,12 @@ describe('fetchPullRequestBySearchQuery', () => {
11
11
  let res;
12
12
  let mockCalls;
13
13
  beforeEach(async () => {
14
- mockCalls = nockHelpers_1.mockGqlRequest({
14
+ mockCalls = (0, nockHelpers_1.mockGqlRequest)({
15
15
  name: 'PullRequestBySearchQuery',
16
16
  statusCode: 200,
17
17
  body: { data: fetchPullRequestBySearchQueryMock_1.fetchPullRequestBySearchQueryMock },
18
18
  });
19
- res = await fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery({
19
+ res = await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)({
20
20
  accessToken: 'myAccessToken',
21
21
  all: false,
22
22
  author: 'sqren',