backport 5.6.5 → 6.1.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.
- package/README.md +166 -41
- package/dist/entrypoint.cli.js +3 -1
- package/dist/entrypoint.module.d.ts +18 -5
- package/dist/entrypoint.module.js +42 -12
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +34 -0
- 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 -25
- package/dist/options/ConfigOptions.d.ts +28 -12
- package/dist/options/cliArgs.d.ts +36 -35
- package/dist/options/cliArgs.js +91 -52
- package/dist/options/cliArgs.test.js +41 -42
- package/dist/options/config/config.d.ts +34 -57
- package/dist/options/config/config.js +5 -39
- package/dist/options/config/config.test.js +11 -25
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.d.ts +2 -49
- package/dist/options/config/globalConfig.js +9 -12
- package/dist/options/config/globalConfig.test.js +7 -5
- package/dist/options/config/projectConfig.d.ts +2 -49
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/projectConfig.test.js +53 -16
- package/dist/options/config/readConfigFile.d.ts +43 -39
- package/dist/options/config/readConfigFile.js +30 -4
- package/dist/options/options.d.ts +57 -31
- package/dist/options/options.js +102 -10
- package/dist/options/options.test.js +263 -61
- package/dist/options/parseRequiredOptions.d.ts +19 -14
- package/dist/options/parseRequiredOptions.js +9 -15
- package/dist/options/parseRequiredOptions.test.js +30 -26
- 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 +196 -0
- package/dist/runWithOptions.js +7 -14
- package/dist/runWithOptions.test.js +140 -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 +20 -6
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +168 -0
- package/dist/services/git.js +93 -67
- package/dist/services/git.test.js +68 -68
- 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 +3 -8
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
- 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 +31 -29
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +110 -0
- 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.d.ts +9 -0
- package/dist/services/github/v4/FetchPullRequestId.js +32 -0
- package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
- package/dist/services/github/v4/apiRequestV4.js +8 -10
- package/dist/services/github/v4/apiRequestV4.test.js +7 -7
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +1 -8
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +6 -32
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +1 -8
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +31 -40
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +6 -7
- package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
- 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 +12 -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 +70 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -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 +27 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -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/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -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 +77 -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 -5
- 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/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +11 -0
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +35 -0
- 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/getOptionsFromGithub.d.ts +66 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -9
- package/dist/services/github/v4/getOptionsFromGithub/index.js +59 -19
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +119 -32
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -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.d.ts +1 -1
- 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 +413 -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 +82 -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 +229 -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 +64 -49
- 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 +327 -0
- package/dist/test/integration/integration.test.js +28 -29
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +7 -11
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -51
- 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 +346 -76
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +11 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +138 -67
- 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 +3 -2
- package/dist/ui/getTargetBranches.js +33 -18
- 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 +11 -10
- package/dist/ui/maybeSetupRepo.test.js +54 -4
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +37 -51
- package/yarn.lock +2414 -2993
|
@@ -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,22 +136,25 @@ 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
|
-
describe('
|
|
136
|
-
it('returns first
|
|
142
|
+
describe('getRepoOwnerAndNameFromGitRemote', () => {
|
|
143
|
+
it('returns first matching pattern', async () => {
|
|
137
144
|
const res = {
|
|
138
145
|
stdout: 'origin\tgit@github.com:elastic/kibana.git (fetch)\norigin\tgit@github.com:elastic/kibana.git (push)\nsqren\tgit@github.com:sqren/kibana.git (fetch)\nsqren\tgit@github.com:sqren/kibana.git (push)\n',
|
|
139
146
|
stderr: '',
|
|
140
147
|
};
|
|
141
148
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
142
|
-
expect(await git_1.
|
|
149
|
+
expect(await (0, git_1.getRepoOwnerAndNameFromGitRemote)()).toEqual({
|
|
150
|
+
repoOwner: 'elastic',
|
|
151
|
+
repoName: 'kibana',
|
|
152
|
+
});
|
|
143
153
|
});
|
|
144
154
|
it('returns undefined when no remotes exist', async () => {
|
|
145
155
|
const res = { stdout: '', stderr: '' };
|
|
146
156
|
jest.spyOn(childProcess, 'exec').mockResolvedValue(res);
|
|
147
|
-
expect(await git_1.
|
|
157
|
+
expect(await (0, git_1.getRepoOwnerAndNameFromGitRemote)()).toEqual(undefined);
|
|
148
158
|
});
|
|
149
159
|
it('handles errors', async () => {
|
|
150
160
|
const err = {
|
|
@@ -156,7 +166,7 @@ describe('getUpstreamFromGitRemote', () => {
|
|
|
156
166
|
stderr: 'fatal: not a git repository (or any of the parent directories): .git\n',
|
|
157
167
|
};
|
|
158
168
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
159
|
-
expect(await git_1.
|
|
169
|
+
expect(await (0, git_1.getRepoOwnerAndNameFromGitRemote)()).toEqual(undefined);
|
|
160
170
|
});
|
|
161
171
|
});
|
|
162
172
|
describe('getConflictingFiles', () => {
|
|
@@ -174,8 +184,11 @@ describe('getConflictingFiles', () => {
|
|
|
174
184
|
repoOwner: 'elastic',
|
|
175
185
|
repoName: 'kibana',
|
|
176
186
|
};
|
|
177
|
-
expect(await git_1.getConflictingFiles(options)).toEqual([
|
|
178
|
-
|
|
187
|
+
expect(await (0, git_1.getConflictingFiles)(options)).toEqual([
|
|
188
|
+
{
|
|
189
|
+
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
190
|
+
relative: 'conflicting-file.txt',
|
|
191
|
+
},
|
|
179
192
|
]);
|
|
180
193
|
});
|
|
181
194
|
});
|
|
@@ -197,7 +210,7 @@ describe('createFeatureBranch', () => {
|
|
|
197
210
|
stderr: "fatal: couldn't find remote ref 4.x\n",
|
|
198
211
|
};
|
|
199
212
|
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"`);
|
|
213
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
201
214
|
});
|
|
202
215
|
it('should throw "Invalid refspec" error', async () => {
|
|
203
216
|
expect.assertions(1);
|
|
@@ -210,14 +223,14 @@ describe('createFeatureBranch', () => {
|
|
|
210
223
|
stderr: "fatal: Invalid refspec 'https://github.com/elastic/kibana.git'\n",
|
|
211
224
|
};
|
|
212
225
|
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"`);
|
|
226
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"The branch \\"4.x\\" is invalid or doesn't exist"`);
|
|
214
227
|
});
|
|
215
228
|
it('should rethrow normal error', async () => {
|
|
216
229
|
expect.assertions(1);
|
|
217
230
|
const err = new Error('just a normal error');
|
|
218
231
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
219
232
|
expect.assertions(1);
|
|
220
|
-
await expect(git_1.createBackportBranch({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
233
|
+
await expect((0, git_1.createBackportBranch)({ options, targetBranch, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
221
234
|
});
|
|
222
235
|
});
|
|
223
236
|
describe('deleteRemote', () => {
|
|
@@ -236,13 +249,13 @@ describe('deleteRemote', () => {
|
|
|
236
249
|
stderr: "fatal: No such remote: 'origin'\n",
|
|
237
250
|
};
|
|
238
251
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
239
|
-
await expect(await git_1.deleteRemote(options, remoteName)).toBe(undefined);
|
|
252
|
+
await expect(await (0, git_1.deleteRemote)(options, remoteName)).toBe(undefined);
|
|
240
253
|
});
|
|
241
254
|
it('should rethrow normal error', async () => {
|
|
242
255
|
const err = new Error('just a normal error');
|
|
243
256
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
244
257
|
expect.assertions(1);
|
|
245
|
-
await expect(git_1.deleteRemote(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
258
|
+
await expect((0, git_1.deleteRemote)(options, remoteName)).rejects.toThrowErrorMatchingInlineSnapshot(`"just a normal error"`);
|
|
246
259
|
});
|
|
247
260
|
});
|
|
248
261
|
describe('cherrypick', () => {
|
|
@@ -250,45 +263,33 @@ describe('cherrypick', () => {
|
|
|
250
263
|
repoOwner: 'elastic',
|
|
251
264
|
repoName: 'kibana',
|
|
252
265
|
};
|
|
253
|
-
const commit = {
|
|
254
|
-
sourceBranch: '7.x',
|
|
255
|
-
formattedMessage: '',
|
|
256
|
-
originalMessage: '',
|
|
257
|
-
sha: 'abcd',
|
|
258
|
-
targetBranchesFromLabels: [],
|
|
259
|
-
existingTargetPullRequests: [],
|
|
260
|
-
};
|
|
261
266
|
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
262
267
|
jest
|
|
263
268
|
.spyOn(childProcess, 'exec')
|
|
264
|
-
// mock git fetch
|
|
265
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
266
269
|
// mock cherry pick command
|
|
267
270
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
268
|
-
expect(await git_1.cherrypick(options,
|
|
271
|
+
expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
|
|
272
|
+
conflictingFiles: [],
|
|
273
|
+
unstagedFiles: [],
|
|
269
274
|
needsResolving: false,
|
|
270
275
|
});
|
|
271
276
|
});
|
|
272
277
|
it('should use mainline option when specified', async () => {
|
|
273
278
|
const execSpy = jest
|
|
274
279
|
.spyOn(childProcess, 'exec')
|
|
275
|
-
// mock git fetch
|
|
276
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
277
280
|
// mock cherry pick command
|
|
278
281
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
279
|
-
await git_1.cherrypick({ ...options, mainline: 1 },
|
|
280
|
-
expect(execSpy.mock.calls[
|
|
282
|
+
await (0, git_1.cherrypick)({ ...options, mainline: 1 }, 'abcd');
|
|
283
|
+
expect(execSpy.mock.calls[0][0]).toBe('git cherry-pick -x --mainline 1 abcd');
|
|
281
284
|
});
|
|
282
285
|
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
283
286
|
jest
|
|
284
287
|
.spyOn(childProcess, 'exec')
|
|
285
|
-
// mock git fetch
|
|
286
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
287
288
|
// mock cherry pick command
|
|
288
289
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
289
290
|
killed: false,
|
|
290
291
|
code: 128,
|
|
291
|
-
cmd: 'git cherry-pick abcd',
|
|
292
|
+
cmd: 'git cherry-pick -x abcd',
|
|
292
293
|
stdout: '',
|
|
293
294
|
stderr: '',
|
|
294
295
|
}))
|
|
@@ -301,15 +302,20 @@ describe('cherrypick', () => {
|
|
|
301
302
|
}))
|
|
302
303
|
// mock getUnstagedFiles
|
|
303
304
|
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
304
|
-
expect(await git_1.cherrypick(options,
|
|
305
|
+
expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
|
|
306
|
+
conflictingFiles: [
|
|
307
|
+
{
|
|
308
|
+
absolute: '/myHomeDir/.backport/repositories/elastic/kibana/conflicting-file.txt',
|
|
309
|
+
relative: 'conflicting-file.txt',
|
|
310
|
+
},
|
|
311
|
+
],
|
|
305
312
|
needsResolving: true,
|
|
313
|
+
unstagedFiles: [],
|
|
306
314
|
});
|
|
307
315
|
});
|
|
308
316
|
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
309
317
|
jest
|
|
310
318
|
.spyOn(childProcess, 'exec')
|
|
311
|
-
// mock git fetch
|
|
312
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
313
319
|
// mock cherry pick command
|
|
314
320
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
315
321
|
killed: false,
|
|
@@ -319,7 +325,7 @@ describe('cherrypick', () => {
|
|
|
319
325
|
stdout: '',
|
|
320
326
|
stderr: 'error: commit 381c7b604110257437a289b1f1742685eb8d79c5 is a merge but no -m option was given.\nfatal: cherry-pick failed\n',
|
|
321
327
|
}));
|
|
322
|
-
await expect(git_1.cherrypick(options,
|
|
328
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
|
|
323
329
|
.toThrowError(`Cherrypick failed because the selected commit was a merge commit. Please try again by specifying the parent with the \`mainline\` argument:
|
|
324
330
|
|
|
325
331
|
> backport --mainline
|
|
@@ -333,8 +339,6 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
333
339
|
it('should gracefully handle empty commits', async () => {
|
|
334
340
|
jest
|
|
335
341
|
.spyOn(childProcess, 'exec')
|
|
336
|
-
// mock git fetch
|
|
337
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
338
342
|
// mock cherry pick command
|
|
339
343
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
340
344
|
killed: false,
|
|
@@ -344,13 +348,11 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
344
348
|
stdout: 'On branch backport/7.x/pr-58692\nYou are currently cherry-picking commit fe6b13b83cc.\n\nnothing to commit, working tree clean\n',
|
|
345
349
|
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
350
|
}));
|
|
347
|
-
await expect(git_1.cherrypick(options,
|
|
351
|
+
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
352
|
});
|
|
349
353
|
it('gracefully handles missing git info', async () => {
|
|
350
354
|
jest
|
|
351
355
|
.spyOn(childProcess, 'exec')
|
|
352
|
-
// mock git fetch
|
|
353
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
354
356
|
// mock cherry pick command
|
|
355
357
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
356
358
|
killed: false,
|
|
@@ -358,9 +360,9 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
358
360
|
signal: null,
|
|
359
361
|
cmd: 'git cherry-pick 83ad852b6ba1a64c8047f07201018eb6fb020db8',
|
|
360
362
|
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 <
|
|
363
|
+
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
364
|
}));
|
|
363
|
-
await expect(git_1.cherrypick(options,
|
|
365
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects
|
|
364
366
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
365
367
|
"Cherrypick failed:
|
|
366
368
|
|
|
@@ -374,22 +376,20 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
374
376
|
to set your account's default identity.
|
|
375
377
|
Omit --global to set the identity only in this repository.
|
|
376
378
|
|
|
377
|
-
fatal: empty ident name (for <
|
|
379
|
+
fatal: empty ident name (for <foo@bar.net>) not allowed
|
|
378
380
|
"
|
|
379
381
|
`);
|
|
380
382
|
});
|
|
381
383
|
it('should re-throw non-cherrypick errors', async () => {
|
|
382
384
|
jest
|
|
383
385
|
.spyOn(childProcess, 'exec')
|
|
384
|
-
// mock git fetch
|
|
385
|
-
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
386
386
|
// mock cherry pick command
|
|
387
387
|
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
388
388
|
// getConflictingFiles
|
|
389
389
|
.mockResolvedValueOnce({ stdout: '', stderr: '' })
|
|
390
390
|
// getUnstagedFiles
|
|
391
391
|
.mockResolvedValueOnce({ stdout: '', stderr: '' });
|
|
392
|
-
await expect(git_1.cherrypick(options,
|
|
392
|
+
await expect((0, git_1.cherrypick)(options, 'abcd')).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
393
393
|
});
|
|
394
394
|
});
|
|
395
395
|
describe('commitChanges', () => {
|
|
@@ -404,7 +404,7 @@ describe('commitChanges', () => {
|
|
|
404
404
|
jest
|
|
405
405
|
.spyOn(childProcess, 'exec')
|
|
406
406
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
407
|
-
await expect(await git_1.commitChanges(commit, options)).toBe(undefined);
|
|
407
|
+
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
408
408
|
});
|
|
409
409
|
it('should swallow error if changes have already been committed manaully', async () => {
|
|
410
410
|
const err = {
|
|
@@ -416,7 +416,7 @@ describe('commitChanges', () => {
|
|
|
416
416
|
stderr: '',
|
|
417
417
|
};
|
|
418
418
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
419
|
-
await expect(await git_1.commitChanges(commit, options)).toBe(undefined);
|
|
419
|
+
await expect(await (0, git_1.commitChanges)(commit, options)).toBe(undefined);
|
|
420
420
|
});
|
|
421
421
|
describe('when commit fails due to empty message', () => {
|
|
422
422
|
let spy;
|
|
@@ -434,7 +434,7 @@ describe('commitChanges', () => {
|
|
|
434
434
|
.spyOn(childProcess, 'exec')
|
|
435
435
|
.mockRejectedValueOnce(err)
|
|
436
436
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
437
|
-
res = await git_1.commitChanges(commit, options);
|
|
437
|
+
res = await (0, git_1.commitChanges)(commit, options);
|
|
438
438
|
});
|
|
439
439
|
it('should manually set the commit message', () => {
|
|
440
440
|
expect(spy).toHaveBeenCalledTimes(2);
|
|
@@ -449,7 +449,7 @@ describe('commitChanges', () => {
|
|
|
449
449
|
const err = new Error('non-cherrypick error');
|
|
450
450
|
jest.spyOn(childProcess, 'exec').mockRejectedValueOnce(err);
|
|
451
451
|
expect.assertions(1);
|
|
452
|
-
await expect(git_1.commitChanges(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
452
|
+
await expect((0, git_1.commitChanges)(commit, options)).rejects.toThrowErrorMatchingInlineSnapshot(`"non-cherrypick error"`);
|
|
453
453
|
});
|
|
454
454
|
});
|
|
455
455
|
describe('addRemote', () => {
|
|
@@ -463,28 +463,28 @@ describe('addRemote', () => {
|
|
|
463
463
|
const spy = jest
|
|
464
464
|
.spyOn(childProcess, 'exec')
|
|
465
465
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
466
|
-
await git_1.addRemote(options, 'elastic');
|
|
466
|
+
await (0, git_1.addRemote)(options, 'elastic');
|
|
467
467
|
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
468
|
});
|
|
469
469
|
it('add correct user remote', async () => {
|
|
470
470
|
const spy = jest
|
|
471
471
|
.spyOn(childProcess, 'exec')
|
|
472
472
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
473
|
-
await git_1.addRemote(options, 'sqren');
|
|
473
|
+
await (0, git_1.addRemote)(options, 'sqren');
|
|
474
474
|
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
475
|
});
|
|
476
476
|
it('allows custom github url', async () => {
|
|
477
477
|
const spy = jest
|
|
478
478
|
.spyOn(childProcess, 'exec')
|
|
479
479
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
480
|
-
await git_1.addRemote({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
|
|
480
|
+
await (0, git_1.addRemote)({ ...options, gitHostname: 'github.my-company.com' }, 'sqren');
|
|
481
481
|
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
482
|
});
|
|
483
483
|
});
|
|
484
484
|
describe('pushBackportBranch', () => {
|
|
485
485
|
const options = {
|
|
486
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
486
487
|
fork: true,
|
|
487
|
-
username: 'sqren',
|
|
488
488
|
repoOwner: 'elastic',
|
|
489
489
|
repoName: 'kibana',
|
|
490
490
|
};
|
|
@@ -498,6 +498,6 @@ describe('pushBackportBranch', () => {
|
|
|
498
498
|
stdout: '',
|
|
499
499
|
stderr: "remote: Repository not found.\nfatal: repository 'https://github.com/sqren/kibana.git/' not found\n",
|
|
500
500
|
});
|
|
501
|
-
await expect(git_1.pushBackportBranch({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/
|
|
501
|
+
await expect((0, git_1.pushBackportBranch)({ options, backportBranch })).rejects.toThrowErrorMatchingInlineSnapshot(`"Error pushing to https://github.com/sqren_authenticated/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
502
|
});
|
|
503
503
|
});
|
|
@@ -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,
|
|
2
|
+
export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
|
|
@@ -7,18 +7,13 @@ 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,
|
|
11
|
-
const
|
|
12
|
-
const text = isSelfAssigning
|
|
10
|
+
async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }, pullNumber, assignees) {
|
|
11
|
+
const text = autoAssign
|
|
13
12
|
? `Self-assigning to #${pullNumber}`
|
|
14
13
|
: `Adding assignees to #${pullNumber}: ${assignees.join(', ')}`;
|
|
15
14
|
logger_1.logger.info(text);
|
|
16
|
-
const spinner = ora_1.default(text).start();
|
|
15
|
+
const spinner = (0, ora_1.default)(text).start();
|
|
17
16
|
try {
|
|
18
|
-
if (dryRun) {
|
|
19
|
-
spinner.succeed(`Dry run: ${text}`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
17
|
const octokit = new rest_1.Octokit({
|
|
23
18
|
auth: accessToken,
|
|
24
19
|
baseUrl: githubApiBaseUrlV3,
|
|
@@ -9,18 +9,16 @@ 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')
|
|
13
|
-
.post('/repos/
|
|
12
|
+
const scope = (0, nock_1.default)('https://api.github.com')
|
|
13
|
+
.post('/repos/elastic/kibana/issues/216/assignees', {
|
|
14
14
|
assignees: ['sqren'],
|
|
15
15
|
})
|
|
16
16
|
.reply(200, 'some response');
|
|
17
|
-
const res = await addAssigneesToPullRequest_1.addAssigneesToPullRequest({
|
|
18
|
-
|
|
19
|
-
repoName: '
|
|
20
|
-
repoOwner: '
|
|
17
|
+
const res = await (0, addAssigneesToPullRequest_1.addAssigneesToPullRequest)({
|
|
18
|
+
author: 'sqren',
|
|
19
|
+
repoName: 'kibana',
|
|
20
|
+
repoOwner: 'elastic',
|
|
21
21
|
accessToken: 'my-token',
|
|
22
|
-
username: 'sqren',
|
|
23
|
-
dryRun: false,
|
|
24
22
|
}, pullNumber, assignees);
|
|
25
23
|
expect(res).toBe(undefined);
|
|
26
24
|
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;
|