backport 6.1.3 → 6.2.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 (169) hide show
  1. package/README.md +40 -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.cli.js +3 -5
  9. package/dist/entrypoint.module.d.ts +6 -3
  10. package/dist/entrypoint.module.js +13 -7
  11. package/dist/entrypoint.module.private.test.js +4 -1
  12. package/dist/main.js +5 -1
  13. package/dist/options/ConfigOptions.d.ts +4 -0
  14. package/dist/options/cliArgs.d.ts +17 -11
  15. package/dist/options/cliArgs.js +36 -5
  16. package/dist/options/config/config.d.ts +10 -1
  17. package/dist/options/config/config.js +9 -3
  18. package/dist/options/config/config.test.js +27 -1
  19. package/dist/options/config/getProjectConfig.d.ts +0 -0
  20. package/dist/options/config/getProjectConfig.js +1 -0
  21. package/dist/options/config/globalConfig.d.ts +2 -2
  22. package/dist/options/config/globalConfig.js +16 -14
  23. package/dist/options/config/globalConfig.test.js +10 -4
  24. package/dist/options/config/projectConfig.d.ts +3 -1
  25. package/dist/options/config/projectConfig.js +5 -2
  26. package/dist/options/config/projectConfig.test.js +35 -6
  27. package/dist/options/config/readConfigFile.d.ts +26 -22
  28. package/dist/options/options.d.ts +18 -9
  29. package/dist/options/options.js +11 -4
  30. package/dist/options/options.test.js +40 -35
  31. package/dist/react-components/0-loadOptions.d.ts +6 -0
  32. package/dist/react-components/0-loadOptions.js +45 -0
  33. package/dist/react-components/1-loadCommit.d.ts +8 -0
  34. package/dist/react-components/1-loadCommit.js +88 -0
  35. package/dist/react-components/1a-loadCommit.d.ts +5 -0
  36. package/dist/react-components/1a-loadCommit.js +76 -0
  37. package/dist/react-components/1b-commitChoices.d.ts +5 -0
  38. package/dist/react-components/1b-commitChoices.js +98 -0
  39. package/dist/react-components/2-commitChoices.d.ts +8 -0
  40. package/dist/react-components/2-commitChoices.js +96 -0
  41. package/dist/react-components/2-commitsPrompt.d.ts +8 -0
  42. package/dist/react-components/2-commitsPrompt.js +96 -0
  43. package/dist/react-components/2-targetBranchChoices.d.ts +9 -0
  44. package/dist/react-components/2-targetBranchChoices.js +109 -0
  45. package/dist/react-components/3-cherrypick.d.ts +1 -0
  46. package/dist/react-components/3-cherrypick.js +2 -0
  47. package/dist/react-components/App.d.ts +2 -0
  48. package/dist/react-components/App.js +35 -0
  49. package/dist/react-components/BackportStateContext.d.ts +33 -0
  50. package/dist/react-components/BackportStateContext.js +42 -0
  51. package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +8 -0
  52. package/dist/react-components/CommitPrompt/2-commitsPrompt.js +96 -0
  53. package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +8 -0
  54. package/dist/react-components/CommitPrompt/CommitPrompt.js +96 -0
  55. package/dist/react-components/CommitPrompt/getCommits.d.ts +2 -0
  56. package/dist/react-components/CommitPrompt/getCommits.js +27 -0
  57. package/dist/react-components/CommitPrompt.d.ts +8 -0
  58. package/dist/react-components/CommitPrompt.js +96 -0
  59. package/dist/react-components/CustomMultiSelect.d.ts +13 -0
  60. package/dist/react-components/CustomMultiSelect.js +21 -0
  61. package/dist/react-components/CustomMultiSelectItem.d.ts +5 -0
  62. package/dist/react-components/CustomMultiSelectItem.js +12 -0
  63. package/dist/react-components/CustomSelect.d.ts +14 -0
  64. package/dist/react-components/CustomSelect.js +34 -0
  65. package/dist/react-components/ErrorBoundary.d.ts +15 -0
  66. package/dist/react-components/ErrorBoundary.js +53 -0
  67. package/dist/react-components/MultiSelect.d.ts +7 -0
  68. package/dist/react-components/MultiSelect.js +16 -0
  69. package/dist/react-components/hooks/useAsync.d.ts +12 -0
  70. package/dist/react-components/hooks/useAsync.js +73 -0
  71. package/dist/runSequentially.test.js +11 -13
  72. package/dist/scripts/postinstall.js +3 -3
  73. package/dist/services/HandledError.d.ts +1 -1
  74. package/dist/services/backportRun/backportRun.ci.d.ts +6 -0
  75. package/dist/services/backportRun/backportRun.ci.js +81 -0
  76. package/dist/services/backportRun/backportRun.d.ts +14 -0
  77. package/dist/services/backportRun/backportRun.interactive.d.ts +1 -0
  78. package/dist/services/backportRun/backportRun.interactive.js +4 -0
  79. package/dist/services/backportRun/backportRun.js +14 -0
  80. package/dist/services/backportRun/backportState.d.ts +4 -0
  81. package/dist/services/backportRun/backportState.js +28 -0
  82. package/dist/services/backportRun/getCommits.d.ts +2 -0
  83. package/dist/services/backportRun/getCommits.js +20 -0
  84. package/dist/services/backportRun/runSequentially.d.ts +20 -0
  85. package/dist/services/backportRun/runSequentially.js +41 -0
  86. package/dist/services/backportRun/runSequentially.test.d.ts +1 -0
  87. package/dist/services/backportRun/runSequentially.test.js +199 -0
  88. package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +12 -0
  89. package/dist/services/cherrypickAndCreateTargetPullRequest.js +206 -0
  90. package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  91. package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +403 -0
  92. package/dist/services/env.d.ts +5 -4
  93. package/dist/services/env.js +13 -11
  94. package/dist/services/env.test.js +0 -6
  95. package/dist/services/getCommits.d.ts +2 -0
  96. package/dist/services/getCommits.js +38 -0
  97. package/dist/services/getCommitsWithoutBackports.d.ts +11 -0
  98. package/dist/services/getCommitsWithoutBackports.js +68 -0
  99. package/dist/services/getCommitsWithoutBackports.test.d.ts +1 -0
  100. package/dist/services/getCommitsWithoutBackports.test.js +259 -0
  101. package/dist/services/getTargetBranches.d.ts +5 -0
  102. package/dist/services/getTargetBranches.js +60 -0
  103. package/dist/services/getTargetBranches.test.d.ts +1 -0
  104. package/dist/services/getTargetBranches.test.js +180 -0
  105. package/dist/services/git.d.ts +2 -1
  106. package/dist/services/git.js +5 -3
  107. package/dist/services/github/v3/createPullRequest.js +8 -5
  108. package/dist/services/github/v3/createPullRequest.test.js +60 -10
  109. package/dist/services/github/v3/createStatusComment.d.ts +2 -2
  110. package/dist/services/github/v3/createStatusComment.js +40 -15
  111. package/dist/services/github/v3/createStatusComment.test.js +174 -86
  112. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  113. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  114. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  116. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  117. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  118. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  119. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  120. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  121. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  122. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  123. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  124. package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
  125. package/dist/services/github/v4/fetchProjectConfig.js +3 -3
  126. package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
  127. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  128. package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
  129. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  130. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  131. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -0
  132. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
  133. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  134. package/dist/services/logger.d.ts +4 -2
  135. package/dist/services/logger.js +31 -32
  136. package/dist/services/maybeSetupRepo.d.ts +2 -0
  137. package/dist/services/maybeSetupRepo.js +33 -0
  138. package/dist/services/maybeSetupRepo.test.d.ts +1 -0
  139. package/dist/services/maybeSetupRepo.test.js +78 -0
  140. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  141. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  142. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  143. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  144. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  145. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  146. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  147. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  148. package/dist/test/backport-e2e.private.test.d.ts +1 -0
  149. package/dist/test/backport-e2e.private.test.js +325 -0
  150. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
  151. package/dist/test/handleUnbackportedPullRequests.private.test.js +43 -0
  152. package/dist/test/inquirer.private.test.js +3 -1
  153. package/dist/test/integration/integration.private.test.js +2 -2
  154. package/dist/test/nockHelpers.js +1 -3
  155. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  156. package/dist/todo-delete.d.ts +1 -0
  157. package/dist/todo-delete.js +17 -0
  158. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -3
  159. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +9 -12
  160. package/dist/ui/getCommits.js +1 -1
  161. package/dist/ui/getCommitsWithoutBackports.js +17 -2
  162. package/dist/ui/maybeSetupRepo.js +0 -6
  163. package/dist/ui/maybeSetupRepo.test.js +8 -4
  164. package/dist/utils/redact.d.ts +1 -0
  165. package/dist/utils/redact.js +7 -0
  166. package/dist/utils/sequentially.d.ts +1 -0
  167. package/dist/utils/sequentially.js +10 -0
  168. package/package.json +11 -11
  169. package/yarn.lock +570 -436
@@ -16,12 +16,11 @@ describe('getPullRequestBody', () => {
16
16
  })).toMatchInlineSnapshot(`
17
17
  "# Backport
18
18
 
19
- This is an automatic backport to 7.x of:
19
+ This is an automatic backport to \`7.x\` of:
20
20
  - #55
21
21
 
22
22
  ### Questions ?
23
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
24
- "
23
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
25
24
  `);
26
25
  });
27
26
  it('when a single commit (non pull request) is backported', () => {
@@ -37,12 +36,11 @@ describe('getPullRequestBody', () => {
37
36
  })).toMatchInlineSnapshot(`
38
37
  "# Backport
39
38
 
40
- This is an automatic backport to 7.x of:
39
+ This is an automatic backport to \`7.x\` of:
41
40
  - My commit message (abcdefgh)
42
41
 
43
42
  ### Questions ?
44
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
45
- "
43
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
46
44
  `);
47
45
  });
48
46
  it('when multiple commits are backported', () => {
@@ -63,18 +61,70 @@ describe('getPullRequestBody', () => {
63
61
  })).toMatchInlineSnapshot(`
64
62
  "# Backport
65
63
 
66
- This is an automatic backport to 7.x of:
64
+ This is an automatic backport to \`7.x\` of:
65
+ - #55
66
+ - Another commit message (qwertyui)
67
+
68
+ ### Questions ?
69
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
70
+ `);
71
+ });
72
+ it('replaces template variables in PR description', () => {
73
+ expect((0, createPullRequest_1.getPullRequestBody)({
74
+ options: {
75
+ prDescription: 'Backporting the following to {targetBranch}:\n{commitMessages}',
76
+ },
77
+ commits: [
78
+ {
79
+ pullNumber: 55,
80
+ sha: 'abcdefghijklm',
81
+ originalMessage: 'My commit message',
82
+ },
83
+ {
84
+ sha: 'qwertyuiop',
85
+ originalMessage: 'Another commit message',
86
+ },
87
+ ],
88
+ targetBranch: '7.x',
89
+ })).toMatchInlineSnapshot(`
90
+ "Backporting the following to 7.x:
91
+ - #55
92
+ - Another commit message (qwertyui)"
93
+ `);
94
+ });
95
+ it('appends text to the default descriptions', () => {
96
+ expect((0, createPullRequest_1.getPullRequestBody)({
97
+ options: {
98
+ prDescription: '{defaultPrDescription}\n\ntext to append',
99
+ },
100
+ commits: [
101
+ {
102
+ pullNumber: 55,
103
+ sha: 'abcdefghijklm',
104
+ originalMessage: 'My commit message',
105
+ },
106
+ {
107
+ sha: 'qwertyuiop',
108
+ originalMessage: 'Another commit message',
109
+ },
110
+ ],
111
+ targetBranch: '7.x',
112
+ })).toMatchInlineSnapshot(`
113
+ "# Backport
114
+
115
+ This is an automatic backport to \`7.x\` of:
67
116
  - #55
68
117
  - Another commit message (qwertyui)
69
118
 
70
119
  ### Questions ?
71
120
  Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
72
- "
121
+
122
+ text to append"
73
123
  `);
74
124
  });
75
125
  });
76
126
  describe('getTitle', () => {
77
- it('when the default title is used', () => {
127
+ it('has the default title', () => {
78
128
  expect((0, createPullRequest_1.getTitle)({
79
129
  options: {},
80
130
  commits: [
@@ -92,7 +142,7 @@ describe('getTitle', () => {
92
142
  targetBranch: '7.x',
93
143
  })).toEqual('[7.x] My commit message | Another commit message');
94
144
  });
95
- it('when a custom PR title is used', () => {
145
+ it('replaces template variables in PR title', () => {
96
146
  expect((0, createPullRequest_1.getTitle)({
97
147
  options: {
98
148
  prTitle: 'Branch: "{targetBranch}". Messages: {commitMessages}',
@@ -1,4 +1,4 @@
1
- import { BackportResponse } from '../../../main';
1
+ import { BackportResponse } from '../../../backportRun';
2
2
  import { ValidConfigOptions } from '../../../options/options';
3
3
  export declare function createStatusComment({ options, backportResponse, }: {
4
4
  options: ValidConfigOptions;
@@ -8,4 +8,4 @@ export declare function getCommentBody({ options, pullNumber, backportResponse,
8
8
  options: ValidConfigOptions;
9
9
  pullNumber: number;
10
10
  backportResponse: BackportResponse;
11
- }): string;
11
+ }): string | undefined;
@@ -2,23 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCommentBody = exports.createStatusComment = void 0;
4
4
  const rest_1 = require("@octokit/rest");
5
+ const redact_1 = require("../../../utils/redact");
5
6
  const logger_1 = require("../../logger");
6
7
  const commitFormatters_1 = require("../commitFormatters");
7
8
  async function createStatusComment({ options, backportResponse, }) {
8
- const { githubApiBaseUrlV3, repoName, repoOwner, accessToken } = options;
9
+ const { githubApiBaseUrlV3, repoName, repoOwner, accessToken, publishStatusComment, } = options;
10
+ if (!publishStatusComment) {
11
+ return;
12
+ }
9
13
  try {
10
14
  const octokit = new rest_1.Octokit({
11
15
  auth: accessToken,
12
16
  baseUrl: githubApiBaseUrlV3,
13
17
  log: logger_1.logger,
14
18
  });
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
19
  await Promise.all(backportResponse.commits.map((commit) => {
23
20
  if (!commit.pullNumber) {
24
21
  return;
@@ -28,11 +25,16 @@ async function createStatusComment({ options, backportResponse, }) {
28
25
  pullNumber: commit.pullNumber,
29
26
  backportResponse,
30
27
  });
28
+ // only post comment if there is a body
29
+ if (!body) {
30
+ return;
31
+ }
31
32
  return octokit.issues.createComment({
33
+ baseUrl: options.githubApiBaseUrlV3,
32
34
  owner: repoOwner,
33
35
  repo: repoName,
34
36
  issue_number: commit.pullNumber,
35
- body,
37
+ body: (0, redact_1.redact)(options.accessToken, body),
36
38
  });
37
39
  }));
38
40
  }
@@ -43,6 +45,18 @@ async function createStatusComment({ options, backportResponse, }) {
43
45
  exports.createStatusComment = createStatusComment;
44
46
  function getCommentBody({ options, pullNumber, backportResponse, }) {
45
47
  const { repoName, repoOwner, autoMerge } = options;
48
+ // custom handling when running backport locally (as opposed to on CI)
49
+ if (!options.ci) {
50
+ // don't post comment when the overall process failed
51
+ if (backportResponse.status === 'failure') {
52
+ return;
53
+ }
54
+ // only post a comment if all backports succeeded
55
+ const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
56
+ if (!didAllBackportsSucceed) {
57
+ return;
58
+ }
59
+ }
46
60
  const backportPRCommand = `\n### How to fix\nRe-run the backport manually:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\``;
47
61
  const supportSection = '\n\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)';
48
62
  if (backportResponse.status === 'failure') {
@@ -52,6 +66,10 @@ The pull request could not be backported due to the following error:
52
66
  ${backportPRCommand}${supportSection}`;
53
67
  }
54
68
  const tableBody = backportResponse.results
69
+ .filter((result) => {
70
+ // only post status updates for successful backports when running manually (non-ci)
71
+ return options.ci || result.status === 'success';
72
+ })
55
73
  .map((result) => {
56
74
  if (result.status === 'success') {
57
75
  return [
@@ -60,7 +78,7 @@ ${backportPRCommand}${supportSection}`;
60
78
  `[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`,
61
79
  ];
62
80
  }
63
- if (result.error.meta?.type === 'commitsWithoutBackports') {
81
+ if (result.error.meta?.type === 'merge-conflict-due-to-missing-backports') {
64
82
  const conflictingPullRequests = result.error.meta.commitsWithoutBackports.map((c) => {
65
83
  return ` - [${(0, commitFormatters_1.getFirstLine)(c.commit.originalMessage)}](${c.commit.pullUrl})`;
66
84
  });
@@ -80,16 +98,23 @@ ${backportPRCommand}${supportSection}`;
80
98
  : '';
81
99
  const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
82
100
  const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
83
- const header = didAllBackportsSucceed
84
- ? '## 💚 All backports created successfully'
85
- : '## 💔 Some backports could not be created';
101
+ let header = '';
102
+ if (didAllBackportsSucceed) {
103
+ header = '## 💚 All backports created successfully';
104
+ }
105
+ else if (didAnyBackportsSucceed) {
106
+ header = '## 💔 Some backports could not be created';
107
+ }
108
+ else {
109
+ header = '## 💔 All backports failed';
110
+ }
86
111
  const autoMergeMessage = autoMerge && didAnyBackportsSucceed
87
112
  ? '\nNote: Successful backport PRs will be merged automatically after passing CI.'
88
113
  : '';
89
114
  const backportPRCommandMessage = !didAllBackportsSucceed
90
115
  ? `${backportPRCommand}`
91
116
  : '';
92
- return (0, logger_1.redactAccessToken)(`${header}\n\n${table}
93
- ${backportPRCommandMessage}${autoMergeMessage}${supportSection}`);
117
+ return `${header}\n\n${table}
118
+ ${backportPRCommandMessage}${autoMergeMessage}${supportSection}`;
94
119
  }
95
120
  exports.getCommentBody = getCommentBody;
@@ -1,40 +1,84 @@
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 nock_1 = __importDefault(require("nock"));
3
7
  const HandledError_1 = require("../../HandledError");
4
8
  const createStatusComment_1 = require("./createStatusComment");
9
+ describe('createStatusComment', () => {
10
+ it('redacts accessToken if it is included in the error message', async () => {
11
+ const accessToken = 'ghp_abcdefg';
12
+ const scope = (0, nock_1.default)('https://api.github.com')
13
+ .post('/repos/elastic/kibana/issues/100/comments')
14
+ .reply(200, 'some response');
15
+ let postedCommentBody = '';
16
+ scope.on('request', (req, interceptor, body) => {
17
+ postedCommentBody = JSON.parse(body).body;
18
+ });
19
+ await (0, createStatusComment_1.createStatusComment)({
20
+ options: {
21
+ repoName: 'kibana',
22
+ repoOwner: 'elastic',
23
+ accessToken,
24
+ backportBinary: 'node scripts/backport',
25
+ publishStatusComment: true,
26
+ githubApiBaseUrlV3: 'https://api.github.com',
27
+ ci: true,
28
+ },
29
+ backportResponse: {
30
+ commits: [{ pullNumber: 100 }],
31
+ status: 'failure',
32
+ errorMessage: `Error message containing very secret access token: ${accessToken}.`,
33
+ },
34
+ });
35
+ expect(postedCommentBody).toContain('Error message containing very secret access token: <REDACTED>');
36
+ scope.done();
37
+ nock_1.default.cleanAll();
38
+ });
39
+ });
5
40
  describe('getCommentBody', () => {
6
- it('when an unknown error occurs', () => {
7
- expect((0, createStatusComment_1.getCommentBody)({
41
+ describe('when an unknown error occurs', () => {
42
+ const getParams = (opts) => ({
8
43
  options: {
9
44
  backportBinary: 'node scripts/backport',
45
+ ...opts,
10
46
  },
11
47
  pullNumber: 55,
12
48
  backportResponse: {
13
49
  status: 'failure',
14
50
  errorMessage: 'A terrible error occured',
15
51
  },
16
- })).toMatchInlineSnapshot(`
17
- "## 💔 Backport failed
18
- The pull request could not be backported due to the following error:
19
- \`A terrible error occured\`
52
+ });
53
+ it('posts a comment when running on ci', () => {
54
+ const params = getParams({ ci: true });
55
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
56
+ "## 💔 Backport failed
57
+ The pull request could not be backported due to the following error:
58
+ \`A terrible error occured\`
20
59
 
21
- ## How to fix
60
+ ### How to fix
61
+ Re-run the backport manually:
62
+ \`\`\`
63
+ node scripts/backport --pr 55
64
+ \`\`\`
22
65
 
23
- Re-run the backport manually:
24
- \`\`\`
25
- node scripts/backport --pr 55
26
- \`\`\`
27
-
28
- ### Questions ?
29
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
30
- `);
66
+ ### Questions ?
67
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
68
+ `);
69
+ });
70
+ it('does not post a comment when running manually', () => {
71
+ const params = getParams({ ci: false });
72
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
73
+ });
31
74
  });
32
- it('when all backports succeed', () => {
33
- expect((0, createStatusComment_1.getCommentBody)({
75
+ describe('when all backports succeed', () => {
76
+ const getParams = (opts) => ({
34
77
  options: {
35
78
  repoName: 'kibana',
36
79
  repoOwner: 'elastic',
37
80
  autoMerge: true,
81
+ ...opts,
38
82
  },
39
83
  pullNumber: 55,
40
84
  backportResponse: {
@@ -54,27 +98,48 @@ describe('getCommentBody', () => {
54
98
  },
55
99
  ],
56
100
  },
57
- })).toMatchInlineSnapshot(`
58
- "## 💚 All backports created successfully
101
+ });
102
+ it('posts a comment on ci', () => {
103
+ const params = getParams({ ci: true });
104
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
105
+ "## 💚 All backports created successfully
106
+
107
+ | Status | Branch | Result |
108
+ |:------:|:------:|:------|
109
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
110
+ |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
111
+
112
+ Note: Successful backport PRs will be merged automatically after passing CI.
59
113
 
60
- | Status | Branch | Result |
61
- |:------:|:------:|:------|
62
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
63
- |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
114
+ ### Questions ?
115
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
116
+ `);
117
+ });
118
+ it('posts a comment when running locally', () => {
119
+ const params = getParams({ ci: false });
120
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
121
+ "## 💚 All backports created successfully
64
122
 
65
- Note: Successful backport PRs will be merged automatically after passing CI.
123
+ | Status | Branch | Result |
124
+ |:------:|:------:|:------|
125
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
126
+ |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
66
127
 
67
- ### Questions ?
68
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
69
- `);
128
+ Note: Successful backport PRs will be merged automatically after passing CI.
129
+
130
+ ### Questions ?
131
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
132
+ `);
133
+ });
70
134
  });
71
- it('when all backports fail', () => {
72
- expect((0, createStatusComment_1.getCommentBody)({
135
+ describe('when all backports fail', () => {
136
+ const getParams = (opts) => ({
73
137
  options: {
74
138
  repoName: 'kibana',
75
139
  repoOwner: 'elastic',
76
140
  autoMerge: true,
77
141
  backportBinary: 'node scripts/backport',
142
+ ...opts,
78
143
  },
79
144
  pullNumber: 55,
80
145
  backportResponse: {
@@ -94,32 +159,40 @@ describe('getCommentBody', () => {
94
159
  },
95
160
  ],
96
161
  },
97
- })).toMatchInlineSnapshot(`
98
- "## 💔 Some backports could not be created
99
-
100
- | Status | Branch | Result |
101
- |:------:|:------:|:------|
102
- |❌|7.x|My boom error!|
103
- |❌|7.1|My boom error!|
162
+ });
163
+ it('posts a comment on CI', () => {
164
+ const params = getParams({ ci: true });
165
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
166
+ "## 💔 All backports failed
104
167
 
105
- ## How to fix
168
+ | Status | Branch | Result |
169
+ |:------:|:------:|:------|
170
+ |❌|7.x|My boom error!|
171
+ |❌|7.1|My boom error!|
106
172
 
107
- Re-run the backport manually:
108
- \`\`\`
109
- node scripts/backport --pr 55
110
- \`\`\`
173
+ ### How to fix
174
+ Re-run the backport manually:
175
+ \`\`\`
176
+ node scripts/backport --pr 55
177
+ \`\`\`
111
178
 
112
- ### Questions ?
113
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
114
- `);
179
+ ### Questions ?
180
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
181
+ `);
182
+ });
183
+ it('does not post a comment when running manaully', () => {
184
+ const params = getParams({ ci: false });
185
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
186
+ });
115
187
  });
116
- it('when some backports fail', () => {
117
- expect((0, createStatusComment_1.getCommentBody)({
188
+ describe('when some backports fail', () => {
189
+ const getParams = (opts) => ({
118
190
  options: {
119
191
  repoName: 'kibana',
120
192
  repoOwner: 'elastic',
121
193
  autoMerge: true,
122
194
  backportBinary: 'node scripts/backport',
195
+ ...opts,
123
196
  },
124
197
  pullNumber: 55,
125
198
  backportResponse: {
@@ -139,33 +212,41 @@ describe('getCommentBody', () => {
139
212
  },
140
213
  ],
141
214
  },
142
- })).toMatchInlineSnapshot(`
143
- "## 💔 Some backports could not be created
215
+ });
216
+ it('post a comment when running on CI', () => {
217
+ const params = getParams({ ci: true });
218
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
219
+ "## 💔 Some backports could not be created
144
220
 
145
- | Status | Branch | Result |
146
- |:------:|:------:|:------|
147
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
148
- |❌|7.1|My boom error!|
221
+ | Status | Branch | Result |
222
+ |:------:|:------:|:------|
223
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
224
+ |❌|7.1|My boom error!|
149
225
 
150
- ## How to fix
226
+ ### How to fix
227
+ Re-run the backport manually:
228
+ \`\`\`
229
+ node scripts/backport --pr 55
230
+ \`\`\`
231
+ Note: Successful backport PRs will be merged automatically after passing CI.
151
232
 
152
- Re-run the backport manually:
153
- \`\`\`
154
- node scripts/backport --pr 55
155
- \`\`\`
156
- Note: Successful backport PRs will be merged automatically after passing CI.
157
-
158
- ### Questions ?
159
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
160
- `);
233
+ ### Questions ?
234
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
235
+ `);
236
+ });
237
+ it('does not post a comment when running manually because some backports failed', () => {
238
+ const params = getParams({ ci: false });
239
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
240
+ });
161
241
  });
162
- it('when some backports fail due to conflicts', () => {
163
- expect((0, createStatusComment_1.getCommentBody)({
242
+ describe('when some backports fail due to conflicts', () => {
243
+ const getParams = (opts) => ({
164
244
  options: {
165
245
  repoName: 'kibana',
166
246
  repoOwner: 'elastic',
167
247
  autoMerge: true,
168
248
  backportBinary: 'node scripts/backport',
249
+ ...opts,
169
250
  },
170
251
  pullNumber: 55,
171
252
  backportResponse: {
@@ -182,7 +263,7 @@ describe('getCommentBody', () => {
182
263
  targetBranch: '7.1',
183
264
  errorMessage: 'My boom error!',
184
265
  error: new HandledError_1.HandledError('Boom!', {
185
- type: 'commitsWithoutBackports',
266
+ type: 'merge-conflict-due-to-missing-backports',
186
267
  commitsWithoutBackports: [
187
268
  {
188
269
  //@ts-expect-error
@@ -208,31 +289,38 @@ describe('getCommentBody', () => {
208
289
  targetBranch: '7.2',
209
290
  errorMessage: 'My boom error!',
210
291
  error: new HandledError_1.HandledError('Boom!', {
211
- type: 'commitsWithoutBackports',
292
+ type: 'merge-conflict-due-to-missing-backports',
212
293
  commitsWithoutBackports: [],
213
294
  }),
214
295
  },
215
296
  ],
216
297
  },
217
- })).toMatchInlineSnapshot(`
218
- "## 💔 Some backports could not be created
219
-
220
- | Status | Branch | Result |
221
- |:------:|:------:|:------|
222
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
223
- |❌|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)|
224
- |❌|7.2|**Backport failed because of merge conflicts**|
225
-
226
- ## How to fix
227
-
228
- Re-run the backport manually:
229
- \`\`\`
230
- node scripts/backport --pr 55
231
- \`\`\`
232
- Note: Successful backport PRs will be merged automatically after passing CI.
233
-
234
- ### Questions ?
235
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
236
- `);
298
+ });
299
+ it('posts a comment when running on CI', () => {
300
+ const params = getParams({ ci: true });
301
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
302
+ "## 💔 Some backports could not be created
303
+
304
+ | Status | Branch | Result |
305
+ |:------:|:------:|:------|
306
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
307
+ |❌|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)|
308
+ |❌|7.2|**Backport failed because of merge conflicts**|
309
+
310
+ ### How to fix
311
+ Re-run the backport manually:
312
+ \`\`\`
313
+ node scripts/backport --pr 55
314
+ \`\`\`
315
+ Note: Successful backport PRs will be merged automatically after passing CI.
316
+
317
+ ### Questions ?
318
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
319
+ `);
320
+ });
321
+ it('does not post a comment when running manually because some backports failed', () => {
322
+ const params = getParams({ ci: false });
323
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
324
+ });
237
325
  });
238
326
  });