backport 8.8.0-beta.1 → 8.9.0-beta.2

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.
@@ -1,14 +1,16 @@
1
1
  import { BackportResponse } from './backportRun';
2
+ import { getOptionsFromGithub } from './lib/github/v4/getOptionsFromGithub/getOptionsFromGithub';
2
3
  import type { Commit } from './lib/sourceCommit/parseSourceCommit';
3
4
  import { ConfigFileOptions } from './options/ConfigOptions';
4
5
  import { ValidConfigOptions } from './options/options';
5
6
  export type { HandledErrorResult, SuccessResult, UnhandledErrorResult, } from './runSequentially';
6
7
  export type { BackportAbortResponse, BackportFailureResponse, BackportResponse, BackportSuccessResponse, } from './backportRun';
8
+ export { getTargetBranchFromLabel } from './lib/sourceCommit/getPullRequestStates';
7
9
  export { BackportError } from './lib/BackportError';
8
10
  export type { Commit } from './lib/sourceCommit/parseSourceCommit';
9
11
  export type { ConfigFileOptions } from './options/ConfigOptions';
10
- export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './lib/github/v4/fetchRemoteProjectConfig';
11
12
  export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
13
+ export { getOptionsFromGithub };
12
14
  export declare function backportRun({ options, processArgs, exitCodeOnFailure, }: {
13
15
  options?: ConfigFileOptions;
14
16
  processArgs?: string[];
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommits = exports.backportRun = exports.getLocalGlobalConfig = exports.getRemoteProjectConfig = exports.BackportError = void 0;
3
+ exports.getCommits = exports.backportRun = exports.getOptionsFromGithub = exports.getLocalGlobalConfig = exports.BackportError = exports.getTargetBranchFromLabel = void 0;
4
4
  const backportRun_1 = require("./backportRun");
5
5
  const fetchCommitByPullNumber_1 = require("./lib/github/v4/fetchCommits/fetchCommitByPullNumber");
6
6
  const fetchCommitBySha_1 = require("./lib/github/v4/fetchCommits/fetchCommitBySha");
7
7
  const fetchCommitsByAuthor_1 = require("./lib/github/v4/fetchCommits/fetchCommitsByAuthor");
8
8
  const fetchPullRequestsBySearchQuery_1 = require("./lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery");
9
9
  const getOptionsFromGithub_1 = require("./lib/github/v4/getOptionsFromGithub/getOptionsFromGithub");
10
+ Object.defineProperty(exports, "getOptionsFromGithub", { enumerable: true, get: function () { return getOptionsFromGithub_1.getOptionsFromGithub; } });
10
11
  const logger_1 = require("./lib/logger");
11
12
  const excludeUndefined_1 = require("./utils/excludeUndefined");
13
+ var getPullRequestStates_1 = require("./lib/sourceCommit/getPullRequestStates");
14
+ Object.defineProperty(exports, "getTargetBranchFromLabel", { enumerable: true, get: function () { return getPullRequestStates_1.getTargetBranchFromLabel; } });
12
15
  var BackportError_1 = require("./lib/BackportError");
13
16
  Object.defineProperty(exports, "BackportError", { enumerable: true, get: function () { return BackportError_1.BackportError; } });
14
- var fetchRemoteProjectConfig_1 = require("./lib/github/v4/fetchRemoteProjectConfig");
15
- Object.defineProperty(exports, "getRemoteProjectConfig", { enumerable: true, get: function () { return fetchRemoteProjectConfig_1.fetchRemoteProjectConfig; } });
16
17
  var globalConfig_1 = require("./options/config/globalConfig");
17
18
  Object.defineProperty(exports, "getLocalGlobalConfig", { enumerable: true, get: function () { return globalConfig_1.getGlobalConfig; } });
18
19
  function backportRun({ options = {}, processArgs = [], exitCodeOnFailure = true, }) {
@@ -30,11 +31,12 @@ async function getCommits(options) {
30
31
  const pullNumbers = Array.isArray(options.pullNumber)
31
32
  ? options.pullNumber
32
33
  : [options.pullNumber];
33
- return Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
34
+ const nestedCommits = await Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitsByPullNumber)({
34
35
  ...optionsFromGithub,
35
36
  ...options,
36
37
  pullNumber,
37
38
  })));
39
+ return nestedCommits.flat();
38
40
  }
39
41
  if (options.sha) {
40
42
  const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
@@ -38,7 +38,8 @@ async function getCommits(options) {
38
38
  spinner.text = `Loading pull request ${pullNumbers
39
39
  .map((pullNumber) => `#${pullNumber}`)
40
40
  .join(', ')}`;
41
- const commits = await Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({ ...options, pullNumber })));
41
+ const nestedCommits = await Promise.all(pullNumbers.map((pullNumber) => (0, fetchCommitByPullNumber_1.fetchCommitsByPullNumber)({ ...options, pullNumber })));
42
+ const commits = nestedCommits.flat();
42
43
  // add styles to make it look like a prompt question
43
44
  spinner.stopAndPersist(getOraPersistsOption('Select pull request', commits
44
45
  .map((commit) => (0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))
@@ -255,54 +255,30 @@ describe('getPullRequestBody', () => {
255
255
  - Another commit message (qwertyui)"
256
256
  `);
257
257
  });
258
- it('appends text to the default descriptions', () => {
259
- expect((0, createPullRequest_1.getPullRequestBody)({
260
- options: {
261
- prDescription: '{defaultPrDescription}\n\ntext to append',
262
- },
263
- commits: [
264
- {
265
- author: {
266
- email: 'soren.louv@elastic.co',
267
- name: 'Søren Louv-Jansen',
268
- },
269
- sourcePullRequest: {
270
- labels: [],
271
- number: 55,
272
- url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
273
- mergeCommit: {
274
- sha: 'abcdefghijklm',
275
- message: 'My commit message (#55)',
276
- },
277
- },
278
- suggestedTargetBranches: [],
279
- sourceCommit: {
280
- branchLabelMapping: {},
281
- committedDate: '',
282
- sha: 'abcdefghijklm',
283
- message: 'My commit message (#55)',
284
- },
285
- sourceBranch: 'main',
286
- targetPullRequestStates: [],
258
+ it('replaces {defaultPrDescription} with the default pr description', () => {
259
+ const commits = [
260
+ {
261
+ sourcePullRequest: {
262
+ url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
287
263
  },
288
- {
289
- author: {
290
- email: 'soren.louv@elastic.co',
291
- name: 'Søren Louv-Jansen',
292
- },
293
- suggestedTargetBranches: [],
294
- sourceCommit: {
295
- branchLabelMapping: {},
296
- committedDate: '',
297
- sha: 'qwertyuiop',
298
- message: 'Another commit message',
299
- },
300
- sourceBranch: 'main',
301
- targetPullRequestStates: [],
264
+ sourceCommit: {
265
+ sha: 'abcdefghijklm',
266
+ message: 'My commit message (#55)',
302
267
  },
303
- ],
304
- targetBranch: '7.x',
305
- })).toMatchInlineSnapshot(`
268
+ sourceBranch: 'main',
269
+ },
270
+ {
271
+ sourceCommit: {
272
+ sha: 'qwertyuiop',
273
+ message: 'Another commit message',
274
+ },
275
+ },
276
+ ];
277
+ const options = {
278
+ prDescription: '{defaultPrDescription}\n\ntext to append',
279
+ };
280
+ expect((0, createPullRequest_1.getPullRequestBody)({ options, commits, targetBranch: '7.x' }))
281
+ .toMatchInlineSnapshot(`
306
282
  "# Backport
307
283
 
308
284
  This will backport the following commits from \`main\` to \`7.x\`:
@@ -317,6 +293,26 @@ describe('getPullRequestBody', () => {
317
293
  text to append"
318
294
  `);
319
295
  });
296
+ it('replaces {commits} with a stringified commits object', () => {
297
+ const commits = [
298
+ {
299
+ sourceCommit: {
300
+ sha: 'foo',
301
+ message: 'My commit message (#55)',
302
+ },
303
+ },
304
+ {
305
+ sourceCommit: {
306
+ sha: 'bar',
307
+ message: 'Another commit message',
308
+ },
309
+ },
310
+ ];
311
+ const options = {
312
+ prDescription: 'Just output the commits: {commits}',
313
+ };
314
+ expect((0, createPullRequest_1.getPullRequestBody)({ options, commits, targetBranch: '7.x' })).toMatchInlineSnapshot(`"Just output the commits: [{\\"sourceCommit\\":{\\"sha\\":\\"foo\\",\\"message\\":\\"My commit message (#55)\\"}},{\\"sourceCommit\\":{\\"sha\\":\\"bar\\",\\"message\\":\\"Another commit message\\"}}]"`);
315
+ });
320
316
  });
321
317
  describe('getTitle', () => {
322
318
  it('has the default title', () => {
@@ -27,14 +27,14 @@ describe('allFetchers', () => {
27
27
  if (!commitByAuthor.sourcePullRequest) {
28
28
  throw new Error('Missing pull number!');
29
29
  }
30
- const commitByPullNumber = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
30
+ const commitByPullNumber = await (0, fetchCommitByPullNumber_1.fetchCommitsByPullNumber)({
31
31
  repoOwner: 'elastic',
32
32
  repoName: 'kibana',
33
33
  accessToken,
34
34
  pullNumber: commitByAuthor.sourcePullRequest.number,
35
35
  sourceBranch: 'master',
36
36
  });
37
- expect(commitByAuthor).toEqual(commitByPullNumber);
37
+ expect(commitByAuthor).toEqual(commitByPullNumber[0]);
38
38
  });
39
39
  it('matches commitByAuthor with commitBySha', async () => {
40
40
  const commitBySha = await (0, fetchCommitBySha_1.fetchCommitBySha)({
@@ -1,6 +1,6 @@
1
1
  import { ValidConfigOptions } from '../../../../options/options';
2
2
  import { Commit } from '../../../sourceCommit/parseSourceCommit';
3
- export declare function fetchCommitByPullNumber(options: {
3
+ export declare function fetchCommitsByPullNumber(options: {
4
4
  accessToken: string;
5
5
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
6
6
  githubApiBaseUrlV4?: string;
@@ -8,4 +8,4 @@ export declare function fetchCommitByPullNumber(options: {
8
8
  repoName: string;
9
9
  repoOwner: string;
10
10
  sourceBranch: string;
11
- }): Promise<Commit>;
11
+ }): Promise<Commit[]>;
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fetchCommitByPullNumber = void 0;
6
+ exports.fetchCommitsByPullNumber = void 0;
7
7
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const BackportError_1 = require("../../../BackportError");
9
9
  const remoteConfig_1 = require("../../../remoteConfig");
10
- const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
11
10
  const apiRequestV4_1 = require("../apiRequestV4");
12
- async function fetchCommitByPullNumber(options) {
11
+ const fetchCommitBySha_1 = require("./fetchCommitBySha");
12
+ const fetchCommitsForRebaseAndMergeStrategy_1 = require("./fetchCommitsForRebaseAndMergeStrategy");
13
+ async function fetchCommitsByPullNumber(options) {
13
14
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', pullNumber, repoName, repoOwner, } = options;
14
15
  const query = (0, graphql_tag_1.default) `
15
16
  query CommitByPullNumber(
@@ -19,14 +20,28 @@ async function fetchCommitByPullNumber(options) {
19
20
  ) {
20
21
  repository(owner: $repoOwner, name: $repoName) {
21
22
  pullRequest(number: $pullNumber) {
23
+ # used to determine if "Rebase and Merge" strategy was used
24
+ commits {
25
+ totalCount
26
+ }
27
+
22
28
  mergeCommit {
23
- ...SourceCommitWithTargetPullRequestFragment
29
+ oid
30
+
31
+ # used to determine if "Rebase and Merge" strategy was used
32
+ committedDate
33
+ history(first: 2) {
34
+ edges {
35
+ node {
36
+ message
37
+ committedDate
38
+ }
39
+ }
40
+ }
24
41
  }
25
42
  }
26
43
  }
27
44
  }
28
-
29
- ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
30
45
  `;
31
46
  let res;
32
47
  try {
@@ -48,10 +63,19 @@ async function fetchCommitByPullNumber(options) {
48
63
  if (!pullRequestNode) {
49
64
  throw new BackportError_1.BackportError(`The PR #${pullNumber} does not exist`);
50
65
  }
51
- const sourceCommit = pullRequestNode.mergeCommit;
52
- if (sourceCommit === null) {
66
+ const { mergeCommit } = pullRequestNode;
67
+ if (mergeCommit === null) {
53
68
  throw new BackportError_1.BackportError(`The PR #${pullNumber} is not merged`);
54
69
  }
55
- return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
70
+ const possiblyRebaseAndMergeStrategy = pullRequestNode.commits.totalCount > 0 &&
71
+ mergeCommit.history.edges.every((c) => c.node.committedDate === mergeCommit.committedDate);
72
+ if (possiblyRebaseAndMergeStrategy) {
73
+ const commits = await (0, fetchCommitsForRebaseAndMergeStrategy_1.fetchCommitsForRebaseAndMergeStrategy)(options, pullRequestNode.commits.totalCount);
74
+ if (commits) {
75
+ return commits;
76
+ }
77
+ }
78
+ const commit = await (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: mergeCommit.oid });
79
+ return [commit];
56
80
  }
57
- exports.fetchCommitByPullNumber = fetchCommitByPullNumber;
81
+ exports.fetchCommitsByPullNumber = fetchCommitsByPullNumber;
@@ -31,10 +31,10 @@ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
31
31
  describe('fetchCommitByPullNumber', () => {
32
32
  describe('snapshot request/response', () => {
33
33
  let spy;
34
- let commit;
34
+ let commits;
35
35
  beforeEach(async () => {
36
36
  spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
37
- commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
37
+ commits = await (0, fetchCommitByPullNumber_1.fetchCommitsByPullNumber)({
38
38
  repoOwner: 'elastic',
39
39
  repoName: 'kibana',
40
40
  accessToken,
@@ -49,17 +49,17 @@ describe('fetchCommitByPullNumber', () => {
49
49
  return { ...acc, [name]: (0, graphql_1.print)(query) };
50
50
  }, {});
51
51
  const queryNames = Object.keys(queries);
52
- expect(queryNames).toEqual(['CommitByPullNumber']);
52
+ expect(queryNames).toEqual(['CommitByPullNumber', 'CommitsBySha']);
53
53
  queryNames.forEach((name) => {
54
54
  expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
55
55
  });
56
56
  });
57
57
  it('returns the correct response', async () => {
58
- expect(commit).toMatchSnapshot();
58
+ expect(commits).toMatchSnapshot();
59
59
  });
60
60
  });
61
61
  describe('when PR was merged', () => {
62
- it('is returned', async () => {
62
+ it('the pull request response is returned', async () => {
63
63
  const options = {
64
64
  accessToken,
65
65
  pullNumber: 5,
@@ -132,7 +132,7 @@ describe('fetchCommitByPullNumber', () => {
132
132
  },
133
133
  ],
134
134
  };
135
- expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual(expectedCommit);
135
+ expect(await (0, fetchCommitByPullNumber_1.fetchCommitsByPullNumber)(options)).toEqual([expectedCommit]);
136
136
  });
137
137
  });
138
138
  describe('when PR is still open', () => {
@@ -144,7 +144,7 @@ describe('fetchCommitByPullNumber', () => {
144
144
  repoOwner: 'backport-org',
145
145
  sourceBranch: 'main',
146
146
  };
147
- await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
147
+ await expect((0, fetchCommitByPullNumber_1.fetchCommitsByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
148
148
  });
149
149
  });
150
150
  describe('when PR does not exist', () => {
@@ -156,7 +156,7 @@ describe('fetchCommitByPullNumber', () => {
156
156
  repoOwner: 'backport-org',
157
157
  sourceBranch: 'main',
158
158
  };
159
- await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Github API v4)`);
159
+ await expect((0, fetchCommitByPullNumber_1.fetchCommitsByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Github API v4)`);
160
160
  });
161
161
  });
162
162
  });
@@ -0,0 +1,9 @@
1
+ import { Commit } from '../../../../entrypoint.module';
2
+ export declare function fetchCommitsForRebaseAndMergeStrategy(options: {
3
+ accessToken: string;
4
+ githubApiBaseUrlV4?: string;
5
+ pullNumber: number;
6
+ repoName: string;
7
+ repoOwner: string;
8
+ sourceBranch: string;
9
+ }, commitsTotalCount: number): Promise<Commit[] | undefined>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fetchCommitsForRebaseAndMergeStrategy = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const apiRequestV4_1 = require("../apiRequestV4");
9
+ const fetchCommitBySha_1 = require("./fetchCommitBySha");
10
+ async function fetchCommitsForRebaseAndMergeStrategy(options, commitsTotalCount) {
11
+ const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', pullNumber, repoName, repoOwner, } = options;
12
+ const query = (0, graphql_tag_1.default) `
13
+ query CommitByPullNumber(
14
+ $repoOwner: String!
15
+ $repoName: String!
16
+ $pullNumber: Int!
17
+ $commitsTotalCount: Int!
18
+ ) {
19
+ repository(owner: $repoOwner, name: $repoName) {
20
+ pullRequest(number: $pullNumber) {
21
+ commits(first: $commitsTotalCount) {
22
+ totalCount
23
+ edges {
24
+ node {
25
+ commit {
26
+ message
27
+ }
28
+ }
29
+ }
30
+ }
31
+
32
+ mergeCommit {
33
+ committedDate
34
+ history(first: $commitsTotalCount) {
35
+ edges {
36
+ node {
37
+ oid
38
+ message
39
+ committedDate
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+ `;
48
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
49
+ githubApiBaseUrlV4,
50
+ accessToken,
51
+ query,
52
+ variables: {
53
+ repoOwner,
54
+ repoName,
55
+ pullNumber,
56
+ commitsTotalCount,
57
+ },
58
+ });
59
+ const pullRequestNode = res.repository.pullRequest;
60
+ if (!pullRequestNode?.mergeCommit) {
61
+ throw new Error('Pull request is not merged');
62
+ }
63
+ if (pullRequestNode.commits.totalCount !== commitsTotalCount) {
64
+ throw new Error(`Specified number of commits is ${commitsTotalCount} whereas the actual number is ${pullRequestNode.commits.totalCount}`);
65
+ }
66
+ const commitsInPullRequest = pullRequestNode.commits.edges;
67
+ const commitsInBaseBranch = pullRequestNode.mergeCommit.history.edges.reverse();
68
+ const didUseRebaseAndMergeStrategy = commitsInBaseBranch.every((c, i) => {
69
+ const hasIdenticalCommittedDate = c.node.committedDate === pullRequestNode.mergeCommit?.committedDate;
70
+ const hasIdenticalCommitMessages = c.node.message === commitsInPullRequest[i].node.commit.message;
71
+ return hasIdenticalCommittedDate && hasIdenticalCommitMessages;
72
+ });
73
+ if (didUseRebaseAndMergeStrategy) {
74
+ const commits = await Promise.all(commitsInBaseBranch.map((c) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: c.node.oid })));
75
+ return commits;
76
+ }
77
+ }
78
+ exports.fetchCommitsForRebaseAndMergeStrategy = fetchCommitsForRebaseAndMergeStrategy;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
+ const fetchCommitsForRebaseAndMergeStrategy_1 = require("./fetchCommitsForRebaseAndMergeStrategy");
5
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
+ describe('fetchCommitsForRebaseAndMergeStrategy', () => {
7
+ it('returns multiple commits for pull requests merged with "Rebase and merge" strategy', async () => {
8
+ const commitsTotalCount = 3;
9
+ const commits = await (0, fetchCommitsForRebaseAndMergeStrategy_1.fetchCommitsForRebaseAndMergeStrategy)({
10
+ accessToken,
11
+ repoOwner: 'backport-org',
12
+ repoName: 'different-merge-strategies',
13
+ pullNumber: 21,
14
+ sourceBranch: 'main',
15
+ }, commitsTotalCount);
16
+ expect(commits?.length).toBe(3);
17
+ });
18
+ it('returns `undefined` for pull request merged with "merge strategy"', async () => {
19
+ const commitsTotalCount = 8;
20
+ const commits = await (0, fetchCommitsForRebaseAndMergeStrategy_1.fetchCommitsForRebaseAndMergeStrategy)({
21
+ accessToken,
22
+ repoOwner: 'backport-org',
23
+ repoName: 'different-merge-strategies',
24
+ pullNumber: 9,
25
+ sourceBranch: 'main',
26
+ }, commitsTotalCount);
27
+ expect(commits).toBe(undefined);
28
+ });
29
+ });
@@ -25,4 +25,11 @@ export declare function getPullRequestStates({ sourceCommit, branchLabelMapping,
25
25
  sourceCommit: SourceCommitWithTargetPullRequest;
26
26
  branchLabelMapping: ValidConfigOptions['branchLabelMapping'];
27
27
  }): TargetPullRequest[];
28
+ export declare function getTargetBranchFromLabel({ branchLabelMapping, label, }: {
29
+ branchLabelMapping: NonNullable<ValidConfigOptions['branchLabelMapping']>;
30
+ label: string;
31
+ }): {
32
+ targetBranch: string;
33
+ labelRegex: string;
34
+ } | undefined;
28
35
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPullRequestStates = exports.getSourcePullRequest = void 0;
3
+ exports.getTargetBranchFromLabel = 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");
@@ -128,3 +128,4 @@ function getTargetBranchFromLabel({ branchLabelMapping, label, }) {
128
128
  }
129
129
  }
130
130
  }
131
+ exports.getTargetBranchFromLabel = getTargetBranchFromLabel;
@@ -21,22 +21,26 @@ describe('different-merge-strategies', () => {
21
21
  ], { waitForString: 'Select commit', timeoutSeconds: 4 });
22
22
  expect(output).toMatchInlineSnapshot(`
23
23
  "? Select commit (Use arrow keys)
24
- ❯ 1. Merge pull request #9 from backport-org/many-merge-commits
25
- 2. Merge strategy: Eighth of many merges
26
- 3. Merge strategy: Seventh of many merges
27
- 4. Merge strategy: Sixth of many merges
28
- 5. Merge strategy: Fifth of many merges
29
- 6. Merge strategy: Fourth of many merges
30
- 7. Merge strategy: Third of many merges
31
- 8. Merge strategy: Second of many merges
32
- 9. Merge strategy: First of many merges
33
- 10.Using squash to merge commits (#3)
34
- 11.Rebase strategy: Second commit
35
- 12.Rebase strategy: First commit
36
- 13.Merge pull request #1 from backport-org/merge-strategy
37
- 14.Merge strategy: Second commit
38
- 15.Merge strategy: First commit
39
- 16.Initial commit"
24
+ ❯ 1. Downsides with \\"Rebase and merge\\"
25
+ 2. Add description for \\"Rebase and merge\\"
26
+ 3. Add \\"Rebase and merge\\" header
27
+ 4. Create rebase-and-merge.txt
28
+ 5. Merge pull request #9 from backport-org/many-merge-commits
29
+ 6. Merge strategy: Eighth of many merges
30
+ 7. Merge strategy: Seventh of many merges
31
+ 8. Merge strategy: Sixth of many merges
32
+ 9. Merge strategy: Fifth of many merges
33
+ 10.Merge strategy: Fourth of many merges
34
+ 11.Merge strategy: Third of many merges
35
+ 12.Merge strategy: Second of many merges
36
+ 13.Merge strategy: First of many merges
37
+ 14.Using squash to merge commits (#3)
38
+ 15.Rebase strategy: Second commit
39
+ 16.Rebase strategy: First commit
40
+ 17.Merge pull request #1 from backport-org/merge-strategy
41
+ 18.Merge strategy: Second commit
42
+ 19.Merge strategy: First commit
43
+ 20.Initial commit"
40
44
  `);
41
45
  });
42
46
  describe('when selecting a merge commit with eight commits', () => {
@@ -87,7 +91,7 @@ describe('different-merge-strategies', () => {
87
91
  });
88
92
  it('backports all immediate children of the merge commit', async () => {
89
93
  const commits = await listCommits(sandboxPath);
90
- expect(commits).toEqual([
94
+ expect(commits.slice(0, 8)).toEqual([
91
95
  'Merge strategy: Eighth of many merges',
92
96
  'Merge strategy: Seventh of many merges',
93
97
  'Merge strategy: Sixth of many merges',
@@ -96,7 +100,6 @@ describe('different-merge-strategies', () => {
96
100
  'Merge strategy: Third of many merges',
97
101
  'Merge strategy: Second of many merges',
98
102
  'Merge strategy: First of many merges',
99
- 'Initial commit',
100
103
  ]);
101
104
  });
102
105
  });
@@ -116,10 +119,9 @@ describe('different-merge-strategies', () => {
116
119
  });
117
120
  it('backports all immediate children of the merge commit', async () => {
118
121
  const commits = await listCommits(sandboxPath);
119
- expect(commits).toEqual([
122
+ expect(commits.slice(0, 2)).toEqual([
120
123
  'Merge strategy: Second commit',
121
124
  'Merge strategy: First commit',
122
- 'Initial commit',
123
125
  ]);
124
126
  });
125
127
  });
@@ -207,7 +209,7 @@ describe('different-merge-strategies', () => {
207
209
  });
208
210
  it('backports all immediate children of the merge commit', async () => {
209
211
  const commits = await listCommits(sandboxPath);
210
- expect(commits).toEqual([
212
+ expect(commits.slice(0, 8)).toEqual([
211
213
  'Merge strategy: Eighth of many merges',
212
214
  'Merge strategy: Seventh of many merges',
213
215
  'Merge strategy: Sixth of many merges',
@@ -216,8 +218,40 @@ describe('different-merge-strategies', () => {
216
218
  'Merge strategy: Third of many merges',
217
219
  'Merge strategy: Second of many merges',
218
220
  'Merge strategy: First of many merges',
219
- 'Create new-file-added-with-many-merge-commits.txt',
220
- 'Initial commit',
221
+ ]);
222
+ });
223
+ });
224
+ describe('when using "Rebase and Merge" strategy', () => {
225
+ let sandboxPath;
226
+ let output;
227
+ beforeAll(async () => {
228
+ sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
229
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
230
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
231
+ '--branch=7.x',
232
+ '--repo=backport-org/different-merge-strategies',
233
+ `--accessToken=${accessToken}`,
234
+ `--dir=${sandboxPath}`,
235
+ '--pr=21',
236
+ '--dry-run',
237
+ ], { showOra: true });
238
+ output = res.output;
239
+ });
240
+ it('backports all commits', async () => {
241
+ const commits = await (await listCommits(sandboxPath)).slice(0, 3);
242
+ expect(commits).toEqual([
243
+ 'Downsides with "Rebase and merge"',
244
+ 'Add description for "Rebase and merge"',
245
+ 'Add "Rebase and merge" header',
246
+ ]);
247
+ });
248
+ it('shows every commit in output', async () => {
249
+ expect(output
250
+ .split('\n')
251
+ .filter((line) => line.startsWith('✔ Cherry-picking:'))).toEqual([
252
+ '✔ Cherry-picking: Add "Rebase and merge" header',
253
+ '✔ Cherry-picking: Add description for "Rebase and merge"',
254
+ '✔ Cherry-picking: Downsides with "Rebase and merge"',
221
255
  ]);
222
256
  });
223
257
  });
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "8.8.0-beta.1";
1
+ export declare const PACKAGE_VERSION = "8.9.0-beta.2";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PACKAGE_VERSION = void 0;
4
- exports.PACKAGE_VERSION = '8.8.0-beta.1';
4
+ exports.PACKAGE_VERSION = '8.9.0-beta.2';