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
@@ -22,11 +22,12 @@ 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
- exports.initLogger = exports.redactAccessToken = exports.updateLogger = exports.logger = exports.consoleLog = void 0;
25
+ exports.initLogger = exports.updateLogger = exports.logger = exports.consoleLog = void 0;
26
26
  const dedent_1 = __importDefault(require("dedent"));
27
27
  const lodash_1 = require("lodash");
28
28
  const safe_json_stringify_1 = __importDefault(require("safe-json-stringify"));
29
29
  const winston_1 = __importStar(require("winston"));
30
+ const redact_1 = require("../utils/redact");
30
31
  const env_1 = require("./env");
31
32
  const { combine } = winston_1.format;
32
33
  let winstonInstance;
@@ -68,11 +69,10 @@ exports.updateLogger = updateLogger;
68
69
  function redactAccessToken(str) {
69
70
  // `redactAccessToken` might be called before access token is set
70
71
  if (accessToken) {
71
- return str.replace(new RegExp(accessToken, 'g'), '<REDACTED>');
72
+ return (0, redact_1.redact)(accessToken, str);
72
73
  }
73
74
  return str;
74
75
  }
75
- exports.redactAccessToken = redactAccessToken;
76
76
  function initLogger() {
77
77
  winstonInstance = winston_1.default.createLogger({
78
78
  transports: [
@@ -0,0 +1,2 @@
1
+ import { ValidConfigOptions } from '../options/options';
2
+ export declare function maybeSetupRepo(options: ValidConfigOptions): Promise<void>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maybeSetupRepo = void 0;
4
+ const git_1 = require("../services/git");
5
+ async function maybeSetupRepo(options) {
6
+ const isAlreadyCloned = await (0, git_1.repoExists)(options);
7
+ // clone repo if folder does not already exists
8
+ if (!isAlreadyCloned) {
9
+ try {
10
+ const spinnerCloneText = 'Cloning repository (one-time operation)';
11
+ // spinner.text = `0% ${spinnerCloneText}`;
12
+ // await cloneRepo(options, (progress: string) => {
13
+ // spinner.text = `${progress}% ${spinnerCloneText}`;
14
+ // });
15
+ // spinner.succeed(`100% ${spinnerCloneText}`);
16
+ }
17
+ catch (e) {
18
+ await (0, git_1.deleteRepo)(options);
19
+ throw e;
20
+ }
21
+ }
22
+ // delete default "origin" remote to avoid confusion
23
+ await (0, git_1.deleteRemote)(options, 'origin');
24
+ // ensure remote are setup with latest accessToken
25
+ await (0, git_1.deleteRemote)(options, options.authenticatedUsername);
26
+ await (0, git_1.addRemote)(options, options.authenticatedUsername);
27
+ // update remote for origin (if the above is a fork)
28
+ if (options.authenticatedUsername !== options.repoOwner) {
29
+ await (0, git_1.deleteRemote)(options, options.repoOwner);
30
+ await (0, git_1.addRemote)(options, options.repoOwner);
31
+ }
32
+ }
33
+ exports.maybeSetupRepo = maybeSetupRepo;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,78 @@
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 os_1 = __importDefault(require("os"));
26
+ const del_1 = __importDefault(require("del"));
27
+ const childProcess = __importStar(require("../services/child-process-promisified"));
28
+ const fs = __importStar(require("../services/fs-promisified"));
29
+ const maybeSetupRepo_1 = require("./maybeSetupRepo");
30
+ describe('maybeSetupRepo', () => {
31
+ let execSpy;
32
+ beforeEach(() => {
33
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
34
+ execSpy = jest
35
+ .spyOn(childProcess, 'exec')
36
+ .mockResolvedValue({ stderr: '', stdout: '' });
37
+ });
38
+ it('should delete repo if an error occurs', async () => {
39
+ expect.assertions(2);
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');
47
+ });
48
+ await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
49
+ accessToken: 'myAccessToken',
50
+ gitHostname: 'github.com',
51
+ repoName: 'kibana',
52
+ repoOwner: 'elastic',
53
+ })).rejects.toThrowError('Simulated git clone failure');
54
+ expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana');
55
+ });
56
+ describe('if repo already exists', () => {
57
+ beforeEach(() => {
58
+ // @ts-expect-error
59
+ jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
60
+ });
61
+ it('should re-create remotes for both source repo and fork', async () => {
62
+ await (0, maybeSetupRepo_1.maybeSetupRepo)({
63
+ accessToken: 'myAccessToken',
64
+ authenticatedUsername: 'sqren_authenticated',
65
+ gitHostname: 'github.com',
66
+ repoName: 'kibana',
67
+ repoOwner: 'elastic',
68
+ });
69
+ expect(execSpy.mock.calls.map(([cmd]) => cmd)).toEqual([
70
+ 'git remote rm origin',
71
+ 'git remote rm sqren_authenticated',
72
+ 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
73
+ 'git remote rm elastic',
74
+ 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
75
+ ]);
76
+ });
77
+ });
78
+ });
@@ -5,5 +5,9 @@ export declare type ExpectedTargetPullRequest = {
5
5
  number?: number;
6
6
  branch: string;
7
7
  state: 'OPEN' | 'CLOSED' | 'MERGED' | 'MISSING';
8
+ mergeCommit?: {
9
+ sha: string;
10
+ message: string;
11
+ };
8
12
  };
9
13
  export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
@@ -34,9 +34,9 @@ function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
34
34
  // at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
35
35
  const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
36
36
  const { targetCommit } = commitEdge.node;
37
- const matchingRepoName = sourceCommit.repository.name === targetCommit.repository.name;
37
+ const matchingRepoName = sourceCommit.repository.name === targetPullRequest.repository.name;
38
38
  const matchingRepoOwner = sourceCommit.repository.owner.login ===
39
- targetCommit.repository.owner.login;
39
+ targetPullRequest.repository.owner.login;
40
40
  const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
41
41
  const matchingMessage = targetCommitMessage === sourceCommitMessage;
42
42
  return matchingRepoName && matchingRepoOwner && matchingMessage;
@@ -52,6 +52,12 @@ function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
52
52
  number: targetPullRequest.number,
53
53
  branch: targetPullRequest.baseRefName,
54
54
  state: targetPullRequest.state,
55
+ mergeCommit: targetPullRequest.targetMergeCommit
56
+ ? {
57
+ sha: targetPullRequest.targetMergeCommit.oid,
58
+ message: targetPullRequest.targetMergeCommit.message,
59
+ }
60
+ : undefined,
55
61
  };
56
62
  });
57
63
  }
@@ -40,6 +40,10 @@ describe('getExpectedTargetPullRequests', () => {
40
40
  state: 'MERGED',
41
41
  number: 5678,
42
42
  url: 'https://github.com/elastic/kibana/pull/5678',
43
+ mergeCommit: {
44
+ message: 'identical messages (#1234)',
45
+ sha: 'target-merge-commit-sha',
46
+ },
43
47
  },
44
48
  ]);
45
49
  });
@@ -122,6 +126,10 @@ describe('getExpectedTargetPullRequests', () => {
122
126
  state: 'MERGED',
123
127
  number: 5678,
124
128
  url: 'https://github.com/elastic/kibana/pull/5678',
129
+ mergeCommit: {
130
+ message: 'message two (#1234)',
131
+ sha: 'target-merge-commit-sha',
132
+ },
125
133
  },
126
134
  ]);
127
135
  });
@@ -168,6 +176,10 @@ describe('getExpectedTargetPullRequests', () => {
168
176
  state: 'MERGED',
169
177
  number: 5678,
170
178
  url: 'https://github.com/elastic/kibana/pull/5678',
179
+ mergeCommit: {
180
+ message: 'message one (#1234)\n\nsomething else',
181
+ sha: 'target-merge-commit-sha',
182
+ },
171
183
  },
172
184
  ]);
173
185
  });
@@ -218,6 +230,10 @@ describe('getExpectedTargetPullRequests', () => {
218
230
  state: 'MERGED',
219
231
  number: 5678,
220
232
  url: 'https://github.com/elastic/kibana/pull/5678',
233
+ mergeCommit: {
234
+ message: 'identical messages (#1234)',
235
+ sha: 'target-merge-commit-sha',
236
+ },
221
237
  },
222
238
  { branch: '7.1', state: 'MISSING' },
223
239
  ]);
@@ -404,6 +420,10 @@ describe('getExpectedTargetPullRequests', () => {
404
420
  number: 5678,
405
421
  state: 'MERGED',
406
422
  url: 'https://github.com/elastic/kibana/pull/5678',
423
+ mergeCommit: {
424
+ message: 'identical messages (#1234)',
425
+ sha: 'target-merge-commit-sha',
426
+ },
407
427
  },
408
428
  { branch: 'branch-1', state: 'MISSING' },
409
429
  { branch: 'branch-2', state: 'MISSING' },
@@ -1,6 +1,7 @@
1
1
  import { SourceCommitWithTargetPullRequest } from './parseSourceCommit';
2
2
  export declare function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems, }: {
3
3
  sourceCommit: {
4
+ sha?: string;
4
5
  message: string;
5
6
  commitedDate?: string;
6
7
  };
@@ -2,65 +2,91 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMockSourceCommit = void 0;
4
4
  function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems = [], }) {
5
+ const defaultTargetPullRequestTitle = 'DO NOT USE: Default Pull Request Title';
6
+ const defaultSourceCommitSha = 'DO NOT USE: default-source-commit-sha';
7
+ const baseMockCommit = {
8
+ repository: {
9
+ name: 'kibana',
10
+ owner: { login: 'elastic' },
11
+ },
12
+ committedDate: sourceCommit.commitedDate ?? '2021-12-22T00:00:00Z',
13
+ oid: sourceCommit.sha ?? defaultSourceCommitSha,
14
+ message: sourceCommit.message,
15
+ };
16
+ if (!sourcePullRequest) {
17
+ return {
18
+ ...baseMockCommit,
19
+ associatedPullRequests: {
20
+ edges: null,
21
+ },
22
+ };
23
+ }
5
24
  return {
6
25
  repository: {
7
26
  name: 'kibana',
8
27
  owner: { login: 'elastic' },
9
28
  },
10
29
  committedDate: sourceCommit.commitedDate ?? '2021-12-22T00:00:00Z',
11
- oid: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
30
+ oid: sourceCommit.sha ?? defaultSourceCommitSha,
12
31
  message: sourceCommit.message,
13
32
  associatedPullRequests: {
14
- edges: !sourcePullRequest
15
- ? null
16
- : [
17
- {
18
- node: {
19
- url: `https://github.com/elastic/kibana/pull/${sourcePullRequest.number}`,
20
- labels: {
21
- nodes: (sourcePullRequest.labels ?? []).map((name) => ({
22
- name,
23
- })),
24
- },
25
- baseRefName: sourcePullRequest.sourceBranch ??
26
- 'source-branch-from-associated-pull-request',
27
- number: sourcePullRequest.number,
28
- timelineItems: {
29
- edges: timelineItems.map((timelineItem) => {
30
- return {
31
- node: {
32
- targetPullRequest: {
33
- __typename: 'PullRequest',
34
- url: `https://github.com/elastic/kibana/pull/${timelineItem.number}`,
35
- title: timelineItem.title ?? 'Default PR title (#123)',
36
- number: timelineItem.number,
37
- state: timelineItem.state,
38
- baseRefName: timelineItem.targetBranch,
39
- commits: {
40
- edges: timelineItem.commitMessages.map((message) => ({
41
- node: {
42
- targetCommit: {
43
- repository: {
44
- name: timelineItem.repoName ?? 'kibana',
45
- owner: {
46
- login: timelineItem.repoOwner ?? 'elastic',
47
- },
48
- },
49
- committedDate: '2021-12-23T00:00:00Z',
50
- oid: 'abc',
51
- message: message,
52
- },
53
- },
54
- })),
33
+ edges: [
34
+ {
35
+ node: {
36
+ sourceMergeCommit: {
37
+ oid: sourceCommit.sha ?? defaultSourceCommitSha,
38
+ message: sourceCommit.message,
39
+ },
40
+ url: `https://github.com/elastic/kibana/pull/${sourcePullRequest.number}`,
41
+ labels: {
42
+ nodes: (sourcePullRequest.labels ?? []).map((name) => ({
43
+ name,
44
+ })),
45
+ },
46
+ baseRefName: sourcePullRequest.sourceBranch ??
47
+ 'source-branch-from-associated-pull-request',
48
+ number: sourcePullRequest.number,
49
+ timelineItems: {
50
+ edges: timelineItems.map((timelineItem) => {
51
+ return {
52
+ node: {
53
+ targetPullRequest: {
54
+ __typename: 'PullRequest',
55
+ url: `https://github.com/elastic/kibana/pull/${timelineItem.number}`,
56
+ title: timelineItem.title ?? defaultTargetPullRequestTitle,
57
+ number: timelineItem.number,
58
+ state: timelineItem.state,
59
+ baseRefName: timelineItem.targetBranch,
60
+ targetMergeCommit: timelineItem.state === 'MERGED'
61
+ ? {
62
+ message: timelineItem.commitMessages[0],
63
+ oid: 'target-merge-commit-sha',
64
+ }
65
+ : null,
66
+ repository: {
67
+ name: timelineItem.repoName ?? 'kibana',
68
+ owner: {
69
+ login: timelineItem.repoOwner ?? 'elastic',
55
70
  },
56
71
  },
72
+ commits: {
73
+ edges: timelineItem.commitMessages.map((message) => ({
74
+ node: {
75
+ targetCommit: {
76
+ oid: 'abc',
77
+ message: message,
78
+ },
79
+ },
80
+ })),
81
+ },
57
82
  },
58
- };
59
- }),
60
- },
83
+ },
84
+ };
85
+ }),
61
86
  },
62
87
  },
63
- ],
88
+ },
89
+ ],
64
90
  },
65
91
  };
66
92
  }
@@ -9,7 +9,7 @@ export interface Commit {
9
9
  pullUrl?: string;
10
10
  expectedTargetPullRequests: ExpectedTargetPullRequest[];
11
11
  }
12
- export interface PullRequestNode {
12
+ export interface SourcePullRequestNode {
13
13
  baseRefName: string;
14
14
  url: string;
15
15
  number: number;
@@ -18,8 +18,12 @@ export interface PullRequestNode {
18
18
  name: string;
19
19
  }[];
20
20
  };
21
+ sourceMergeCommit: {
22
+ oid: string;
23
+ message: string;
24
+ };
21
25
  timelineItems: {
22
- edges: Array<TimelineEdge>;
26
+ edges: TimelineEdge[];
23
27
  };
24
28
  }
25
29
  export declare type TimelineEdge = TimelinePullRequestEdge | TimelineIssueEdge;
@@ -32,10 +36,23 @@ export interface TimelinePullRequestEdge {
32
36
  state: 'OPEN' | 'CLOSED' | 'MERGED';
33
37
  baseRefName: string;
34
38
  number: number;
39
+ targetMergeCommit: {
40
+ oid: string;
41
+ message: string;
42
+ } | null;
43
+ repository: {
44
+ name: string;
45
+ owner: {
46
+ login: string;
47
+ };
48
+ };
35
49
  commits: {
36
50
  edges: Array<{
37
51
  node: {
38
- targetCommit: InnerCommitNode;
52
+ targetCommit: {
53
+ message: string;
54
+ oid: string;
55
+ };
39
56
  };
40
57
  }>;
41
58
  };
@@ -49,7 +66,7 @@ interface TimelineIssueEdge {
49
66
  };
50
67
  };
51
68
  }
52
- declare type InnerCommitNode = {
69
+ export declare type SourceCommitWithTargetPullRequest = {
53
70
  repository: {
54
71
  name: string;
55
72
  owner: {
@@ -59,11 +76,9 @@ declare type InnerCommitNode = {
59
76
  oid: string;
60
77
  message: string;
61
78
  committedDate: string;
62
- };
63
- export declare type SourceCommitWithTargetPullRequest = InnerCommitNode & {
64
79
  associatedPullRequests: {
65
80
  edges: {
66
- node: PullRequestNode;
81
+ node: SourcePullRequestNode;
67
82
  }[] | null;
68
83
  };
69
84
  };
@@ -76,7 +91,6 @@ export declare function parseSourceCommit({ sourceCommit, options, }: {
76
91
  };
77
92
  }): Commit;
78
93
  export declare const sourceCommitWithTargetPullRequestFragment: {
79
- name: string;
80
94
  source: string;
81
95
  };
82
96
  export {};
@@ -6,7 +6,9 @@ const commitFormatters_1 = require("../github/commitFormatters");
6
6
  const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
7
7
  function parseSourceCommit({ sourceCommit, options, }) {
8
8
  const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
9
- const commitMessage = sourceCommit.message;
9
+ // use info from associated pull request if available. Fall back to commit info
10
+ const commitMessage = sourcePullRequest?.sourceMergeCommit.message ?? sourceCommit.message;
11
+ const commitSha = sourcePullRequest?.sourceMergeCommit.oid ?? sourceCommit.oid;
10
12
  const pullNumber = sourcePullRequest?.number ?? (0, commitFormatters_1.extractPullNumber)(commitMessage);
11
13
  const sourceBranch = sourcePullRequest?.baseRefName ?? options.sourceBranch;
12
14
  const branchLabelMapping = getBranchLabelMappingForCommit(sourceCommit, options.branchLabelMapping, options.historicalBranchLabelMappings);
@@ -14,7 +16,7 @@ function parseSourceCommit({ sourceCommit, options, }) {
14
16
  return {
15
17
  committedDate: sourceCommit.committedDate,
16
18
  sourceBranch,
17
- sha: sourceCommit.oid,
19
+ sha: commitSha,
18
20
  originalMessage: commitMessage,
19
21
  pullNumber,
20
22
  pullUrl: sourcePullRequest?.url,
@@ -23,9 +25,9 @@ function parseSourceCommit({ sourceCommit, options, }) {
23
25
  }
24
26
  exports.parseSourceCommit = parseSourceCommit;
25
27
  exports.sourceCommitWithTargetPullRequestFragment = {
26
- name: 'SourceCommitWithTargetPullRequest',
27
28
  source: /* GraphQL */ `
28
- fragment InnerCommitNode on Commit {
29
+ fragment SourceCommitWithTargetPullRequest on Commit {
30
+ # Source Commit
29
31
  repository {
30
32
  name
31
33
  owner {
@@ -35,14 +37,11 @@ exports.sourceCommitWithTargetPullRequestFragment = {
35
37
  oid
36
38
  message
37
39
  committedDate
38
- }
39
40
 
40
- fragment SourceCommitWithTargetPullRequest on Commit {
41
- ...InnerCommitNode
41
+ # Source pull request: PR where source commit was merged in
42
42
  associatedPullRequests(first: 1) {
43
43
  edges {
44
44
  node {
45
- # Source PR
46
45
  url
47
46
  number
48
47
  labels(first: 50) {
@@ -51,6 +50,14 @@ exports.sourceCommitWithTargetPullRequestFragment = {
51
50
  }
52
51
  }
53
52
  baseRefName
53
+
54
+ # source merge commit (the commit that actually went into the source branch)
55
+ sourceMergeCommit: mergeCommit {
56
+ oid
57
+ message
58
+ }
59
+
60
+ # (possible) backport pull requests referenced in the source pull request
54
61
  timelineItems(last: 20, itemTypes: CROSS_REFERENCED_EVENT) {
55
62
  edges {
56
63
  node {
@@ -58,8 +65,19 @@ exports.sourceCommitWithTargetPullRequestFragment = {
58
65
  targetPullRequest: source {
59
66
  __typename
60
67
 
61
- # Target PRs
68
+ # Target PRs (backport PRs)
62
69
  ... on PullRequest {
70
+ # target merge commit: the backport commit that was merged into the target branch
71
+ targetMergeCommit: mergeCommit {
72
+ oid
73
+ message
74
+ }
75
+ repository {
76
+ name
77
+ owner {
78
+ login
79
+ }
80
+ }
63
81
  url
64
82
  title
65
83
  state
@@ -69,7 +87,8 @@ exports.sourceCommitWithTargetPullRequestFragment = {
69
87
  edges {
70
88
  node {
71
89
  targetCommit: commit {
72
- ...InnerCommitNode
90
+ message
91
+ oid
73
92
  }
74
93
  }
75
94
  }
@@ -96,6 +96,10 @@ describe('parseSourceCommit', () => {
96
96
  number: 5678,
97
97
  state: 'MERGED',
98
98
  url: 'https://github.com/elastic/kibana/pull/5678',
99
+ mergeCommit: {
100
+ message: 'My commit message (#66)',
101
+ sha: 'target-merge-commit-sha',
102
+ },
99
103
  },
100
104
  {
101
105
  branch: '6.2',
@@ -170,7 +174,7 @@ describe('parseSourceCommit', () => {
170
174
  });
171
175
  it('returns the correct source commit', () => {
172
176
  const mockSourceCommit = (0, getMockSourceCommit_1.getMockSourceCommit)({
173
- sourceCommit: { message: 'My commit message (#1234)' },
177
+ sourceCommit: { message: 'My commit message (#1234)', sha: 'my-sha' },
174
178
  sourcePullRequest: {
175
179
  number: 1234,
176
180
  labels: ['v6.3.0', 'v6.2.0', 'v6.1.0'],
@@ -207,6 +211,10 @@ describe('parseSourceCommit', () => {
207
211
  number: 5678,
208
212
  state: 'MERGED',
209
213
  url: 'https://github.com/elastic/kibana/pull/5678',
214
+ mergeCommit: {
215
+ message: 'My commit message (#1234)',
216
+ sha: 'target-merge-commit-sha',
217
+ },
210
218
  },
211
219
  {
212
220
  branch: '6.2',
@@ -222,7 +230,7 @@ describe('parseSourceCommit', () => {
222
230
  originalMessage: 'My commit message (#1234)',
223
231
  pullNumber: 1234,
224
232
  pullUrl: 'https://github.com/elastic/kibana/pull/1234',
225
- sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
233
+ sha: 'my-sha',
226
234
  sourceBranch: 'source-branch-from-associated-pull-request',
227
235
  });
228
236
  });
@@ -0,0 +1 @@
1
+ export {};