backport 6.1.2 → 6.2.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 (166) hide show
  1. package/README.md +39 -37
  2. package/dist/backportRun.d.ts +14 -0
  3. package/dist/backportRun.js +75 -0
  4. package/dist/entrypoint.api.d.ts +22 -0
  5. package/dist/entrypoint.api.js +57 -0
  6. package/dist/entrypoint.api.private.test.d.ts +1 -0
  7. package/dist/entrypoint.api.private.test.js +37 -0
  8. package/dist/entrypoint.module.d.ts +4 -1
  9. package/dist/entrypoint.module.js +10 -4
  10. package/dist/entrypoint.module.private.test.js +4 -1
  11. package/dist/main.js +5 -1
  12. package/dist/options/ConfigOptions.d.ts +2 -0
  13. package/dist/options/cliArgs.d.ts +5 -1
  14. package/dist/options/cliArgs.js +24 -2
  15. package/dist/options/config/config.d.ts +6 -1
  16. package/dist/options/config/config.js +2 -2
  17. package/dist/options/config/config.test.js +1 -1
  18. package/dist/options/config/getProjectConfig.d.ts +0 -0
  19. package/dist/options/config/getProjectConfig.js +1 -0
  20. package/dist/options/config/globalConfig.d.ts +1 -1
  21. package/dist/options/config/globalConfig.js +4 -8
  22. package/dist/options/config/globalConfig.test.js +2 -2
  23. package/dist/options/config/readConfigFile.d.ts +3 -1
  24. package/dist/options/options.d.ts +8 -1
  25. package/dist/options/options.js +9 -2
  26. package/dist/options/options.test.js +7 -3
  27. package/dist/react-components/0-loadOptions.d.ts +6 -0
  28. package/dist/react-components/0-loadOptions.js +45 -0
  29. package/dist/react-components/1-loadCommit.d.ts +8 -0
  30. package/dist/react-components/1-loadCommit.js +88 -0
  31. package/dist/react-components/1a-loadCommit.d.ts +5 -0
  32. package/dist/react-components/1a-loadCommit.js +76 -0
  33. package/dist/react-components/1b-commitChoices.d.ts +5 -0
  34. package/dist/react-components/1b-commitChoices.js +98 -0
  35. package/dist/react-components/2-commitChoices.d.ts +8 -0
  36. package/dist/react-components/2-commitChoices.js +96 -0
  37. package/dist/react-components/2-commitsPrompt.d.ts +8 -0
  38. package/dist/react-components/2-commitsPrompt.js +96 -0
  39. package/dist/react-components/2-targetBranchChoices.d.ts +9 -0
  40. package/dist/react-components/2-targetBranchChoices.js +109 -0
  41. package/dist/react-components/3-cherrypick.d.ts +1 -0
  42. package/dist/react-components/3-cherrypick.js +2 -0
  43. package/dist/react-components/App.d.ts +2 -0
  44. package/dist/react-components/App.js +35 -0
  45. package/dist/react-components/BackportStateContext.d.ts +33 -0
  46. package/dist/react-components/BackportStateContext.js +42 -0
  47. package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +8 -0
  48. package/dist/react-components/CommitPrompt/2-commitsPrompt.js +96 -0
  49. package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +8 -0
  50. package/dist/react-components/CommitPrompt/CommitPrompt.js +96 -0
  51. package/dist/react-components/CommitPrompt/getCommits.d.ts +2 -0
  52. package/dist/react-components/CommitPrompt/getCommits.js +27 -0
  53. package/dist/react-components/CommitPrompt.d.ts +8 -0
  54. package/dist/react-components/CommitPrompt.js +96 -0
  55. package/dist/react-components/CustomMultiSelect.d.ts +13 -0
  56. package/dist/react-components/CustomMultiSelect.js +21 -0
  57. package/dist/react-components/CustomMultiSelectItem.d.ts +5 -0
  58. package/dist/react-components/CustomMultiSelectItem.js +12 -0
  59. package/dist/react-components/CustomSelect.d.ts +14 -0
  60. package/dist/react-components/CustomSelect.js +34 -0
  61. package/dist/react-components/ErrorBoundary.d.ts +15 -0
  62. package/dist/react-components/ErrorBoundary.js +53 -0
  63. package/dist/react-components/MultiSelect.d.ts +7 -0
  64. package/dist/react-components/MultiSelect.js +16 -0
  65. package/dist/react-components/hooks/useAsync.d.ts +12 -0
  66. package/dist/react-components/hooks/useAsync.js +73 -0
  67. package/dist/runSequentially.test.js +10 -7
  68. package/dist/services/HandledError.d.ts +1 -1
  69. package/dist/services/backportRun/backportRun.ci.d.ts +6 -0
  70. package/dist/services/backportRun/backportRun.ci.js +81 -0
  71. package/dist/services/backportRun/backportRun.d.ts +14 -0
  72. package/dist/services/backportRun/backportRun.interactive.d.ts +1 -0
  73. package/dist/services/backportRun/backportRun.interactive.js +4 -0
  74. package/dist/services/backportRun/backportRun.js +14 -0
  75. package/dist/services/backportRun/backportState.d.ts +4 -0
  76. package/dist/services/backportRun/backportState.js +28 -0
  77. package/dist/services/backportRun/getCommits.d.ts +2 -0
  78. package/dist/services/backportRun/getCommits.js +20 -0
  79. package/dist/services/backportRun/runSequentially.d.ts +20 -0
  80. package/dist/services/backportRun/runSequentially.js +41 -0
  81. package/dist/services/backportRun/runSequentially.test.d.ts +1 -0
  82. package/dist/services/backportRun/runSequentially.test.js +199 -0
  83. package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +12 -0
  84. package/dist/services/cherrypickAndCreateTargetPullRequest.js +206 -0
  85. package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  86. package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +403 -0
  87. package/dist/services/env.d.ts +2 -3
  88. package/dist/services/env.js +9 -10
  89. package/dist/services/env.test.js +0 -6
  90. package/dist/services/getCommits.d.ts +2 -0
  91. package/dist/services/getCommits.js +38 -0
  92. package/dist/services/getCommitsWithoutBackports.d.ts +11 -0
  93. package/dist/services/getCommitsWithoutBackports.js +68 -0
  94. package/dist/services/getCommitsWithoutBackports.test.d.ts +1 -0
  95. package/dist/services/getCommitsWithoutBackports.test.js +259 -0
  96. package/dist/services/getTargetBranches.d.ts +5 -0
  97. package/dist/services/getTargetBranches.js +60 -0
  98. package/dist/services/getTargetBranches.test.d.ts +1 -0
  99. package/dist/services/getTargetBranches.test.js +180 -0
  100. package/dist/services/git.d.ts +2 -1
  101. package/dist/services/git.js +5 -3
  102. package/dist/services/github/v3/createPullRequest.js +1 -1
  103. package/dist/services/github/v3/createPullRequest.test.js +3 -3
  104. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  105. package/dist/services/github/v3/createStatusComment.js +40 -15
  106. package/dist/services/github/v3/createStatusComment.test.js +190 -73
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  108. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  110. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  111. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  112. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  114. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  115. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  116. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  118. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  119. package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
  120. package/dist/services/github/v4/fetchProjectConfig.js +3 -3
  121. package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
  122. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  123. package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
  124. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  125. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  126. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
  127. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
  128. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  129. package/dist/services/logger.d.ts +0 -1
  130. package/dist/services/logger.js +3 -3
  131. package/dist/services/maybeSetupRepo.d.ts +2 -0
  132. package/dist/services/maybeSetupRepo.js +33 -0
  133. package/dist/services/maybeSetupRepo.test.d.ts +1 -0
  134. package/dist/services/maybeSetupRepo.test.js +78 -0
  135. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  136. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  137. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  138. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  139. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  140. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  141. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  142. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  143. package/dist/test/backport-e2e.private.test.d.ts +1 -0
  144. package/dist/test/backport-e2e.private.test.js +327 -0
  145. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  146. package/dist/test/handleUnbackportedPullRequests.private.test.js +43 -0
  147. package/dist/test/inquirer.private.test.js +1 -1
  148. package/dist/test/integration/integration.private.test.js +2 -2
  149. package/dist/test/nockHelpers.js +1 -3
  150. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  151. package/dist/todo-delete.d.ts +1 -0
  152. package/dist/todo-delete.js +17 -0
  153. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -3
  154. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
  155. package/dist/ui/getCommits.js +1 -1
  156. package/dist/ui/getCommitsWithoutBackports.js +17 -2
  157. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  158. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  159. package/dist/ui/maybeSetupRepo.js +0 -6
  160. package/dist/ui/maybeSetupRepo.test.js +8 -4
  161. package/dist/utils/redact.d.ts +1 -0
  162. package/dist/utils/redact.js +7 -0
  163. package/dist/utils/sequentially.d.ts +1 -0
  164. package/dist/utils/sequentially.js +10 -0
  165. package/package.json +3 -3
  166. package/yarn.lock +462 -284
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getCommitsWithoutBackports = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
+ const git_1 = require("../services/git");
8
9
  const commitFormatters_1 = require("../services/github/commitFormatters");
9
10
  const fetchCommitsByAuthor_1 = require("../services/github/v4/fetchCommits/fetchCommitsByAuthor");
10
11
  // when the user is facing a git conflict we should help them understand
@@ -20,9 +21,11 @@ conflictingFiles, }) {
20
21
  const commitsInConflictingPaths = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
21
22
  ...options,
22
23
  author: null,
24
+ dateSince: null,
25
+ dateUntil: commit.committedDate,
23
26
  commitPaths: conflictingFiles,
24
27
  });
25
- return commitsInConflictingPaths
28
+ const promises = await Promise.all(commitsInConflictingPaths
26
29
  .filter((c) => {
27
30
  // exclude the commit we are currently trying to backport
28
31
  if (c.sha === commit.sha) {
@@ -41,7 +44,19 @@ conflictingFiles, }) {
41
44
  return hasUnmergedPr;
42
45
  })
43
46
  .slice(0, 10) // limit to max 10 commits
44
- .map((c) => {
47
+ .map(async (c) => {
48
+ const results = await Promise.all(c.expectedTargetPullRequests.map(async (targetPr) => {
49
+ if (!targetPr.mergeCommit) {
50
+ return false;
51
+ }
52
+ return (0, git_1.getIsCommitInBranch)(options, targetPr.mergeCommit.sha);
53
+ }));
54
+ const isCommitInBranch = results.some((inBranch) => inBranch === true);
55
+ return { c, isCommitInBranch };
56
+ }));
57
+ return promises
58
+ .filter(({ isCommitInBranch }) => !isCommitInBranch)
59
+ .map(({ c }) => {
45
60
  // get pull request for the target branch (if it exists)
46
61
  const pendingBackportPr = c.expectedTargetPullRequests.find((pr) => pr.branch === targetBranch && pr.state === 'OPEN');
47
62
  const formatted = pendingBackportPr
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const strip_ansi_1 = __importDefault(require("strip-ansi"));
26
+ const git = __importStar(require("../services/git"));
27
+ const fetchCommitsByAuthorModule = __importStar(require("../services/github/v4/fetchCommits/fetchCommitsByAuthor"));
28
+ const getCommitsWithoutBackports_1 = require("./getCommitsWithoutBackports");
29
+ describe('getCommitsWithoutBackports', () => {
30
+ afterEach(() => {
31
+ jest.restoreAllMocks();
32
+ });
33
+ describe('expectedTargetPullRequests', () => {
34
+ function setupExpectedPullRequests({ expectedTargetPullRequests, }) {
35
+ // simulate 1 unbackported commit
36
+ jest
37
+ .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
38
+ .mockResolvedValueOnce([
39
+ {
40
+ committedDate: '10',
41
+ expectedTargetPullRequests,
42
+ originalMessage: 'First commit (#1)',
43
+ sha: 'xyz',
44
+ sourceBranch: 'main',
45
+ pullUrl: 'https://www.github.com/foo/bar/pull/123',
46
+ },
47
+ ]);
48
+ // simulate commit is definitely not backported
49
+ jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
50
+ return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
51
+ options: {},
52
+ commit: {
53
+ committedDate: '100',
54
+ expectedTargetPullRequests: [],
55
+ originalMessage: 'Second commit (#2)',
56
+ sha: 'abc',
57
+ sourceBranch: 'main',
58
+ },
59
+ targetBranch: '7.x',
60
+ conflictingFiles: ['/foo/bar/baz.ts'],
61
+ });
62
+ }
63
+ it('should not unbackported commits if no backports were expected', async () => {
64
+ const commitsWithoutBackports = await setupExpectedPullRequests({
65
+ expectedTargetPullRequests: [],
66
+ });
67
+ expect(commitsWithoutBackports.length).toEqual(0);
68
+ });
69
+ it('should display as missing if a backport is CLOSED', async () => {
70
+ const commitsWithoutBackports = await setupExpectedPullRequests({
71
+ expectedTargetPullRequests: [
72
+ {
73
+ state: 'CLOSED',
74
+ branch: '7.x',
75
+ number: 456,
76
+ url: 'https://www.github.com/foo/bar/pull/456',
77
+ },
78
+ ],
79
+ });
80
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
81
+ });
82
+ it('should display as missing if a backport is MISSING', async () => {
83
+ const commitsWithoutBackports = await setupExpectedPullRequests({
84
+ expectedTargetPullRequests: [{ state: 'MISSING', branch: '7.x' }],
85
+ });
86
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport missing)\n https://www.github.com/foo/bar/pull/123');
87
+ });
88
+ it('should display as pending if a backport is OPEN', async () => {
89
+ const commitsWithoutBackports = await setupExpectedPullRequests({
90
+ expectedTargetPullRequests: [
91
+ {
92
+ state: 'OPEN',
93
+ branch: '7.x',
94
+ url: 'https://www.github.com/foo/bar/pull/456',
95
+ number: 456,
96
+ },
97
+ ],
98
+ });
99
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
100
+ });
101
+ it('should not display commit as unbackported if a backport was MERGED', async () => {
102
+ const commitsWithoutBackports = await setupExpectedPullRequests({
103
+ expectedTargetPullRequests: [
104
+ {
105
+ state: 'MERGED',
106
+ branch: '7.x',
107
+ number: 456,
108
+ url: 'https://www.github.com/foo/bar/pull/456',
109
+ },
110
+ ],
111
+ });
112
+ expect(commitsWithoutBackports).toEqual([]);
113
+ });
114
+ });
115
+ describe('commitDate', () => {
116
+ function setupCommitDateDiff({ offendingCommitDate, currentCommitDate, }) {
117
+ // simulate 1 commit with a pending backport
118
+ jest
119
+ .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
120
+ .mockResolvedValueOnce([
121
+ {
122
+ committedDate: offendingCommitDate,
123
+ expectedTargetPullRequests: [
124
+ {
125
+ state: 'OPEN',
126
+ branch: '7.x',
127
+ number: 456,
128
+ url: 'https://www.github.com/foo/bar/pull/456',
129
+ },
130
+ ],
131
+ originalMessage: 'First commit (#1)',
132
+ sha: 'xyz',
133
+ sourceBranch: 'main',
134
+ pullNumber: 123,
135
+ pullUrl: 'https://www.github.com/foo/bar/pull/123',
136
+ },
137
+ ]);
138
+ // simulate commit is definitely not backported
139
+ jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
140
+ return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
141
+ options: {},
142
+ commit: {
143
+ committedDate: currentCommitDate,
144
+ expectedTargetPullRequests: [],
145
+ originalMessage: 'Second commit (#2)',
146
+ sha: 'abc',
147
+ sourceBranch: 'main',
148
+ },
149
+ targetBranch: '7.x',
150
+ conflictingFiles: ['/foo/bar/baz.ts'],
151
+ });
152
+ }
153
+ it('should not display commit as unbackport if is newer than the commit currently being backported', async () => {
154
+ const commitsWithoutBackports = await setupCommitDateDiff({
155
+ offendingCommitDate: '100',
156
+ currentCommitDate: '10',
157
+ });
158
+ expect(commitsWithoutBackports).toEqual([]);
159
+ });
160
+ it('should display commit as unbackport if is older than the commit currently being backported', async () => {
161
+ const commitsWithoutBackports = await setupCommitDateDiff({
162
+ offendingCommitDate: '10',
163
+ currentCommitDate: '100',
164
+ });
165
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
166
+ });
167
+ });
168
+ describe('targetBranch', () => {
169
+ function setupTargetBranchDiff({ offendingCommitTargetBranch, currentCommitTargetBranch, }) {
170
+ // return mock commits that also touched the conflicting files
171
+ jest
172
+ .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
173
+ .mockResolvedValueOnce([
174
+ {
175
+ pullUrl: 'https://www.github.com/foo/bar/pull/123',
176
+ pullNumber: 123,
177
+ committedDate: '10',
178
+ expectedTargetPullRequests: [
179
+ {
180
+ branch: offendingCommitTargetBranch,
181
+ state: 'OPEN',
182
+ url: 'https://www.github.com/foo/bar/pull/456',
183
+ number: 456,
184
+ },
185
+ ],
186
+ originalMessage: 'First commit (#1)',
187
+ sha: 'xyz',
188
+ sourceBranch: 'main',
189
+ },
190
+ ]);
191
+ // simulate commit is definitely not backported
192
+ jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
193
+ return (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
194
+ options: {},
195
+ // commit that is being backported
196
+ commit: {
197
+ pullUrl: 'https://www.github.com/foo/bar/pull/123',
198
+ pullNumber: 123,
199
+ committedDate: '100',
200
+ expectedTargetPullRequests: [],
201
+ originalMessage: 'Second commit (#2)',
202
+ sha: 'abc',
203
+ sourceBranch: 'main',
204
+ },
205
+ targetBranch: currentCommitTargetBranch,
206
+ conflictingFiles: ['/foo/bar/baz.ts'],
207
+ });
208
+ }
209
+ it('should display backport as pending if target branches match', async () => {
210
+ const commitsWithoutBackports = await setupTargetBranchDiff({
211
+ offendingCommitTargetBranch: '7.x',
212
+ currentCommitTargetBranch: '7.x',
213
+ });
214
+ expect((0, strip_ansi_1.default)(commitsWithoutBackports[0].formatted)).toEqual(' - First commit (#1) (backport pending)\n https://www.github.com/foo/bar/pull/456');
215
+ });
216
+ it("should not display commit if target branches don't match", async () => {
217
+ const commitsWithoutBackports = await setupTargetBranchDiff({
218
+ offendingCommitTargetBranch: '7.x',
219
+ currentCommitTargetBranch: '8.x',
220
+ });
221
+ expect(commitsWithoutBackports.length).toBe(0);
222
+ });
223
+ });
224
+ describe("when conflicting commit doesn't have an associated pull request", () => {
225
+ it('should be ignored', async () => {
226
+ jest
227
+ .spyOn(fetchCommitsByAuthorModule, 'fetchCommitsByAuthor')
228
+ .mockResolvedValueOnce([
229
+ {
230
+ // intentionally left out:
231
+ // pullNumber: 33,
232
+ // pullUrl: 'https://www.github.com/foo/bar/pull/123',
233
+ committedDate: '10',
234
+ expectedTargetPullRequests: [],
235
+ originalMessage: 'First commit (#1)',
236
+ sha: 'xyz',
237
+ sourceBranch: 'main',
238
+ },
239
+ ]);
240
+ // simulate commit is definitely not backported
241
+ jest.spyOn(git, 'getIsCommitInBranch').mockResolvedValueOnce(false);
242
+ const commitsWithoutBackports = await (0, getCommitsWithoutBackports_1.getCommitsWithoutBackports)({
243
+ options: {},
244
+ commit: {
245
+ pullUrl: 'https://www.github.com/foo/bar/pull/123',
246
+ pullNumber: 123,
247
+ committedDate: '100',
248
+ expectedTargetPullRequests: [],
249
+ originalMessage: 'Second commit (#2)',
250
+ sha: 'abc',
251
+ sourceBranch: 'main',
252
+ },
253
+ targetBranch: '7.x',
254
+ conflictingFiles: ['/foo/bar/baz.ts'],
255
+ });
256
+ expect(commitsWithoutBackports.length).toEqual(0);
257
+ });
258
+ });
259
+ });
@@ -1,12 +1,7 @@
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.maybeSetupRepo = void 0;
7
- const make_dir_1 = __importDefault(require("make-dir"));
8
4
  const ora = require("ora");
9
- const env_1 = require("../services/env");
10
5
  const git_1 = require("../services/git");
11
6
  async function maybeSetupRepo(options) {
12
7
  const isAlreadyCloned = await (0, git_1.repoExists)(options);
@@ -16,7 +11,6 @@ async function maybeSetupRepo(options) {
16
11
  try {
17
12
  const spinnerCloneText = 'Cloning repository (one-time operation)';
18
13
  spinner.text = `0% ${spinnerCloneText}`;
19
- await (0, make_dir_1.default)((0, env_1.getRepoOwnerPath)(options));
20
14
  await (0, git_1.cloneRepo)(options, (progress) => {
21
15
  spinner.text = `${progress}% ${spinnerCloneText}`;
22
16
  });
@@ -24,7 +24,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  const os_1 = __importDefault(require("os"));
26
26
  const del_1 = __importDefault(require("del"));
27
- const makeDir = require("make-dir");
28
27
  const childProcess = __importStar(require("../services/child-process-promisified"));
29
28
  const fs = __importStar(require("../services/fs-promisified"));
30
29
  const maybeSetupRepo_1 = require("./maybeSetupRepo");
@@ -38,15 +37,20 @@ describe('maybeSetupRepo', () => {
38
37
  });
39
38
  it('should delete repo if an error occurs', async () => {
40
39
  expect.assertions(2);
41
- makeDir.mockImplementationOnce(() => {
42
- throw new Error('makeDir failed');
40
+ execSpy = jest
41
+ .spyOn(childProcess, 'execAsCallback')
42
+ .mockImplementation((cmd) => {
43
+ if (cmd.startsWith('git clone')) {
44
+ throw new Error('Simulated git clone failure');
45
+ }
46
+ throw new Error('unknown error');
43
47
  });
44
48
  await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
45
49
  accessToken: 'myAccessToken',
46
50
  gitHostname: 'github.com',
47
51
  repoName: 'kibana',
48
52
  repoOwner: 'elastic',
49
- })).rejects.toThrowError('makeDir failed');
53
+ })).rejects.toThrowError('Simulated git clone failure');
50
54
  expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana');
51
55
  });
52
56
  describe('if repo already exists', () => {
@@ -0,0 +1 @@
1
+ export declare function redact(stringToRedact: string, str: string): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redact = void 0;
4
+ function redact(stringToRedact, str) {
5
+ return str.replace(new RegExp(stringToRedact, 'g'), '<REDACTED>');
6
+ }
7
+ exports.redact = redact;
@@ -0,0 +1 @@
1
+ export declare function sequentially<T>(items: T[], handler: (item: T) => Promise<void>): Promise<void>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sequentially = void 0;
4
+ function sequentially(items, handler) {
5
+ return items.reduce(async (p, item) => {
6
+ await p;
7
+ return handler(item);
8
+ }, Promise.resolve());
9
+ }
10
+ exports.sequentially = sequentially;
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "6.1.2",
17
+ "version": "6.2.0",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {
@@ -95,9 +95,9 @@
95
95
  "graphql-config": "^4.1.0",
96
96
  "graphql-tag": "^2.12.6",
97
97
  "husky": "^7.0.4",
98
- "jest": "^27.4.5",
98
+ "jest": "^27.4.7",
99
99
  "jest-snapshot-serializer-ansi": "^1.0.0",
100
- "lint-staged": "^12.1.5",
100
+ "lint-staged": "^12.1.7",
101
101
  "nock": "^13.2.1",
102
102
  "prettier": "^2.5.1",
103
103
  "strip-ansi": "^6.0.1",