backport 7.2.0 → 7.3.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 (68) hide show
  1. package/README.md +12 -5
  2. package/dist/backportRun.js +12 -1
  3. package/dist/entrypoint.cli.d.ts +0 -1
  4. package/dist/entrypoint.cli.js +0 -1
  5. package/dist/entrypoint.cli.private.test.js +1 -0
  6. package/dist/options/ConfigOptions.d.ts +3 -1
  7. package/dist/options/cliArgs.d.ts +3 -1
  8. package/dist/options/cliArgs.js +16 -7
  9. package/dist/options/config/config.d.ts +3 -1
  10. package/dist/options/config/readConfigFile.d.ts +3 -1
  11. package/dist/options/options.d.ts +3 -1
  12. package/dist/options/options.js +3 -1
  13. package/dist/options/options.test.js +2 -1
  14. package/dist/runSequentially.d.ts +3 -1
  15. package/dist/runSequentially.js +2 -3
  16. package/dist/services/git.d.ts +15 -7
  17. package/dist/services/git.integration.test.js +38 -58
  18. package/dist/services/git.js +21 -28
  19. package/dist/services/git.test.js +56 -17
  20. package/dist/services/github/v3/createPullRequest.test.js +52 -0
  21. package/dist/services/github/v3/createStatusComment.test.js +12 -2
  22. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
  23. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +1 -0
  24. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +1 -0
  25. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -0
  26. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -0
  27. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -3
  28. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -1
  29. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
  30. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +20 -0
  31. package/dist/services/prompt.test.js +5 -0
  32. package/dist/services/sourceCommit/getMockSourceCommit.js +1 -0
  33. package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -0
  34. package/dist/services/sourceCommit/parseSourceCommit.js +6 -0
  35. package/dist/services/sourceCommit/parseSourceCommit.test.js +1 -0
  36. package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
  37. package/dist/test/e2e/cli/cli.private.test.js +219 -0
  38. package/dist/test/e2e/cli/commit-author.private.test.d.ts +1 -0
  39. package/dist/test/e2e/cli/commit-author.private.test.js +96 -0
  40. package/dist/test/e2e/cli/different-merge-strategies.private.test.d.ts +1 -0
  41. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +108 -0
  42. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.d.ts +1 -0
  43. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +49 -0
  44. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -0
  45. package/dist/test/e2e/cli/runBackportViaCli.js +53 -0
  46. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.d.ts +1 -0
  47. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +73 -0
  48. package/dist/test/e2e/module/module.mutation.test.d.ts +1 -0
  49. package/dist/test/e2e/module/module.mutation.test.js +369 -0
  50. package/dist/test/e2e/module.e2e.mutation.test.d.ts +1 -0
  51. package/dist/test/e2e/module.e2e.mutation.test.js +369 -0
  52. package/dist/test/e2e/module.e2e.private.test.js +6 -0
  53. package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -0
  54. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +3 -1
  55. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +29 -10
  56. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +38 -25
  57. package/dist/ui/getCommitsWithoutBackports.test.js +20 -0
  58. package/dist/ui/getGitConfigAuthor.d.ts +6 -0
  59. package/dist/ui/getGitConfigAuthor.js +15 -0
  60. package/dist/ui/getTargetBranches.test.js +2 -0
  61. package/dist/ui/setupRepo.d.ts +2 -0
  62. package/dist/ui/setupRepo.js +56 -0
  63. package/dist/ui/setupRepo.test.d.ts +1 -0
  64. package/dist/ui/setupRepo.test.js +236 -0
  65. package/dist/utils/packageVersion.d.ts +1 -1
  66. package/dist/utils/packageVersion.js +1 -1
  67. package/package.json +11 -11
  68. package/yarn.lock +61 -81
@@ -9,6 +9,10 @@ exports.commitsByAuthorMock = {
9
9
  edges: [
10
10
  {
11
11
  node: {
12
+ author: {
13
+ email: 'soren.louv@elastic.co',
14
+ name: 'Søren Louv-Jansen',
15
+ },
12
16
  repository: {
13
17
  name: 'kibana',
14
18
  owner: { login: 'elastic' },
@@ -23,6 +27,10 @@ exports.commitsByAuthorMock = {
23
27
  },
24
28
  {
25
29
  node: {
30
+ author: {
31
+ email: 'soren.louv@elastic.co',
32
+ name: 'Søren Louv-Jansen',
33
+ },
26
34
  repository: {
27
35
  name: 'kibana',
28
36
  owner: { login: 'elastic' },
@@ -56,6 +64,10 @@ exports.commitsByAuthorMock = {
56
64
  },
57
65
  {
58
66
  node: {
67
+ author: {
68
+ email: 'soren.louv@elastic.co',
69
+ name: 'Søren Louv-Jansen',
70
+ },
59
71
  repository: {
60
72
  name: 'kibana',
61
73
  owner: { login: 'elastic' },
@@ -122,6 +134,10 @@ exports.commitsByAuthorMock = {
122
134
  },
123
135
  {
124
136
  node: {
137
+ author: {
138
+ email: 'soren.louv@elastic.co',
139
+ name: 'Søren Louv-Jansen',
140
+ },
125
141
  repository: {
126
142
  name: 'kibana',
127
143
  owner: { login: 'elastic' },
@@ -136,6 +152,10 @@ exports.commitsByAuthorMock = {
136
152
  },
137
153
  {
138
154
  node: {
155
+ author: {
156
+ email: 'soren.louv@elastic.co',
157
+ name: 'Søren Louv-Jansen',
158
+ },
139
159
  repository: {
140
160
  name: 'kibana',
141
161
  owner: { login: 'elastic' },
@@ -10,6 +10,7 @@ describe('prompt', () => {
10
10
  it('should display status badges via `expectedTargetPullRequests`', () => {
11
11
  const commits = [
12
12
  {
13
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
13
14
  sourceBranch: 'master',
14
15
  sourceCommit: {
15
16
  committedDate: '1',
@@ -42,6 +43,7 @@ describe('prompt', () => {
42
43
  it('should list choices', () => {
43
44
  const commits = [
44
45
  {
46
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
45
47
  sourceBranch: 'master',
46
48
  sourceCommit: {
47
49
  committedDate: '',
@@ -59,6 +61,7 @@ describe('prompt', () => {
59
61
  expectedTargetPullRequests: [],
60
62
  },
61
63
  {
64
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
62
65
  sourceBranch: 'master',
63
66
  sourceCommit: {
64
67
  committedDate: '',
@@ -76,6 +79,7 @@ describe('prompt', () => {
76
79
  expectedTargetPullRequests: [],
77
80
  },
78
81
  {
82
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
79
83
  sourceBranch: 'master',
80
84
  sourceCommit: {
81
85
  committedDate: '',
@@ -93,6 +97,7 @@ describe('prompt', () => {
93
97
  expectedTargetPullRequests: [],
94
98
  },
95
99
  {
100
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
96
101
  sourceBranch: 'master',
97
102
  sourceCommit: {
98
103
  committedDate: '',
@@ -5,6 +5,7 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
5
5
  const defaultTargetPullRequestTitle = 'DO NOT USE: Default Pull Request Title';
6
6
  const defaultSourceCommitSha = 'DO NOT USE: default-source-commit-sha';
7
7
  const baseMockCommit = {
8
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
8
9
  repository: {
9
10
  name: 'kibana',
10
11
  owner: { login: 'elastic' },
@@ -2,6 +2,7 @@ import { ValidConfigOptions } from '../../options/options';
2
2
  import { RemoteConfigHistory } from '../remoteConfig';
3
3
  import { ExpectedTargetPullRequest } from './getExpectedTargetPullRequests';
4
4
  export interface Commit {
5
+ author: SourceCommitWithTargetPullRequest['author'];
5
6
  sourceCommit: {
6
7
  committedDate: string;
7
8
  message: string;
@@ -86,6 +87,10 @@ export declare type SourceCommitWithTargetPullRequest = {
86
87
  sha: string;
87
88
  message: string;
88
89
  committedDate: string;
90
+ author: {
91
+ name: string;
92
+ email: string;
93
+ };
89
94
  associatedPullRequests: {
90
95
  edges: {
91
96
  node: SourcePullRequestNode;
@@ -10,6 +10,7 @@ const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests
10
10
  function parseSourceCommit({ sourceCommit, options, }) {
11
11
  const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
12
12
  return {
13
+ author: sourceCommit.author,
13
14
  sourceCommit: {
14
15
  committedDate: sourceCommit.committedDate,
15
16
  message: sourceCommit.message,
@@ -46,6 +47,11 @@ exports.SourceCommitWithTargetPullRequestFragment = (0, graphql_tag_1.default) `
46
47
  message
47
48
  committedDate
48
49
 
50
+ author {
51
+ name
52
+ email
53
+ }
54
+
49
55
  # Source pull request: PR where source commit was merged in
50
56
  associatedPullRequests(first: 1) {
51
57
  edges {
@@ -183,6 +183,7 @@ describe('parseSourceCommit', () => {
183
183
  },
184
184
  });
185
185
  const expectedCommit = {
186
+ author: { email: 'soren.louv@elastic.co', name: 'Søren Louv-Jansen' },
186
187
  sourceCommit: {
187
188
  committedDate: '2021-12-22T00:00:00Z',
188
189
  message: 'My commit message (#1234)',
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,219 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const child_process_promisified_1 = require("../../../services/child-process-promisified");
23
+ const packageVersion = __importStar(require("../../../utils/packageVersion"));
24
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
25
+ const sandbox_1 = require("../../sandbox");
26
+ const runBackportViaCli_1 = require("./runBackportViaCli");
27
+ const TIMEOUT_IN_SECONDS = 15;
28
+ jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
29
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
30
+ describe('backport cli', () => {
31
+ it('--version', async () => {
32
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--version`], {
33
+ showOra: true,
34
+ });
35
+ expect(res).toEqual(process.env.npm_package_version);
36
+ });
37
+ it('-v', async () => {
38
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([`-v`], {
39
+ showOra: true,
40
+ });
41
+ expect(res).toEqual(process.env.npm_package_version);
42
+ });
43
+ it('PACKAGE_VERSION should match', async () => {
44
+ // @ts-expect-error
45
+ expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(process.env.npm_package_version);
46
+ });
47
+ it('--help', async () => {
48
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--help`]);
49
+ expect(res).toMatchInlineSnapshot(`
50
+ "entrypoint.cli.ts [args]
51
+ Options:
52
+ -v, -V, --version Show version number [boolean]
53
+ --accessToken, --accesstoken Github access token [string]
54
+ -a, --all List all commits [boolean]
55
+ --assignee, --assign Add assignees to the target pull request [array]
56
+ --autoAssign Auto assign the target pull request to yourself [boolean]
57
+ --autoMerge Enable auto-merge for created pull requests [boolean]
58
+ --autoMergeMethod Sets auto-merge method when using --auto-merge. Default:
59
+ merge [string] [choices: \\"merge\\", \\"rebase\\", \\"squash\\"]
60
+ --ci Disable interactive prompts [boolean]
61
+ --cherrypickRef Append commit message with \\"(cherry picked from commit...)
62
+ [boolean]
63
+ --configFile, --config Path to project config [string]
64
+ --since ISO-8601 date for filtering commits [string]
65
+ --until ISO-8601 date for filtering commits [string]
66
+ --dir Location where the temporary repository will be stored
67
+ [string]
68
+ --details Show details about each commit [boolean]
69
+ --dryRun Run backport locally without pushing to Github [boolean]
70
+ --editor Editor to be opened during conflict resolution [string]
71
+ --skipRemoteConfig Use local .backportrc.json config instead of loading from
72
+ Github [boolean]
73
+ --fork Create backports in fork or origin repo. Defaults to true
74
+ [boolean]
75
+ --gitAuthorName Set commit author name [string]
76
+ --gitAuthorEmail Set commit author email [string]
77
+ --mainline Parent id of merge commit. Defaults to 1 when supplied
78
+ without arguments [number]
79
+ -n, --maxNumber, --number Number of commits to choose from [number]
80
+ --multiple Select multiple branches/commits [boolean]
81
+ --multipleBranches Backport to multiple branches [boolean]
82
+ --multipleCommits Backport multiple commits [boolean]
83
+ --noCherrypickRef Do not append commit message with \\"(cherry picked from
84
+ commit...)\\" [boolean]
85
+ --noStatusComment Don't publish status comment to Github [boolean]
86
+ --noVerify Bypass the pre-commit and commit-msg hooks [boolean]
87
+ --noFork Create backports in the origin repo [boolean]
88
+ -p, --path Only list commits touching files under the specified path
89
+ [array]
90
+ --prDescription, --description Description to be added to pull request [string]
91
+ --prTitle, --title Title of pull request [string]
92
+ --prFilter Filter source pull requests by a query [string]
93
+ --pullNumber, --pr Pull request to backport [number]
94
+ --resetAuthor Set yourself as commit author [boolean]
95
+ --reviewer Add reviewer to the target PR [array]
96
+ --repoForkOwner The owner of the fork where the backport branch is pushed.
97
+ Defaults to the currently authenticated user [string]
98
+ --repoOwner Repository owner [string]
99
+ --repoName Repository name [string]
100
+ --repo Repo owner and name [string]
101
+ --sha, --commit Commit sha to backport [string]
102
+ --sourceBranch Specify a non-default branch (normally \\"master\\") to backport
103
+ from [string]
104
+ --sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
105
+ -b, --targetBranch, --branch Branch(es) to backport to [array]
106
+ --targetBranchChoice List branches to backport to [array]
107
+ -l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
108
+ --verbose Show additional debug information [boolean]
109
+ --verify Opposite of no-verify [boolean]
110
+ --help Show help [boolean]
111
+ For bugs, feature requests or questions: https://github.com/sqren/backport/issues
112
+ Or contact me directly: https://twitter.com/sorenlouv"
113
+ `);
114
+ });
115
+ it('should return error when branch is missing', async () => {
116
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
117
+ '--skip-remote-config',
118
+ '--repo=backport-org/backport-e2e',
119
+ `--accessToken=${accessToken}`,
120
+ ]);
121
+ expect(res).toMatchInlineSnapshot(`
122
+ "Please specify a target branch: \\"--branch 6.1\\".
123
+ Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
124
+ `);
125
+ });
126
+ it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
127
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
128
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
129
+ await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
130
+ await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
131
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--accessToken=${accessToken}`], {
132
+ cwd: sandboxPath,
133
+ waitForString: 'Select commit',
134
+ });
135
+ expect(res).toMatchInlineSnapshot(`
136
+ "? Select commit (Use arrow keys)
137
+ ❯ 1. Add sheep emoji (#9) 7.8
138
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
139
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
140
+ 4. Add family emoji (#2) 7.x
141
+ 5. Add \`backport\` dep
142
+ 6. Merge pull request #1 from backport-org/add-heart-emoji
143
+ 7. Add ❤️ emoji
144
+ 8. Update .backportrc.json
145
+ 9. Bump to 8.0.0
146
+ 10.Add package.json"
147
+ `);
148
+ });
149
+ it('should return error when access token is invalid', async () => {
150
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
151
+ '--branch=foo',
152
+ '--repo=foo/bar',
153
+ '--accessToken=some-token',
154
+ ]);
155
+ expect(res).toContain('Please check your access token and make sure it is valid');
156
+ });
157
+ it(`should return error when repo doesn't exist`, async () => {
158
+ const res = await (0, runBackportViaCli_1.runBackportViaCli)([
159
+ '--branch=foo',
160
+ '--repo=foo/bar',
161
+ '--author=sqren',
162
+ `--accessToken=${accessToken}`,
163
+ ]);
164
+ expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
165
+ });
166
+ it(`should list commits from master`, async () => {
167
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
168
+ '--branch=foo',
169
+ '--repo=backport-org/backport-e2e',
170
+ '--author=sqren',
171
+ `--accessToken=${accessToken}`,
172
+ '--max-number=6',
173
+ ], { waitForString: 'Select commit' });
174
+ expect(output).toMatchInlineSnapshot(`
175
+ "? Select commit (Use arrow keys)
176
+ ❯ 1. Add sheep emoji (#9) 7.8
177
+ 2. Change Ulysses to Gretha (conflict) (#8) 7.x
178
+ 3. Add 🍏 emoji (#5) 7.x, 7.8
179
+ 4. Add family emoji (#2) 7.x
180
+ 5. Add \`backport\` dep
181
+ 6. Merge pull request #1 from backport-org/add-heart-emoji"
182
+ `);
183
+ });
184
+ it(`should filter commits by "since" and "until"`, async () => {
185
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
186
+ '--branch=foo',
187
+ '--repo=backport-org/backport-e2e',
188
+ `--accessToken=${accessToken}`,
189
+ '--since=2020-08-15T10:00:00.000Z',
190
+ '--until=2020-08-15T10:30:00.000Z',
191
+ ], { waitForString: 'Select commit' });
192
+ expect(output).toMatchInlineSnapshot(`
193
+ "? Select commit (Use arrow keys)
194
+ ❯ 1. Bump to 8.0.0
195
+ 2. Add package.json
196
+ 3. Update .backportrc.json
197
+ 4. Create .backportrc.json"
198
+ `);
199
+ });
200
+ it(`should list commits from 7.x`, async () => {
201
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
202
+ '--branch=foo',
203
+ '--repo=backport-org/backport-e2e',
204
+ '--author=sqren',
205
+ `--accessToken=${accessToken}`,
206
+ '--max-number=6',
207
+ '--source-branch=7.x',
208
+ ], { waitForString: 'Select commit' });
209
+ expect(output).toMatchInlineSnapshot(`
210
+ "? Select commit (Use arrow keys)
211
+ ❯ 1. Add 🍏 emoji (#5) (#6)
212
+ 2. Change Ulysses to Carol
213
+ 3. Add family emoji (#2) (#4)
214
+ 4. Update .backportrc.json
215
+ 5. Branch off: 7.9.0 (7.x)
216
+ 6. Bump to 8.0.0"
217
+ `);
218
+ });
219
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,96 @@
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
+ const promises_1 = __importDefault(require("fs/promises"));
7
+ const child_process_promisified_1 = require("../../../services/child-process-promisified");
8
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
9
+ const sandbox_1 = require("../../sandbox");
10
+ const runBackportViaCli_1 = require("./runBackportViaCli");
11
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
12
+ describe('commit author', () => {
13
+ let sourceRepo;
14
+ let backportRepo;
15
+ beforeEach(async () => {
16
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
17
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
18
+ sourceRepo = `${sandboxPath}/sourceRepo`;
19
+ backportRepo = `${sandboxPath}/backportRepo`;
20
+ await (0, child_process_promisified_1.exec)(`git clone https://github.com/backport-org/commit-author.git ${sourceRepo}`, { cwd: sandboxPath });
21
+ await promises_1.default.writeFile(`${sandboxPath}/.backportrc.json`, JSON.stringify({
22
+ repoName: 'commit-author',
23
+ repoOwner: 'backport-org',
24
+ }));
25
+ });
26
+ // eslint-disable-next-line jest/no-commented-out-tests
27
+ // it('use commit author from source commit', async () => {
28
+ // await runBackportViaCli(
29
+ // [
30
+ // `--accessToken=${accessToken}`,
31
+ // `--dir=${backportRepo}`,
32
+ // '--branch=production',
33
+ // '--pr=2',
34
+ // '--dry-run',
35
+ // ],
36
+ // { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true }
37
+ // );
38
+ // const { authorEmail, authorName } = await getCommitAuthor({
39
+ // cwd: backportRepo,
40
+ // });
41
+ // expect(authorName).toEqual('Sonny Long (demo)');
42
+ // expect(authorEmail).toEqual('71195571+sqren-demo@users.noreply.github.com');
43
+ // });
44
+ it('use commit author from git config in source repo', async () => {
45
+ await (0, child_process_promisified_1.exec)(`git config user.name "Peter Kanin"`, { cwd: sourceRepo });
46
+ await (0, child_process_promisified_1.exec)(`git config user.email "kanin@zoo.dk"`, { cwd: sourceRepo });
47
+ await (0, runBackportViaCli_1.runBackportViaCli)([
48
+ `--accessToken=${accessToken}`,
49
+ `--dir=${backportRepo}`,
50
+ '--branch=production',
51
+ '--pr=2',
52
+ '--dry-run',
53
+ ], { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true });
54
+ const { authorEmail, authorName } = await getCommitAuthor({
55
+ cwd: backportRepo,
56
+ });
57
+ expect(authorName).toEqual('Peter Kanin');
58
+ expect(authorEmail).toEqual('kanin@zoo.dk');
59
+ });
60
+ it('use commit author from cli args', async () => {
61
+ await (0, runBackportViaCli_1.runBackportViaCli)([
62
+ `--accessToken=${accessToken}`,
63
+ `--dir=${backportRepo}`,
64
+ '--branch=production',
65
+ '--pr=2',
66
+ '--dry-run',
67
+ '--gitAuthorName="Donald Duck"',
68
+ '--gitAuthorEmail=duck@disney.com',
69
+ ], { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true });
70
+ const { authorEmail, authorName } = await getCommitAuthor({
71
+ cwd: backportRepo,
72
+ });
73
+ expect(authorName).toEqual('Donald Duck');
74
+ expect(authorEmail).toEqual('duck@disney.com');
75
+ });
76
+ it('use resetAuthor option to set current user as author of commit', async () => {
77
+ await (0, runBackportViaCli_1.runBackportViaCli)([
78
+ `--accessToken=${accessToken}`,
79
+ `--dir=${backportRepo}`,
80
+ '--branch=production',
81
+ '--pr=2',
82
+ '--dry-run',
83
+ '--reset-author',
84
+ ], { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true });
85
+ const { authorEmail, authorName } = await getCommitAuthor({
86
+ cwd: backportRepo,
87
+ });
88
+ expect(authorName).toEqual('sqren');
89
+ expect(authorEmail).toEqual('sqren@users.noreply.github.com');
90
+ });
91
+ });
92
+ async function getCommitAuthor({ cwd }) {
93
+ const { stdout: authorName } = await (0, child_process_promisified_1.exec)('git --no-pager log -1 --format=format:"%cn"', { cwd });
94
+ const { stdout: authorEmail } = await (0, child_process_promisified_1.exec)('git --no-pager log -1 --format=format:"%ce"', { cwd });
95
+ return { authorName, authorEmail };
96
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const child_process_promisified_1 = require("../../../services/child-process-promisified");
4
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
5
+ const sandbox_1 = require("../../sandbox");
6
+ const runBackportViaCli_1 = require("./runBackportViaCli");
7
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
8
+ describe('different-merge-strategies', () => {
9
+ it('list all commits regardless how they were merged', async () => {
10
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
11
+ '--branch=foo',
12
+ '--repo=backport-org/different-merge-strategies',
13
+ `--accessToken=${accessToken}`,
14
+ '-n=20',
15
+ ], { waitForString: 'Select commit' });
16
+ expect(output).toMatchInlineSnapshot(`
17
+ "? Select commit (Use arrow keys)
18
+ ❯ 1. Merge pull request #9 from backport-org/many-merge-commits
19
+ 2. Merge strategy: Eighth of many merges
20
+ 3. Merge strategy: Seventh of many merges
21
+ 4. Merge strategy: Sixth of many merges
22
+ 5. Merge strategy: Fifth of many merges
23
+ 6. Merge strategy: Fourth of many merges
24
+ 7. Merge strategy: Third of many merges
25
+ 8. Merge strategy: Second of many merges
26
+ 9. Merge strategy: First of many merges
27
+ 10.Using squash to merge commits (#3) 7.x
28
+ 11.Rebase strategy: Second commit 7.x
29
+ 12.Rebase strategy: First commit
30
+ 13.Merge pull request #1 from backport-org/merge-strategy
31
+ 14.Merge strategy: Second commit
32
+ 15.Merge strategy: First commit
33
+ 16.Initial commit"
34
+ `);
35
+ });
36
+ describe('when selecting a merge commit', () => {
37
+ let output;
38
+ let sandboxPath;
39
+ beforeAll(async () => {
40
+ sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
41
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
42
+ output = await (0, runBackportViaCli_1.runBackportViaCli)([
43
+ '--branch=7.x',
44
+ '--repo=backport-org/different-merge-strategies',
45
+ `--accessToken=${accessToken}`,
46
+ `--dir=${sandboxPath}`,
47
+ '--pr=9',
48
+ '--dry-run',
49
+ ], { waitForString: 'Dry run complete', showOra: true });
50
+ });
51
+ it('runs to completion without errors', () => {
52
+ expect(output).toMatchInlineSnapshot(`
53
+ "- Initializing...
54
+ ? Select pull request Merge pull request #9 from backport-org/many-merge-commits
55
+ ✔ 100% Cloning repository from github.com (one-time operation)
56
+ Backporting to 7.x:
57
+ - Pulling latest changes
58
+ ✔ Pulling latest changes
59
+ - Cherry-picking: Merge pull request #9 from backport-org/many-merge-commits
60
+ ✔ Cherry-picking: Merge pull request #9 from backport-org/many-merge-commits
61
+ ✔ Dry run complete"
62
+ `);
63
+ });
64
+ it('backports all immediate children of the merge commit', async () => {
65
+ const commits = await listCommits(sandboxPath);
66
+ expect(commits).toEqual([
67
+ 'Merge strategy: Eighth of many merges',
68
+ 'Merge strategy: Seventh of many merges',
69
+ 'Merge strategy: Sixth of many merges',
70
+ 'Merge strategy: Fifth of many merges',
71
+ 'Merge strategy: Fourth of many merges',
72
+ 'Merge strategy: Third of many merges',
73
+ 'Merge strategy: Second of many merges',
74
+ 'Merge strategy: First of many merges',
75
+ 'Initial commit',
76
+ ]);
77
+ });
78
+ });
79
+ describe('when selecting anoter merge commit', () => {
80
+ let sandboxPath;
81
+ beforeAll(async () => {
82
+ sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
83
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
84
+ await (0, runBackportViaCli_1.runBackportViaCli)([
85
+ '--branch=7.x',
86
+ '--repo=backport-org/different-merge-strategies',
87
+ `--accessToken=${accessToken}`,
88
+ `--dir=${sandboxPath}`,
89
+ '--pr=1',
90
+ '--dry-run',
91
+ ], { waitForString: 'Dry run complete', showOra: true });
92
+ });
93
+ it('backports all immediate children of the merge commit', async () => {
94
+ const commits = await listCommits(sandboxPath);
95
+ expect(commits).toEqual([
96
+ 'Merge strategy: Second commit',
97
+ 'Merge strategy: First commit',
98
+ 'Initial commit',
99
+ ]);
100
+ });
101
+ });
102
+ });
103
+ async function listCommits(sandboxPath) {
104
+ const { stdout } = await (0, child_process_promisified_1.exec)('git --no-pager log --pretty=format:%s', {
105
+ cwd: sandboxPath,
106
+ });
107
+ return stdout.split('\n');
108
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
4
+ const runBackportViaCli_1 = require("./runBackportViaCli");
5
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
+ describe('repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
7
+ it('should list commits', async () => {
8
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
9
+ '--branch=foo',
10
+ '--repo=backport-org/repo-with-backportrc-removed',
11
+ `--accessToken=${accessToken}`,
12
+ ], { waitForString: 'Select commit' });
13
+ expect(output).toMatchInlineSnapshot(`
14
+ "? Select commit (Use arrow keys)
15
+ ❯ 1. Rename README.me to README.md
16
+ 2. Merge pull request #1 from backport-org/add-readme
17
+ 3. Create README.me
18
+ 4. Delete .backportrc.json
19
+ 5. Create .backportrc.json
20
+ 6. Delete .backportrc.json
21
+ 7. Create .backportrc.json"
22
+ `);
23
+ });
24
+ it('should attempt to backport by PR', async () => {
25
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
26
+ '--branch=foo',
27
+ '--repo=backport-org/repo-with-backportrc-removed',
28
+ '--pr=1',
29
+ `--accessToken=${accessToken}`,
30
+ ], { waitForString: "is invalid or doesn't exist" });
31
+ expect(output).toMatchInlineSnapshot(`
32
+ "
33
+ Backporting to foo:
34
+ The branch \\"foo\\" is invalid or doesn't exist"
35
+ `);
36
+ });
37
+ it('should attempt to backport by commit sha', async () => {
38
+ const output = await (0, runBackportViaCli_1.runBackportViaCli)([
39
+ '--branch=foo',
40
+ '--repo=backport-org/repo-with-backportrc-removed',
41
+ '--sha=be59df6912a550c8cb49ba3e18be3e512f3d608c',
42
+ `--accessToken=${accessToken}`,
43
+ ], { waitForString: `Backporting to foo:` });
44
+ expect(output).toMatchInlineSnapshot(`
45
+ "
46
+ Backporting to foo:"
47
+ `);
48
+ });
49
+ });
@@ -0,0 +1,5 @@
1
+ export declare function runBackportViaCli(cliArgs: string[], { showOra, waitForString, cwd, }?: {
2
+ showOra?: boolean;
3
+ waitForString?: string;
4
+ cwd?: string;
5
+ }): Promise<string>;