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
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
4
+ const fetchRemoteProjectConfig_1 = require("./fetchRemoteProjectConfig");
5
+ describe('fetchRemoteProjectConfig', () => {
6
+ let devAccessToken;
7
+ beforeEach(async () => {
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ it('returns the backport config from "main" branch', async () => {
11
+ const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
12
+ repoOwner: 'backport-org',
13
+ repoName: 'repo-with-project-config',
14
+ accessToken: devAccessToken,
15
+ sourceBranch: 'main',
16
+ });
17
+ expect(projectConfig).toEqual({
18
+ autoMerge: true,
19
+ autoMergeMethod: 'squash',
20
+ branchLabelMapping: {
21
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
22
+ '^v8.1.0$': 'main',
23
+ },
24
+ targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
25
+ targetPRLabels: ['backport'],
26
+ repoOwner: 'backport-org',
27
+ repoName: 'repo-with-project-config',
28
+ });
29
+ });
30
+ it('returns the backport config from "branch-with-legacy-config" branch', async () => {
31
+ const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
32
+ repoOwner: 'backport-org',
33
+ repoName: 'repo-with-project-config',
34
+ accessToken: devAccessToken,
35
+ sourceBranch: 'branch-with-legacy-config',
36
+ });
37
+ expect(projectConfig).toEqual({
38
+ targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
39
+ repoOwner: 'backport-org',
40
+ repoName: 'repo-with-project-config',
41
+ });
42
+ });
43
+ it('throws an error if config does not exist', async () => {
44
+ const promise = (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
45
+ repoOwner: 'backport-org',
46
+ repoName: 'repo-with-project-config',
47
+ accessToken: devAccessToken,
48
+ sourceBranch: 'branch-with-no-config',
49
+ });
50
+ await expect(promise).rejects.toThrowError('Project config does not exist');
51
+ });
52
+ });
@@ -32,12 +32,15 @@ export declare function getOptionsFromGithub(options: {
32
32
  cherrypickRef?: boolean | undefined;
33
33
  ci?: boolean | undefined;
34
34
  commitPaths?: string[] | undefined;
35
+ configFile?: string | undefined;
35
36
  details?: boolean | undefined;
37
+ dir?: string | undefined;
36
38
  editor?: string | undefined;
37
39
  fork?: boolean | undefined;
38
40
  gitHostname?: string | undefined;
39
41
  githubApiBaseUrlV3?: string | undefined;
40
42
  githubApiBaseUrlV4?: string | undefined;
43
+ logFilePath?: string | undefined;
41
44
  maxNumber?: number | undefined;
42
45
  multiple?: boolean | undefined;
43
46
  multipleBranches?: boolean | undefined;
@@ -46,6 +49,7 @@ export declare function getOptionsFromGithub(options: {
46
49
  prDescription?: string | undefined;
47
50
  prFilter?: string | undefined;
48
51
  prTitle?: string | undefined;
52
+ publishStatusComment?: boolean | undefined;
49
53
  pullNumber?: number | undefined;
50
54
  repoName?: string | undefined;
51
55
  repoOwner?: string | undefined;
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getOptionsFromGithub = void 0;
7
- const ora_1 = __importDefault(require("ora"));
8
4
  const readConfigFile_1 = require("../../../../options/config/readConfigFile");
9
5
  const filterEmpty_1 = require("../../../../utils/filterEmpty");
10
6
  const HandledError_1 = require("../../../HandledError");
@@ -16,7 +12,6 @@ const query_1 = require("./query");
16
12
  async function getOptionsFromGithub(options) {
17
13
  const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
18
14
  let res;
19
- const spinner = (0, ora_1.default)().start('Initializing...');
20
15
  try {
21
16
  res = await (0, apiRequestV4_1.apiRequestV4)({
22
17
  githubApiBaseUrlV4,
@@ -25,10 +20,8 @@ async function getOptionsFromGithub(options) {
25
20
  variables: { repoOwner, repoName },
26
21
  handleError: false,
27
22
  });
28
- spinner.stop();
29
23
  }
30
24
  catch (e) {
31
- spinner.stop();
32
25
  const error = e;
33
26
  (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
34
27
  error,
@@ -40,6 +40,10 @@ exports.commitsByAuthorMock = {
40
40
  nodes: [{ name: 'my-label-b' }],
41
41
  },
42
42
  number: 85,
43
+ sourceMergeCommit: {
44
+ oid: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
45
+ message: 'Add witch (#85)',
46
+ },
43
47
  timelineItems: {
44
48
  edges: [],
45
49
  },
@@ -68,12 +72,24 @@ exports.commitsByAuthorMock = {
68
72
  },
69
73
  baseRefName: 'master',
70
74
  number: 80,
75
+ sourceMergeCommit: {
76
+ oid: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
77
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
78
+ },
71
79
  timelineItems: {
72
80
  edges: [
73
81
  {
74
82
  node: {
75
83
  targetPullRequest: {
76
84
  __typename: 'PullRequest',
85
+ targetMergeCommit: {
86
+ oid: 'target-merge-commit-sha',
87
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
88
+ },
89
+ repository: {
90
+ name: 'kibana',
91
+ owner: { login: 'elastic' },
92
+ },
77
93
  url: 'https://github.com/elastic/kibana/pull/99',
78
94
  title: 'some title',
79
95
  state: 'MERGED',
@@ -84,11 +100,6 @@ exports.commitsByAuthorMock = {
84
100
  {
85
101
  node: {
86
102
  targetCommit: {
87
- repository: {
88
- name: 'kibana',
89
- owner: { login: 'elastic' },
90
- },
91
- committedDate: '2021-12-23T00:00:00Z',
92
103
  oid: 'abc',
93
104
  message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
94
105
  },
@@ -9,8 +9,10 @@ export declare const logger: {
9
9
  debug: (message: string, meta?: unknown) => void;
10
10
  };
11
11
  export declare function updateLogger(options: ConfigFileOptions): void;
12
- export declare function redactAccessToken(str: string): string;
13
- export declare function initLogger(): {
12
+ export declare function initLogger({ ci, logFilePath, }: {
13
+ ci?: boolean;
14
+ logFilePath?: string;
15
+ }): {
14
16
  error: (message: string, meta?: unknown) => void;
15
17
  warn: (message: string, meta?: unknown) => void;
16
18
  info: (message: string, meta?: unknown) => void;
@@ -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;
@@ -59,46 +60,21 @@ function updateLogger(options) {
59
60
  accessToken = options.accessToken;
60
61
  // set log level
61
62
  winstonInstance.level = options.verbose ? 'debug' : 'info';
62
- // output logs to console in ci env
63
- if (options.ci) {
64
- winstonInstance.add(new winston_1.default.transports.Console());
65
- }
66
63
  }
67
64
  exports.updateLogger = updateLogger;
68
65
  function redactAccessToken(str) {
69
66
  // `redactAccessToken` might be called before access token is set
70
67
  if (accessToken) {
71
- return str.replace(new RegExp(accessToken, 'g'), '<REDACTED>');
68
+ return (0, redact_1.redact)(accessToken, str);
72
69
  }
73
70
  return str;
74
71
  }
75
- exports.redactAccessToken = redactAccessToken;
76
- function initLogger() {
72
+ function initLogger({ ci, logFilePath, }) {
73
+ const fileTransport = getFileTransport({ logFilePath });
77
74
  winstonInstance = winston_1.default.createLogger({
78
- transports: [
79
- // log to file
80
- new winston_1.default.transports.File({
81
- level: 'debug',
82
- format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
83
- fillExcept: ['message', 'level', 'timestamp', 'label'],
84
- }), winston_1.format.printf((info) => {
85
- // format without metadata
86
- if (!info.metadata.meta) {
87
- return redactAccessToken(`${info.timestamp}: ${info.message}`);
88
- }
89
- // format when metadata is a string
90
- if ((0, lodash_1.isString)(info.metadata.meta)) {
91
- return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
92
- }
93
- if (info.metadata.meta.stack) {
94
- return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
95
- }
96
- // format when metadata is an object
97
- return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
98
- })),
99
- filename: (0, env_1.getLogfilePath)(),
100
- }),
101
- ],
75
+ transports: ci
76
+ ? [fileTransport, new winston_1.default.transports.Console()]
77
+ : [fileTransport],
102
78
  });
103
79
  // wait exiting until logs have been flushed to disk
104
80
  winstonInstance.on('finish', () => {
@@ -107,6 +83,29 @@ function initLogger() {
107
83
  return exports.logger;
108
84
  }
109
85
  exports.initLogger = initLogger;
86
+ function getFileTransport({ logFilePath }) {
87
+ return new winston_1.default.transports.File({
88
+ level: 'debug',
89
+ format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
90
+ fillExcept: ['message', 'level', 'timestamp', 'label'],
91
+ }), winston_1.format.printf((info) => {
92
+ // format without metadata
93
+ if (!info.metadata.meta) {
94
+ return redactAccessToken(`${info.timestamp}: ${info.message}`);
95
+ }
96
+ // format when metadata is a string
97
+ if ((0, lodash_1.isString)(info.metadata.meta)) {
98
+ return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
99
+ }
100
+ if (info.metadata.meta.stack) {
101
+ return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
102
+ }
103
+ // format when metadata is an object
104
+ return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
105
+ })),
106
+ filename: (0, env_1.getLogfilePath)({ logFilePath }),
107
+ });
108
+ }
110
109
  // log levels:
111
110
  // - error
112
111
  // - warn
@@ -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
  }