backport 8.6.0 → 8.7.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 (65) hide show
  1. package/dist/entrypoint.module.private.test.js +78 -52
  2. package/dist/lib/{cherrypickAndCreateTargetPullRequest.d.ts → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.d.ts} +2 -2
  3. package/dist/lib/cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.js +98 -0
  4. package/dist/lib/{cherrypickAndCreateTargetPullRequest.test.d.ts → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.test.d.ts} +0 -0
  5. package/dist/lib/{cherrypickAndCreateTargetPullRequest.test.js → cherrypickAndCreateTargetPullRequest/cherrypickAndCreateTargetPullRequest.test.js} +12 -10
  6. package/dist/lib/cherrypickAndCreateTargetPullRequest/getBackportBranchName.d.ts +2 -0
  7. package/dist/lib/cherrypickAndCreateTargetPullRequest/getBackportBranchName.js +22 -0
  8. package/dist/lib/{getCommitsWithoutBackports.d.ts → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.d.ts} +2 -2
  9. package/dist/lib/{getCommitsWithoutBackports.js → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.js} +6 -6
  10. package/dist/lib/{getCommitsWithoutBackports.test.d.ts → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.test.d.ts} +0 -0
  11. package/dist/lib/{getCommitsWithoutBackports.test.js → cherrypickAndCreateTargetPullRequest/getCommitsWithoutBackports.test.js} +24 -17
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest/getMergeCommit.d.ts +3 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest/getMergeCommit.js +17 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.d.ts +7 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.js +33 -0
  16. package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.test.d.ts +1 -0
  17. package/dist/lib/cherrypickAndCreateTargetPullRequest/getTargetPRLabels.test.js +166 -0
  18. package/dist/lib/cherrypickAndCreateTargetPullRequest/waitForCherrypick.d.ts +3 -0
  19. package/dist/lib/cherrypickAndCreateTargetPullRequest/waitForCherrypick.js +154 -0
  20. package/dist/lib/getSourceBranchFromCommits.d.ts +2 -0
  21. package/dist/lib/getSourceBranchFromCommits.js +10 -0
  22. package/dist/lib/getTargetBranches.js +2 -3
  23. package/dist/lib/getTargetBranches.test.js +6 -4
  24. package/dist/lib/git.test.js +1 -1
  25. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +11 -2
  26. package/dist/lib/github/v3/addAssigneesToPullRequest.js +9 -1
  27. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +5 -2
  28. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +10 -2
  29. package/dist/lib/github/v3/addLabelsToPullRequest.js +5 -1
  30. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +1 -1
  31. package/dist/lib/github/v3/addReviewersToPullRequest.js +5 -1
  32. package/dist/lib/github/v3/createPullRequest.js +7 -1
  33. package/dist/lib/github/v3/createPullRequest.test.js +22 -13
  34. package/dist/lib/github/v3/createStatusComment.test.js +4 -2
  35. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +4 -0
  36. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +10 -1
  37. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +5 -1
  38. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -1
  39. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -4
  40. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +7 -5
  41. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -2
  42. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +6 -5
  43. package/dist/lib/prompt.test.js +14 -6
  44. package/dist/lib/prompts.js +2 -2
  45. package/dist/lib/sourceCommit/getPullRequestStates.d.ts +3 -2
  46. package/dist/lib/sourceCommit/getPullRequestStates.js +13 -20
  47. package/dist/lib/sourceCommit/getPullRequestStates.test.js +69 -28
  48. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +2 -1
  49. package/dist/lib/sourceCommit/parseSourceCommit.js +15 -7
  50. package/dist/lib/sourceCommit/parseSourceCommit.test.js +15 -4
  51. package/dist/runSequentially.js +5 -5
  52. package/dist/test/e2e/cli/commit-author.private.test.js +3 -3
  53. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +6 -2
  54. package/dist/test/e2e/cli/gracefully-handles-corrupt-repo.private.test.js +5 -1
  55. package/dist/test/e2e/cli/repo-with-changing-branchLabelMapping.private.test.js +2 -2
  56. package/dist/test/e2e/cli/repo-with-programatically-added-commits.mutation.test.js +1 -1
  57. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +6 -2
  58. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +4 -4
  59. package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -1
  60. package/dist/utils/filterUnmergedCommits.js +1 -1
  61. package/dist/utils/packageVersion.d.ts +1 -1
  62. package/dist/utils/packageVersion.js +1 -1
  63. package/package.json +7 -7
  64. package/yarn.lock +75 -75
  65. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +0 -255
@@ -46,13 +46,13 @@ async function getOptionsFromGithub(options) {
46
46
  exports.getOptionsFromGithub = getOptionsFromGithub;
47
47
  async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
48
48
  if (skipRemoteConfig) {
49
- logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
49
+ logger_1.logger.info('Remote config: Skipping. `--skip-remote-config` specified via config file or cli');
50
50
  return;
51
51
  }
52
52
  const remoteConfig = res.repository.defaultBranchRef.target.remoteConfigHistory.edges?.[0]
53
53
  ?.remoteConfig;
54
54
  if (!remoteConfig) {
55
- logger_1.logger.info("Skipping remote config: remote config doesn't exist");
55
+ logger_1.logger.info("Remote config: Skipping. Remote config doesn't exist");
56
56
  return;
57
57
  }
58
58
  if (cwd) {
@@ -62,18 +62,19 @@ async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
62
62
  (0, git_1.getLocalConfigFileCommitDate)({ cwd }),
63
63
  ]);
64
64
  if (isLocalConfigUntracked) {
65
- logger_1.logger.info('Skipping remote config: local config is new');
65
+ logger_1.logger.info('Remote config: Skipping. Local config is new');
66
66
  return;
67
67
  }
68
68
  if (isLocalConfigModified) {
69
- logger_1.logger.info('Skipping remote config: local config is modified');
69
+ logger_1.logger.info('Remote config: Skipping. Local config is modified');
70
70
  return;
71
71
  }
72
72
  if (localCommitDate &&
73
73
  localCommitDate > Date.parse(remoteConfig.committedDate)) {
74
- logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
74
+ logger_1.logger.info(`Remote config: Skipping. Local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
75
75
  return;
76
76
  }
77
77
  }
78
+ logger_1.logger.info('Remote config: Parsing.');
78
79
  return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
79
80
  }
@@ -7,7 +7,7 @@ const strip_ansi_1 = __importDefault(require("strip-ansi"));
7
7
  const prompts_1 = require("./prompts");
8
8
  describe('prompt', () => {
9
9
  describe('getChoicesForCommitPrompt', () => {
10
- it('should display status badges via `pullRequestStates`', () => {
10
+ it('should display status badges via `targetPullRequestStates`', () => {
11
11
  const commits = [
12
12
  {
13
13
  author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
@@ -20,6 +20,7 @@ describe('prompt', () => {
20
20
  message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
21
21
  },
22
22
  sourcePullRequest: {
23
+ labels: [],
23
24
  number: 119700,
24
25
  url: 'foo',
25
26
  mergeCommit: {
@@ -27,8 +28,9 @@ describe('prompt', () => {
27
28
  message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
28
29
  },
29
30
  },
30
- pullRequestStates: [
31
+ targetPullRequestStates: [
31
32
  {
33
+ labelRegex: 'foo tbd',
32
34
  number: 120178,
33
35
  branch: '8.0',
34
36
  label: '',
@@ -36,6 +38,7 @@ describe('prompt', () => {
36
38
  state: 'MERGED',
37
39
  },
38
40
  {
41
+ labelRegex: 'foo tbd',
39
42
  number: 120179,
40
43
  branch: '7.16',
41
44
  state: 'MERGED',
@@ -43,6 +46,7 @@ describe('prompt', () => {
43
46
  isSourceBranch: false,
44
47
  },
45
48
  {
49
+ labelRegex: 'foo tbd',
46
50
  number: 120179,
47
51
  branch: '7.15',
48
52
  state: 'NOT_CREATED',
@@ -73,6 +77,7 @@ describe('prompt', () => {
73
77
  message: '[APM] Prefer service.name for logs correlation (#120694)',
74
78
  },
75
79
  sourcePullRequest: {
80
+ labels: [],
76
81
  number: 120694,
77
82
  url: 'foo',
78
83
  mergeCommit: {
@@ -80,7 +85,7 @@ describe('prompt', () => {
80
85
  message: '[APM] Prefer service.name for logs correlation (#120694)',
81
86
  },
82
87
  },
83
- pullRequestStates: [],
88
+ targetPullRequestStates: [],
84
89
  },
85
90
  {
86
91
  author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
@@ -93,6 +98,7 @@ describe('prompt', () => {
93
98
  message: '[APM] Disable telemetry in agent config endpoint (#120106)',
94
99
  },
95
100
  sourcePullRequest: {
101
+ labels: [],
96
102
  number: 120106,
97
103
  url: 'foo',
98
104
  mergeCommit: {
@@ -100,7 +106,7 @@ describe('prompt', () => {
100
106
  message: '[APM] Disable telemetry in agent config endpoint (#120106)',
101
107
  },
102
108
  },
103
- pullRequestStates: [],
109
+ targetPullRequestStates: [],
104
110
  },
105
111
  {
106
112
  author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
@@ -113,6 +119,7 @@ describe('prompt', () => {
113
119
  message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
114
120
  },
115
121
  sourcePullRequest: {
122
+ labels: [],
116
123
  number: 119915,
117
124
  url: 'foo',
118
125
  mergeCommit: {
@@ -120,7 +127,7 @@ describe('prompt', () => {
120
127
  message: '[APM] Remove index_pattern.json and add custom field formatters (#119915)',
121
128
  },
122
129
  },
123
- pullRequestStates: [],
130
+ targetPullRequestStates: [],
124
131
  },
125
132
  {
126
133
  author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
@@ -133,6 +140,7 @@ describe('prompt', () => {
133
140
  message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
134
141
  },
135
142
  sourcePullRequest: {
143
+ labels: [],
136
144
  number: 119700,
137
145
  url: 'foo',
138
146
  mergeCommit: {
@@ -140,7 +148,7 @@ describe('prompt', () => {
140
148
  message: '[APM] Remove log-log descriptions from correlation charts (#119700)',
141
149
  },
142
150
  },
143
- pullRequestStates: [],
151
+ targetPullRequestStates: [],
144
152
  },
145
153
  ];
146
154
  const choices = (0, prompts_1.getChoicesForCommitPrompt)(commits, false).map(({ name, short }) => ({ name: (0, strip_ansi_1.default)(name), short }));
@@ -44,7 +44,7 @@ function getPrLink(number, url) {
44
44
  return url ? `(${(0, terminal_link_1.default)(`#${number}`, url)})` : '';
45
45
  }
46
46
  function getDetailedPullStatus(c) {
47
- const items = c.pullRequestStates
47
+ const items = c.targetPullRequestStates
48
48
  .filter(({ isSourceBranch }) => !isSourceBranch)
49
49
  .map((pr) => {
50
50
  const prLink = getPrLink(pr.number, pr.url);
@@ -56,7 +56,7 @@ function getDetailedPullStatus(c) {
56
56
  return `${list}\n`;
57
57
  }
58
58
  function getSimplePullStatus(c) {
59
- return c.pullRequestStates
59
+ return c.targetPullRequestStates
60
60
  .filter(({ isSourceBranch }) => !isSourceBranch)
61
61
  .map(({ state, branch }) => {
62
62
  if (state === 'MERGED') {
@@ -1,5 +1,5 @@
1
1
  import { ValidConfigOptions } from '../../options/options';
2
- import { SourceCommitWithTargetPullRequest } from './parseSourceCommit';
2
+ import { SourcePullRequestNode, SourceCommitWithTargetPullRequest } from './parseSourceCommit';
3
3
  export declare type PullRequestState = 'OPEN' | 'CLOSED' | 'MERGED' | 'NOT_CREATED';
4
4
  declare type CreatedPullRequest = {
5
5
  url: string;
@@ -12,6 +12,7 @@ declare type CreatedPullRequest = {
12
12
  };
13
13
  };
14
14
  declare type TargetBranchWithLabel = {
15
+ labelRegex: string;
15
16
  branch: string;
16
17
  label: string;
17
18
  isSourceBranch: boolean;
@@ -19,7 +20,7 @@ declare type TargetBranchWithLabel = {
19
20
  export declare type TargetPullRequest = (CreatedPullRequest & Partial<TargetBranchWithLabel>) | ((TargetBranchWithLabel & Partial<CreatedPullRequest>) & {
20
21
  state: PullRequestState;
21
22
  });
22
- export declare function getSourceCommitBranchLabelMapping(sourceCommit: SourceCommitWithTargetPullRequest): ValidConfigOptions['branchLabelMapping'];
23
+ export declare function getSourcePullRequest(sourceCommit: SourceCommitWithTargetPullRequest): SourcePullRequestNode | undefined;
23
24
  export declare function getPullRequestStates({ sourceCommit, branchLabelMapping, }: {
24
25
  sourceCommit: SourceCommitWithTargetPullRequest;
25
26
  branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
@@ -1,21 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPullRequestStates = exports.getSourceCommitBranchLabelMapping = void 0;
3
+ exports.getPullRequestStates = exports.getSourcePullRequest = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const filterEmpty_1 = require("../../utils/filterEmpty");
6
6
  const commitFormatters_1 = require("../github/commitFormatters");
7
- const remoteConfig_1 = require("../remoteConfig");
8
7
  function getSourcePullRequest(sourceCommit) {
9
8
  return sourceCommit.associatedPullRequests.edges?.[0]?.node;
10
9
  }
11
- function getSourceCommitBranchLabelMapping(sourceCommit) {
12
- const sourcePullRequest = getSourcePullRequest(sourceCommit);
13
- const remoteConfig = sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
14
- if (remoteConfig) {
15
- return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping;
16
- }
17
- }
18
- exports.getSourceCommitBranchLabelMapping = getSourceCommitBranchLabelMapping;
10
+ exports.getSourcePullRequest = getSourcePullRequest;
19
11
  function mergeByKey(obj1, obj2, key) {
20
12
  const merged = (0, lodash_1.merge)((0, lodash_1.keyBy)(obj1, key), (0, lodash_1.keyBy)(obj2, key));
21
13
  const a = (0, lodash_1.values)(merged);
@@ -110,10 +102,11 @@ function getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping) {
110
102
  const targetBranchesFromLabels = sourcePullRequest.labels.nodes
111
103
  .map((label) => label.name)
112
104
  .map((label) => {
113
- const branch = getTargetBranchFromLabel({ branchLabelMapping, label });
114
- if (branch) {
115
- const isSourceBranch = branch === sourcePullRequest.baseRefName;
116
- return { branch, label, isSourceBranch };
105
+ const res = getTargetBranchFromLabel({ branchLabelMapping, label });
106
+ if (res) {
107
+ const { labelRegex, targetBranch } = res;
108
+ const isSourceBranch = targetBranch === sourcePullRequest.baseRefName;
109
+ return { branch: targetBranch, label, labelRegex, isSourceBranch };
117
110
  }
118
111
  })
119
112
  .filter(filterEmpty_1.filterNil);
@@ -121,17 +114,17 @@ function getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping) {
121
114
  }
122
115
  function getTargetBranchFromLabel({ branchLabelMapping, label, }) {
123
116
  // only get first match
124
- const result = Object.entries(branchLabelMapping).find(([labelPattern]) => {
125
- const regex = new RegExp(labelPattern);
117
+ const result = Object.entries(branchLabelMapping).find(([labelRegex]) => {
118
+ const regex = new RegExp(labelRegex);
126
119
  const isMatch = label.match(regex) !== null;
127
120
  return isMatch;
128
121
  });
129
122
  if (result) {
130
- const [labelPattern, targetBranchPattern] = result;
131
- const regex = new RegExp(labelPattern);
132
- const targetBranch = label.replace(regex, targetBranchPattern);
123
+ const [labelRegex, targetBranchReplaceValue] = result;
124
+ const regex = new RegExp(labelRegex);
125
+ const targetBranch = label.replace(regex, targetBranchReplaceValue);
133
126
  if (targetBranch) {
134
- return targetBranch;
127
+ return { targetBranch, labelRegex };
135
128
  }
136
129
  }
137
130
  }