backport 6.1.5 → 6.3.0-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -6
- package/dist/{main.d.ts → backportRun.d.ts} +3 -3
- package/dist/{main.js → backportRun.js} +21 -10
- package/dist/{entrypoint.module.private.test.d.ts → entrypoint.cli.e2e.private.test.d.ts} +0 -0
- package/dist/entrypoint.cli.e2e.private.test.js +277 -0
- package/dist/entrypoint.cli.js +3 -5
- package/dist/{options/getValidatedOptions.test.d.ts → entrypoint.cli.private.test.d.ts} +0 -0
- package/dist/{entrypoint.module.private.test.js → entrypoint.cli.private.test.js} +17 -8
- package/dist/entrypoint.module.d.ts +2 -2
- package/dist/entrypoint.module.js +4 -4
- package/dist/options/ConfigOptions.d.ts +5 -1
- package/dist/options/cliArgs.d.ts +16 -14
- package/dist/options/cliArgs.js +15 -5
- package/dist/options/cliArgs.test.js +28 -10
- package/dist/options/config/config.d.ts +10 -4
- package/dist/options/config/config.js +7 -6
- package/dist/options/config/config.test.js +11 -1
- package/dist/options/config/globalConfig.d.ts +1 -1
- package/dist/options/config/globalConfig.js +15 -9
- package/dist/options/config/globalConfig.test.js +19 -32
- package/dist/options/config/projectConfig.d.ts +3 -1
- package/dist/options/config/projectConfig.js +5 -2
- package/dist/options/config/projectConfig.test.js +41 -31
- package/dist/options/config/readConfigFile.d.ts +27 -23
- package/dist/options/config/readConfigFile.js +2 -2
- package/dist/options/options.d.ts +18 -39
- package/dist/options/options.js +40 -32
- package/dist/options/options.test.js +83 -47
- package/dist/runSequentially.d.ts +0 -1
- package/dist/runSequentially.js +0 -1
- package/dist/runSequentially.test.js +39 -20
- package/dist/scripts/postinstall.js +3 -3
- package/dist/services/HandledError.d.ts +6 -4
- package/dist/services/HandledError.js +18 -3
- package/dist/services/child-process-promisified.d.ts +3 -1
- package/dist/services/env.d.ts +3 -1
- package/dist/services/env.js +4 -1
- package/dist/services/env.test.js +2 -2
- package/dist/services/git.d.ts +22 -9
- package/dist/services/git.integration.test.js +123 -24
- package/dist/services/git.js +66 -54
- package/dist/services/git.test.js +35 -20
- package/dist/services/github/commitFormatters.d.ts +0 -1
- package/dist/services/github/commitFormatters.js +1 -8
- package/dist/services/github/v3/createPullRequest.js +16 -10
- package/dist/services/github/v3/createPullRequest.test.js +248 -33
- package/dist/services/github/v3/createStatusComment.d.ts +1 -1
- package/dist/services/github/v3/createStatusComment.js +26 -15
- package/dist/services/github/v3/createStatusComment.test.js +165 -70
- package/dist/services/github/v3/getGithubV3ErrorMessage.d.ts +2 -1
- package/dist/services/github/v4/FetchPullRequestId.d.ts +0 -7
- package/dist/services/github/v4/apiRequestV4.d.ts +21 -17
- package/dist/services/github/v4/apiRequestV4.js +38 -28
- package/dist/services/github/v4/apiRequestV4.test.js +4 -4
- package/dist/services/github/v4/disablePullRequestAutoMerge.d.ts +0 -7
- package/dist/services/github/v4/enablePullRequestAutoMerge.d.ts +0 -7
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +37 -19
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +17 -8
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +23 -14
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +4 -4
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +41 -19
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +1 -8
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +31 -14
- package/dist/services/github/v4/fetchExistingPullRequest.d.ts +0 -4
- package/dist/services/github/v4/fetchExistingPullRequest.js +1 -2
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.d.ts +0 -9
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +6 -2
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +41 -34
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +6 -0
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +2 -1
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +56 -0
- package/dist/{options/parseRequiredOptions.test.d.ts → services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts} +0 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +11 -11
- package/dist/services/github/v4/throwOnInvalidAccessToken.d.ts +4 -5
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -7
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
- package/dist/services/logger.d.ts +9 -3
- package/dist/services/logger.js +38 -35
- package/dist/services/prompt.test.js +66 -19
- package/dist/services/prompts.js +12 -10
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +1 -1
- package/dist/services/sourceCommit/getMockSourceCommit.js +6 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +18 -10
- package/dist/services/sourceCommit/parseSourceCommit.js +20 -14
- package/dist/services/sourceCommit/parseSourceCommit.test.js +18 -20
- package/dist/{runWithOptions.test.d.ts → test/backport-e2e.mutation.test.d.ts} +0 -0
- package/dist/test/{integration/integration.private.test.js → backport-e2e.mutation.test.js} +143 -123
- package/dist/{scripts/generate-gql.d.ts → test/handleUnbackportedPullRequests.private.test.d.ts} +0 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +57 -0
- package/dist/test/mockConfigFiles.js +4 -20
- package/dist/test/mocks.d.ts +10 -0
- package/dist/test/mocks.js +23 -0
- package/dist/test/private/getDevAccessToken.js +5 -4
- package/dist/test/sandbox.d.ts +5 -0
- package/dist/test/sandbox.js +43 -0
- package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
- package/dist/test/setupFiles/automatic-mocks.js +27 -11
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -13
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +50 -27
- package/dist/ui/getCommits.js +8 -14
- package/dist/ui/getCommitsWithoutBackports.js +6 -6
- package/dist/ui/getCommitsWithoutBackports.test.js +91 -39
- package/dist/ui/getTargetBranches.js +1 -1
- package/dist/ui/getTargetBranches.test.js +26 -8
- package/dist/ui/maybeSetupRepo.js +25 -5
- package/dist/ui/maybeSetupRepo.test.js +144 -14
- package/dist/utils/maybe.d.ts +1 -0
- package/dist/utils/maybe.js +7 -0
- package/dist/utils/packageVersion.d.ts +1 -0
- package/dist/{types/PromiseReturnType.js → utils/packageVersion.js} +2 -0
- package/package.json +24 -20
- package/yarn.lock +160 -237
- package/dist/index.d.ts +0 -783
- package/dist/index.js +0 -8001
- package/dist/ink.d.ts +0 -1
- package/dist/ink.js +0 -49
- package/dist/options/config/getOptionsFromGit.d.ts +0 -4
- package/dist/options/config/getOptionsFromGit.js +0 -8
- package/dist/options/getValidatedOptions.d.ts +0 -49
- package/dist/options/getValidatedOptions.js +0 -45
- package/dist/options/getValidatedOptions.test.js +0 -97
- package/dist/options/parseRequiredOptions.d.ts +0 -71
- package/dist/options/parseRequiredOptions.js +0 -68
- package/dist/options/parseRequiredOptions.test.js +0 -122
- package/dist/runWithOptions.d.ts +0 -9
- package/dist/runWithOptions.js +0 -43
- package/dist/runWithOptions.test.js +0 -304
- package/dist/scripts/generate-gql.js +0 -15
- package/dist/services/fs-promisified.d.ts +0 -6
- package/dist/services/fs-promisified.js +0 -12
- package/dist/services/getExpectedTarget.d.ts +0 -9
- package/dist/services/getExpectedTarget.js +0 -77
- package/dist/services/getExpectedTargetPullRequests.d.ts +0 -9
- package/dist/services/getExpectedTargetPullRequests.js +0 -77
- package/dist/services/github/v4/fetchCommitByPullNumber.d.ts +0 -5
- package/dist/services/github/v4/fetchCommitByPullNumber.js +0 -86
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +0 -57
- package/dist/services/github/v4/fetchCommitBySha.d.ts +0 -5
- package/dist/services/github/v4/fetchCommitBySha.js +0 -95
- package/dist/services/github/v4/fetchCommitBySha.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommitBySha.private.test.js +0 -50
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +0 -28
- package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +0 -52
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +0 -3
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +0 -55
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +0 -252
- package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +0 -28
- package/dist/services/github/v4/fetchCommitsByAuthor.js +0 -161
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +0 -115
- package/dist/services/github/v4/fetchCommitsByAuthor.test.d.ts +0 -1
- package/dist/services/github/v4/fetchCommitsByAuthor.test.js +0 -272
- package/dist/services/github/v4/fetchDefaultBranch.d.ts +0 -9
- package/dist/services/github/v4/fetchDefaultBranch.js +0 -24
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +0 -4
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.js +0 -52
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +0 -32
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.d.ts +0 -4
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.js +0 -72
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/index.private.test.js +0 -34
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.d.ts +0 -40
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks/query.js +0 -72
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.d.ts +0 -17
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.js +0 -69
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchDefaultRepoBranchAndPerformStartupChecks.private.test.js +0 -32
- package/dist/services/github/v4/fetchMergedPullRequests.d.ts +0 -37
- package/dist/services/github/v4/fetchMergedPullRequests.js +0 -37
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +0 -59
- package/dist/services/github/v4/fetchMergedPullRequests.test.d.ts +0 -1
- package/dist/services/github/v4/fetchMergedPullRequests.test.js +0 -22
- package/dist/services/github/v4/fetchProjectConfig.d.ts +0 -8
- package/dist/services/github/v4/fetchProjectConfig.js +0 -56
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +0 -52
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +0 -1
- package/dist/services/github/v4/fetchProjectConfig.test.js +0 -37
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.d.ts +0 -9
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +0 -92
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +0 -66
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.d.ts +0 -1
- package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +0 -242
- package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +0 -7
- package/dist/services/github/v4/getExistingTargetPullRequests.js +0 -45
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +0 -63
- package/dist/services/github/v4/getOptionsFromGithub/index.js +0 -139
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.d.ts +0 -1
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +0 -147
- package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -5
- package/dist/services/github/v4/getTargetBranchesFromLabels.js +0 -20
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.d.ts +0 -1
- package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +0 -201
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +0 -2
- package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +0 -843
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +0 -2
- package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +0 -73
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +0 -12
- package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +0 -44
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +0 -5
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +0 -20
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +0 -1
- package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +0 -201
- package/dist/services/sourceCommit/sourceCommit.d.ts +0 -78
- package/dist/services/sourceCommit/sourceCommit.js +0 -86
- package/dist/services/sourceCommit/sourceCommit.test.d.ts +0 -1
- package/dist/services/sourceCommit/sourceCommit.test.js +0 -287
- package/dist/services/sourceCommit.d.ts +0 -78
- package/dist/services/sourceCommit.js +0 -86
- package/dist/services/sourceCommit.test.d.ts +0 -1
- package/dist/services/sourceCommit.test.js +0 -280
- package/dist/test/inquirer.private.test.d.ts +0 -1
- package/dist/test/inquirer.private.test.js +0 -168
- package/dist/test/integration/createSpies.d.ts +0 -17
- package/dist/test/integration/createSpies.js +0 -85
- package/dist/test/integration/envConstants.d.ts +0 -5
- package/dist/test/integration/envConstants.js +0 -9
- package/dist/test/integration/helpers.d.ts +0 -7
- package/dist/test/integration/helpers.js +0 -31
- package/dist/test/integration/integration.private.test.d.ts +0 -1
- package/dist/test/integration/integration.test.d.ts +0 -1
- package/dist/test/integration/integration.test.js +0 -214
- package/dist/todo-delete.d.ts +0 -1
- package/dist/todo-delete.js +0 -17
- package/dist/types/Commit.d.ts +0 -85
- package/dist/types/Commit.js +0 -139
- package/dist/types/PromiseReturnType.d.ts +0 -1
- package/dist/types/commitNode.d.ts +0 -89
- package/dist/types/commitNode.js +0 -139
- package/dist/types/commitNode.test.d.ts +0 -1
- package/dist/types/commitNode.test.js +0 -255
- package/dist/types/commitWithAssociatedPullRequests.d.ts +0 -86
- package/dist/types/commitWithAssociatedPullRequests.js +0 -145
- package/dist/ui/cherrypickAndCreatePullRequest.test.d.ts +0 -1
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +0 -617
- package/dist/ui/getTargetBranchesFromLabels.d.ts +0 -6
- package/dist/ui/getTargetBranchesFromLabels.js +0 -40
- package/dist/ui/getTargetBranchesFromLabels.test.d.ts +0 -1
- package/dist/ui/getTargetBranchesFromLabels.test.js +0 -288
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const os_1 = __importDefault(require("os"));
|
|
26
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
27
|
-
const lodash_1 = require("lodash");
|
|
28
|
-
const nock_1 = __importDefault(require("nock"));
|
|
29
|
-
const runWithOptions_1 = require("./runWithOptions");
|
|
30
|
-
const childProcess = __importStar(require("./services/child-process-promisified"));
|
|
31
|
-
const fs = __importStar(require("./services/fs-promisified"));
|
|
32
|
-
const commitsByAuthorMock_1 = require("./services/github/v4/mocks/commitsByAuthorMock");
|
|
33
|
-
const nockHelpers_1 = require("./test/nockHelpers");
|
|
34
|
-
jest.mock('./services/child-process-promisified', () => {
|
|
35
|
-
return {
|
|
36
|
-
exec: jest.fn(async (cmd) => {
|
|
37
|
-
throw new Error(`Mock required for exec with cmd: "${cmd}"`);
|
|
38
|
-
}),
|
|
39
|
-
execAsCallback: jest.fn((...args) => {
|
|
40
|
-
(0, lodash_1.last)(args)();
|
|
41
|
-
return {
|
|
42
|
-
stderr: {
|
|
43
|
-
on: () => null,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}),
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
describe('runWithOptions', () => {
|
|
50
|
-
let rpcExecMock;
|
|
51
|
-
let rpcExecOriginalMock;
|
|
52
|
-
let inquirerPromptMock;
|
|
53
|
-
let res;
|
|
54
|
-
let createPullRequestCalls;
|
|
55
|
-
let commitsByAuthorCalls;
|
|
56
|
-
let authorIdCalls;
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
jest.clearAllMocks();
|
|
59
|
-
nock_1.default.cleanAll();
|
|
60
|
-
});
|
|
61
|
-
beforeEach(async () => {
|
|
62
|
-
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
63
|
-
const options = {
|
|
64
|
-
accessToken: 'myAccessToken',
|
|
65
|
-
all: false,
|
|
66
|
-
assignees: [],
|
|
67
|
-
author: 'sqren',
|
|
68
|
-
autoAssign: false,
|
|
69
|
-
autoFixConflicts: undefined,
|
|
70
|
-
autoMerge: false,
|
|
71
|
-
autoMergeMethod: 'merge',
|
|
72
|
-
branchLabelMapping: undefined,
|
|
73
|
-
ci: false,
|
|
74
|
-
cherrypickRef: true,
|
|
75
|
-
commitPaths: [],
|
|
76
|
-
details: false,
|
|
77
|
-
editor: 'code',
|
|
78
|
-
forceLocalConfig: undefined,
|
|
79
|
-
fork: true,
|
|
80
|
-
gitHostname: 'github.com',
|
|
81
|
-
githubApiBaseUrlV3: 'https://api.github.com',
|
|
82
|
-
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
83
|
-
mainline: undefined,
|
|
84
|
-
maxNumber: 10,
|
|
85
|
-
multipleBranches: false,
|
|
86
|
-
multipleCommits: false,
|
|
87
|
-
noVerify: true,
|
|
88
|
-
prDescription: 'myPrDescription',
|
|
89
|
-
prFilter: undefined,
|
|
90
|
-
prTitle: 'myPrTitle {targetBranch} {commitMessages}',
|
|
91
|
-
pullNumber: undefined,
|
|
92
|
-
repoName: 'kibana',
|
|
93
|
-
repoOwner: 'elastic',
|
|
94
|
-
resetAuthor: false,
|
|
95
|
-
sha: undefined,
|
|
96
|
-
sourceBranch: 'my-source-branch-from-options',
|
|
97
|
-
sourcePRLabels: [],
|
|
98
|
-
targetBranches: [],
|
|
99
|
-
upstream: 'elastic/kibana',
|
|
100
|
-
targetBranchChoices: [
|
|
101
|
-
{ name: '6.x' },
|
|
102
|
-
{ name: '6.0' },
|
|
103
|
-
{ name: '5.6' },
|
|
104
|
-
{ name: '5.5' },
|
|
105
|
-
{ name: '5.4' },
|
|
106
|
-
],
|
|
107
|
-
targetPRLabels: [],
|
|
108
|
-
username: 'sqren',
|
|
109
|
-
verbose: false,
|
|
110
|
-
};
|
|
111
|
-
rpcExecMock = jest
|
|
112
|
-
.spyOn(childProcess, 'exec')
|
|
113
|
-
.mockResolvedValue({ stdout: 'success', stderr: '' });
|
|
114
|
-
rpcExecOriginalMock = jest.spyOn(childProcess, 'execAsCallback');
|
|
115
|
-
jest.spyOn(fs, 'writeFile').mockResolvedValue(undefined);
|
|
116
|
-
inquirerPromptMock = jest
|
|
117
|
-
.spyOn(inquirer_1.default, 'prompt')
|
|
118
|
-
.mockImplementationOnce((async (args) => {
|
|
119
|
-
return { promptResult: args[0].choices[0].value };
|
|
120
|
-
}))
|
|
121
|
-
.mockImplementationOnce((async (args) => {
|
|
122
|
-
return { promptResult: args[0].choices[0].name };
|
|
123
|
-
}));
|
|
124
|
-
authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
125
|
-
name: 'AuthorId',
|
|
126
|
-
statusCode: 200,
|
|
127
|
-
body: { data: { user: { id: 'sqren_author_id' } } },
|
|
128
|
-
});
|
|
129
|
-
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
130
|
-
name: 'CommitsByAuthor',
|
|
131
|
-
statusCode: 200,
|
|
132
|
-
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
133
|
-
});
|
|
134
|
-
const scope = (0, nock_1.default)('https://api.github.com')
|
|
135
|
-
.post('/repos/elastic/kibana/pulls')
|
|
136
|
-
.reply(200, { html_url: 'pull request url', number: 1337 });
|
|
137
|
-
createPullRequestCalls = (0, nockHelpers_1.getNockCallsForScope)(scope);
|
|
138
|
-
res = await (0, runWithOptions_1.runWithOptions)(options);
|
|
139
|
-
scope.done();
|
|
140
|
-
});
|
|
141
|
-
it('returns pull request', () => {
|
|
142
|
-
expect(res).toEqual([
|
|
143
|
-
{
|
|
144
|
-
pullRequestUrl: 'pull request url',
|
|
145
|
-
success: true,
|
|
146
|
-
targetBranch: '6.x',
|
|
147
|
-
},
|
|
148
|
-
]);
|
|
149
|
-
});
|
|
150
|
-
it('creates pull request', () => {
|
|
151
|
-
expect(createPullRequestCalls).toEqual([
|
|
152
|
-
{
|
|
153
|
-
base: '6.x',
|
|
154
|
-
body: 'Backports the following commits to 6.x:\n - Add 👻 (2e63475c)\n\nmyPrDescription',
|
|
155
|
-
head: 'sqren:backport/6.x/commit-2e63475c',
|
|
156
|
-
title: 'myPrTitle 6.x Add 👻',
|
|
157
|
-
},
|
|
158
|
-
]);
|
|
159
|
-
});
|
|
160
|
-
it('retrieves author id', () => {
|
|
161
|
-
expect(authorIdCalls).toMatchInlineSnapshot(`
|
|
162
|
-
Array [
|
|
163
|
-
Object {
|
|
164
|
-
"query": "
|
|
165
|
-
query AuthorId($login: String!) {
|
|
166
|
-
user(login: $login) {
|
|
167
|
-
id
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
",
|
|
171
|
-
"variables": Object {
|
|
172
|
-
"login": "sqren",
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
]
|
|
176
|
-
`);
|
|
177
|
-
});
|
|
178
|
-
it('retrieves commits by author', () => {
|
|
179
|
-
expect(commitsByAuthorCalls.map((body) => body.variables)).toEqual([
|
|
180
|
-
{
|
|
181
|
-
authorId: 'sqren_author_id',
|
|
182
|
-
maxNumber: 10,
|
|
183
|
-
commitPath: null,
|
|
184
|
-
repoName: 'kibana',
|
|
185
|
-
repoOwner: 'elastic',
|
|
186
|
-
sourceBranch: 'my-source-branch-from-options',
|
|
187
|
-
},
|
|
188
|
-
]);
|
|
189
|
-
});
|
|
190
|
-
it('prompt calls should match snapshot', () => {
|
|
191
|
-
expect(inquirer_1.default.prompt).toHaveBeenCalledTimes(2);
|
|
192
|
-
expect(
|
|
193
|
-
// @ts-expect-error
|
|
194
|
-
inquirerPromptMock.mock.calls[0][0][0].choices.map(({ name, short }) => ({
|
|
195
|
-
name,
|
|
196
|
-
short,
|
|
197
|
-
}))).toMatchInlineSnapshot(`
|
|
198
|
-
Array [
|
|
199
|
-
Object {
|
|
200
|
-
"name": "1. Add 👻 ",
|
|
201
|
-
"short": "2e63475c",
|
|
202
|
-
},
|
|
203
|
-
Object {
|
|
204
|
-
"name": "2. Add witch (#85) ",
|
|
205
|
-
"short": "#85 (f3b618b9)",
|
|
206
|
-
},
|
|
207
|
-
Object {
|
|
208
|
-
"name": "3. Add SF mention (#80) 6.3",
|
|
209
|
-
"short": "#80 (79cf1845)",
|
|
210
|
-
},
|
|
211
|
-
Object {
|
|
212
|
-
"name": "4. Add backport config ",
|
|
213
|
-
"short": "3827bbba",
|
|
214
|
-
},
|
|
215
|
-
Object {
|
|
216
|
-
"name": "5. Initial commit ",
|
|
217
|
-
"short": "5ea0da55",
|
|
218
|
-
},
|
|
219
|
-
]
|
|
220
|
-
`);
|
|
221
|
-
});
|
|
222
|
-
it('exec should be called with correct args', () => {
|
|
223
|
-
expect(rpcExecMock).toHaveBeenCalledTimes(10);
|
|
224
|
-
expect(rpcExecMock.mock.calls).toMatchInlineSnapshot(`
|
|
225
|
-
Array [
|
|
226
|
-
Array [
|
|
227
|
-
"git remote rm origin",
|
|
228
|
-
Object {
|
|
229
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
230
|
-
},
|
|
231
|
-
],
|
|
232
|
-
Array [
|
|
233
|
-
"git remote rm sqren",
|
|
234
|
-
Object {
|
|
235
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
236
|
-
},
|
|
237
|
-
],
|
|
238
|
-
Array [
|
|
239
|
-
"git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git",
|
|
240
|
-
Object {
|
|
241
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
242
|
-
},
|
|
243
|
-
],
|
|
244
|
-
Array [
|
|
245
|
-
"git remote rm elastic",
|
|
246
|
-
Object {
|
|
247
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
Array [
|
|
251
|
-
"git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git",
|
|
252
|
-
Object {
|
|
253
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
254
|
-
},
|
|
255
|
-
],
|
|
256
|
-
Array [
|
|
257
|
-
"git reset --hard && git clean -d --force && git fetch elastic 6.x && git checkout -B backport/6.x/commit-2e63475c elastic/6.x --no-track",
|
|
258
|
-
Object {
|
|
259
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
Array [
|
|
263
|
-
"git fetch elastic my-source-branch-from-options:my-source-branch-from-options --force",
|
|
264
|
-
Object {
|
|
265
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
Array [
|
|
269
|
-
"git cherry-pick 2e63475c483f7844b0f2833bc57fdee32095bacb",
|
|
270
|
-
Object {
|
|
271
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
Array [
|
|
275
|
-
"git push sqren backport/6.x/commit-2e63475c:backport/6.x/commit-2e63475c --force",
|
|
276
|
-
Object {
|
|
277
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
278
|
-
},
|
|
279
|
-
],
|
|
280
|
-
Array [
|
|
281
|
-
"git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/6.x/commit-2e63475c",
|
|
282
|
-
Object {
|
|
283
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic/kibana",
|
|
284
|
-
},
|
|
285
|
-
],
|
|
286
|
-
]
|
|
287
|
-
`);
|
|
288
|
-
});
|
|
289
|
-
it('git clone should be called with correct args', () => {
|
|
290
|
-
expect(rpcExecOriginalMock).toHaveBeenCalledTimes(1);
|
|
291
|
-
expect(rpcExecOriginalMock.mock.calls).toMatchInlineSnapshot(`
|
|
292
|
-
Array [
|
|
293
|
-
Array [
|
|
294
|
-
"git clone https://x-access-token:myAccessToken@github.com/elastic/kibana.git --progress",
|
|
295
|
-
Object {
|
|
296
|
-
"cwd": "/myHomeDir/.backport/repositories/elastic",
|
|
297
|
-
"maxBuffer": 104857600,
|
|
298
|
-
},
|
|
299
|
-
[Function],
|
|
300
|
-
],
|
|
301
|
-
]
|
|
302
|
-
`);
|
|
303
|
-
});
|
|
304
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fetchCommitBySha_1 = require("../services/github/v4/fetchCommits/fetchCommitBySha");
|
|
4
|
-
const getDevAccessToken_1 = require("../test/private/getDevAccessToken");
|
|
5
|
-
async function init() {
|
|
6
|
-
const accessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
7
|
-
const res = (0, fetchCommitBySha_1.fetchCommitBySha)({
|
|
8
|
-
accessToken,
|
|
9
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
10
|
-
repoName: 'backport-org',
|
|
11
|
-
repoOwner: 'backport-e2e',
|
|
12
|
-
sha: 'b484e161b705b39dbbfc5005e67ca24d05b23c37',
|
|
13
|
-
sourceBranch: 'main',
|
|
14
|
-
});
|
|
15
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
export declare const writeFile: typeof fs.writeFile.__promisify__;
|
|
4
|
-
export declare const readFile: typeof fs.readFile.__promisify__;
|
|
5
|
-
export declare const stat: typeof fs.stat.__promisify__;
|
|
6
|
-
export declare const chmod: typeof fs.chmod.__promisify__;
|
|
@@ -1,12 +0,0 @@
|
|
|
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.chmod = exports.stat = exports.readFile = exports.writeFile = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const util_1 = require("util");
|
|
9
|
-
exports.writeFile = (0, util_1.promisify)(fs_1.default.writeFile);
|
|
10
|
-
exports.readFile = (0, util_1.promisify)(fs_1.default.readFile);
|
|
11
|
-
exports.stat = (0, util_1.promisify)(fs_1.default.stat);
|
|
12
|
-
exports.chmod = (0, util_1.promisify)(fs_1.default.chmod);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ValidConfigOptions } from '../options/options';
|
|
2
|
-
import { SourceCommitWithTargetPullRequest } from './sourceCommit';
|
|
3
|
-
export declare type ExpectedTargetPullRequest = {
|
|
4
|
-
url?: string;
|
|
5
|
-
number?: number;
|
|
6
|
-
branch: string;
|
|
7
|
-
state: 'OPEN' | 'CLOSED' | 'MERGED' | 'MISSING';
|
|
8
|
-
};
|
|
9
|
-
export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExpectedTargetPullRequests = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const getTargetBranchesFromLabels_1 = require("../services/github/v4/getTargetBranchesFromLabels");
|
|
6
|
-
const filterEmpty_1 = require("../utils/filterEmpty");
|
|
7
|
-
const commitFormatters_1 = require("./github/commitFormatters");
|
|
8
|
-
function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
|
|
9
|
-
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
10
|
-
// if there is no source pull request the commit was pushed directly to the source branch
|
|
11
|
-
// in that case there will be no labels, and thus not possible to deduce the expected target branches
|
|
12
|
-
if (!sourcePullRequest) {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
|
|
16
|
-
// if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
|
|
17
|
-
if (!branchLabelMapping) {
|
|
18
|
-
return existingTargetPullRequests;
|
|
19
|
-
}
|
|
20
|
-
const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
|
|
21
|
-
return [...existingTargetPullRequests, ...missingTargetPullRequests];
|
|
22
|
-
}
|
|
23
|
-
exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
|
|
24
|
-
function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
25
|
-
const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
|
|
26
|
-
return sourcePullRequest.timelineItems.edges
|
|
27
|
-
.filter(filterEmpty_1.filterNil)
|
|
28
|
-
.filter(filterPullRequests)
|
|
29
|
-
.filter((item) => {
|
|
30
|
-
const { targetPullRequest } = item.node;
|
|
31
|
-
// ignore closed PRs
|
|
32
|
-
if (targetPullRequest.state === 'CLOSED') {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
// at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
|
|
36
|
-
const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
|
|
37
|
-
const { targetCommit } = commitEdge.node;
|
|
38
|
-
const matchingRepoName = sourceCommit.repository.name === targetCommit.repository.name;
|
|
39
|
-
const matchingRepoOwner = sourceCommit.repository.owner.login ===
|
|
40
|
-
targetCommit.repository.owner.login;
|
|
41
|
-
const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
|
|
42
|
-
const matchingMessage = targetCommitMessage === sourceCommitMessage;
|
|
43
|
-
return matchingRepoName && matchingRepoOwner && matchingMessage;
|
|
44
|
-
});
|
|
45
|
-
const titleIncludesMessage = targetPullRequest.title.includes(sourceCommitMessage);
|
|
46
|
-
const titleIncludesNumber = targetPullRequest.title.includes(sourcePullRequest.number.toString());
|
|
47
|
-
return didCommitMatch || (titleIncludesMessage && titleIncludesNumber);
|
|
48
|
-
})
|
|
49
|
-
.map((item) => {
|
|
50
|
-
const { targetPullRequest } = item.node;
|
|
51
|
-
return {
|
|
52
|
-
url: targetPullRequest.url,
|
|
53
|
-
number: targetPullRequest.number,
|
|
54
|
-
branch: targetPullRequest.baseRefName,
|
|
55
|
-
state: targetPullRequest.state,
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
|
|
60
|
-
const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
|
|
61
|
-
const targetBranchesFromLabels = labels
|
|
62
|
-
.map((label) => (0, getTargetBranchesFromLabels_1.getTargetBranchForLabel)({ branchLabelMapping, label }))
|
|
63
|
-
.filter(filterEmpty_1.filterNil)
|
|
64
|
-
.filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
|
|
65
|
-
const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
|
|
66
|
-
const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
|
|
67
|
-
return expected
|
|
68
|
-
.filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
|
|
69
|
-
.map((branch) => {
|
|
70
|
-
return { branch, state: 'MISSING' };
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
// narrow TimelineEdge to TimelinePullRequestEdge
|
|
74
|
-
function filterPullRequests(item) {
|
|
75
|
-
const { targetPullRequest } = item.node;
|
|
76
|
-
return targetPullRequest.__typename === 'PullRequest';
|
|
77
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ValidConfigOptions } from '../options/options';
|
|
2
|
-
import { SourceCommitWithTargetPullRequest } from './sourceCommit';
|
|
3
|
-
export declare type ExpectedTargetPullRequest = {
|
|
4
|
-
url?: string;
|
|
5
|
-
number?: number;
|
|
6
|
-
branch: string;
|
|
7
|
-
state: 'OPEN' | 'CLOSED' | 'MERGED' | 'MISSING';
|
|
8
|
-
};
|
|
9
|
-
export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExpectedTargetPullRequests = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const getTargetBranchesFromLabels_1 = require("../services/github/v4/getTargetBranchesFromLabels");
|
|
6
|
-
const filterEmpty_1 = require("../utils/filterEmpty");
|
|
7
|
-
const commitFormatters_1 = require("./github/commitFormatters");
|
|
8
|
-
function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
|
|
9
|
-
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
10
|
-
// if there is no source pull request the commit was pushed directly to the source branch
|
|
11
|
-
// in that case there will be no labels, and thus not possible to deduce the expected target branches
|
|
12
|
-
if (!sourcePullRequest) {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
const existingTargetPullRequests = getExistingTargetPullRequests(sourceCommit, sourcePullRequest);
|
|
16
|
-
// if there's no `branchLabelMapping`, it's not possible to deduce the missing target branches
|
|
17
|
-
if (!branchLabelMapping) {
|
|
18
|
-
return existingTargetPullRequests;
|
|
19
|
-
}
|
|
20
|
-
const missingTargetPullRequests = getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping);
|
|
21
|
-
return [...existingTargetPullRequests, ...missingTargetPullRequests];
|
|
22
|
-
}
|
|
23
|
-
exports.getExpectedTargetPullRequests = getExpectedTargetPullRequests;
|
|
24
|
-
function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
25
|
-
const sourceCommitMessage = (0, commitFormatters_1.getFirstLine)(sourceCommit.message);
|
|
26
|
-
return sourcePullRequest.timelineItems.edges
|
|
27
|
-
.filter(filterEmpty_1.filterNil)
|
|
28
|
-
.filter(filterPullRequests)
|
|
29
|
-
.filter((item) => {
|
|
30
|
-
const { targetPullRequest } = item.node;
|
|
31
|
-
// ignore closed PRs
|
|
32
|
-
if (targetPullRequest.state === 'CLOSED') {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
// at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
|
|
36
|
-
const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
|
|
37
|
-
const { targetCommit } = commitEdge.node;
|
|
38
|
-
const matchingRepoName = sourceCommit.repository.name === targetCommit.repository.name;
|
|
39
|
-
const matchingRepoOwner = sourceCommit.repository.owner.login ===
|
|
40
|
-
targetCommit.repository.owner.login;
|
|
41
|
-
const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
|
|
42
|
-
const matchingMessage = targetCommitMessage === sourceCommitMessage;
|
|
43
|
-
return matchingRepoName && matchingRepoOwner && matchingMessage;
|
|
44
|
-
});
|
|
45
|
-
const titleIncludesMessage = targetPullRequest.title.includes(sourceCommitMessage);
|
|
46
|
-
const titleIncludesNumber = targetPullRequest.title.includes(sourcePullRequest.number.toString());
|
|
47
|
-
return didCommitMatch || (titleIncludesMessage && titleIncludesNumber);
|
|
48
|
-
})
|
|
49
|
-
.map((item) => {
|
|
50
|
-
const { targetPullRequest } = item.node;
|
|
51
|
-
return {
|
|
52
|
-
url: targetPullRequest.url,
|
|
53
|
-
number: targetPullRequest.number,
|
|
54
|
-
branch: targetPullRequest.baseRefName,
|
|
55
|
-
state: targetPullRequest.state,
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function getMissingTargetPullRequests(sourcePullRequest, existingTargetPullRequests, branchLabelMapping) {
|
|
60
|
-
const labels = sourcePullRequest.labels.nodes.map((label) => label.name);
|
|
61
|
-
const targetBranchesFromLabels = labels
|
|
62
|
-
.map((label) => (0, getTargetBranchesFromLabels_1.getTargetBranchForLabel)({ branchLabelMapping, label }))
|
|
63
|
-
.filter(filterEmpty_1.filterNil)
|
|
64
|
-
.filter((targetBranch) => targetBranch !== sourcePullRequest.baseRefName);
|
|
65
|
-
const expectedTargetBranches = existingTargetPullRequests.map((pr) => pr.branch);
|
|
66
|
-
const expected = (0, lodash_1.uniq)(targetBranchesFromLabels);
|
|
67
|
-
return expected
|
|
68
|
-
.filter((targetBranch) => !expectedTargetBranches.includes(targetBranch))
|
|
69
|
-
.map((branch) => {
|
|
70
|
-
return { branch, state: 'MISSING' };
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
// narrow TimelineEdge to TimelinePullRequestEdge
|
|
74
|
-
function filterPullRequests(item) {
|
|
75
|
-
const { targetPullRequest } = item.node;
|
|
76
|
-
return targetPullRequest.__typename === 'PullRequest';
|
|
77
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
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.fetchCommitByPullNumber = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const ora_1 = __importDefault(require("ora"));
|
|
9
|
-
const HandledError_1 = require("../../HandledError");
|
|
10
|
-
const commitFormatters_1 = require("../commitFormatters");
|
|
11
|
-
const apiRequestV4_1 = require("./apiRequestV4");
|
|
12
|
-
const getExistingTargetPullRequests_1 = require("./getExistingTargetPullRequests");
|
|
13
|
-
const getTargetBranchesFromLabels_1 = require("./getTargetBranchesFromLabels");
|
|
14
|
-
async function fetchCommitByPullNumber(options) {
|
|
15
|
-
const { accessToken, githubApiBaseUrlV4, pullNumber, repoName, repoOwner } = options;
|
|
16
|
-
const query = /* GraphQL */ `
|
|
17
|
-
query CommitByPullNumber(
|
|
18
|
-
$repoOwner: String!
|
|
19
|
-
$repoName: String!
|
|
20
|
-
$pullNumber: Int!
|
|
21
|
-
) {
|
|
22
|
-
repository(owner: $repoOwner, name: $repoName) {
|
|
23
|
-
pullRequest(number: $pullNumber) {
|
|
24
|
-
...${getExistingTargetPullRequests_1.pullRequestFragment.name}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
${getExistingTargetPullRequests_1.pullRequestFragment.source}
|
|
30
|
-
`;
|
|
31
|
-
const spinner = (0, ora_1.default)(`Loading merge commit from pull request #${options.pullNumber}`).start();
|
|
32
|
-
let res;
|
|
33
|
-
try {
|
|
34
|
-
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
35
|
-
githubApiBaseUrlV4,
|
|
36
|
-
accessToken,
|
|
37
|
-
query,
|
|
38
|
-
variables: {
|
|
39
|
-
repoOwner,
|
|
40
|
-
repoName,
|
|
41
|
-
pullNumber,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
spinner.stop();
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
spinner.fail();
|
|
48
|
-
throw e;
|
|
49
|
-
}
|
|
50
|
-
const pullRequestNode = res.repository.pullRequest;
|
|
51
|
-
if (pullRequestNode.mergeCommit === null) {
|
|
52
|
-
throw new HandledError_1.HandledError(`The PR #${pullNumber} is not merged`);
|
|
53
|
-
}
|
|
54
|
-
const committedDate = pullRequestNode.mergeCommit.committedDate;
|
|
55
|
-
const sourceBranch = pullRequestNode.baseRefName;
|
|
56
|
-
const sha = pullRequestNode.mergeCommit.oid;
|
|
57
|
-
const commitMessage = pullRequestNode.mergeCommit.message;
|
|
58
|
-
const formattedMessage = (0, commitFormatters_1.getFormattedCommitMessage)({
|
|
59
|
-
message: commitMessage,
|
|
60
|
-
sha,
|
|
61
|
-
pullNumber,
|
|
62
|
-
});
|
|
63
|
-
// add styles to make it look like a prompt question
|
|
64
|
-
spinner.stopAndPersist({
|
|
65
|
-
symbol: chalk_1.default.green('?'),
|
|
66
|
-
text: `${chalk_1.default.bold('Select pull request')} ${chalk_1.default.cyan(formattedMessage)}`,
|
|
67
|
-
});
|
|
68
|
-
const existingTargetPullRequests = (0, getExistingTargetPullRequests_1.getExistingTargetPullRequests)(pullRequestNode);
|
|
69
|
-
const targetBranchesFromLabels = (0, getTargetBranchesFromLabels_1.getTargetBranchesFromLabels)({
|
|
70
|
-
sourceBranch: pullRequestNode.baseRefName,
|
|
71
|
-
existingTargetPullRequests,
|
|
72
|
-
branchLabelMapping: options.branchLabelMapping,
|
|
73
|
-
labels: (0, getExistingTargetPullRequests_1.getPullRequestLabels)(pullRequestNode),
|
|
74
|
-
});
|
|
75
|
-
return {
|
|
76
|
-
committedDate,
|
|
77
|
-
sourceBranch,
|
|
78
|
-
targetBranchesFromLabels,
|
|
79
|
-
sha,
|
|
80
|
-
formattedMessage,
|
|
81
|
-
originalMessage: commitMessage,
|
|
82
|
-
pullNumber,
|
|
83
|
-
existingTargetPullRequests,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
exports.fetchCommitByPullNumber = fetchCommitByPullNumber;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
-
const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
|
|
5
|
-
describe('fetchCommitByPullNumber', () => {
|
|
6
|
-
let devAccessToken;
|
|
7
|
-
beforeAll(async () => {
|
|
8
|
-
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
-
});
|
|
10
|
-
describe('when PR was merged', () => {
|
|
11
|
-
it('is returned', async () => {
|
|
12
|
-
const options = {
|
|
13
|
-
accessToken: devAccessToken,
|
|
14
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
15
|
-
pullNumber: 5,
|
|
16
|
-
repoName: 'backport-e2e',
|
|
17
|
-
repoOwner: 'backport-org',
|
|
18
|
-
};
|
|
19
|
-
expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual({
|
|
20
|
-
formattedMessage: 'Add 🍏 emoji (#5)',
|
|
21
|
-
originalMessage: 'Add 🍏 emoji (#5)',
|
|
22
|
-
pullNumber: 5,
|
|
23
|
-
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
24
|
-
sourceBranch: 'master',
|
|
25
|
-
targetBranchesFromLabels: [],
|
|
26
|
-
existingTargetPullRequests: [
|
|
27
|
-
{ branch: '7.x', state: 'MERGED', number: 6 },
|
|
28
|
-
{ branch: '7.8', state: 'MERGED', number: 7 },
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
describe('when PR is still open', () => {
|
|
34
|
-
it('throws an error', async () => {
|
|
35
|
-
const options = {
|
|
36
|
-
accessToken: devAccessToken,
|
|
37
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
38
|
-
pullNumber: 11,
|
|
39
|
-
repoName: 'backport-e2e',
|
|
40
|
-
repoOwner: 'backport-org',
|
|
41
|
-
};
|
|
42
|
-
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe('when PR does not exist', () => {
|
|
46
|
-
it('throws an error', async () => {
|
|
47
|
-
const options = {
|
|
48
|
-
accessToken: devAccessToken,
|
|
49
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
50
|
-
pullNumber: 9999999999999,
|
|
51
|
-
repoName: 'backport-e2e',
|
|
52
|
-
repoOwner: 'backport-org',
|
|
53
|
-
};
|
|
54
|
-
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Unhandled Github v4 error)`);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
});
|