backport 5.6.6 → 6.0.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 +48 -39
- package/dist/entrypoint.cli.js +1 -1
- package/dist/entrypoint.module.d.ts +6 -5
- package/dist/entrypoint.module.js +8 -6
- package/dist/ink.d.ts +1 -0
- package/dist/ink.js +49 -0
- package/dist/main.d.ts +11 -6
- package/dist/main.js +40 -24
- package/dist/options/ConfigOptions.d.ts +13 -8
- package/dist/options/cliArgs.d.ts +11 -9
- package/dist/options/cliArgs.js +74 -36
- package/dist/options/cliArgs.test.js +33 -37
- package/dist/options/config/config.d.ts +17 -15
- package/dist/options/config/config.js +8 -8
- package/dist/options/config/config.test.js +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -1
- package/dist/options/config/globalConfig.d.ts +2 -51
- package/dist/options/config/globalConfig.js +8 -8
- package/dist/options/config/globalConfig.test.js +7 -3
- package/dist/options/config/projectConfig.d.ts +2 -51
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/projectConfig.test.js +3 -3
- package/dist/options/config/readConfigFile.d.ts +2 -51
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +19 -14
- package/dist/options/options.js +5 -6
- package/dist/options/options.test.js +48 -11
- package/dist/options/parseRequiredOptions.d.ts +18 -13
- package/dist/options/parseRequiredOptions.js +8 -12
- package/dist/options/parseRequiredOptions.test.js +25 -16
- package/dist/runSequentially.d.ts +20 -0
- package/dist/runSequentially.js +41 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +235 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +138 -17
- package/dist/scripts/generate-gql.d.ts +1 -0
- package/dist/scripts/generate-gql.js +15 -0
- package/dist/scripts/postinstall.js +4 -4
- package/dist/scripts/postinstall.test.js +9 -2
- package/dist/scripts/runPostinstall.js +1 -1
- package/dist/services/HandledError.d.ts +11 -1
- package/dist/services/HandledError.js +2 -1
- package/dist/services/child-process-promisified.d.ts +1 -1
- package/dist/services/child-process-promisified.js +1 -1
- package/dist/services/env.js +5 -5
- package/dist/services/env.test.js +11 -4
- package/dist/services/fs-promisified.js +4 -4
- package/dist/services/getExpectedTarget.d.ts +9 -0
- package/dist/services/getExpectedTarget.js +77 -0
- package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/getExpectedTargetPullRequests.js +77 -0
- package/dist/services/git.d.ts +15 -4
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +86 -61
- package/dist/services/git.test.js +61 -64
- package/dist/services/github/commitFormatters.d.ts +3 -7
- package/dist/services/github/commitFormatters.js +10 -19
- package/dist/services/github/commitFormatters.test.js +2 -24
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -6
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +2 -3
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
- package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
- package/dist/services/github/v3/createPullRequest.d.ts +3 -2
- package/dist/services/github/v3/createPullRequest.js +32 -23
- package/dist/services/github/v3/createStatusComment.d.ts +11 -0
- package/dist/services/github/v3/createStatusComment.js +97 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +209 -0
- package/dist/services/github/v4/FetchPullRequestId.js +1 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +5 -7
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +8 -7
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +94 -33
- package/dist/services/github/v4/fetchAuthorId.js +1 -1
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommitBySha.js +14 -12
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +5 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +67 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +5 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +16 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +90 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +130 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +127 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +81 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
- package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
- package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -3
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
- package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
- package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +16 -10
- package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +25 -7
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +13 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +13 -15
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
- package/dist/services/logger.d.ts +3 -3
- package/dist/services/logger.js +16 -15
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +87 -0
- package/dist/services/prompts.d.ts +10 -4
- package/dist/services/prompts.js +85 -22
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +396 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +114 -0
- package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit/sourceCommit.js +86 -0
- package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
- package/dist/services/sourceCommit.d.ts +78 -0
- package/dist/services/sourceCommit.js +86 -0
- package/dist/services/sourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit.test.js +280 -0
- package/dist/test/inquirer.private.test.js +22 -15
- package/dist/test/integration/createSpies.js +6 -6
- package/dist/test/integration/envConstants.js +5 -6
- package/dist/test/integration/helpers.js +1 -1
- package/dist/test/integration/integration.private.test.d.ts +1 -0
- package/dist/test/integration/integration.private.test.js +308 -0
- package/dist/test/integration/integration.test.js +28 -29
- package/dist/test/nockHelpers.js +3 -7
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +0 -22
- package/dist/types/Commit.d.ts +85 -0
- package/dist/types/Commit.js +139 -0
- package/dist/types/commitNode.d.ts +89 -0
- package/dist/types/commitNode.js +139 -0
- package/dist/types/commitNode.test.d.ts +1 -0
- package/dist/types/commitNode.test.js +255 -0
- package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
- package/dist/types/commitWithAssociatedPullRequests.js +145 -0
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +277 -59
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +131 -68
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommits.js +55 -25
- package/dist/ui/getTargetBranches.d.ts +2 -2
- package/dist/ui/getTargetBranches.js +16 -17
- package/dist/ui/getTargetBranches.test.js +75 -99
- package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
- package/dist/ui/getTargetBranchesFromLabels.js +40 -0
- package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
- package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
- package/dist/ui/maybeSetupRepo.js +9 -9
- package/dist/ui/maybeSetupRepo.test.js +5 -1
- package/package.json +36 -51
- package/yarn.lock +2387 -2987
|
@@ -18,12 +18,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
21
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const os_1 = __importDefault(require("os"));
|
|
22
26
|
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
23
|
-
const git_1 = require("../services/git");
|
|
24
27
|
const ExecError_1 = require("../test/ExecError");
|
|
28
|
+
const git_1 = require("./git");
|
|
25
29
|
beforeEach(() => {
|
|
26
|
-
jest.
|
|
30
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
31
|
+
});
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
jest.restoreAllMocks();
|
|
27
34
|
});
|
|
28
35
|
describe('getUnstagedFiles', () => {
|
|
29
36
|
it('should split lines and remove empty', async () => {
|
|
@@ -35,7 +42,7 @@ describe('getUnstagedFiles', () => {
|
|
|
35
42
|
repoOwner: 'elastic',
|
|
36
43
|
repoName: 'kibana',
|
|
37
44
|
};
|
|
38
|
-
await expect(await git_1.getUnstagedFiles(options)).toEqual([
|
|
45
|
+
await expect(await (0, git_1.getUnstagedFiles)(options)).toEqual([
|
|
39
46
|
'/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
40
47
|
'/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file2.txt',
|
|
41
48
|
]);
|
|
@@ -49,7 +56,7 @@ describe('getUnstagedFiles', () => {
|
|
|
49
56
|
repoOwner: 'elastic',
|
|
50
57
|
repoName: 'kibana',
|
|
51
58
|
};
|
|
52
|
-
await expect(await git_1.getUnstagedFiles(options)).toEqual([]);
|
|
59
|
+
await expect(await (0, git_1.getUnstagedFiles)(options)).toEqual([]);
|
|
53
60
|
});
|
|
54
61
|
});
|
|
55
62
|
describe('getLocalConfigFileCommitDate', () => {
|
|
@@ -59,12 +66,12 @@ describe('getLocalConfigFileCommitDate', () => {
|
|
|
59
66
|
stderr: '',
|
|
60
67
|
};
|
|
61
68
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
62
|
-
expect(await git_1.getLocalConfigFileCommitDate()).toEqual(1608142239000);
|
|
69
|
+
expect(await (0, git_1.getLocalConfigFileCommitDate)()).toEqual(1608142239000);
|
|
63
70
|
});
|
|
64
71
|
it('returns empty when file does not exists', async () => {
|
|
65
72
|
const res = { stdout: '', stderr: '' };
|
|
66
73
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
67
|
-
expect(await git_1.getLocalConfigFileCommitDate()).toEqual(undefined);
|
|
74
|
+
expect(await (0, git_1.getLocalConfigFileCommitDate)()).toEqual(undefined);
|
|
68
75
|
});
|
|
69
76
|
it('handles errors', async () => {
|
|
70
77
|
const err = {
|
|
@@ -76,19 +83,19 @@ describe('getLocalConfigFileCommitDate', () => {
|
|
|
76
83
|
stderr: 'any error',
|
|
77
84
|
};
|
|
78
85
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
79
|
-
expect(await git_1.getLocalConfigFileCommitDate()).toEqual(undefined);
|
|
86
|
+
expect(await (0, git_1.getLocalConfigFileCommitDate)()).toEqual(undefined);
|
|
80
87
|
});
|
|
81
88
|
});
|
|
82
89
|
describe('isLocalConfigFileUntracked', () => {
|
|
83
90
|
it('returns "false" if file does not exist', async () => {
|
|
84
91
|
const res = { stdout: '', stderr: '' };
|
|
85
92
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
86
|
-
expect(await git_1.isLocalConfigFileUntracked()).toEqual(false);
|
|
93
|
+
expect(await (0, git_1.isLocalConfigFileUntracked)()).toEqual(false);
|
|
87
94
|
});
|
|
88
95
|
it('returns "true" if file is untracked', async () => {
|
|
89
96
|
const res = { stdout: '.backportrc.json\n', stderr: '' };
|
|
90
97
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
91
|
-
expect(await git_1.isLocalConfigFileUntracked()).toEqual(true);
|
|
98
|
+
expect(await (0, git_1.isLocalConfigFileUntracked)()).toEqual(true);
|
|
92
99
|
});
|
|
93
100
|
it('handles errors', async () => {
|
|
94
101
|
const err = {
|
|
@@ -100,24 +107,24 @@ describe('isLocalConfigFileUntracked', () => {
|
|
|
100
107
|
stderr: 'any error',
|
|
101
108
|
};
|
|
102
109
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
103
|
-
expect(await git_1.isLocalConfigFileUntracked()).toEqual(undefined);
|
|
110
|
+
expect(await (0, git_1.isLocalConfigFileUntracked)()).toEqual(undefined);
|
|
104
111
|
});
|
|
105
112
|
});
|
|
106
113
|
describe('isLocalConfigFileModified', () => {
|
|
107
114
|
it('returns "false" if file does not exist', async () => {
|
|
108
115
|
const res = { stdout: '', stderr: '' };
|
|
109
116
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
110
|
-
expect(await git_1.isLocalConfigFileModified()).toEqual(false);
|
|
117
|
+
expect(await (0, git_1.isLocalConfigFileModified)()).toEqual(false);
|
|
111
118
|
});
|
|
112
119
|
it('returns "false" if file is untracked', async () => {
|
|
113
120
|
const res = { stdout: '', stderr: '' };
|
|
114
121
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
115
|
-
expect(await git_1.isLocalConfigFileModified()).toEqual(false);
|
|
122
|
+
expect(await (0, git_1.isLocalConfigFileModified)()).toEqual(false);
|
|
116
123
|
});
|
|
117
124
|
it('returns "true" if file is staged', async () => {
|
|
118
125
|
const res = { stdout: '.backportrc.json\n', stderr: '' };
|
|
119
126
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
120
|
-
expect(await git_1.isLocalConfigFileModified()).toEqual(true);
|
|
127
|
+
expect(await (0, git_1.isLocalConfigFileModified)()).toEqual(true);
|
|
121
128
|
});
|
|
122
129
|
it('handles errors', async () => {
|
|
123
130
|
const err = {
|
|
@@ -129,7 +136,7 @@ describe('isLocalConfigFileModified', () => {
|
|
|
129
136
|
stderr: 'any error',
|
|
130
137
|
};
|
|
131
138
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
132
|
-
expect(await git_1.isLocalConfigFileModified()).toEqual(undefined);
|
|
139
|
+
expect(await (0, git_1.isLocalConfigFileModified)()).toEqual(undefined);
|
|
133
140
|
});
|
|
134
141
|
});
|
|
135
142
|
describe('getUpstreamFromGitRemote', () => {
|
|
@@ -139,12 +146,12 @@ describe('getUpstreamFromGitRemote', () => {
|
|
|
139
146
|
stderr: '',
|
|
140
147
|
};
|
|
141
148
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
142
|
-
expect(await git_1.getUpstreamFromGitRemote()).toEqual('elastic/kibana');
|
|
149
|
+
expect(await (0, git_1.getUpstreamFromGitRemote)()).toEqual('elastic/kibana');
|
|
143
150
|
});
|
|
144
151
|
it('returns undefined when no remotes exist', async () => {
|
|
145
152
|
const res = { stdout: '', stderr: '' };
|
|
146
153
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
147
|
-
expect(await git_1.getUpstreamFromGitRemote()).toEqual(undefined);
|
|
154
|
+
expect(await (0, git_1.getUpstreamFromGitRemote)()).toEqual(undefined);
|
|
148
155
|
});
|
|
149
156
|
it('handles errors', async () => {
|
|
150
157
|
const err = {
|
|
@@ -156,7 +163,7 @@ describe('getUpstreamFromGitRemote', () => {
|
|
|
156
163
|
stderr: 'fatal: not a git repository (or any of the parent directories): .git\n',
|
|
157
164
|
};
|
|
158
165
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
159
|
-
expect(await git_1.getUpstreamFromGitRemote()).toEqual(undefined);
|
|
166
|
+
expect(await (0, git_1.getUpstreamFromGitRemote)()).toEqual(undefined);
|
|
160
167
|
});
|
|
161
168
|
});
|
|
162
169
|
describe('getConflictingFiles', () => {
|
|
@@ -174,8 +181,11 @@ describe('getConflictingFiles', () => {
|
|
|
174
181
|
repoOwner: 'elastic',
|
|
175
182
|
repoName: 'kibana',
|
|
176
183
|
};
|
|
177
|
-
expect(await git_1.getConflictingFiles(options)).toEqual([
|
|
178
|
-
|
|
184
|
+
expect(await (0, git_1.getConflictingFiles)(options)).toEqual([
|
|
185
|
+
{
|
|
186
|
+
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
187
|
+
relative: 'conflicting-file.txt',
|
|
188
|
+
},
|
|
179
189
|
]);
|
|
180
190
|
});
|
|
181
191
|
});
|
|
@@ -197,7 +207,7 @@ describe('createFeatureBranch', () => {
|
|
|
197
207
|
stderr: "fatal: couldn't find remote ref 4.x\n",
|
|
198
208
|
};
|
|
199
209
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
200
|
-
await expect(git_1.createBackportBranch({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
210
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
201
211
|
});
|
|
202
212
|
it('should throw "Invalid refspec" error', async () => {
|
|
203
213
|
expect.assertions(1);
|
|
@@ -210,14 +220,14 @@ describe('createFeatureBranch', () => {
|
|
|
210
220
|
stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
|
|
211
221
|
};
|
|
212
222
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
213
|
-
await expect(git_1.createBackportBranch({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
223
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
214
224
|
});
|
|
215
225
|
it('should rethrow normal error', async () => {
|
|
216
226
|
expect.assertions(1);
|
|
217
227
|
const err = new Error('just a normal error');
|
|
218
228
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
219
229
|
expect.assertions(1);
|
|
220
|
-
await expect(git_1.createBackportBranch({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
230
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
221
231
|
});
|
|
222
232
|
});
|
|
223
233
|
describe('deleteRemote', () => {
|
|
@@ -236,13 +246,13 @@ describe('deleteRemote', () => {
|
|
|
236
246
|
stderr: "fatal: No such remote: 'origin'\n",
|
|
237
247
|
};
|
|
238
248
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
239
|
-
await expect(await git_1.deleteRemote(options, remoteName)).toBe(undefined);
|
|
249
|
+
await expect(await (0, git_1.deleteRemote)(options, remoteName)).toBe(undefined);
|
|
240
250
|
});
|
|
241
251
|
it('should rethrow normal error', async () => {
|
|
242
252
|
const err = new Error('just a normal error');
|
|
243
253
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
244
254
|
expect.assertions(1);
|
|
245
|
-
await expect(git_1.deleteRemote(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
255
|
+
await expect((0, git_1.deleteRemote)(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
246
256
|
});
|
|
247
257
|
});
|
|
248
258
|
describe('cherrypick', () => {
|
|
@@ -250,40 +260,28 @@ describe('cherrypick', () => {
|
|
|
250
260
|
repoOwner: 'elastic',
|
|
251
261
|
repoName: 'kibana',
|
|
252
262
|
};
|
|
253
|
-
const commit = {
|
|
254
|
-
sourceBranch: '7.x',
|
|
255
|
-
formattedMessage: '',
|
|
256
|
-
originalMessage: '',
|
|
257
|
-
sha: 'abcd',
|
|
258
|
-
targetBranchesFromLabels: [],
|
|
259
|
-
existingTargetPullRequests: [],
|
|
260
|
-
};
|
|
261
263
|
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
262
264
|
jest
|
|
263
265
|
.spyOn(childProcess, 'exec')
|
|
264
|
-
// mock git fetch
|
|
265
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
266
266
|
// mock cherry pick command
|
|
267
267
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
268
|
-
expect(await git_1.cherrypick(options,
|
|
268
|
+
expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
|
|
269
|
+
conflictingFiles: [],
|
|
270
|
+
unstagedFiles: [],
|
|
269
271
|
needsResolving: false,
|
|
270
272
|
});
|
|
271
273
|
});
|
|
272
274
|
it('should use mainline option when specified', async () => {
|
|
273
275
|
const execSpy = jest
|
|
274
276
|
.spyOn(childProcess, 'exec')
|
|
275
|
-
// mock git fetch
|
|
276
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
277
277
|
// mock cherry pick command
|
|
278
278
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
279
|
-
await git_1.cherrypick({ ...options, mainline: 1 },
|
|
280
|
-
expect(execSpy.mock.calls[
|
|
279
|
+
await (0, git_1.cherrypick)({ ...options, mainline: 1 }, 'abcd');
|
|
280
|
+
expect(execSpy.mock.calls[0][0]).toBe('git cherry-pick --mainline 1 abcd');
|
|
281
281
|
});
|
|
282
282
|
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
283
283
|
jest
|
|
284
284
|
.spyOn(childProcess, 'exec')
|
|
285
|
-
// mock git fetch
|
|
286
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
287
285
|
// mock cherry pick command
|
|
288
286
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
289
287
|
killed: false,
|
|
@@ -301,15 +299,20 @@ describe('cherrypick', () => {
|
|
|
301
299
|
}))
|
|
302
300
|
// mock getUnstagedFiles
|
|
303
301
|
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
304
|
-
expect(await git_1.cherrypick(options,
|
|
302
|
+
expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
|
|
303
|
+
conflictingFiles: [
|
|
304
|
+
{
|
|
305
|
+
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
306
|
+
relative: 'conflicting-file.txt',
|
|
307
|
+
},
|
|
308
|
+
],
|
|
305
309
|
needsResolving: true,
|
|
310
|
+
unstagedFiles: [],
|
|
306
311
|
});
|
|
307
312
|
});
|
|
308
313
|
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
309
314
|
jest
|
|
310
315
|
.spyOn(childProcess, 'exec')
|
|
311
|
-
// mock git fetch
|
|
312
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
313
316
|
// mock cherry pick command
|
|
314
317
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
315
318
|
killed: false,
|
|
@@ -319,7 +322,7 @@ describe('cherrypick', () => {
|
|
|
319
322
|
stdout: '',
|
|
320
323
|
stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
|
|
321
324
|
}));
|
|
322
|
-
await expect(git_1.cherrypick(options,
|
|
325
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
|
|
323
326
|
.toThrowError(`Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the \`mainline\` argument:
|
|
324
327
|
|
|
325
328
|
> backport --mainline
|
|
@@ -333,8 +336,6 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
333
336
|
it('should gracefully handle empty commits', async () => {
|
|
334
337
|
jest
|
|
335
338
|
.spyOn(childProcess, 'exec')
|
|
336
|
-
// mock git fetch
|
|
337
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
338
339
|
// mock cherry pick command
|
|
339
340
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
340
341
|
killed: false,
|
|
@@ -344,13 +345,11 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
344
345
|
stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
|
|
345
346
|
stderr: "The previous cherry-pick is now empty, possibly due to conflict resolution.\nIf you wish to commit it anyway, use:\n\n git commit --allow-empty\n\nOtherwise, please use 'git cherry-pick --skip'\n",
|
|
346
347
|
}));
|
|
347
|
-
await expect(git_1.cherrypick(options,
|
|
348
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowError(`Cherrypick failed because the selected commit (abcd) is empty. Did you already backport this commit?`);
|
|
348
349
|
});
|
|
349
350
|
it('gracefully handles missing git info', async () => {
|
|
350
351
|
jest
|
|
351
352
|
.spyOn(childProcess, 'exec')
|
|
352
|
-
// mock git fetch
|
|
353
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
354
353
|
// mock cherry pick command
|
|
355
354
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
356
355
|
killed: false,
|
|
@@ -358,9 +357,9 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
358
357
|
signal: null,
|
|
359
358
|
cmd: 'git cherry-pick 83ad852b6ba1a64c8047f07201018eb6fb020db8',
|
|
360
359
|
stdout: '',
|
|
361
|
-
stderr: '\n*** Please tell me who you are.\n\nRun\n\n git config --global user.email "you@example.com"\n git config --global user.name "Your Name"\n\nto set your account\'s default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: empty ident name (for <
|
|
360
|
+
stderr: '\n*** Please tell me who you are.\n\nRun\n\n git config --global user.email "you@example.com"\n git config --global user.name "Your Name"\n\nto set your account\'s default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: empty ident name (for <foo@bar.net>) not allowed\n',
|
|
362
361
|
}));
|
|
363
|
-
await expect(git_1.cherrypick(options,
|
|
362
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
|
|
364
363
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
365
364
|
"Cherrypick failed:
|
|
366
365
|
|
|
@@ -374,22 +373,20 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
374
373
|
to set your account's default identity.
|
|
375
374
|
Omit --global to set the identity only in this repository.
|
|
376
375
|
|
|
377
|
-
fatal: empty ident name (for <
|
|
376
|
+
fatal: empty ident name (for <foo@bar.net>) not allowed
|
|
378
377
|
"
|
|
379
378
|
`);
|
|
380
379
|
});
|
|
381
380
|
it('should re-throw non-cherrypick errors', async () => {
|
|
382
381
|
jest
|
|
383
382
|
.spyOn(childProcess, 'exec')
|
|
384
|
-
// mock git fetch
|
|
385
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
386
383
|
// mock cherry pick command
|
|
387
384
|
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
388
385
|
// getConflictingFiles
|
|
389
386
|
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
|
390
387
|
// getUnstagedFiles
|
|
391
388
|
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
392
|
-
await expect(git_1.cherrypick(options,
|
|
389
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
393
390
|
});
|
|
394
391
|
});
|
|
395
392
|
describe('commitChanges', () => {
|
|
@@ -404,7 +401,7 @@ describe('commitChanges', () => {
|
|
|
404
401
|
jest
|
|
405
402
|
.spyOn(childProcess, 'exec')
|
|
406
403
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
407
|
-
await expect(await git_1.commitChanges(commit, options)).toBe(undefined);
|
|
404
|
+
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
408
405
|
});
|
|
409
406
|
it('should swallow error if changes have already been committed manaully', async () => {
|
|
410
407
|
const err = {
|
|
@@ -416,7 +413,7 @@ describe('commitChanges', () => {
|
|
|
416
413
|
stderr: '',
|
|
417
414
|
};
|
|
418
415
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
419
|
-
await expect(await git_1.commitChanges(commit, options)).toBe(undefined);
|
|
416
|
+
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
420
417
|
});
|
|
421
418
|
describe('when commit fails due to empty message', () => {
|
|
422
419
|
let spy;
|
|
@@ -434,7 +431,7 @@ describe('commitChanges', () => {
|
|
|
434
431
|
.spyOn(childProcess, 'exec')
|
|
435
432
|
.mockRejectedValueOnce(err)
|
|
436
433
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
437
|
-
res = await git_1.commitChanges(commit, options);
|
|
434
|
+
res = await (0, git_1.commitChanges)(commit, options);
|
|
438
435
|
});
|
|
439
436
|
it('should manually set the commit message', () => {
|
|
440
437
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
@@ -449,7 +446,7 @@ describe('commitChanges', () => {
|
|
|
449
446
|
const err = new Error('non-cherrypick error');
|
|
450
447
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
451
448
|
expect.assertions(1);
|
|
452
|
-
await expect(git_1.commitChanges(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
449
|
+
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
453
450
|
});
|
|
454
451
|
});
|
|
455
452
|
describe('addRemote', () => {
|
|
@@ -463,21 +460,21 @@ describe('addRemote', () => {
|
|
|
463
460
|
const spy = jest
|
|
464
461
|
.spyOn(childProcess, 'exec')
|
|
465
462
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
466
|
-
await git_1.addRemote(options, 'elastic');
|
|
463
|
+
await (0, git_1.addRemote)(options, 'elastic');
|
|
467
464
|
return expect(spy).toHaveBeenCalledWith('git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
|
|
468
465
|
});
|
|
469
466
|
it('add correct user remote', async () => {
|
|
470
467
|
const spy = jest
|
|
471
468
|
.spyOn(childProcess, 'exec')
|
|
472
469
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
473
|
-
await git_1.addRemote(options, 'sqren');
|
|
470
|
+
await (0, git_1.addRemote)(options, 'sqren');
|
|
474
471
|
return expect(spy).toHaveBeenCalledWith('git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
|
|
475
472
|
});
|
|
476
473
|
it('allows custom github url', async () => {
|
|
477
474
|
const spy = jest
|
|
478
475
|
.spyOn(childProcess, 'exec')
|
|
479
476
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
480
|
-
await git_1.addRemote({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
|
|
477
|
+
await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
|
|
481
478
|
return expect(spy).toHaveBeenCalledWith('git remote add sqren https://x-access-token:myAccessToken@github.my-company.com/sqren/kibana.git', { cwd: '/myHomeDir/.backport/repositories/elastic/kibana' });
|
|
482
479
|
});
|
|
483
480
|
});
|
|
@@ -498,6 +495,6 @@ describe('pushBackportBranch', () => {
|
|
|
498
495
|
stdout: '',
|
|
499
496
|
stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
|
|
500
497
|
});
|
|
501
|
-
await expect(git_1.pushBackportBranch({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/sqren/kibana. Repository does not exist. Either fork the source repository (https://github.com/elastic/kibana) or disable fork mode \\"--fork
|
|
498
|
+
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/sqren/kibana. Repository does not exist. Either fork the source repository (https://github.com/elastic/kibana) or disable fork mode \\"--no-fork\\". Read more about \\"fork mode\\" in the docs: https://github.com/sqren/backport/blob/3a182b17e0e7237c12915895aea9d71f49eb2886/docs/configuration.md#fork"`);
|
|
502
499
|
});
|
|
503
500
|
});
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export declare function getShortSha(sha: string): string;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
5
|
-
pullNumber?: number;
|
|
6
|
-
sha: string;
|
|
7
|
-
}): string;
|
|
8
|
-
export declare function getPullNumberFromMessage(firstMessageLine: string): number | undefined;
|
|
2
|
+
export declare function getFirstLine(message: string): string;
|
|
3
|
+
export declare function stripPullNumber(message: string): string;
|
|
4
|
+
export declare function extractPullNumber(firstMessageLine: string): number | undefined;
|
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.extractPullNumber = exports.stripPullNumber = exports.getFirstLine = exports.getShortSha = void 0;
|
|
4
4
|
function getShortSha(sha) {
|
|
5
5
|
return sha.slice(0, 8);
|
|
6
6
|
}
|
|
7
7
|
exports.getShortSha = getShortSha;
|
|
8
|
-
function
|
|
8
|
+
function getFirstLine(message) {
|
|
9
9
|
return message.split('\n')[0];
|
|
10
10
|
}
|
|
11
|
-
exports.
|
|
12
|
-
function
|
|
13
|
-
const firstMessageLine =
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
if (messageHasPullNumber) {
|
|
17
|
-
return firstMessageLine;
|
|
18
|
-
}
|
|
19
|
-
// message doesn't contain pull number. Add it
|
|
20
|
-
if (pullNumber) {
|
|
21
|
-
return `${firstMessageLine} (#${pullNumber})`;
|
|
22
|
-
}
|
|
23
|
-
// pull number not available. Add commit
|
|
24
|
-
return `${firstMessageLine} (${getShortSha(sha)})`;
|
|
11
|
+
exports.getFirstLine = getFirstLine;
|
|
12
|
+
function stripPullNumber(message) {
|
|
13
|
+
const firstMessageLine = getFirstLine(message);
|
|
14
|
+
const messageWithoutPullNumber = firstMessageLine.replace(/( \(#\d+\))$/, '');
|
|
15
|
+
return messageWithoutPullNumber;
|
|
25
16
|
}
|
|
26
|
-
exports.
|
|
27
|
-
function
|
|
17
|
+
exports.stripPullNumber = stripPullNumber;
|
|
18
|
+
function extractPullNumber(firstMessageLine) {
|
|
28
19
|
const matches = firstMessageLine.match(/\(#(\d+)\)/);
|
|
29
20
|
if (matches) {
|
|
30
21
|
return parseInt(matches[1], 10);
|
|
31
22
|
}
|
|
32
23
|
}
|
|
33
|
-
exports.
|
|
24
|
+
exports.extractPullNumber = extractPullNumber;
|
|
@@ -3,31 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const commitFormatters_1 = require("./commitFormatters");
|
|
4
4
|
describe('getFirstCommitMessageLine', () => {
|
|
5
5
|
it('should only return the first line of the message', () => {
|
|
6
|
-
expect(commitFormatters_1.
|
|
6
|
+
expect((0, commitFormatters_1.getFirstLine)('My commit message (#1234)\n\n Additional commit message body')).toEqual('My commit message (#1234)');
|
|
7
7
|
});
|
|
8
8
|
it('should return the commit message as-is', () => {
|
|
9
|
-
expect(commitFormatters_1.
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
describe('getFormattedCommitMessage', () => {
|
|
13
|
-
it('should return the first message line verbatim', () => {
|
|
14
|
-
expect(commitFormatters_1.getFormattedCommitMessage({
|
|
15
|
-
message: 'This is my commit message (#1234)\n\nthis is a second line',
|
|
16
|
-
pullNumber: 1234,
|
|
17
|
-
sha: 'sha123456789',
|
|
18
|
-
})).toBe('This is my commit message (#1234)');
|
|
19
|
-
});
|
|
20
|
-
it('should add pullNumber as suffix', () => {
|
|
21
|
-
expect(commitFormatters_1.getFormattedCommitMessage({
|
|
22
|
-
message: 'This is my commit message\n\nthis is a second line',
|
|
23
|
-
pullNumber: 1234,
|
|
24
|
-
sha: 'sha123456789',
|
|
25
|
-
})).toBe('This is my commit message (#1234)');
|
|
26
|
-
});
|
|
27
|
-
it('should add commit sha as suffix', () => {
|
|
28
|
-
expect(commitFormatters_1.getFormattedCommitMessage({
|
|
29
|
-
message: 'This is my commit message\n\nthis is a second line',
|
|
30
|
-
sha: 'sha123456789',
|
|
31
|
-
})).toBe('This is my commit message (sha12345)');
|
|
9
|
+
expect((0, commitFormatters_1.getFirstLine)('My commit message')).toEqual('My commit message');
|
|
32
10
|
});
|
|
33
11
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, username,
|
|
2
|
+
export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, username, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
|
|
@@ -7,18 +7,14 @@ exports.addAssigneesToPullRequest = void 0;
|
|
|
7
7
|
const rest_1 = require("@octokit/rest");
|
|
8
8
|
const ora_1 = __importDefault(require("ora"));
|
|
9
9
|
const logger_1 = require("../../logger");
|
|
10
|
-
async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, username,
|
|
10
|
+
async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, username, }, pullNumber, assignees) {
|
|
11
11
|
const isSelfAssigning = assignees.length === 1 && assignees[0] === username;
|
|
12
12
|
const text = isSelfAssigning
|
|
13
13
|
? `Self-assigning to #${pullNumber}`
|
|
14
14
|
: `Adding assignees to #${pullNumber}: ${assignees.join(', ')}`;
|
|
15
15
|
logger_1.logger.info(text);
|
|
16
|
-
const spinner = ora_1.default(text).start();
|
|
16
|
+
const spinner = (0, ora_1.default)(text).start();
|
|
17
17
|
try {
|
|
18
|
-
if (dryRun) {
|
|
19
|
-
spinner.succeed(`Dry run: ${text}`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
18
|
const octokit = new rest_1.Octokit({
|
|
23
19
|
auth: accessToken,
|
|
24
20
|
baseUrl: githubApiBaseUrlV3,
|
|
@@ -9,18 +9,17 @@ describe('addAssigneesToPullRequest', () => {
|
|
|
9
9
|
it('should add assignees to PR', async () => {
|
|
10
10
|
const pullNumber = 216;
|
|
11
11
|
const assignees = ['sqren'];
|
|
12
|
-
const scope = nock_1.default('https://api.github.com')
|
|
12
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
13
13
|
.post('/repos/backport-org/backport-demo/issues/216/assignees', {
|
|
14
14
|
assignees: ['sqren'],
|
|
15
15
|
})
|
|
16
16
|
.reply(200, 'some response');
|
|
17
|
-
const res = await addAssigneesToPullRequest_1.addAssigneesToPullRequest({
|
|
17
|
+
const res = await (0, addAssigneesToPullRequest_1.addAssigneesToPullRequest)({
|
|
18
18
|
githubApiBaseUrlV3: 'https://api.github.com',
|
|
19
19
|
repoName: 'backport-demo',
|
|
20
20
|
repoOwner: 'backport-org',
|
|
21
21
|
accessToken: 'my-token',
|
|
22
22
|
username: 'sqren',
|
|
23
|
-
dryRun: false,
|
|
24
23
|
}, pullNumber, assignees);
|
|
25
24
|
expect(res).toBe(undefined);
|
|
26
25
|
scope.done();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken
|
|
2
|
+
export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
|
|
@@ -7,15 +7,11 @@ exports.addLabelsToPullRequest = void 0;
|
|
|
7
7
|
const rest_1 = require("@octokit/rest");
|
|
8
8
|
const ora_1 = __importDefault(require("ora"));
|
|
9
9
|
const logger_1 = require("../../logger");
|
|
10
|
-
async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken
|
|
10
|
+
async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, labels) {
|
|
11
11
|
const text = `Adding labels: ${labels.join(', ')}`;
|
|
12
12
|
logger_1.logger.info(text);
|
|
13
|
-
const spinner = ora_1.default(text).start();
|
|
13
|
+
const spinner = (0, ora_1.default)(text).start();
|
|
14
14
|
try {
|
|
15
|
-
if (dryRun) {
|
|
16
|
-
spinner.succeed(`Dry run: ${text}`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
15
|
const octokit = new rest_1.Octokit({
|
|
20
16
|
auth: accessToken,
|
|
21
17
|
baseUrl: githubApiBaseUrlV3,
|
|
@@ -0,0 +1,34 @@
|
|
|
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.addReviewersToPullRequest = void 0;
|
|
7
|
+
const rest_1 = require("@octokit/rest");
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
9
|
+
const logger_1 = require("../../logger");
|
|
10
|
+
async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, reviewers) {
|
|
11
|
+
const text = `Adding reviewers: ${reviewers}`;
|
|
12
|
+
logger_1.logger.info(text);
|
|
13
|
+
const spinner = (0, ora_1.default)(text).start();
|
|
14
|
+
try {
|
|
15
|
+
const octokit = new rest_1.Octokit({
|
|
16
|
+
auth: accessToken,
|
|
17
|
+
baseUrl: githubApiBaseUrlV3,
|
|
18
|
+
log: logger_1.logger,
|
|
19
|
+
});
|
|
20
|
+
await octokit.pulls.requestReviewers({
|
|
21
|
+
owner: repoOwner,
|
|
22
|
+
repo: repoName,
|
|
23
|
+
pull_number: pullNumber,
|
|
24
|
+
reviewers,
|
|
25
|
+
});
|
|
26
|
+
spinner.succeed();
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
const message = e.response?.data?.message;
|
|
30
|
+
spinner.fail(`Adding reviewers. ${message ? message : ''}`);
|
|
31
|
+
logger_1.logger.info(`Could not add reviewers to PR ${pullNumber}`, e.stack);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.addReviewersToPullRequest = addReviewersToPullRequest;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
import { Commit } from '
|
|
2
|
+
import { Commit } from '../../sourceCommit/parseSourceCommit';
|
|
3
3
|
export interface PullRequestPayload {
|
|
4
4
|
owner: string;
|
|
5
5
|
repo: string;
|
|
@@ -15,8 +15,9 @@ export declare function createPullRequest({ options, prPayload, }: {
|
|
|
15
15
|
}): Promise<{
|
|
16
16
|
url: string;
|
|
17
17
|
number: number;
|
|
18
|
+
didUpdate: boolean;
|
|
18
19
|
}>;
|
|
19
|
-
export declare function
|
|
20
|
+
export declare function getPullRequestBody({ options, commits, targetBranch, }: {
|
|
20
21
|
options: ValidConfigOptions;
|
|
21
22
|
commits: Commit[];
|
|
22
23
|
targetBranch: string;
|