backport 5.6.5 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/README.md +166 -41
  2. package/dist/entrypoint.cli.js +3 -1
  3. package/dist/entrypoint.module.d.ts +18 -5
  4. package/dist/entrypoint.module.js +42 -12
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +34 -0
  7. package/dist/ink.d.ts +1 -0
  8. package/dist/ink.js +49 -0
  9. package/dist/main.d.ts +11 -6
  10. package/dist/main.js +40 -25
  11. package/dist/options/ConfigOptions.d.ts +28 -12
  12. package/dist/options/cliArgs.d.ts +36 -35
  13. package/dist/options/cliArgs.js +91 -52
  14. package/dist/options/cliArgs.test.js +41 -42
  15. package/dist/options/config/config.d.ts +34 -57
  16. package/dist/options/config/config.js +5 -39
  17. package/dist/options/config/config.test.js +11 -25
  18. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  19. package/dist/options/config/getOptionsFromGit.js +1 -3
  20. package/dist/options/config/globalConfig.d.ts +2 -49
  21. package/dist/options/config/globalConfig.js +9 -12
  22. package/dist/options/config/globalConfig.test.js +7 -5
  23. package/dist/options/config/projectConfig.d.ts +2 -49
  24. package/dist/options/config/projectConfig.js +2 -2
  25. package/dist/options/config/projectConfig.test.js +53 -16
  26. package/dist/options/config/readConfigFile.d.ts +43 -39
  27. package/dist/options/config/readConfigFile.js +30 -4
  28. package/dist/options/options.d.ts +57 -31
  29. package/dist/options/options.js +102 -10
  30. package/dist/options/options.test.js +263 -61
  31. package/dist/options/parseRequiredOptions.d.ts +19 -14
  32. package/dist/options/parseRequiredOptions.js +9 -15
  33. package/dist/options/parseRequiredOptions.test.js +30 -26
  34. package/dist/runSequentially.d.ts +20 -0
  35. package/dist/runSequentially.js +41 -0
  36. package/dist/runSequentially.test.d.ts +1 -0
  37. package/dist/runSequentially.test.js +196 -0
  38. package/dist/runWithOptions.js +7 -14
  39. package/dist/runWithOptions.test.js +140 -17
  40. package/dist/scripts/generate-gql.d.ts +1 -0
  41. package/dist/scripts/generate-gql.js +15 -0
  42. package/dist/scripts/postinstall.js +4 -4
  43. package/dist/scripts/postinstall.test.js +9 -2
  44. package/dist/scripts/runPostinstall.js +1 -1
  45. package/dist/services/HandledError.d.ts +11 -1
  46. package/dist/services/HandledError.js +2 -1
  47. package/dist/services/child-process-promisified.d.ts +1 -1
  48. package/dist/services/child-process-promisified.js +1 -1
  49. package/dist/services/env.js +5 -5
  50. package/dist/services/env.test.js +11 -4
  51. package/dist/services/fs-promisified.js +4 -4
  52. package/dist/services/getExpectedTarget.d.ts +9 -0
  53. package/dist/services/getExpectedTarget.js +77 -0
  54. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  55. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  56. package/dist/services/git.d.ts +20 -6
  57. package/dist/services/git.integration.test.d.ts +1 -0
  58. package/dist/services/git.integration.test.js +168 -0
  59. package/dist/services/git.js +93 -67
  60. package/dist/services/git.test.js +68 -68
  61. package/dist/services/github/commitFormatters.d.ts +3 -7
  62. package/dist/services/github/commitFormatters.js +10 -19
  63. package/dist/services/github/commitFormatters.test.js +2 -24
  64. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  66. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  67. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  68. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  69. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  70. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  71. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  72. package/dist/services/github/v3/createPullRequest.js +31 -29
  73. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  74. package/dist/services/github/v3/createPullRequest.test.js +110 -0
  75. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  76. package/dist/services/github/v3/createStatusComment.js +97 -0
  77. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  78. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  79. package/dist/services/github/v4/FetchPullRequestId.d.ts +9 -0
  80. package/dist/services/github/v4/FetchPullRequestId.js +32 -0
  81. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  82. package/dist/services/github/v4/apiRequestV4.js +8 -10
  83. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  84. package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +1 -8
  85. package/dist/services/github/v4/disablePullRequestAutoMerge.js +6 -32
  86. package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +1 -8
  87. package/dist/services/github/v4/enablePullRequestAutoMerge.js +31 -40
  88. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  89. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  90. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  91. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  92. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  93. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  94. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  95. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  96. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  97. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  110. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  113. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  114. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  115. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  119. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  120. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  121. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  122. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  123. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  124. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  125. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  126. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  127. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  128. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  129. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  130. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  131. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  132. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  133. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  134. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  135. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  136. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  137. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
  138. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
  139. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  140. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  141. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  142. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  143. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  144. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
  145. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  146. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  147. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  148. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -9
  149. package/dist/services/github/v4/getOptionsFromGithub/index.js +59 -19
  150. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +119 -32
  151. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
  152. package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -15
  153. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  154. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  155. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  156. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  157. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  158. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  159. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  160. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  161. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  162. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  163. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  164. package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +1 -1
  165. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  166. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  167. package/dist/services/logger.d.ts +3 -3
  168. package/dist/services/logger.js +16 -15
  169. package/dist/services/prompt.test.d.ts +1 -0
  170. package/dist/services/prompt.test.js +87 -0
  171. package/dist/services/prompts.d.ts +10 -4
  172. package/dist/services/prompts.js +85 -22
  173. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  174. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  175. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  176. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +413 -0
  177. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  178. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  179. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  180. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  181. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  182. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  183. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  184. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  185. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  186. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  187. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  188. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  189. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  190. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  191. package/dist/services/sourceCommit.d.ts +78 -0
  192. package/dist/services/sourceCommit.js +86 -0
  193. package/dist/services/sourceCommit.test.d.ts +1 -0
  194. package/dist/services/sourceCommit.test.js +280 -0
  195. package/dist/test/inquirer.private.test.js +64 -49
  196. package/dist/test/integration/createSpies.js +6 -6
  197. package/dist/test/integration/envConstants.js +5 -6
  198. package/dist/test/integration/helpers.js +1 -1
  199. package/dist/test/integration/integration.private.test.d.ts +1 -0
  200. package/dist/test/integration/integration.private.test.js +327 -0
  201. package/dist/test/integration/integration.test.js +28 -29
  202. package/dist/test/mockConfigFiles.d.ts +5 -0
  203. package/dist/test/mockConfigFiles.js +37 -0
  204. package/dist/test/nockHelpers.d.ts +1 -1
  205. package/dist/test/nockHelpers.js +7 -11
  206. package/dist/test/private/getDevAccessToken.js +1 -1
  207. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  208. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  209. package/dist/types/Commit.d.ts +85 -0
  210. package/dist/types/Commit.js +139 -0
  211. package/dist/types/commitNode.d.ts +89 -0
  212. package/dist/types/commitNode.js +139 -0
  213. package/dist/types/commitNode.test.d.ts +1 -0
  214. package/dist/types/commitNode.test.js +255 -0
  215. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  216. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  217. package/dist/ui/cherrypickAndCreatePullRequest.test.js +346 -76
  218. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
  219. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
  220. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  221. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  222. package/dist/ui/getCommits.d.ts +1 -1
  223. package/dist/ui/getCommits.js +55 -25
  224. package/dist/ui/getTargetBranches.d.ts +3 -2
  225. package/dist/ui/getTargetBranches.js +33 -18
  226. package/dist/ui/getTargetBranches.test.js +75 -99
  227. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  228. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  229. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  230. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  231. package/dist/ui/maybeSetupRepo.js +11 -10
  232. package/dist/ui/maybeSetupRepo.test.js +54 -4
  233. package/dist/utils/excludeUndefined.d.ts +6 -0
  234. package/dist/utils/excludeUndefined.js +7 -0
  235. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  236. package/dist/utils/excludeUndefined.test.js +24 -0
  237. package/package.json +37 -51
  238. package/yarn.lock +2414 -2993
@@ -22,13 +22,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const os_1 = __importDefault(require("os"));
25
26
  const inquirer_1 = __importDefault(require("inquirer"));
27
+ const lodash_1 = require("lodash");
26
28
  const nock_1 = __importDefault(require("nock"));
27
29
  const runWithOptions_1 = require("./runWithOptions");
28
30
  const childProcess = __importStar(require("./services/child-process-promisified"));
29
31
  const fs = __importStar(require("./services/fs-promisified"));
30
32
  const commitsByAuthorMock_1 = require("./services/github/v4/mocks/commitsByAuthorMock");
31
33
  const nockHelpers_1 = require("./test/nockHelpers");
34
+ jest.mock('./services/child-process-promisified', () => {
35
+ return {
36
+ exec: jest.fn(async (cmd) => {
37
+ throw new Error(`Mock required for exec with cmd: "${cmd}"`);
38
+ }),
39
+ execAsCallback: jest.fn((...args) => {
40
+ (0, lodash_1.last)(args)();
41
+ return {
42
+ stderr: {
43
+ on: () => null,
44
+ },
45
+ };
46
+ }),
47
+ };
48
+ });
32
49
  describe('runWithOptions', () => {
33
50
  let rpcExecMock;
34
51
  let rpcExecOriginalMock;
@@ -42,6 +59,7 @@ describe('runWithOptions', () => {
42
59
  nock_1.default.cleanAll();
43
60
  });
44
61
  beforeEach(async () => {
62
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
45
63
  const options = {
46
64
  accessToken: 'myAccessToken',
47
65
  all: false,
@@ -49,9 +67,13 @@ describe('runWithOptions', () => {
49
67
  author: 'sqren',
50
68
  autoAssign: false,
51
69
  autoFixConflicts: undefined,
70
+ autoMerge: false,
71
+ autoMergeMethod: 'merge',
52
72
  branchLabelMapping: undefined,
53
73
  ci: false,
54
- dryRun: false,
74
+ cherrypickRef: true,
75
+ commitPaths: [],
76
+ details: false,
55
77
  editor: 'code',
56
78
  forceLocalConfig: undefined,
57
79
  fork: true,
@@ -63,19 +85,18 @@ describe('runWithOptions', () => {
63
85
  multipleBranches: false,
64
86
  multipleCommits: false,
65
87
  noVerify: true,
66
- path: undefined,
67
88
  prDescription: 'myPrDescription',
89
+ prFilter: undefined,
68
90
  prTitle: 'myPrTitle {targetBranch} {commitMessages}',
69
91
  pullNumber: undefined,
70
- upstream: 'elastic/kibana',
71
92
  repoName: 'kibana',
72
93
  repoOwner: 'elastic',
73
94
  resetAuthor: false,
74
95
  sha: undefined,
75
- sourceBranch: 'mySourceBranch',
96
+ sourceBranch: 'my-source-branch-from-options',
76
97
  sourcePRLabels: [],
77
- prFilter: undefined,
78
98
  targetBranches: [],
99
+ upstream: 'elastic/kibana',
79
100
  targetBranchChoices: [
80
101
  { name: '6.x' },
81
102
  { name: '6.0' },
@@ -100,21 +121,21 @@ describe('runWithOptions', () => {
100
121
  .mockImplementationOnce((async (args) => {
101
122
  return { promptResult: args[0].choices[0].name };
102
123
  }));
103
- authorIdCalls = nockHelpers_1.mockGqlRequest({
124
+ authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
104
125
  name: 'AuthorId',
105
126
  statusCode: 200,
106
127
  body: { data: { user: { id: 'sqren_author_id' } } },
107
128
  });
108
- commitsByAuthorCalls = nockHelpers_1.mockGqlRequest({
129
+ commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
109
130
  name: 'CommitsByAuthor',
110
131
  statusCode: 200,
111
- body: { data: commitsByAuthorMock_1.commitsWithPullRequestsMock },
132
+ body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
112
133
  });
113
- const scope = nock_1.default('https://api.github.com')
134
+ const scope = (0, nock_1.default)('https://api.github.com')
114
135
  .post('/repos/elastic/kibana/pulls')
115
136
  .reply(200, { html_url: 'pull request url', number: 1337 });
116
- createPullRequestCalls = nockHelpers_1.getNockCallsForScope(scope);
117
- res = await runWithOptions_1.runWithOptions(options);
137
+ createPullRequestCalls = (0, nockHelpers_1.getNockCallsForScope)(scope);
138
+ res = await (0, runWithOptions_1.runWithOptions)(options);
118
139
  scope.done();
119
140
  });
120
141
  it('returns pull request', () => {
@@ -132,7 +153,7 @@ describe('runWithOptions', () => {
132
153
  base: '6.x',
133
154
  body: 'Backports the following commits to 6.x:\n - Add 👻 (2e63475c)\n\nmyPrDescription',
134
155
  head: 'sqren:backport/6.x/commit-2e63475c',
135
- title: 'myPrTitle 6.x Add 👻 (2e63475c)',
156
+ title: 'myPrTitle 6.x Add 👻',
136
157
  },
137
158
  ]);
138
159
  });
@@ -158,24 +179,126 @@ describe('runWithOptions', () => {
158
179
  expect(commitsByAuthorCalls.map((body) => body.variables)).toEqual([
159
180
  {
160
181
  authorId: 'sqren_author_id',
161
- historyPath: null,
162
182
  maxNumber: 10,
183
+ commitPath: null,
163
184
  repoName: 'kibana',
164
185
  repoOwner: 'elastic',
165
- sourceBranch: 'mySourceBranch',
186
+ sourceBranch: 'my-source-branch-from-options',
166
187
  },
167
188
  ]);
168
189
  });
169
190
  it('prompt calls should match snapshot', () => {
170
191
  expect(inquirer_1.default.prompt).toHaveBeenCalledTimes(2);
171
- expect(inquirerPromptMock.mock.calls).toMatchSnapshot();
192
+ expect(
193
+ // @ts-expect-error
194
+ inquirerPromptMock.mock.calls[0][0][0].choices.map(({ name, short }) => ({
195
+ name,
196
+ short,
197
+ }))).toMatchInlineSnapshot(`
198
+ Array [
199
+ Object {
200
+ "name": "1. Add 👻 ",
201
+ "short": "2e63475c",
202
+ },
203
+ Object {
204
+ "name": "2. Add witch (#85) ",
205
+ "short": "#85 (f3b618b9)",
206
+ },
207
+ Object {
208
+ "name": "3. Add SF mention (#80) 6.3",
209
+ "short": "#80 (79cf1845)",
210
+ },
211
+ Object {
212
+ "name": "4. Add backport config ",
213
+ "short": "3827bbba",
214
+ },
215
+ Object {
216
+ "name": "5. Initial commit ",
217
+ "short": "5ea0da55",
218
+ },
219
+ ]
220
+ `);
172
221
  });
173
222
  it('exec should be called with correct args', () => {
174
223
  expect(rpcExecMock).toHaveBeenCalledTimes(10);
175
- expect(rpcExecMock.mock.calls).toMatchSnapshot();
224
+ expect(rpcExecMock.mock.calls).toMatchInlineSnapshot(`
225
+ Array [
226
+ Array [
227
+ "git remote rm origin",
228
+ Object {
229
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
230
+ },
231
+ ],
232
+ Array [
233
+ "git remote rm sqren",
234
+ Object {
235
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
236
+ },
237
+ ],
238
+ Array [
239
+ "git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git",
240
+ Object {
241
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
242
+ },
243
+ ],
244
+ Array [
245
+ "git remote rm elastic",
246
+ Object {
247
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
248
+ },
249
+ ],
250
+ Array [
251
+ "git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git",
252
+ Object {
253
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
254
+ },
255
+ ],
256
+ Array [
257
+ "git reset --hard && git clean -d --force && git fetch elastic 6.x && git checkout -B backport/6.x/commit-2e63475c elastic/6.x --no-track",
258
+ Object {
259
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
260
+ },
261
+ ],
262
+ Array [
263
+ "git fetch elastic my-source-branch-from-options:my-source-branch-from-options --force",
264
+ Object {
265
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
266
+ },
267
+ ],
268
+ Array [
269
+ "git cherry-pick 2e63475c483f7844b0f2833bc57fdee32095bacb",
270
+ Object {
271
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
272
+ },
273
+ ],
274
+ Array [
275
+ "git push sqren backport/6.x/commit-2e63475c:backport/6.x/commit-2e63475c --force",
276
+ Object {
277
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
278
+ },
279
+ ],
280
+ Array [
281
+ "git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/6.x/commit-2e63475c",
282
+ Object {
283
+ "cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
284
+ },
285
+ ],
286
+ ]
287
+ `);
176
288
  });
177
289
  it('git clone should be called with correct args', () => {
178
290
  expect(rpcExecOriginalMock).toHaveBeenCalledTimes(1);
179
- expect(rpcExecOriginalMock.mock.calls).toMatchSnapshot();
291
+ expect(rpcExecOriginalMock.mock.calls).toMatchInlineSnapshot(`
292
+ Array [
293
+ Array [
294
+ "git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git --progress",
295
+ Object {
296
+ "cwd": "/myHomeDir/.backport/repositories/elastic",
297
+ "maxBuffer": 104857600,
298
+ },
299
+ [Function],
300
+ ],
301
+ ]
302
+ `);
180
303
  });
181
304
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
4
+ const getDevAccessToken_1 = require("../test/private/getDevAccessToken");
5
+ async function init() {
6
+ const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
7
+ const res = (0, fetchCommitBySha_1.fetchCommitBySha)({
8
+ accessToken,
9
+ githubApiBaseUrlV4: 'https://api.github.com/graphql',
10
+ repoName: 'backport-org',
11
+ repoOwner: 'backport-e2e',
12
+ sha: 'b484e161b705b39dbbfc5005e67ca24d05b23c37',
13
+ sourceBranch: 'main',
14
+ });
15
+ }
@@ -6,14 +6,14 @@ const env_1 = require("../services/env");
6
6
  const logger_1 = require("../services/logger");
7
7
  async function postinstall() {
8
8
  try {
9
- const didCreate = await globalConfig_1.createGlobalConfigAndFolderIfNotExist();
9
+ const didCreate = await (0, globalConfig_1.createGlobalConfigAndFolderIfNotExist)();
10
10
  if (didCreate) {
11
- const GLOBAL_CONFIG_PATH = env_1.getGlobalConfigPath();
12
- logger_1.consoleLog(`Global config successfully created in ${GLOBAL_CONFIG_PATH}`);
11
+ const GLOBAL_CONFIG_PATH = (0, env_1.getGlobalConfigPath)();
12
+ (0, logger_1.consoleLog)(`Global config successfully created in ${GLOBAL_CONFIG_PATH}`);
13
13
  }
14
14
  }
15
15
  catch (e) {
16
- logger_1.consoleLog(`Global config could not be created:\n${e.stack}`);
16
+ (0, logger_1.consoleLog)(`Global config could not be created:\n${e.stack}`);
17
17
  }
18
18
  }
19
19
  exports.postinstall = postinstall;
@@ -18,19 +18,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
21
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const os_1 = __importDefault(require("os"));
22
26
  const globalConfig = __importStar(require("../options/config/globalConfig"));
23
27
  const logger = __importStar(require("../services/logger"));
24
28
  const postinstall_1 = require("./postinstall");
25
29
  describe('postinstall', () => {
26
30
  beforeEach(() => {
31
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
32
+ });
33
+ afterEach(() => {
27
34
  jest.clearAllMocks();
28
35
  });
29
36
  it("should create global config if it doesn't exist", async () => {
30
37
  const createGlobalConfigAndFolderIfNotExistSpy = jest
31
38
  .spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
32
39
  .mockResolvedValueOnce(true);
33
- await postinstall_1.postinstall();
40
+ await (0, postinstall_1.postinstall)();
34
41
  expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
35
42
  expect(logger.consoleLog).toBeCalledWith('Global config successfully created in /myHomeDir/.backport/config.json');
36
43
  });
@@ -39,7 +46,7 @@ describe('postinstall', () => {
39
46
  const createGlobalConfigAndFolderIfNotExistSpy = jest
40
47
  .spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist')
41
48
  .mockResolvedValueOnce(false);
42
- await postinstall_1.postinstall();
49
+ await (0, postinstall_1.postinstall)();
43
50
  expect(createGlobalConfigAndFolderIfNotExistSpy).toBeCalledTimes(1);
44
51
  expect(consoleSpy).toBeCalledTimes(0);
45
52
  });
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const postinstall_1 = require("./postinstall");
4
- postinstall_1.postinstall();
4
+ (0, postinstall_1.postinstall)();
@@ -1,3 +1,13 @@
1
+ import { Commit } from './sourceCommit/parseSourceCommit';
2
+ declare type Meta = {
3
+ type: 'commitsWithoutBackports';
4
+ commitsWithoutBackports: {
5
+ formatted: string;
6
+ commit: Commit;
7
+ }[];
8
+ };
1
9
  export declare class HandledError extends Error {
2
- constructor(message: string);
10
+ meta?: Meta;
11
+ constructor(message: string, meta?: Meta);
3
12
  }
13
+ export {};
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandledError = void 0;
4
4
  class HandledError extends Error {
5
- constructor(message) {
5
+ constructor(message, meta) {
6
6
  super(message);
7
7
  Error.captureStackTrace(this, HandledError);
8
8
  this.name = 'HandledError';
9
+ this.meta = meta;
9
10
  }
10
11
  }
11
12
  exports.HandledError = HandledError;
@@ -4,4 +4,4 @@ export declare function exec(cmd: string, options: child_process.ExecOptions): P
4
4
  stdout: string;
5
5
  stderr: string;
6
6
  }>;
7
- export declare const execAsCallback: (command: string, options: (import("fs").BaseEncodingOptions & child_process.ExecOptions) | null | undefined, callback?: ((error: child_process.ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined) => child_process.ChildProcess;
7
+ export declare const execAsCallback: (command: string, options: (import("fs").ObjectEncodingOptions & child_process.ExecOptions) | null | undefined, callback?: ((error: child_process.ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined) => child_process.ChildProcess;
@@ -8,7 +8,7 @@ const child_process_1 = __importDefault(require("child_process"));
8
8
  const util_1 = require("util");
9
9
  const logger_1 = require("./logger");
10
10
  async function exec(cmd, options) {
11
- const execPromisified = util_1.promisify(child_process_1.default.exec);
11
+ const execPromisified = (0, util_1.promisify)(child_process_1.default.exec);
12
12
  try {
13
13
  const res = await execPromisified(cmd, {
14
14
  maxBuffer: 100 * 1024 * 1024,
@@ -7,22 +7,22 @@ exports.getRepoPath = exports.getRepoOwnerPath = exports.getReposPath = exports.
7
7
  const os_1 = require("os");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  function getLogfilePath() {
10
- return path_1.default.join(os_1.homedir(), '.backport', 'backport.log');
10
+ return path_1.default.join((0, os_1.homedir)(), '.backport', 'backport.log');
11
11
  }
12
12
  exports.getLogfilePath = getLogfilePath;
13
13
  function getGlobalConfigPath() {
14
- return path_1.default.join(os_1.homedir(), '.backport', 'config.json');
14
+ return path_1.default.join((0, os_1.homedir)(), '.backport', 'config.json');
15
15
  }
16
16
  exports.getGlobalConfigPath = getGlobalConfigPath;
17
17
  function getReposPath() {
18
- return path_1.default.join(os_1.homedir(), '.backport', 'repositories');
18
+ return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories');
19
19
  }
20
20
  exports.getReposPath = getReposPath;
21
21
  function getRepoOwnerPath({ repoOwner }) {
22
- return path_1.default.join(os_1.homedir(), '.backport', 'repositories', repoOwner);
22
+ return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories', repoOwner);
23
23
  }
24
24
  exports.getRepoOwnerPath = getRepoOwnerPath;
25
25
  function getRepoPath({ repoOwner, repoName }) {
26
- return path_1.default.join(os_1.homedir(), '.backport', 'repositories', repoOwner, repoName);
26
+ return path_1.default.join((0, os_1.homedir)(), '.backport', 'repositories', repoOwner, repoName);
27
27
  }
28
28
  exports.getRepoPath = getRepoPath;
@@ -1,18 +1,25 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const os_1 = __importDefault(require("os"));
3
7
  const env_1 = require("../services/env");
4
8
  describe('env', () => {
9
+ beforeEach(() => {
10
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
11
+ });
5
12
  test('getGlobalConfigPath', () => {
6
- expect(env_1.getGlobalConfigPath()).toBe('/myHomeDir/.backport/config.json');
13
+ expect((0, env_1.getGlobalConfigPath)()).toBe('/myHomeDir/.backport/config.json');
7
14
  });
8
15
  test('getReposPath', () => {
9
- expect(env_1.getReposPath()).toBe('/myHomeDir/.backport/repositories');
16
+ expect((0, env_1.getReposPath)()).toBe('/myHomeDir/.backport/repositories');
10
17
  });
11
18
  test('getRepoOwnerPath', () => {
12
- expect(env_1.getRepoOwnerPath({ repoOwner: 'elastic' })).toBe('/myHomeDir/.backport/repositories/elastic');
19
+ expect((0, env_1.getRepoOwnerPath)({ repoOwner: 'elastic' })).toBe('/myHomeDir/.backport/repositories/elastic');
13
20
  });
14
21
  test('getRepoPath', () => {
15
- expect(env_1.getRepoPath({
22
+ expect((0, env_1.getRepoPath)({
16
23
  repoOwner: 'elastic',
17
24
  repoName: 'kibana',
18
25
  })).toBe('/myHomeDir/.backport/repositories/elastic/kibana');
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.chmod = exports.stat = exports.readFile = exports.writeFile = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const util_1 = require("util");
9
- exports.writeFile = util_1.promisify(fs_1.default.writeFile);
10
- exports.readFile = util_1.promisify(fs_1.default.readFile);
11
- exports.stat = util_1.promisify(fs_1.default.stat);
12
- exports.chmod = util_1.promisify(fs_1.default.chmod);
9
+ exports.writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
10
+ exports.readFile = (0, util_1.promisify)(fs_1.default.readFile);
11
+ exports.stat = (0, util_1.promisify)(fs_1.default.stat);
12
+ exports.chmod = (0, util_1.promisify)(fs_1.default.chmod);
@@ -0,0 +1,9 @@
1
+ import { ValidConfigOptions } from '../options/options';
2
+ import { SourceCommitWithTargetPullRequest } from './sourceCommit';
3
+ export declare type ExpectedTargetPullRequest = {
4
+ url?: string;
5
+ number?: number;
6
+ branch: string;
7
+ state: 'OPEN' | 'CLOSED' | 'MERGED' | 'MISSING';
8
+ };
9
+ export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExpectedTargetPullRequests = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const getTargetBranchesFromLabels_1 = require("../services/github/v4/getTargetBranchesFromLabels");
6
+ const filterEmpty_1 = require("../utils/filterEmpty");
7
+ const commitFormatters_1 = require("./github/commitFormatters");
8
+ function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
9
+ const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
10
+ // if there is no source pull request the commit was pushed directly to the source branch
11
+ // in that case there will be no labels, and thus not possible to deduce the expected target branches
12
+ if (!sourcePullRequest) {
13
+ return [];
14
+ }
15
+ const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
16
+ // if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
17
+ if (!branchLabelMapping) {
18
+ return existingTargetPullRequests;
19
+ }
20
+ const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
21
+ return [...existingTargetPullRequests, ...missingTargetPullRequests];
22
+ }
23
+ exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
24
+ function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
25
+ const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
26
+ return sourcePullRequest.timelineItems.edges
27
+ .filter(filterEmpty_1.filterNil)
28
+ .filter(filterPullRequests)
29
+ .filter((item) => {
30
+ const { targetPullRequest } = item.node;
31
+ // ignore closed PRs
32
+ if (targetPullRequest.state === 'CLOSED') {
33
+ return false;
34
+ }
35
+ // at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
36
+ const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
37
+ const { targetCommit } = commitEdge.node;
38
+ const matchingRepoName = sourceCommit.repository.name === targetCommit.repository.name;
39
+ const matchingRepoOwner = sourceCommit.repository.owner.login ===
40
+ targetCommit.repository.owner.login;
41
+ const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
42
+ const matchingMessage = targetCommitMessage === sourceCommitMessage;
43
+ return matchingRepoName && matchingRepoOwner && matchingMessage;
44
+ });
45
+ const titleIncludesMessage = targetPullRequest.title.includes(sourceCommitMessage);
46
+ const titleIncludesNumber = targetPullRequest.title.includes(sourcePullRequest.number.toString());
47
+ return didCommitMatch || (titleIncludesMessage && titleIncludesNumber);
48
+ })
49
+ .map((item) => {
50
+ const { targetPullRequest } = item.node;
51
+ return {
52
+ url: targetPullRequest.url,
53
+ number: targetPullRequest.number,
54
+ branch: targetPullRequest.baseRefName,
55
+ state: targetPullRequest.state,
56
+ };
57
+ });
58
+ }
59
+ function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
60
+ const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
61
+ const targetBranchesFromLabels = labels
62
+ .map((label) => (0, getTargetBranchesFromLabels_1.getTargetBranchForLabel)({ branchLabelMapping, label }))
63
+ .filter(filterEmpty_1.filterNil)
64
+ .filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
65
+ const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
66
+ const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
67
+ return expected
68
+ .filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
69
+ .map((branch) => {
70
+ return { branch, state: 'MISSING' };
71
+ });
72
+ }
73
+ // narrow TimelineEdge to TimelinePullRequestEdge
74
+ function filterPullRequests(item) {
75
+ const { targetPullRequest } = item.node;
76
+ return targetPullRequest.__typename === 'PullRequest';
77
+ }
@@ -0,0 +1,9 @@
1
+ import { ValidConfigOptions } from '../options/options';
2
+ import { SourceCommitWithTargetPullRequest } from './sourceCommit';
3
+ export declare type ExpectedTargetPullRequest = {
4
+ url?: string;
5
+ number?: number;
6
+ branch: string;
7
+ state: 'OPEN' | 'CLOSED' | 'MERGED' | 'MISSING';
8
+ };
9
+ export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExpectedTargetPullRequests = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const getTargetBranchesFromLabels_1 = require("../services/github/v4/getTargetBranchesFromLabels");
6
+ const filterEmpty_1 = require("../utils/filterEmpty");
7
+ const commitFormatters_1 = require("./github/commitFormatters");
8
+ function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
9
+ const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
10
+ // if there is no source pull request the commit was pushed directly to the source branch
11
+ // in that case there will be no labels, and thus not possible to deduce the expected target branches
12
+ if (!sourcePullRequest) {
13
+ return [];
14
+ }
15
+ const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
16
+ // if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
17
+ if (!branchLabelMapping) {
18
+ return existingTargetPullRequests;
19
+ }
20
+ const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
21
+ return [...existingTargetPullRequests, ...missingTargetPullRequests];
22
+ }
23
+ exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
24
+ function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
25
+ const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
26
+ return sourcePullRequest.timelineItems.edges
27
+ .filter(filterEmpty_1.filterNil)
28
+ .filter(filterPullRequests)
29
+ .filter((item) => {
30
+ const { targetPullRequest } = item.node;
31
+ // ignore closed PRs
32
+ if (targetPullRequest.state === 'CLOSED') {
33
+ return false;
34
+ }
35
+ // at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
36
+ const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
37
+ const { targetCommit } = commitEdge.node;
38
+ const matchingRepoName = sourceCommit.repository.name === targetCommit.repository.name;
39
+ const matchingRepoOwner = sourceCommit.repository.owner.login ===
40
+ targetCommit.repository.owner.login;
41
+ const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
42
+ const matchingMessage = targetCommitMessage === sourceCommitMessage;
43
+ return matchingRepoName && matchingRepoOwner && matchingMessage;
44
+ });
45
+ const titleIncludesMessage = targetPullRequest.title.includes(sourceCommitMessage);
46
+ const titleIncludesNumber = targetPullRequest.title.includes(sourcePullRequest.number.toString());
47
+ return didCommitMatch || (titleIncludesMessage && titleIncludesNumber);
48
+ })
49
+ .map((item) => {
50
+ const { targetPullRequest } = item.node;
51
+ return {
52
+ url: targetPullRequest.url,
53
+ number: targetPullRequest.number,
54
+ branch: targetPullRequest.baseRefName,
55
+ state: targetPullRequest.state,
56
+ };
57
+ });
58
+ }
59
+ function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
60
+ const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
61
+ const targetBranchesFromLabels = labels
62
+ .map((label) => (0, getTargetBranchesFromLabels_1.getTargetBranchForLabel)({ branchLabelMapping, label }))
63
+ .filter(filterEmpty_1.filterNil)
64
+ .filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
65
+ const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
66
+ const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
67
+ return expected
68
+ .filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
69
+ .map((branch) => {
70
+ return { branch, state: 'MISSING' };
71
+ });
72
+ }
73
+ // narrow TimelineEdge to TimelinePullRequestEdge
74
+ function filterPullRequests(item) {
75
+ const { targetPullRequest } = item.node;
76
+ return targetPullRequest.__typename === 'PullRequest';
77
+ }