backport 7.2.0-beta.3 → 7.3.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.
- package/README.md +10 -5
- package/dist/entrypoint.cli.d.ts +0 -1
- package/dist/entrypoint.cli.js +0 -1
- package/dist/entrypoint.cli.private.test.js +1 -0
- package/dist/options/ConfigOptions.d.ts +2 -0
- package/dist/options/config/config.d.ts +2 -0
- package/dist/options/config/readConfigFile.d.ts +2 -0
- package/dist/options/options.d.ts +2 -0
- package/dist/runSequentially.js +2 -2
- package/dist/services/git.d.ts +11 -2
- package/dist/services/git.integration.test.js +12 -46
- package/dist/services/git.js +31 -15
- package/dist/services/git.test.js +12 -1
- package/dist/services/github/v3/createPullRequest.test.js +52 -0
- package/dist/services/github/v3/createStatusComment.test.js +12 -2
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +2 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +1 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +20 -0
- package/dist/services/prompt.test.js +5 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +6 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +1 -0
- package/dist/test/e2e/cli/cli.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/cli.private.test.js +215 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/different-merge-strategies.private.test.js +108 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +49 -0
- package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -0
- package/dist/test/e2e/cli/runBackportViaCli.js +53 -0
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.d.ts +1 -0
- package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +73 -0
- package/dist/test/e2e/module.e2e.mutation.test.d.ts +1 -0
- package/dist/test/e2e/module.e2e.mutation.test.js +369 -0
- package/dist/test/e2e/module.e2e.private.test.js +6 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +24 -14
- package/dist/ui/getCommitsWithoutBackports.test.js +20 -0
- package/dist/ui/getTargetBranches.test.js +2 -0
- package/dist/ui/setupRepo.d.ts +3 -0
- package/dist/ui/setupRepo.js +88 -0
- package/dist/ui/setupRepo.test.d.ts +1 -0
- package/dist/ui/setupRepo.test.js +288 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +6 -6
- package/yarn.lock +3 -3
|
@@ -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,215 @@
|
|
|
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 [boolean]
|
|
74
|
+
--mainline Parent id of merge commit. Defaults to 1 when supplied
|
|
75
|
+
without arguments [number]
|
|
76
|
+
-n, --maxNumber, --number Number of commits to choose from [number]
|
|
77
|
+
--multiple Select multiple branches/commits [boolean]
|
|
78
|
+
--multipleBranches Backport to multiple branches [boolean]
|
|
79
|
+
--multipleCommits Backport multiple commits [boolean]
|
|
80
|
+
--noCherrypickRef Do not append commit message with \\"(cherry picked from
|
|
81
|
+
commit...)\\" [boolean]
|
|
82
|
+
--noStatusComment Don't publish status comment to Github [boolean]
|
|
83
|
+
--noVerify Bypass the pre-commit and commit-msg hooks [boolean]
|
|
84
|
+
--noFork Create backports in the origin repo [boolean]
|
|
85
|
+
-p, --path Only list commits touching files under the specified path
|
|
86
|
+
[array]
|
|
87
|
+
--prDescription, --description Description to be added to pull request [string]
|
|
88
|
+
--prTitle, --title Title of pull request [string]
|
|
89
|
+
--prFilter Filter source pull requests by a query [string]
|
|
90
|
+
--pullNumber, --pr Pull request to backport [number]
|
|
91
|
+
--resetAuthor Set yourself as commit author [boolean]
|
|
92
|
+
--reviewer Add reviewer to the target PR [array]
|
|
93
|
+
--repoOwner Repository owner [string]
|
|
94
|
+
--repoName Repository name [string]
|
|
95
|
+
--repo Repo owner and name [string]
|
|
96
|
+
--sha, --commit Commit sha to backport [string]
|
|
97
|
+
--sourceBranch Specify a non-default branch (normally \\"master\\") to backport
|
|
98
|
+
from [string]
|
|
99
|
+
--sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
|
|
100
|
+
-b, --targetBranch, --branch Branch(es) to backport to [array]
|
|
101
|
+
--targetBranchChoice List branches to backport to [array]
|
|
102
|
+
-l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
|
|
103
|
+
--username Defaults to the authenticated user [string]
|
|
104
|
+
--verbose Show additional debug information [boolean]
|
|
105
|
+
--verify Opposite of no-verify [boolean]
|
|
106
|
+
--help Show help [boolean]
|
|
107
|
+
For bugs, feature requests or questions: https://github.com/sqren/backport/issues
|
|
108
|
+
Or contact me directly: https://twitter.com/sorenlouv"
|
|
109
|
+
`);
|
|
110
|
+
});
|
|
111
|
+
it('should return error when branch is missing', async () => {
|
|
112
|
+
const res = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
113
|
+
'--skip-remote-config',
|
|
114
|
+
'--repo=backport-org/backport-e2e',
|
|
115
|
+
`--accessToken=${accessToken}`,
|
|
116
|
+
]);
|
|
117
|
+
expect(res).toMatchInlineSnapshot(`
|
|
118
|
+
"Please specify a target branch: \\"--branch 6.1\\".
|
|
119
|
+
Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
|
|
120
|
+
`);
|
|
121
|
+
});
|
|
122
|
+
it('should list commits based on .git/config when `repoOwner`/`repoName` is missing', async () => {
|
|
123
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
124
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
125
|
+
await (0, child_process_promisified_1.exec)(`git init`, { cwd: sandboxPath });
|
|
126
|
+
await (0, child_process_promisified_1.exec)(`git remote add origin git@github.com:backport-org/backport-e2e.git`, { cwd: sandboxPath });
|
|
127
|
+
const res = await (0, runBackportViaCli_1.runBackportViaCli)([`--accessToken=${accessToken}`], {
|
|
128
|
+
cwd: sandboxPath,
|
|
129
|
+
waitForString: 'Select commit',
|
|
130
|
+
});
|
|
131
|
+
expect(res).toMatchInlineSnapshot(`
|
|
132
|
+
"? Select commit (Use arrow keys)
|
|
133
|
+
❯ 1. Add sheep emoji (#9) 7.8
|
|
134
|
+
2. Change Ulysses to Gretha (conflict) (#8) 7.x
|
|
135
|
+
3. Add 🍏 emoji (#5) 7.x, 7.8
|
|
136
|
+
4. Add family emoji (#2) 7.x
|
|
137
|
+
5. Add \`backport\` dep
|
|
138
|
+
6. Merge pull request #1 from backport-org/add-heart-emoji
|
|
139
|
+
7. Add ❤️ emoji
|
|
140
|
+
8. Update .backportrc.json
|
|
141
|
+
9. Bump to 8.0.0
|
|
142
|
+
10.Add package.json"
|
|
143
|
+
`);
|
|
144
|
+
});
|
|
145
|
+
it('should return error when access token is invalid', async () => {
|
|
146
|
+
const res = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
147
|
+
'--branch=foo',
|
|
148
|
+
'--repo=foo/bar',
|
|
149
|
+
'--accessToken=some-token',
|
|
150
|
+
]);
|
|
151
|
+
expect(res).toContain('Please check your access token and make sure it is valid');
|
|
152
|
+
});
|
|
153
|
+
it(`should return error when repo doesn't exist`, async () => {
|
|
154
|
+
const res = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
155
|
+
'--branch=foo',
|
|
156
|
+
'--repo=foo/bar',
|
|
157
|
+
'--author=sqren',
|
|
158
|
+
`--accessToken=${accessToken}`,
|
|
159
|
+
]);
|
|
160
|
+
expect(res).toMatchInlineSnapshot(`"The repository \\"foo/bar\\" doesn't exist"`);
|
|
161
|
+
});
|
|
162
|
+
it(`should list commits from master`, async () => {
|
|
163
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
164
|
+
'--branch=foo',
|
|
165
|
+
'--repo=backport-org/backport-e2e',
|
|
166
|
+
'--author=sqren',
|
|
167
|
+
`--accessToken=${accessToken}`,
|
|
168
|
+
'--max-number=6',
|
|
169
|
+
], { waitForString: 'Select commit' });
|
|
170
|
+
expect(output).toMatchInlineSnapshot(`
|
|
171
|
+
"? Select commit (Use arrow keys)
|
|
172
|
+
❯ 1. Add sheep emoji (#9) 7.8
|
|
173
|
+
2. Change Ulysses to Gretha (conflict) (#8) 7.x
|
|
174
|
+
3. Add 🍏 emoji (#5) 7.x, 7.8
|
|
175
|
+
4. Add family emoji (#2) 7.x
|
|
176
|
+
5. Add \`backport\` dep
|
|
177
|
+
6. Merge pull request #1 from backport-org/add-heart-emoji"
|
|
178
|
+
`);
|
|
179
|
+
});
|
|
180
|
+
it(`should filter commits by "since" and "until"`, async () => {
|
|
181
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
182
|
+
'--branch=foo',
|
|
183
|
+
'--repo=backport-org/backport-e2e',
|
|
184
|
+
`--accessToken=${accessToken}`,
|
|
185
|
+
'--since=2020-08-15T10:00:00.000Z',
|
|
186
|
+
'--until=2020-08-15T10:30:00.000Z',
|
|
187
|
+
], { waitForString: 'Select commit' });
|
|
188
|
+
expect(output).toMatchInlineSnapshot(`
|
|
189
|
+
"? Select commit (Use arrow keys)
|
|
190
|
+
❯ 1. Bump to 8.0.0
|
|
191
|
+
2. Add package.json
|
|
192
|
+
3. Update .backportrc.json
|
|
193
|
+
4. Create .backportrc.json"
|
|
194
|
+
`);
|
|
195
|
+
});
|
|
196
|
+
it(`should list commits from 7.x`, async () => {
|
|
197
|
+
const output = await (0, runBackportViaCli_1.runBackportViaCli)([
|
|
198
|
+
'--branch=foo',
|
|
199
|
+
'--repo=backport-org/backport-e2e',
|
|
200
|
+
'--author=sqren',
|
|
201
|
+
`--accessToken=${accessToken}`,
|
|
202
|
+
'--max-number=6',
|
|
203
|
+
'--source-branch=7.x',
|
|
204
|
+
], { waitForString: 'Select commit' });
|
|
205
|
+
expect(output).toMatchInlineSnapshot(`
|
|
206
|
+
"? Select commit (Use arrow keys)
|
|
207
|
+
❯ 1. Add 🍏 emoji (#5) (#6)
|
|
208
|
+
2. Change Ulysses to Carol
|
|
209
|
+
3. Add family emoji (#2) (#4)
|
|
210
|
+
4. Update .backportrc.json
|
|
211
|
+
5. Branch off: 7.9.0 (7.x)
|
|
212
|
+
6. Bump to 8.0.0"
|
|
213
|
+
`);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,53 @@
|
|
|
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.runBackportViaCli = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
11
|
+
const TIMEOUT_IN_SECONDS = 15;
|
|
12
|
+
jest.setTimeout(TIMEOUT_IN_SECONDS * 1000);
|
|
13
|
+
function runBackportViaCli(cliArgs, { showOra, waitForString, cwd, } = {}) {
|
|
14
|
+
const tsNodeBinary = path_1.default.resolve('./node_modules/.bin/ts-node');
|
|
15
|
+
const entrypointFile = path_1.default.resolve('./src/entrypoint.cli.ts');
|
|
16
|
+
const proc = (0, child_process_1.spawn)(tsNodeBinary, [
|
|
17
|
+
'--transpile-only',
|
|
18
|
+
entrypointFile,
|
|
19
|
+
'--log-file-path',
|
|
20
|
+
'/dev/null',
|
|
21
|
+
...cliArgs,
|
|
22
|
+
], { cwd });
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
let data = '';
|
|
25
|
+
const timeoutSeconds = 2;
|
|
26
|
+
const rejectOnTimeout = (0, lodash_1.debounce)(() => {
|
|
27
|
+
reject(`Expectation '${waitForString}' not found within ${timeoutSeconds} second in:\n\n${data.toString()}`);
|
|
28
|
+
}, timeoutSeconds * 1000, { maxWait: 15000 });
|
|
29
|
+
// fail if expectations hasn't been found within 10 seconds
|
|
30
|
+
const onChunk = (chunk) => {
|
|
31
|
+
data += chunk;
|
|
32
|
+
const stringfiedData = data.toString();
|
|
33
|
+
rejectOnTimeout();
|
|
34
|
+
// remove ansi codes and whitespace
|
|
35
|
+
const output = (0, strip_ansi_1.default)(stringfiedData).replace(/\s+$/gm, '');
|
|
36
|
+
if (!waitForString || output.includes(waitForString)) {
|
|
37
|
+
rejectOnTimeout.cancel();
|
|
38
|
+
resolve(output);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
proc.stdout.on('data', onChunk);
|
|
42
|
+
// ora (loading spinner) is redirected to stderr
|
|
43
|
+
if (showOra) {
|
|
44
|
+
proc.stderr.on('data', onChunk);
|
|
45
|
+
}
|
|
46
|
+
proc.on('error', (err) => {
|
|
47
|
+
reject(`runBackportViaCli failed with: ${err}`);
|
|
48
|
+
});
|
|
49
|
+
}).finally(() => {
|
|
50
|
+
proc.kill();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.runBackportViaCli = runBackportViaCli;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|