backport 6.1.3 → 6.2.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 +40 -37
- package/dist/backportRun.d.ts +14 -0
- package/dist/backportRun.js +75 -0
- package/dist/entrypoint.api.d.ts +22 -0
- package/dist/entrypoint.api.js +57 -0
- package/dist/entrypoint.api.private.test.d.ts +1 -0
- package/dist/entrypoint.api.private.test.js +37 -0
- package/dist/entrypoint.cli.js +3 -5
- package/dist/entrypoint.module.d.ts +6 -3
- package/dist/entrypoint.module.js +13 -7
- package/dist/entrypoint.module.private.test.js +4 -1
- package/dist/main.js +5 -1
- package/dist/options/ConfigOptions.d.ts +4 -0
- package/dist/options/cliArgs.d.ts +17 -11
- package/dist/options/cliArgs.js +36 -5
- package/dist/options/config/config.d.ts +10 -1
- package/dist/options/config/config.js +9 -3
- package/dist/options/config/config.test.js +27 -1
- package/dist/options/config/getProjectConfig.d.ts +0 -0
- package/dist/options/config/getProjectConfig.js +1 -0
- package/dist/options/config/globalConfig.d.ts +2 -2
- package/dist/options/config/globalConfig.js +16 -14
- package/dist/options/config/globalConfig.test.js +10 -4
- package/dist/options/config/projectConfig.d.ts +3 -1
- package/dist/options/config/projectConfig.js +5 -2
- package/dist/options/config/projectConfig.test.js +35 -6
- package/dist/options/config/readConfigFile.d.ts +26 -22
- package/dist/options/options.d.ts +18 -9
- package/dist/options/options.js +11 -4
- package/dist/options/options.test.js +40 -35
- package/dist/react-components/0-loadOptions.d.ts +6 -0
- package/dist/react-components/0-loadOptions.js +45 -0
- package/dist/react-components/1-loadCommit.d.ts +8 -0
- package/dist/react-components/1-loadCommit.js +88 -0
- package/dist/react-components/1a-loadCommit.d.ts +5 -0
- package/dist/react-components/1a-loadCommit.js +76 -0
- package/dist/react-components/1b-commitChoices.d.ts +5 -0
- package/dist/react-components/1b-commitChoices.js +98 -0
- package/dist/react-components/2-commitChoices.d.ts +8 -0
- package/dist/react-components/2-commitChoices.js +96 -0
- package/dist/react-components/2-commitsPrompt.d.ts +8 -0
- package/dist/react-components/2-commitsPrompt.js +96 -0
- package/dist/react-components/2-targetBranchChoices.d.ts +9 -0
- package/dist/react-components/2-targetBranchChoices.js +109 -0
- package/dist/react-components/3-cherrypick.d.ts +1 -0
- package/dist/react-components/3-cherrypick.js +2 -0
- package/dist/react-components/App.d.ts +2 -0
- package/dist/react-components/App.js +35 -0
- package/dist/react-components/BackportStateContext.d.ts +33 -0
- package/dist/react-components/BackportStateContext.js +42 -0
- package/dist/react-components/CommitPrompt/2-commitsPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt/2-commitsPrompt.js +96 -0
- package/dist/react-components/CommitPrompt/CommitPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt/CommitPrompt.js +96 -0
- package/dist/react-components/CommitPrompt/getCommits.d.ts +2 -0
- package/dist/react-components/CommitPrompt/getCommits.js +27 -0
- package/dist/react-components/CommitPrompt.d.ts +8 -0
- package/dist/react-components/CommitPrompt.js +96 -0
- package/dist/react-components/CustomMultiSelect.d.ts +13 -0
- package/dist/react-components/CustomMultiSelect.js +21 -0
- package/dist/react-components/CustomMultiSelectItem.d.ts +5 -0
- package/dist/react-components/CustomMultiSelectItem.js +12 -0
- package/dist/react-components/CustomSelect.d.ts +14 -0
- package/dist/react-components/CustomSelect.js +34 -0
- package/dist/react-components/ErrorBoundary.d.ts +15 -0
- package/dist/react-components/ErrorBoundary.js +53 -0
- package/dist/react-components/MultiSelect.d.ts +7 -0
- package/dist/react-components/MultiSelect.js +16 -0
- package/dist/react-components/hooks/useAsync.d.ts +12 -0
- package/dist/react-components/hooks/useAsync.js +73 -0
- package/dist/runSequentially.test.js +11 -13
- package/dist/scripts/postinstall.js +3 -3
- package/dist/services/HandledError.d.ts +1 -1
- package/dist/services/backportRun/backportRun.ci.d.ts +6 -0
- package/dist/services/backportRun/backportRun.ci.js +81 -0
- package/dist/services/backportRun/backportRun.d.ts +14 -0
- package/dist/services/backportRun/backportRun.interactive.d.ts +1 -0
- package/dist/services/backportRun/backportRun.interactive.js +4 -0
- package/dist/services/backportRun/backportRun.js +14 -0
- package/dist/services/backportRun/backportState.d.ts +4 -0
- package/dist/services/backportRun/backportState.js +28 -0
- package/dist/services/backportRun/getCommits.d.ts +2 -0
- package/dist/services/backportRun/getCommits.js +20 -0
- package/dist/services/backportRun/runSequentially.d.ts +20 -0
- package/dist/services/backportRun/runSequentially.js +41 -0
- package/dist/services/backportRun/runSequentially.test.d.ts +1 -0
- package/dist/services/backportRun/runSequentially.test.js +199 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.d.ts +12 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.js +206 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/services/cherrypickAndCreateTargetPullRequest.test.js +403 -0
- package/dist/services/env.d.ts +5 -4
- package/dist/services/env.js +13 -11
- package/dist/services/env.test.js +0 -6
- package/dist/services/getCommits.d.ts +2 -0
- package/dist/services/getCommits.js +38 -0
- package/dist/services/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/services/getCommitsWithoutBackports.js +68 -0
- package/dist/services/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/services/getCommitsWithoutBackports.test.js +259 -0
- package/dist/services/getTargetBranches.d.ts +5 -0
- package/dist/services/getTargetBranches.js +60 -0
- package/dist/services/getTargetBranches.test.d.ts +1 -0
- package/dist/services/getTargetBranches.test.js +180 -0
- package/dist/services/git.d.ts +2 -1
- package/dist/services/git.js +5 -3
- package/dist/services/github/v3/createPullRequest.js +8 -5
- package/dist/services/github/v3/createPullRequest.test.js +60 -10
- package/dist/services/github/v3/createStatusComment.d.ts +2 -2
- package/dist/services/github/v3/createStatusComment.js +40 -15
- package/dist/services/github/v3/createStatusComment.test.js +174 -86
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
- package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchProjectConfig.js +3 -3
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +4 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
- package/dist/services/logger.d.ts +4 -2
- package/dist/services/logger.js +31 -32
- package/dist/services/maybeSetupRepo.d.ts +2 -0
- package/dist/services/maybeSetupRepo.js +33 -0
- package/dist/services/maybeSetupRepo.test.d.ts +1 -0
- package/dist/services/maybeSetupRepo.test.js +78 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
- package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
- package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
- package/dist/test/backport-e2e.private.test.d.ts +1 -0
- package/dist/test/backport-e2e.private.test.js +325 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +43 -0
- package/dist/test/inquirer.private.test.js +3 -1
- package/dist/test/integration/integration.private.test.js +2 -2
- package/dist/test/nockHelpers.js +1 -3
- package/dist/test/setupFiles/automatic-mocks.js +1 -0
- package/dist/todo-delete.d.ts +1 -0
- package/dist/todo-delete.js +17 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -3
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +9 -12
- package/dist/ui/getCommits.js +1 -1
- package/dist/ui/getCommitsWithoutBackports.js +17 -2
- package/dist/ui/maybeSetupRepo.js +0 -6
- package/dist/ui/maybeSetupRepo.test.js +8 -4
- package/dist/utils/redact.d.ts +1 -0
- package/dist/utils/redact.js +7 -0
- package/dist/utils/sequentially.d.ts +1 -0
- package/dist/utils/sequentially.js +10 -0
- package/package.json +11 -11
- package/yarn.lock +570 -436
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchRemoteProjectConfig_1 = require("./fetchRemoteProjectConfig");
|
|
5
|
+
describe('fetchRemoteProjectConfig', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
it('returns the backport config from "main" branch', async () => {
|
|
11
|
+
const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
12
|
+
repoOwner: 'backport-org',
|
|
13
|
+
repoName: 'repo-with-project-config',
|
|
14
|
+
accessToken: devAccessToken,
|
|
15
|
+
sourceBranch: 'main',
|
|
16
|
+
});
|
|
17
|
+
expect(projectConfig).toEqual({
|
|
18
|
+
autoMerge: true,
|
|
19
|
+
autoMergeMethod: 'squash',
|
|
20
|
+
branchLabelMapping: {
|
|
21
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
22
|
+
'^v8.1.0$': 'main',
|
|
23
|
+
},
|
|
24
|
+
targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
|
|
25
|
+
targetPRLabels: ['backport'],
|
|
26
|
+
repoOwner: 'backport-org',
|
|
27
|
+
repoName: 'repo-with-project-config',
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it('returns the backport config from "branch-with-legacy-config" branch', async () => {
|
|
31
|
+
const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
32
|
+
repoOwner: 'backport-org',
|
|
33
|
+
repoName: 'repo-with-project-config',
|
|
34
|
+
accessToken: devAccessToken,
|
|
35
|
+
sourceBranch: 'branch-with-legacy-config',
|
|
36
|
+
});
|
|
37
|
+
expect(projectConfig).toEqual({
|
|
38
|
+
targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
|
|
39
|
+
repoOwner: 'backport-org',
|
|
40
|
+
repoName: 'repo-with-project-config',
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('throws an error if config does not exist', async () => {
|
|
44
|
+
const promise = (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
45
|
+
repoOwner: 'backport-org',
|
|
46
|
+
repoName: 'repo-with-project-config',
|
|
47
|
+
accessToken: devAccessToken,
|
|
48
|
+
sourceBranch: 'branch-with-no-config',
|
|
49
|
+
});
|
|
50
|
+
await expect(promise).rejects.toThrowError('Project config does not exist');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -32,12 +32,15 @@ export declare function getOptionsFromGithub(options: {
|
|
|
32
32
|
cherrypickRef?: boolean | undefined;
|
|
33
33
|
ci?: boolean | undefined;
|
|
34
34
|
commitPaths?: string[] | undefined;
|
|
35
|
+
configFile?: string | undefined;
|
|
35
36
|
details?: boolean | undefined;
|
|
37
|
+
dir?: string | undefined;
|
|
36
38
|
editor?: string | undefined;
|
|
37
39
|
fork?: boolean | undefined;
|
|
38
40
|
gitHostname?: string | undefined;
|
|
39
41
|
githubApiBaseUrlV3?: string | undefined;
|
|
40
42
|
githubApiBaseUrlV4?: string | undefined;
|
|
43
|
+
logFilePath?: string | undefined;
|
|
41
44
|
maxNumber?: number | undefined;
|
|
42
45
|
multiple?: boolean | undefined;
|
|
43
46
|
multipleBranches?: boolean | undefined;
|
|
@@ -46,6 +49,7 @@ export declare function getOptionsFromGithub(options: {
|
|
|
46
49
|
prDescription?: string | undefined;
|
|
47
50
|
prFilter?: string | undefined;
|
|
48
51
|
prTitle?: string | undefined;
|
|
52
|
+
publishStatusComment?: boolean | undefined;
|
|
49
53
|
pullNumber?: number | undefined;
|
|
50
54
|
repoName?: string | undefined;
|
|
51
55
|
repoOwner?: string | undefined;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getOptionsFromGithub = void 0;
|
|
7
|
-
const ora_1 = __importDefault(require("ora"));
|
|
8
4
|
const readConfigFile_1 = require("../../../../options/config/readConfigFile");
|
|
9
5
|
const filterEmpty_1 = require("../../../../utils/filterEmpty");
|
|
10
6
|
const HandledError_1 = require("../../../HandledError");
|
|
@@ -16,7 +12,6 @@ const query_1 = require("./query");
|
|
|
16
12
|
async function getOptionsFromGithub(options) {
|
|
17
13
|
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
18
14
|
let res;
|
|
19
|
-
const spinner = (0, ora_1.default)().start('Initializing...');
|
|
20
15
|
try {
|
|
21
16
|
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
22
17
|
githubApiBaseUrlV4,
|
|
@@ -25,10 +20,8 @@ async function getOptionsFromGithub(options) {
|
|
|
25
20
|
variables: { repoOwner, repoName },
|
|
26
21
|
handleError: false,
|
|
27
22
|
});
|
|
28
|
-
spinner.stop();
|
|
29
23
|
}
|
|
30
24
|
catch (e) {
|
|
31
|
-
spinner.stop();
|
|
32
25
|
const error = e;
|
|
33
26
|
(0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
|
|
34
27
|
error,
|
|
@@ -40,6 +40,10 @@ exports.commitsByAuthorMock = {
|
|
|
40
40
|
nodes: [{ name: 'my-label-b' }],
|
|
41
41
|
},
|
|
42
42
|
number: 85,
|
|
43
|
+
sourceMergeCommit: {
|
|
44
|
+
oid: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
45
|
+
message: 'Add witch (#85)',
|
|
46
|
+
},
|
|
43
47
|
timelineItems: {
|
|
44
48
|
edges: [],
|
|
45
49
|
},
|
|
@@ -68,12 +72,24 @@ exports.commitsByAuthorMock = {
|
|
|
68
72
|
},
|
|
69
73
|
baseRefName: 'master',
|
|
70
74
|
number: 80,
|
|
75
|
+
sourceMergeCommit: {
|
|
76
|
+
oid: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
77
|
+
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
78
|
+
},
|
|
71
79
|
timelineItems: {
|
|
72
80
|
edges: [
|
|
73
81
|
{
|
|
74
82
|
node: {
|
|
75
83
|
targetPullRequest: {
|
|
76
84
|
__typename: 'PullRequest',
|
|
85
|
+
targetMergeCommit: {
|
|
86
|
+
oid: 'target-merge-commit-sha',
|
|
87
|
+
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
88
|
+
},
|
|
89
|
+
repository: {
|
|
90
|
+
name: 'kibana',
|
|
91
|
+
owner: { login: 'elastic' },
|
|
92
|
+
},
|
|
77
93
|
url: 'https://github.com/elastic/kibana/pull/99',
|
|
78
94
|
title: 'some title',
|
|
79
95
|
state: 'MERGED',
|
|
@@ -84,11 +100,6 @@ exports.commitsByAuthorMock = {
|
|
|
84
100
|
{
|
|
85
101
|
node: {
|
|
86
102
|
targetCommit: {
|
|
87
|
-
repository: {
|
|
88
|
-
name: 'kibana',
|
|
89
|
-
owner: { login: 'elastic' },
|
|
90
|
-
},
|
|
91
|
-
committedDate: '2021-12-23T00:00:00Z',
|
|
92
103
|
oid: 'abc',
|
|
93
104
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
94
105
|
},
|
|
@@ -9,8 +9,10 @@ export declare const logger: {
|
|
|
9
9
|
debug: (message: string, meta?: unknown) => void;
|
|
10
10
|
};
|
|
11
11
|
export declare function updateLogger(options: ConfigFileOptions): void;
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
12
|
+
export declare function initLogger({ ci, logFilePath, }: {
|
|
13
|
+
ci?: boolean;
|
|
14
|
+
logFilePath?: string;
|
|
15
|
+
}): {
|
|
14
16
|
error: (message: string, meta?: unknown) => void;
|
|
15
17
|
warn: (message: string, meta?: unknown) => void;
|
|
16
18
|
info: (message: string, meta?: unknown) => void;
|
package/dist/services/logger.js
CHANGED
|
@@ -22,11 +22,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.initLogger = exports.
|
|
25
|
+
exports.initLogger = exports.updateLogger = exports.logger = exports.consoleLog = void 0;
|
|
26
26
|
const dedent_1 = __importDefault(require("dedent"));
|
|
27
27
|
const lodash_1 = require("lodash");
|
|
28
28
|
const safe_json_stringify_1 = __importDefault(require("safe-json-stringify"));
|
|
29
29
|
const winston_1 = __importStar(require("winston"));
|
|
30
|
+
const redact_1 = require("../utils/redact");
|
|
30
31
|
const env_1 = require("./env");
|
|
31
32
|
const { combine } = winston_1.format;
|
|
32
33
|
let winstonInstance;
|
|
@@ -59,46 +60,21 @@ function updateLogger(options) {
|
|
|
59
60
|
accessToken = options.accessToken;
|
|
60
61
|
// set log level
|
|
61
62
|
winstonInstance.level = options.verbose ? 'debug' : 'info';
|
|
62
|
-
// output logs to console in ci env
|
|
63
|
-
if (options.ci) {
|
|
64
|
-
winstonInstance.add(new winston_1.default.transports.Console());
|
|
65
|
-
}
|
|
66
63
|
}
|
|
67
64
|
exports.updateLogger = updateLogger;
|
|
68
65
|
function redactAccessToken(str) {
|
|
69
66
|
// `redactAccessToken` might be called before access token is set
|
|
70
67
|
if (accessToken) {
|
|
71
|
-
return
|
|
68
|
+
return (0, redact_1.redact)(accessToken, str);
|
|
72
69
|
}
|
|
73
70
|
return str;
|
|
74
71
|
}
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
function initLogger({ ci, logFilePath, }) {
|
|
73
|
+
const fileTransport = getFileTransport({ logFilePath });
|
|
77
74
|
winstonInstance = winston_1.default.createLogger({
|
|
78
|
-
transports:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
level: 'debug',
|
|
82
|
-
format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
|
|
83
|
-
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
84
|
-
}), winston_1.format.printf((info) => {
|
|
85
|
-
// format without metadata
|
|
86
|
-
if (!info.metadata.meta) {
|
|
87
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}`);
|
|
88
|
-
}
|
|
89
|
-
// format when metadata is a string
|
|
90
|
-
if ((0, lodash_1.isString)(info.metadata.meta)) {
|
|
91
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
|
|
92
|
-
}
|
|
93
|
-
if (info.metadata.meta.stack) {
|
|
94
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
|
|
95
|
-
}
|
|
96
|
-
// format when metadata is an object
|
|
97
|
-
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
|
|
98
|
-
})),
|
|
99
|
-
filename: (0, env_1.getLogfilePath)(),
|
|
100
|
-
}),
|
|
101
|
-
],
|
|
75
|
+
transports: ci
|
|
76
|
+
? [fileTransport, new winston_1.default.transports.Console()]
|
|
77
|
+
: [fileTransport],
|
|
102
78
|
});
|
|
103
79
|
// wait exiting until logs have been flushed to disk
|
|
104
80
|
winstonInstance.on('finish', () => {
|
|
@@ -107,6 +83,29 @@ function initLogger() {
|
|
|
107
83
|
return exports.logger;
|
|
108
84
|
}
|
|
109
85
|
exports.initLogger = initLogger;
|
|
86
|
+
function getFileTransport({ logFilePath }) {
|
|
87
|
+
return new winston_1.default.transports.File({
|
|
88
|
+
level: 'debug',
|
|
89
|
+
format: combine(winston_1.format.splat(), winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.metadata({
|
|
90
|
+
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
91
|
+
}), winston_1.format.printf((info) => {
|
|
92
|
+
// format without metadata
|
|
93
|
+
if (!info.metadata.meta) {
|
|
94
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}`);
|
|
95
|
+
}
|
|
96
|
+
// format when metadata is a string
|
|
97
|
+
if ((0, lodash_1.isString)(info.metadata.meta)) {
|
|
98
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, dedent_1.default)(info.metadata.meta)}\n`);
|
|
99
|
+
}
|
|
100
|
+
if (info.metadata.meta.stack) {
|
|
101
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${info.metadata.meta.stack}\n`);
|
|
102
|
+
}
|
|
103
|
+
// format when metadata is an object
|
|
104
|
+
return redactAccessToken(`${info.timestamp}: ${info.message}\n${(0, safe_json_stringify_1.default)(info.metadata.meta, null, 2)}\n`);
|
|
105
|
+
})),
|
|
106
|
+
filename: (0, env_1.getLogfilePath)({ logFilePath }),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
110
109
|
// log levels:
|
|
111
110
|
// - error
|
|
112
111
|
// - warn
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maybeSetupRepo = void 0;
|
|
4
|
+
const git_1 = require("../services/git");
|
|
5
|
+
async function maybeSetupRepo(options) {
|
|
6
|
+
const isAlreadyCloned = await (0, git_1.repoExists)(options);
|
|
7
|
+
// clone repo if folder does not already exists
|
|
8
|
+
if (!isAlreadyCloned) {
|
|
9
|
+
try {
|
|
10
|
+
const spinnerCloneText = 'Cloning repository (one-time operation)';
|
|
11
|
+
// spinner.text = `0% ${spinnerCloneText}`;
|
|
12
|
+
// await cloneRepo(options, (progress: string) => {
|
|
13
|
+
// spinner.text = `${progress}% ${spinnerCloneText}`;
|
|
14
|
+
// });
|
|
15
|
+
// spinner.succeed(`100% ${spinnerCloneText}`);
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
await (0, git_1.deleteRepo)(options);
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// delete default "origin" remote to avoid confusion
|
|
23
|
+
await (0, git_1.deleteRemote)(options, 'origin');
|
|
24
|
+
// ensure remote are setup with latest accessToken
|
|
25
|
+
await (0, git_1.deleteRemote)(options, options.authenticatedUsername);
|
|
26
|
+
await (0, git_1.addRemote)(options, options.authenticatedUsername);
|
|
27
|
+
// update remote for origin (if the above is a fork)
|
|
28
|
+
if (options.authenticatedUsername !== options.repoOwner) {
|
|
29
|
+
await (0, git_1.deleteRemote)(options, options.repoOwner);
|
|
30
|
+
await (0, git_1.addRemote)(options, options.repoOwner);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.maybeSetupRepo = maybeSetupRepo;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
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 del_1 = __importDefault(require("del"));
|
|
27
|
+
const childProcess = __importStar(require("../services/child-process-promisified"));
|
|
28
|
+
const fs = __importStar(require("../services/fs-promisified"));
|
|
29
|
+
const maybeSetupRepo_1 = require("./maybeSetupRepo");
|
|
30
|
+
describe('maybeSetupRepo', () => {
|
|
31
|
+
let execSpy;
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
34
|
+
execSpy = jest
|
|
35
|
+
.spyOn(childProcess, 'exec')
|
|
36
|
+
.mockResolvedValue({ stderr: '', stdout: '' });
|
|
37
|
+
});
|
|
38
|
+
it('should delete repo if an error occurs', async () => {
|
|
39
|
+
expect.assertions(2);
|
|
40
|
+
execSpy = jest
|
|
41
|
+
.spyOn(childProcess, 'execAsCallback')
|
|
42
|
+
.mockImplementation((cmd) => {
|
|
43
|
+
if (cmd.startsWith('git clone')) {
|
|
44
|
+
throw new Error('Simulated git clone failure');
|
|
45
|
+
}
|
|
46
|
+
throw new Error('unknown error');
|
|
47
|
+
});
|
|
48
|
+
await expect((0, maybeSetupRepo_1.maybeSetupRepo)({
|
|
49
|
+
accessToken: 'myAccessToken',
|
|
50
|
+
gitHostname: 'github.com',
|
|
51
|
+
repoName: 'kibana',
|
|
52
|
+
repoOwner: 'elastic',
|
|
53
|
+
})).rejects.toThrowError('Simulated git clone failure');
|
|
54
|
+
expect(del_1.default).toHaveBeenCalledWith('/myHomeDir/.backport/repositories/elastic/kibana');
|
|
55
|
+
});
|
|
56
|
+
describe('if repo already exists', () => {
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
// @ts-expect-error
|
|
59
|
+
jest.spyOn(fs, 'stat').mockResolvedValue({ isDirectory: () => true });
|
|
60
|
+
});
|
|
61
|
+
it('should re-create remotes for both source repo and fork', async () => {
|
|
62
|
+
await (0, maybeSetupRepo_1.maybeSetupRepo)({
|
|
63
|
+
accessToken: 'myAccessToken',
|
|
64
|
+
authenticatedUsername: 'sqren_authenticated',
|
|
65
|
+
gitHostname: 'github.com',
|
|
66
|
+
repoName: 'kibana',
|
|
67
|
+
repoOwner: 'elastic',
|
|
68
|
+
});
|
|
69
|
+
expect(execSpy.mock.calls.map(([cmd]) => cmd)).toEqual([
|
|
70
|
+
'git remote rm origin',
|
|
71
|
+
'git remote rm sqren_authenticated',
|
|
72
|
+
'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
|
|
73
|
+
'git remote rm elastic',
|
|
74
|
+
'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -5,5 +5,9 @@ export declare type ExpectedTargetPullRequest = {
|
|
|
5
5
|
number?: number;
|
|
6
6
|
branch: string;
|
|
7
7
|
state: 'OPEN' | 'CLOSED' | 'MERGED' | 'MISSING';
|
|
8
|
+
mergeCommit?: {
|
|
9
|
+
sha: string;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
8
12
|
};
|
|
9
13
|
export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
|
|
@@ -34,9 +34,9 @@ function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
|
34
34
|
// at least one of the commits in `targetPullRequest` should match the merge commit from the source pull request
|
|
35
35
|
const didCommitMatch = targetPullRequest.commits.edges.some((commitEdge) => {
|
|
36
36
|
const { targetCommit } = commitEdge.node;
|
|
37
|
-
const matchingRepoName = sourceCommit.repository.name ===
|
|
37
|
+
const matchingRepoName = sourceCommit.repository.name === targetPullRequest.repository.name;
|
|
38
38
|
const matchingRepoOwner = sourceCommit.repository.owner.login ===
|
|
39
|
-
|
|
39
|
+
targetPullRequest.repository.owner.login;
|
|
40
40
|
const targetCommitMessage = (0, commitFormatters_1.getFirstLine)(targetCommit.message);
|
|
41
41
|
const matchingMessage = targetCommitMessage === sourceCommitMessage;
|
|
42
42
|
return matchingRepoName && matchingRepoOwner && matchingMessage;
|
|
@@ -52,6 +52,12 @@ function getExistingTargetPullRequests(sourceCommit, sourcePullRequest) {
|
|
|
52
52
|
number: targetPullRequest.number,
|
|
53
53
|
branch: targetPullRequest.baseRefName,
|
|
54
54
|
state: targetPullRequest.state,
|
|
55
|
+
mergeCommit: targetPullRequest.targetMergeCommit
|
|
56
|
+
? {
|
|
57
|
+
sha: targetPullRequest.targetMergeCommit.oid,
|
|
58
|
+
message: targetPullRequest.targetMergeCommit.message,
|
|
59
|
+
}
|
|
60
|
+
: undefined,
|
|
55
61
|
};
|
|
56
62
|
});
|
|
57
63
|
}
|
|
@@ -40,6 +40,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
40
40
|
state: 'MERGED',
|
|
41
41
|
number: 5678,
|
|
42
42
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
43
|
+
mergeCommit: {
|
|
44
|
+
message: 'identical messages (#1234)',
|
|
45
|
+
sha: 'target-merge-commit-sha',
|
|
46
|
+
},
|
|
43
47
|
},
|
|
44
48
|
]);
|
|
45
49
|
});
|
|
@@ -122,6 +126,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
122
126
|
state: 'MERGED',
|
|
123
127
|
number: 5678,
|
|
124
128
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
129
|
+
mergeCommit: {
|
|
130
|
+
message: 'message two (#1234)',
|
|
131
|
+
sha: 'target-merge-commit-sha',
|
|
132
|
+
},
|
|
125
133
|
},
|
|
126
134
|
]);
|
|
127
135
|
});
|
|
@@ -168,6 +176,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
168
176
|
state: 'MERGED',
|
|
169
177
|
number: 5678,
|
|
170
178
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
179
|
+
mergeCommit: {
|
|
180
|
+
message: 'message one (#1234)\n\nsomething else',
|
|
181
|
+
sha: 'target-merge-commit-sha',
|
|
182
|
+
},
|
|
171
183
|
},
|
|
172
184
|
]);
|
|
173
185
|
});
|
|
@@ -218,6 +230,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
218
230
|
state: 'MERGED',
|
|
219
231
|
number: 5678,
|
|
220
232
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
233
|
+
mergeCommit: {
|
|
234
|
+
message: 'identical messages (#1234)',
|
|
235
|
+
sha: 'target-merge-commit-sha',
|
|
236
|
+
},
|
|
221
237
|
},
|
|
222
238
|
{ branch: '7.1', state: 'MISSING' },
|
|
223
239
|
]);
|
|
@@ -404,6 +420,10 @@ describe('getExpectedTargetPullRequests', () => {
|
|
|
404
420
|
number: 5678,
|
|
405
421
|
state: 'MERGED',
|
|
406
422
|
url: 'https://github.com/elastic/kibana/pull/5678',
|
|
423
|
+
mergeCommit: {
|
|
424
|
+
message: 'identical messages (#1234)',
|
|
425
|
+
sha: 'target-merge-commit-sha',
|
|
426
|
+
},
|
|
407
427
|
},
|
|
408
428
|
{ branch: 'branch-1', state: 'MISSING' },
|
|
409
429
|
{ branch: 'branch-2', state: 'MISSING' },
|
|
@@ -2,65 +2,91 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMockSourceCommit = void 0;
|
|
4
4
|
function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems = [], }) {
|
|
5
|
+
const defaultTargetPullRequestTitle = 'DO NOT USE: Default Pull Request Title';
|
|
6
|
+
const defaultSourceCommitSha = 'DO NOT USE: default-source-commit-sha';
|
|
7
|
+
const baseMockCommit = {
|
|
8
|
+
repository: {
|
|
9
|
+
name: 'kibana',
|
|
10
|
+
owner: { login: 'elastic' },
|
|
11
|
+
},
|
|
12
|
+
committedDate: sourceCommit.commitedDate ?? '2021-12-22T00:00:00Z',
|
|
13
|
+
oid: sourceCommit.sha ?? defaultSourceCommitSha,
|
|
14
|
+
message: sourceCommit.message,
|
|
15
|
+
};
|
|
16
|
+
if (!sourcePullRequest) {
|
|
17
|
+
return {
|
|
18
|
+
...baseMockCommit,
|
|
19
|
+
associatedPullRequests: {
|
|
20
|
+
edges: null,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
5
24
|
return {
|
|
6
25
|
repository: {
|
|
7
26
|
name: 'kibana',
|
|
8
27
|
owner: { login: 'elastic' },
|
|
9
28
|
},
|
|
10
29
|
committedDate: sourceCommit.commitedDate ?? '2021-12-22T00:00:00Z',
|
|
11
|
-
oid:
|
|
30
|
+
oid: sourceCommit.sha ?? defaultSourceCommitSha,
|
|
12
31
|
message: sourceCommit.message,
|
|
13
32
|
associatedPullRequests: {
|
|
14
|
-
edges:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
message: message,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
})),
|
|
33
|
+
edges: [
|
|
34
|
+
{
|
|
35
|
+
node: {
|
|
36
|
+
sourceMergeCommit: {
|
|
37
|
+
oid: sourceCommit.sha ?? defaultSourceCommitSha,
|
|
38
|
+
message: sourceCommit.message,
|
|
39
|
+
},
|
|
40
|
+
url: `https://github.com/elastic/kibana/pull/${sourcePullRequest.number}`,
|
|
41
|
+
labels: {
|
|
42
|
+
nodes: (sourcePullRequest.labels ?? []).map((name) => ({
|
|
43
|
+
name,
|
|
44
|
+
})),
|
|
45
|
+
},
|
|
46
|
+
baseRefName: sourcePullRequest.sourceBranch ??
|
|
47
|
+
'source-branch-from-associated-pull-request',
|
|
48
|
+
number: sourcePullRequest.number,
|
|
49
|
+
timelineItems: {
|
|
50
|
+
edges: timelineItems.map((timelineItem) => {
|
|
51
|
+
return {
|
|
52
|
+
node: {
|
|
53
|
+
targetPullRequest: {
|
|
54
|
+
__typename: 'PullRequest',
|
|
55
|
+
url: `https://github.com/elastic/kibana/pull/${timelineItem.number}`,
|
|
56
|
+
title: timelineItem.title ?? defaultTargetPullRequestTitle,
|
|
57
|
+
number: timelineItem.number,
|
|
58
|
+
state: timelineItem.state,
|
|
59
|
+
baseRefName: timelineItem.targetBranch,
|
|
60
|
+
targetMergeCommit: timelineItem.state === 'MERGED'
|
|
61
|
+
? {
|
|
62
|
+
message: timelineItem.commitMessages[0],
|
|
63
|
+
oid: 'target-merge-commit-sha',
|
|
64
|
+
}
|
|
65
|
+
: null,
|
|
66
|
+
repository: {
|
|
67
|
+
name: timelineItem.repoName ?? 'kibana',
|
|
68
|
+
owner: {
|
|
69
|
+
login: timelineItem.repoOwner ?? 'elastic',
|
|
55
70
|
},
|
|
56
71
|
},
|
|
72
|
+
commits: {
|
|
73
|
+
edges: timelineItem.commitMessages.map((message) => ({
|
|
74
|
+
node: {
|
|
75
|
+
targetCommit: {
|
|
76
|
+
oid: 'abc',
|
|
77
|
+
message: message,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
})),
|
|
81
|
+
},
|
|
57
82
|
},
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}),
|
|
61
86
|
},
|
|
62
87
|
},
|
|
63
|
-
|
|
88
|
+
},
|
|
89
|
+
],
|
|
64
90
|
},
|
|
65
91
|
};
|
|
66
92
|
}
|