backport 6.1.0 โ†’ 6.1.4

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 (63) hide show
  1. package/README.md +45 -34
  2. package/dist/entrypoint.module.d.ts +2 -0
  3. package/dist/entrypoint.module.js +5 -1
  4. package/dist/entrypoint.module.private.test.js +16 -12
  5. package/dist/main.js +1 -1
  6. package/dist/options/ConfigOptions.d.ts +1 -0
  7. package/dist/options/cliArgs.d.ts +5 -3
  8. package/dist/options/cliArgs.js +20 -6
  9. package/dist/options/cliArgs.test.js +0 -7
  10. package/dist/options/config/config.d.ts +1 -0
  11. package/dist/options/config/globalConfig.js +1 -1
  12. package/dist/options/config/readConfigFile.d.ts +1 -0
  13. package/dist/options/options.d.ts +8 -0
  14. package/dist/options/options.js +9 -4
  15. package/dist/options/options.test.js +150 -104
  16. package/dist/runSequentially.test.js +13 -6
  17. package/dist/services/HandledError.d.ts +1 -1
  18. package/dist/services/git.d.ts +2 -1
  19. package/dist/services/git.js +4 -2
  20. package/dist/services/github/v3/createPullRequest.js +1 -1
  21. package/dist/services/github/v3/createPullRequest.test.js +38 -6
  22. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  23. package/dist/services/github/v3/createStatusComment.js +43 -25
  24. package/dist/services/github/v3/createStatusComment.test.js +155 -73
  25. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  26. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  27. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  28. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  29. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  30. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  31. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  32. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  33. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  34. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  35. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  36. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  37. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  38. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  39. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  40. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  41. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +37 -0
  42. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  43. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  44. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  45. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  46. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  47. package/dist/test/inquirer.private.test.js +4 -15
  48. package/dist/test/integration/integration.private.test.js +14 -4
  49. package/dist/test/nockHelpers.js +1 -3
  50. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  51. package/dist/ui/cherrypickAndCreatePullRequest.test.js +19 -6
  52. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
  53. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -48
  54. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
  55. package/dist/ui/getCommits.js +1 -1
  56. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  57. package/dist/ui/getCommitsWithoutBackports.js +68 -0
  58. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  59. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  60. package/dist/utils/excludeUndefined.js +1 -1
  61. package/dist/utils/excludeUndefined.test.js +3 -3
  62. package/package.json +3 -3
  63. package/yarn.lock +462 -284
@@ -12,13 +12,6 @@ async function createStatusComment({ options, backportResponse, }) {
12
12
  baseUrl: githubApiBaseUrlV3,
13
13
  log: logger_1.logger,
14
14
  });
15
- // don't post update if there are no new pull requests created
16
- if (backportResponse.status === 'success') {
17
- const hasOnlyUpdates = backportResponse.results.every((result) => result.status === 'success' && result.didUpdate);
18
- if (hasOnlyUpdates) {
19
- return;
20
- }
21
- }
22
15
  await Promise.all(backportResponse.commits.map((commit) => {
23
16
  if (!commit.pullNumber) {
24
17
  return;
@@ -28,6 +21,10 @@ async function createStatusComment({ options, backportResponse, }) {
28
21
  pullNumber: commit.pullNumber,
29
22
  backportResponse,
30
23
  });
24
+ // only post comment if there is a body
25
+ if (!body) {
26
+ return;
27
+ }
31
28
  return octokit.issues.createComment({
32
29
  owner: repoOwner,
33
30
  repo: repoName,
@@ -43,16 +40,31 @@ async function createStatusComment({ options, backportResponse, }) {
43
40
  exports.createStatusComment = createStatusComment;
44
41
  function getCommentBody({ options, pullNumber, backportResponse, }) {
45
42
  const { repoName, repoOwner, autoMerge } = options;
46
- const backportPRCommand = `To backport manually run: \`node scripts/backport --pr ${pullNumber}\`.\nFor more info read the [Backport documentation](https://github.com/sqren/backport#backport)`;
43
+ // custom handling when running backport locally (as opposed to on CI)
44
+ if (!options.ci) {
45
+ // don't post comment when the overall process failed
46
+ if (backportResponse.status === 'failure') {
47
+ return;
48
+ }
49
+ // only post a comment if all backports succeeded
50
+ const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
51
+ if (!didAllBackportsSucceed) {
52
+ return;
53
+ }
54
+ }
55
+ const backportPRCommand = `\n### How to fix\nRe-run the backport manually:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\``;
56
+ const supportSection = '\n\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)';
47
57
  if (backportResponse.status === 'failure') {
48
58
  return `## ๐Ÿ’” Backport failed
49
59
  The pull request could not be backported due to the following error:
50
60
  \`${backportResponse.errorMessage}\`
51
-
52
- ${backportPRCommand}
53
- `;
61
+ ${backportPRCommand}${supportSection}`;
54
62
  }
55
63
  const tableBody = backportResponse.results
64
+ .filter((result) => {
65
+ // only post status updates for successful backports when running manually (non-ci)
66
+ return options.ci || result.status === 'success';
67
+ })
56
68
  .map((result) => {
57
69
  if (result.status === 'success') {
58
70
  return [
@@ -61,17 +73,15 @@ ${backportPRCommand}
61
73
  `[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`,
62
74
  ];
63
75
  }
64
- if (result.error.meta?.type === 'commitsWithoutBackports') {
65
- const conflictMessage = result.error.meta.commitsWithoutBackports.map((c) => {
66
- if (c.commit.pullNumber) {
67
- return ` - [#${c.commit.pullNumber}](${c.commit.pullUrl})`;
68
- }
69
- return ` - ${(0, commitFormatters_1.getFirstLine)(c.commit.originalMessage)} (${(0, commitFormatters_1.getShortSha)(c.commit.sha)})`;
76
+ if (result.error.meta?.type === 'merge-conflict-due-to-missing-backports') {
77
+ const conflictingPullRequests = result.error.meta.commitsWithoutBackports.map((c) => {
78
+ return ` - [${(0, commitFormatters_1.getFirstLine)(c.commit.originalMessage)}](${c.commit.pullUrl})`;
70
79
  });
80
+ const conflictSection = `<br><br>You might need to backport the following PRs to ${result.targetBranch}:<br>${conflictingPullRequests.join('<br>')}`;
71
81
  return [
72
82
  'โŒ',
73
83
  result.targetBranch,
74
- `Could not backport due to conflicts, possibly caused by the following unbackported commits:<br>${conflictMessage.join('<br>')}`,
84
+ `**Backport failed because of merge conflicts**${conflictingPullRequests.length > 0 ? conflictSection : ''}`,
75
85
  ];
76
86
  }
77
87
  return ['โŒ', result.targetBranch, result.errorMessage];
@@ -79,19 +89,27 @@ ${backportPRCommand}
79
89
  .map((line) => line.join('|'))
80
90
  .join('|\n|');
81
91
  const table = backportResponse.results.length
82
- ? `| Status | Branch | Result |\n|:------:|:------:|:------:|\n|${tableBody}|`
92
+ ? `| Status | Branch | Result |\n|:------:|:------:|:------|\n|${tableBody}|`
83
93
  : '';
84
94
  const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
85
95
  const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
86
- const header = didAllBackportsSucceed
87
- ? '## ๐Ÿ’š All backports created successfully'
88
- : '## ๐Ÿ’” Some backports could not be created';
96
+ let header = '';
97
+ if (didAllBackportsSucceed) {
98
+ header = '## ๐Ÿ’š All backports created successfully';
99
+ }
100
+ else if (didAnyBackportsSucceed) {
101
+ header = '## ๐Ÿ’” Some backports could not be created';
102
+ }
103
+ else {
104
+ header = '## ๐Ÿ’” All backports failed';
105
+ }
89
106
  const autoMergeMessage = autoMerge && didAnyBackportsSucceed
90
- ? 'Note: Successful backport PRs will be merged automatically after passing CI.\n'
107
+ ? '\nNote: Successful backport PRs will be merged automatically after passing CI.'
91
108
  : '';
92
109
  const backportPRCommandMessage = !didAllBackportsSucceed
93
- ? `${backportPRCommand}\n\n`
110
+ ? `${backportPRCommand}`
94
111
  : '';
95
- return (0, logger_1.redactAccessToken)(`${header}\n\n${table}\n\n${backportPRCommandMessage}${autoMergeMessage}`);
112
+ return (0, logger_1.redactAccessToken)(`${header}\n\n${table}
113
+ ${backportPRCommandMessage}${autoMergeMessage}${supportSection}`);
96
114
  }
97
115
  exports.getCommentBody = getCommentBody;
@@ -3,30 +3,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const HandledError_1 = require("../../HandledError");
4
4
  const createStatusComment_1 = require("./createStatusComment");
5
5
  describe('getCommentBody', () => {
6
- it('when an unknown error occurs', () => {
7
- expect((0, createStatusComment_1.getCommentBody)({
8
- options: {},
6
+ describe('when an unknown error occurs', () => {
7
+ const getParams = (opts) => ({
8
+ options: {
9
+ backportBinary: 'node scripts/backport',
10
+ ...opts,
11
+ },
9
12
  pullNumber: 55,
10
13
  backportResponse: {
11
14
  status: 'failure',
12
15
  errorMessage: 'A terrible error occured',
13
16
  },
14
- })).toMatchInlineSnapshot(`
15
- "## ๐Ÿ’” Backport failed
16
- The pull request could not be backported due to the following error:
17
- \`A terrible error occured\`
18
-
19
- To backport manually run: \`node scripts/backport --pr 55\`.
20
- For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
21
- "
22
- `);
17
+ });
18
+ it('posts a comment when running on ci', () => {
19
+ const params = getParams({ ci: true });
20
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
21
+ "## ๐Ÿ’” Backport failed
22
+ The pull request could not be backported due to the following error:
23
+ \`A terrible error occured\`
24
+
25
+ ### How to fix
26
+ Re-run the backport manually:
27
+ \`\`\`
28
+ node scripts/backport --pr 55
29
+ \`\`\`
30
+
31
+ ### Questions ?
32
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
33
+ `);
34
+ });
35
+ it('does not post a comment when running manually', () => {
36
+ const params = getParams({ ci: false });
37
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
38
+ });
23
39
  });
24
- it('when all backports succeed', () => {
25
- expect((0, createStatusComment_1.getCommentBody)({
40
+ describe('when all backports succeed', () => {
41
+ const getParams = (opts) => ({
26
42
  options: {
27
43
  repoName: 'kibana',
28
44
  repoOwner: 'elastic',
29
45
  autoMerge: true,
46
+ ...opts,
30
47
  },
31
48
  pullNumber: 55,
32
49
  backportResponse: {
@@ -46,24 +63,48 @@ describe('getCommentBody', () => {
46
63
  },
47
64
  ],
48
65
  },
49
- })).toMatchInlineSnapshot(`
50
- "## ๐Ÿ’š All backports created successfully
66
+ });
67
+ it('posts a comment on ci', () => {
68
+ const params = getParams({ ci: true });
69
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
70
+ "## ๐Ÿ’š All backports created successfully
71
+
72
+ | Status | Branch | Result |
73
+ |:------:|:------:|:------|
74
+ |โœ…|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
75
+ |โœ…|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
51
76
 
52
- | Status | Branch | Result |
53
- |:------:|:------:|:------:|
54
- |โœ…|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
55
- |โœ…|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
77
+ Note: Successful backport PRs will be merged automatically after passing CI.
56
78
 
57
- Note: Successful backport PRs will be merged automatically after passing CI.
58
- "
59
- `);
79
+ ### Questions ?
80
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
81
+ `);
82
+ });
83
+ it('posts a comment when running locally', () => {
84
+ const params = getParams({ ci: false });
85
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
86
+ "## ๐Ÿ’š All backports created successfully
87
+
88
+ | Status | Branch | Result |
89
+ |:------:|:------:|:------|
90
+ |โœ…|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
91
+ |โœ…|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
92
+
93
+ Note: Successful backport PRs will be merged automatically after passing CI.
94
+
95
+ ### Questions ?
96
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
97
+ `);
98
+ });
60
99
  });
61
- it('when all backports fail', () => {
62
- expect((0, createStatusComment_1.getCommentBody)({
100
+ describe('when all backports fail', () => {
101
+ const getParams = (opts) => ({
63
102
  options: {
64
103
  repoName: 'kibana',
65
104
  repoOwner: 'elastic',
66
105
  autoMerge: true,
106
+ backportBinary: 'node scripts/backport',
107
+ ...opts,
67
108
  },
68
109
  pullNumber: 55,
69
110
  backportResponse: {
@@ -83,26 +124,40 @@ describe('getCommentBody', () => {
83
124
  },
84
125
  ],
85
126
  },
86
- })).toMatchInlineSnapshot(`
87
- "## ๐Ÿ’” Some backports could not be created
127
+ });
128
+ it('posts a comment on CI', () => {
129
+ const params = getParams({ ci: true });
130
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
131
+ "## ๐Ÿ’” All backports failed
88
132
 
89
- | Status | Branch | Result |
90
- |:------:|:------:|:------:|
91
- |โŒ|7.x|My boom error!|
92
- |โŒ|7.1|My boom error!|
133
+ | Status | Branch | Result |
134
+ |:------:|:------:|:------|
135
+ |โŒ|7.x|My boom error!|
136
+ |โŒ|7.1|My boom error!|
93
137
 
94
- To backport manually run: \`node scripts/backport --pr 55\`.
95
- For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
138
+ ### How to fix
139
+ Re-run the backport manually:
140
+ \`\`\`
141
+ node scripts/backport --pr 55
142
+ \`\`\`
96
143
 
97
- "
98
- `);
144
+ ### Questions ?
145
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
146
+ `);
147
+ });
148
+ it('does not post a comment when running manaully', () => {
149
+ const params = getParams({ ci: false });
150
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
151
+ });
99
152
  });
100
- it('when some backports fail', () => {
101
- expect((0, createStatusComment_1.getCommentBody)({
153
+ describe('when some backports fail', () => {
154
+ const getParams = (opts) => ({
102
155
  options: {
103
156
  repoName: 'kibana',
104
157
  repoOwner: 'elastic',
105
158
  autoMerge: true,
159
+ backportBinary: 'node scripts/backport',
160
+ ...opts,
106
161
  },
107
162
  pullNumber: 55,
108
163
  backportResponse: {
@@ -122,27 +177,41 @@ describe('getCommentBody', () => {
122
177
  },
123
178
  ],
124
179
  },
125
- })).toMatchInlineSnapshot(`
126
- "## ๐Ÿ’” Some backports could not be created
180
+ });
181
+ it('post a comment when running on CI', () => {
182
+ const params = getParams({ ci: true });
183
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
184
+ "## ๐Ÿ’” Some backports could not be created
127
185
 
128
- | Status | Branch | Result |
129
- |:------:|:------:|:------:|
130
- |โœ…|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
131
- |โŒ|7.1|My boom error!|
186
+ | Status | Branch | Result |
187
+ |:------:|:------:|:------|
188
+ |โœ…|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
189
+ |โŒ|7.1|My boom error!|
132
190
 
133
- To backport manually run: \`node scripts/backport --pr 55\`.
134
- For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
191
+ ### How to fix
192
+ Re-run the backport manually:
193
+ \`\`\`
194
+ node scripts/backport --pr 55
195
+ \`\`\`
196
+ Note: Successful backport PRs will be merged automatically after passing CI.
135
197
 
136
- Note: Successful backport PRs will be merged automatically after passing CI.
137
- "
138
- `);
198
+ ### Questions ?
199
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
200
+ `);
201
+ });
202
+ it('does not post a comment when running manually because some backports failed', () => {
203
+ const params = getParams({ ci: false });
204
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
205
+ });
139
206
  });
140
- it('when some backports fail due to conflicts', () => {
141
- expect((0, createStatusComment_1.getCommentBody)({
207
+ describe('when some backports fail due to conflicts', () => {
208
+ const getParams = (opts) => ({
142
209
  options: {
143
210
  repoName: 'kibana',
144
211
  repoOwner: 'elastic',
145
212
  autoMerge: true,
213
+ backportBinary: 'node scripts/backport',
214
+ ...opts,
146
215
  },
147
216
  pullNumber: 55,
148
217
  backportResponse: {
@@ -159,13 +228,22 @@ describe('getCommentBody', () => {
159
228
  targetBranch: '7.1',
160
229
  errorMessage: 'My boom error!',
161
230
  error: new HandledError_1.HandledError('Boom!', {
162
- type: 'commitsWithoutBackports',
231
+ type: 'merge-conflict-due-to-missing-backports',
163
232
  commitsWithoutBackports: [
164
233
  {
165
234
  //@ts-expect-error
166
235
  commit: {
167
236
  pullNumber: 5,
168
237
  pullUrl: 'url-to-pr-5',
238
+ originalMessage: 'New Zealand commit message',
239
+ },
240
+ },
241
+ {
242
+ //@ts-expect-error
243
+ commit: {
244
+ pullNumber: 44,
245
+ pullUrl: 'url-to-pr-44',
246
+ originalMessage: 'Australia commit',
169
247
  },
170
248
  },
171
249
  ],
@@ -176,34 +254,38 @@ describe('getCommentBody', () => {
176
254
  targetBranch: '7.2',
177
255
  errorMessage: 'My boom error!',
178
256
  error: new HandledError_1.HandledError('Boom!', {
179
- type: 'commitsWithoutBackports',
180
- commitsWithoutBackports: [
181
- {
182
- //@ts-expect-error
183
- commit: {
184
- sha: 'acdefg',
185
- originalMessage: 'Some long message\nin multiple lines',
186
- },
187
- },
188
- ],
257
+ type: 'merge-conflict-due-to-missing-backports',
258
+ commitsWithoutBackports: [],
189
259
  }),
190
260
  },
191
261
  ],
192
262
  },
193
- })).toMatchInlineSnapshot(`
194
- "## ๐Ÿ’” Some backports could not be created
263
+ });
264
+ it('posts a comment when running on CI', () => {
265
+ const params = getParams({ ci: true });
266
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
267
+ "## ๐Ÿ’” Some backports could not be created
195
268
 
196
- | Status | Branch | Result |
197
- |:------:|:------:|:------:|
198
- |โœ…|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
199
- |โŒ|7.1|Could not backport due to conflicts, possibly caused by the following unbackported commits:<br> - [#5](url-to-pr-5)|
200
- |โŒ|7.2|Could not backport due to conflicts, possibly caused by the following unbackported commits:<br> - Some long message (acdefg)|
269
+ | Status | Branch | Result |
270
+ |:------:|:------:|:------|
271
+ |โœ…|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
272
+ |โŒ|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
273
+ |โŒ|7.2|**Backport failed because of merge conflicts**|
201
274
 
202
- To backport manually run: \`node scripts/backport --pr 55\`.
203
- For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
275
+ ### How to fix
276
+ Re-run the backport manually:
277
+ \`\`\`
278
+ node scripts/backport --pr 55
279
+ \`\`\`
280
+ Note: Successful backport PRs will be merged automatically after passing CI.
204
281
 
205
- Note: Successful backport PRs will be merged automatically after passing CI.
206
- "
207
- `);
282
+ ### Questions ?
283
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
284
+ `);
285
+ });
286
+ it('does not post a comment when running manually because some backports failed', () => {
287
+ const params = getParams({ ci: false });
288
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
289
+ });
208
290
  });
209
291
  });
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
+ const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
5
+ const fetchCommitBySha_1 = require("./fetchCommitBySha");
6
+ const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
7
+ const fetchPullRequestBySearchQuery_1 = require("./fetchPullRequestBySearchQuery");
8
+ describe('allFetchers', () => {
9
+ let devAccessToken;
10
+ beforeEach(async () => {
11
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
12
+ });
13
+ it('all fetchers return the same commit', async () => {
14
+ const commitsByAuthor = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
15
+ accessToken: devAccessToken,
16
+ author: 'sqren',
17
+ historicalBranchLabelMappings: [],
18
+ maxNumber: 1,
19
+ repoName: 'kibana',
20
+ repoOwner: 'elastic',
21
+ sourceBranch: 'main',
22
+ dateSince: '2021-01-10T00:00:00Z',
23
+ dateUntil: '2022-01-01T00:00:00Z',
24
+ commitPaths: [],
25
+ });
26
+ const commitByAuthor = commitsByAuthor[0];
27
+ if (!commitByAuthor.pullNumber) {
28
+ throw new Error('Missing pullnumber!');
29
+ }
30
+ const commitByPullNumber = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
31
+ repoOwner: 'elastic',
32
+ repoName: 'kibana',
33
+ accessToken: devAccessToken,
34
+ pullNumber: commitByAuthor.pullNumber,
35
+ sourceBranch: 'master',
36
+ historicalBranchLabelMappings: [],
37
+ });
38
+ const commitBySha = await (0, fetchCommitBySha_1.fetchCommitBySha)({
39
+ repoOwner: 'elastic',
40
+ repoName: 'kibana',
41
+ accessToken: devAccessToken,
42
+ sha: commitByAuthor.sha,
43
+ sourceBranch: 'main',
44
+ historicalBranchLabelMappings: [],
45
+ });
46
+ const commitsBySearchQuery = await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)({
47
+ repoOwner: 'elastic',
48
+ repoName: 'kibana',
49
+ accessToken: devAccessToken,
50
+ maxNumber: 1,
51
+ prFilter: `[APM] Add note about synthtrace to APM docs`,
52
+ sourceBranch: 'main',
53
+ });
54
+ expect(commitByAuthor).toEqual(commitByPullNumber);
55
+ expect(commitByAuthor).toEqual(commitBySha);
56
+ expect(commitByAuthor).toEqual(commitsBySearchQuery[0]);
57
+ expect(commitByAuthor).toEqual({
58
+ committedDate: '2021-12-20T14:20:16Z',
59
+ expectedTargetPullRequests: [
60
+ {
61
+ branch: '8.0',
62
+ mergeCommit: {
63
+ message: '[APM] Add note about synthtrace to APM docs (#121633) (#121643)\n\nCo-authored-by: Sรธren Louv-Jansen <soren.louv@elastic.co>',
64
+ sha: '842adfdeb5541b059231857522f9009771a46107',
65
+ },
66
+ number: 121643,
67
+ state: 'MERGED',
68
+ url: 'https://github.com/elastic/kibana/pull/121643',
69
+ },
70
+ ],
71
+ originalMessage: '[APM] Add note about synthtrace to APM docs (#121633)',
72
+ pullNumber: 121633,
73
+ pullUrl: 'https://github.com/elastic/kibana/pull/121633',
74
+ sha: 'd421ddcf6157150596581c7885afa3690cec6339',
75
+ sourceBranch: 'main',
76
+ });
77
+ });
78
+ });
@@ -15,7 +15,7 @@ async function fetchCommitByPullNumber(options) {
15
15
  repository(owner: $repoOwner, name: $repoName) {
16
16
  pullRequest(number: $pullNumber) {
17
17
  mergeCommit {
18
- ...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
18
+ ...SourceCommitWithTargetPullRequest
19
19
  }
20
20
  }
21
21
  }
@@ -1,12 +1,68 @@
1
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
+ };
2
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
3
26
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
27
+ const apiRequestV4Module = __importStar(require("../apiRequestV4"));
4
28
  const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
5
29
  describe('fetchCommitByPullNumber', () => {
6
30
  let devAccessToken;
7
31
  beforeAll(async () => {
8
32
  devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
33
  });
34
+ describe('snapshot request/response', () => {
35
+ let spy;
36
+ let commit;
37
+ beforeEach(async () => {
38
+ spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
39
+ commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
40
+ repoOwner: 'elastic',
41
+ repoName: 'kibana',
42
+ accessToken: devAccessToken,
43
+ pullNumber: 121633,
44
+ sourceBranch: 'master',
45
+ historicalBranchLabelMappings: [],
46
+ });
47
+ });
48
+ it('makes the right queries', () => {
49
+ const queries = spy.mock.calls.reduce((acc, call) => {
50
+ const query = call[0].query;
51
+ const ast = (0, graphql_tag_1.default)(query);
52
+ //@ts-expect-error
53
+ const name = ast.definitions[0].name.value;
54
+ return { ...acc, [name]: query };
55
+ }, {});
56
+ const queryNames = Object.keys(queries);
57
+ expect(queryNames).toEqual(['CommitByPullNumber']);
58
+ queryNames.forEach((name) => {
59
+ expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
60
+ });
61
+ });
62
+ it('returns the correct response', async () => {
63
+ expect(commit).toMatchSnapshot();
64
+ });
65
+ });
10
66
  describe('when PR was merged', () => {
11
67
  it('is returned', async () => {
12
68
  const options = {
@@ -30,12 +86,20 @@ describe('fetchCommitByPullNumber', () => {
30
86
  state: 'MERGED',
31
87
  number: 6,
32
88
  url: 'https://github.com/backport-org/backport-e2e/pull/6',
89
+ mergeCommit: {
90
+ message: 'Add ๐Ÿ emoji (#5) (#6)',
91
+ sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
92
+ },
33
93
  },
34
94
  {
35
95
  branch: '7.8',
36
96
  state: 'MERGED',
37
97
  number: 7,
38
98
  url: 'https://github.com/backport-org/backport-e2e/pull/7',
99
+ mergeCommit: {
100
+ message: 'Add ๐Ÿ emoji (#5) (#7)',
101
+ sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
102
+ },
39
103
  },
40
104
  ],
41
105
  });
@@ -7,13 +7,13 @@ const apiRequestV4_1 = require("../apiRequestV4");
7
7
  async function fetchCommitBySha(options) {
8
8
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
9
9
  const query = /* GraphQL */ `
10
- query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
11
- repository(owner: $repoOwner, name: $repoName) {
12
- object(expression: $oid) {
13
- ...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
10
+ query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
11
+ repository(owner: $repoOwner, name: $repoName) {
12
+ object(expression: $oid) {
13
+ ...SourceCommitWithTargetPullRequest
14
+ }
14
15
  }
15
16
  }
16
- }
17
17
 
18
18
  ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
19
19
  `;