backport 7.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/backportRun.d.ts +1 -0
- package/dist/backportRun.js +4 -3
- package/dist/entrypoint.cli.e2e.private.test.js +58 -19
- package/dist/entrypoint.cli.js +12 -1
- package/dist/options/ConfigOptions.d.ts +1 -0
- package/dist/options/cliArgs.d.ts +1 -1
- package/dist/options/cliArgs.test.js +12 -0
- package/dist/options/config/config.d.ts +1 -0
- package/dist/options/config/projectConfig.js +2 -2
- package/dist/options/config/readConfigFile.d.ts +2 -1
- package/dist/options/options.d.ts +2 -5
- package/dist/options/options.test.js +26 -28
- package/dist/runSequentially.test.js +1 -2
- package/dist/services/HandledError.js +3 -1
- package/dist/services/git.js +5 -8
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
- package/dist/services/github/v3/createPullRequest.js +2 -5
- package/dist/services/github/v3/createPullRequest.test.js +5 -5
- package/dist/services/github/v3/createStatusComment.test.js +7 -7
- package/dist/services/github/v4/FetchPullRequestId.js +5 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +3 -1
- package/dist/services/github/v4/apiRequestV4.js +7 -7
- package/dist/services/github/v4/apiRequestV4.test.js +38 -11
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
- package/dist/services/github/v4/fetchAuthorId.js +5 -1
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +6 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +3 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +6 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -11
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +7 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +6 -2
- package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -4
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +14 -55
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -19
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +5 -0
- package/dist/services/logger.d.ts +5 -5
- package/dist/services/logger.js +24 -23
- package/dist/services/remoteConfig.d.ts +18 -0
- package/dist/services/remoteConfig.js +39 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +20 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
- package/dist/services/sourceCommit/parseSourceCommit.js +73 -71
- package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
- package/dist/test/backport-e2e.mutation.test.js +3 -3
- package/dist/test/nockHelpers.js +6 -2
- package/dist/test/setupFiles/automatic-mocks.js +5 -1
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +3 -3
- package/dist/ui/getCommits.js +2 -2
- package/dist/ui/ora.d.ts +9 -0
- package/dist/ui/ora.js +21 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +2 -2
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.fetchPullRequestBySearchQuery = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
4
8
|
const lodash_1 = require("lodash");
|
|
5
9
|
const HandledError_1 = require("../../../HandledError");
|
|
6
10
|
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
7
11
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
8
12
|
async function fetchPullRequestBySearchQuery(options) {
|
|
9
13
|
const { accessToken, githubApiBaseUrlV4, maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, author, } = options;
|
|
10
|
-
const query =
|
|
14
|
+
const query = (0, graphql_tag_1.default) `
|
|
11
15
|
query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
|
|
12
16
|
search(query: $query, type: ISSUE, first: $maxNumber) {
|
|
13
17
|
nodes {
|
|
@@ -20,7 +24,7 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment
|
|
27
|
+
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
|
|
24
28
|
`;
|
|
25
29
|
const authorFilter = author ? ` author:${author}` : '';
|
|
26
30
|
const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter} ${prFilter} base:${sourceBranch}`;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.fetchExistingPullRequest = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
4
8
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
9
|
async function fetchExistingPullRequest({ options, prPayload, }) {
|
|
6
10
|
const { githubApiBaseUrlV4, accessToken } = options;
|
|
7
|
-
const query =
|
|
11
|
+
const query = (0, graphql_tag_1.default) `
|
|
8
12
|
query ExistingPullRequest(
|
|
9
13
|
$repoOwner: String!
|
|
10
14
|
$repoName: String!
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.fetchPullRequestAutoMergeMethod = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
4
8
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
9
|
async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
|
|
6
10
|
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
7
|
-
const query =
|
|
11
|
+
const query = (0, graphql_tag_1.default) `
|
|
8
12
|
query PullRequestAutoMergeMethod(
|
|
9
13
|
$repoOwner: String!
|
|
10
14
|
$repoName: String!
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.fetchRemoteProjectConfig = void 0;
|
|
4
|
-
const
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const remoteConfig_1 = require("../../remoteConfig");
|
|
5
9
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
6
10
|
async function fetchRemoteProjectConfig(options) {
|
|
7
11
|
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
|
|
8
|
-
const query =
|
|
12
|
+
const query = (0, graphql_tag_1.default) `
|
|
9
13
|
query ProjectConfig(
|
|
10
14
|
$repoOwner: String!
|
|
11
15
|
$repoName: String!
|
|
@@ -14,27 +18,13 @@ async function fetchRemoteProjectConfig(options) {
|
|
|
14
18
|
repository(owner: $repoOwner, name: $repoName) {
|
|
15
19
|
ref(qualifiedName: $sourceBranch) {
|
|
16
20
|
target {
|
|
17
|
-
...
|
|
18
|
-
history(first: 1, path: ".backportrc.json") {
|
|
19
|
-
edges {
|
|
20
|
-
remoteConfig: node {
|
|
21
|
-
file(path: ".backportrc.json") {
|
|
22
|
-
... on TreeEntry {
|
|
23
|
-
object {
|
|
24
|
-
... on Blob {
|
|
25
|
-
text
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
21
|
+
...RemoteConfigHistory
|
|
34
22
|
}
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
25
|
}
|
|
26
|
+
|
|
27
|
+
${remoteConfig_1.RemoteConfigHistoryFragment}
|
|
38
28
|
`;
|
|
39
29
|
try {
|
|
40
30
|
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
@@ -47,7 +37,10 @@ async function fetchRemoteProjectConfig(options) {
|
|
|
47
37
|
sourceBranch,
|
|
48
38
|
},
|
|
49
39
|
});
|
|
50
|
-
|
|
40
|
+
const remoteConfig = res.repository.ref.target.remoteConfigHistory.edges?.[0].remoteConfig;
|
|
41
|
+
if (remoteConfig) {
|
|
42
|
+
return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
|
|
43
|
+
}
|
|
51
44
|
}
|
|
52
45
|
catch (e) {
|
|
53
46
|
throw new Error('Project config does not exist');
|
|
@@ -8,10 +8,6 @@ export declare function getOptionsFromGithub(options: {
|
|
|
8
8
|
skipRemoteConfig?: boolean;
|
|
9
9
|
cwd?: string;
|
|
10
10
|
}): Promise<{
|
|
11
|
-
historicalBranchLabelMappings: {
|
|
12
|
-
branchLabelMapping: Record<string, string>;
|
|
13
|
-
committedDate: string;
|
|
14
|
-
}[];
|
|
15
11
|
accessToken?: string | undefined;
|
|
16
12
|
assignees?: string[] | undefined;
|
|
17
13
|
author?: string | null | undefined;
|
|
@@ -62,6 +58,7 @@ export declare function getOptionsFromGithub(options: {
|
|
|
62
58
|
verbose?: boolean | undefined;
|
|
63
59
|
help?: boolean | undefined;
|
|
64
60
|
version?: boolean | undefined;
|
|
61
|
+
v?: boolean | undefined;
|
|
65
62
|
branchLabelMapping?: Record<string, string> | undefined;
|
|
66
63
|
upstream?: string | undefined;
|
|
67
64
|
branches?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOptionsFromGithub = void 0;
|
|
4
|
-
const readConfigFile_1 = require("../../../../options/config/readConfigFile");
|
|
5
|
-
const filterEmpty_1 = require("../../../../utils/filterEmpty");
|
|
6
4
|
const HandledError_1 = require("../../../HandledError");
|
|
7
5
|
const git_1 = require("../../../git");
|
|
8
6
|
const logger_1 = require("../../../logger");
|
|
7
|
+
const remoteConfig_1 = require("../../../remoteConfig");
|
|
9
8
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
10
9
|
const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
|
|
11
10
|
const query_1 = require("./query");
|
|
@@ -32,30 +31,24 @@ async function getOptionsFromGithub(options) {
|
|
|
32
31
|
if (res.repository.illegalBackportBranch) {
|
|
33
32
|
throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
34
33
|
}
|
|
35
|
-
const
|
|
36
|
-
const latestRemoteConfig = historicalRemoteConfigs[0]?.remoteConfig;
|
|
37
|
-
const skipRemoteConfig = await getSkipRemoteConfigFile(options.cwd, options.skipRemoteConfig, latestRemoteConfig);
|
|
38
|
-
const remoteConfig = skipRemoteConfig
|
|
39
|
-
? {}
|
|
40
|
-
: parseRemoteConfig(latestRemoteConfig);
|
|
34
|
+
const remoteConfig = await getRemoteConfigFileOptions(res, options.cwd, options.skipRemoteConfig);
|
|
41
35
|
return {
|
|
42
36
|
authenticatedUsername: options.username ?? res.viewer.login,
|
|
43
37
|
sourceBranch: res.repository.defaultBranchRef.name,
|
|
44
38
|
...remoteConfig,
|
|
45
|
-
historicalBranchLabelMappings: skipRemoteConfig
|
|
46
|
-
? []
|
|
47
|
-
: getHistoricalBranchLabelMappings(historicalRemoteConfigs),
|
|
48
39
|
};
|
|
49
40
|
}
|
|
50
41
|
exports.getOptionsFromGithub = getOptionsFromGithub;
|
|
51
|
-
async function
|
|
42
|
+
async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
|
|
52
43
|
if (skipRemoteConfig) {
|
|
53
44
|
logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
|
|
54
|
-
return
|
|
45
|
+
return;
|
|
55
46
|
}
|
|
47
|
+
const remoteConfig = res.repository.defaultBranchRef.target.remoteConfigHistory.edges?.[0]
|
|
48
|
+
?.remoteConfig;
|
|
56
49
|
if (!remoteConfig) {
|
|
57
50
|
logger_1.logger.info("Skipping remote config: remote config doesn't exist");
|
|
58
|
-
return
|
|
51
|
+
return;
|
|
59
52
|
}
|
|
60
53
|
if (cwd) {
|
|
61
54
|
const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
|
|
@@ -65,61 +58,27 @@ async function getSkipRemoteConfigFile(cwd, skipRemoteConfig, remoteConfig) {
|
|
|
65
58
|
]);
|
|
66
59
|
if (isLocalConfigUntracked) {
|
|
67
60
|
logger_1.logger.info('Skipping remote config: local config is new');
|
|
68
|
-
return
|
|
61
|
+
return;
|
|
69
62
|
}
|
|
70
63
|
if (isLocalConfigModified) {
|
|
71
64
|
logger_1.logger.info('Skipping remote config: local config is modified');
|
|
72
|
-
return
|
|
65
|
+
return;
|
|
73
66
|
}
|
|
74
67
|
if (localCommitDate &&
|
|
75
68
|
localCommitDate > Date.parse(remoteConfig.committedDate)) {
|
|
76
69
|
logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
function parseRemoteConfig(remoteConfig) {
|
|
83
|
-
if (!remoteConfig) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
logger_1.logger.info('Using remote config');
|
|
88
|
-
return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(remoteConfig.file.object.text));
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
logger_1.logger.info('Parsing remote config failed', e);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function getHistoricalBranchLabelMappings(historicalRemoteConfigs) {
|
|
96
|
-
return historicalRemoteConfigs
|
|
97
|
-
.map((edge) => {
|
|
98
|
-
try {
|
|
99
|
-
const remoteConfig = JSON.parse(edge.remoteConfig.file.object.text);
|
|
100
|
-
if (!remoteConfig.branchLabelMapping) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
branchLabelMapping: remoteConfig.branchLabelMapping,
|
|
105
|
-
committedDate: edge.remoteConfig.committedDate,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
logger_1.logger.info('Could not get historical remote config', e);
|
|
110
70
|
return;
|
|
111
71
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
72
|
+
}
|
|
73
|
+
return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
|
|
114
74
|
}
|
|
115
75
|
function swallowErrorIfConfigFileIsMissing(error) {
|
|
116
76
|
const { data, errors } = error.axiosResponse.data;
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
return isMatch && error.type === 'NOT_FOUND';
|
|
77
|
+
const missingConfigError = errors?.some((error) => {
|
|
78
|
+
return error.path.includes('remoteConfig') && error.type === 'NOT_FOUND';
|
|
120
79
|
});
|
|
121
80
|
// swallow error if it's just the config file that's missing
|
|
122
|
-
if (
|
|
81
|
+
if (missingConfigError && data != null) {
|
|
123
82
|
return data;
|
|
124
83
|
}
|
|
125
84
|
// Throw unexpected error
|
|
@@ -41,24 +41,6 @@ describe('getOptionsFromGithub', () => {
|
|
|
41
41
|
'^v7.9.0$': '7.x',
|
|
42
42
|
'^v8.0.0$': 'master',
|
|
43
43
|
},
|
|
44
|
-
historicalBranchLabelMappings: [
|
|
45
|
-
{
|
|
46
|
-
branchLabelMapping: {
|
|
47
|
-
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
48
|
-
'^v7.9.0$': '7.x',
|
|
49
|
-
'^v8.0.0$': 'master',
|
|
50
|
-
},
|
|
51
|
-
committedDate: '2020-08-15T10:33:06Z',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
|
|
55
|
-
committedDate: '2020-08-15T10:20:23Z',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
|
|
59
|
-
committedDate: '2020-08-15T10:17:57Z',
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
44
|
sourceBranch: 'master',
|
|
63
45
|
targetBranchChoices: [
|
|
64
46
|
{ checked: true, name: 'master' },
|
|
@@ -129,7 +111,6 @@ describe('getOptionsFromGithub', () => {
|
|
|
129
111
|
expect(options).toEqual({
|
|
130
112
|
authenticatedUsername: 'sqren',
|
|
131
113
|
sourceBranch: 'main',
|
|
132
|
-
historicalBranchLabelMappings: [],
|
|
133
114
|
});
|
|
134
115
|
});
|
|
135
116
|
});
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
committedDate: string;
|
|
3
|
-
file: {
|
|
4
|
-
object: {
|
|
5
|
-
text: string;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
};
|
|
1
|
+
import { RemoteConfigHistory } from '../../../remoteConfig';
|
|
9
2
|
export interface GithubConfigOptionsResponse {
|
|
10
3
|
viewer: {
|
|
11
4
|
login: string;
|
|
@@ -16,14 +9,8 @@ export interface GithubConfigOptionsResponse {
|
|
|
16
9
|
} | null;
|
|
17
10
|
defaultBranchRef: {
|
|
18
11
|
name: string;
|
|
19
|
-
target:
|
|
20
|
-
history: {
|
|
21
|
-
edges: Array<{
|
|
22
|
-
remoteConfig: RemoteConfig;
|
|
23
|
-
}>;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
12
|
+
target: RemoteConfigHistory;
|
|
26
13
|
};
|
|
27
14
|
};
|
|
28
15
|
}
|
|
29
|
-
export declare const query
|
|
16
|
+
export declare const query: import("graphql").DocumentNode;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.query = void 0;
|
|
4
|
-
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const remoteConfig_1 = require("../../../remoteConfig");
|
|
9
|
+
exports.query = (0, graphql_tag_1.default) `
|
|
5
10
|
query GithubConfigOptions($repoOwner: String!, $repoName: String!) {
|
|
6
11
|
viewer {
|
|
7
12
|
login
|
|
@@ -14,26 +19,11 @@ exports.query = `
|
|
|
14
19
|
defaultBranchRef {
|
|
15
20
|
name
|
|
16
21
|
target {
|
|
17
|
-
...
|
|
18
|
-
history(first: 20, path: ".backportrc.json") {
|
|
19
|
-
edges {
|
|
20
|
-
remoteConfig: node {
|
|
21
|
-
committedDate
|
|
22
|
-
file(path: ".backportrc.json") {
|
|
23
|
-
... on TreeEntry {
|
|
24
|
-
object {
|
|
25
|
-
... on Blob {
|
|
26
|
-
text
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
22
|
+
...RemoteConfigHistory
|
|
35
23
|
}
|
|
36
24
|
}
|
|
37
25
|
}
|
|
38
26
|
}
|
|
27
|
+
|
|
28
|
+
${remoteConfig_1.RemoteConfigHistoryFragment}
|
|
39
29
|
`;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getRepoOwnerAndNameFromGitRemotes = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
4
8
|
const maybe_1 = require("../../../utils/maybe");
|
|
5
9
|
const git_1 = require("../../git");
|
|
6
10
|
const logger_1 = require("../../logger");
|
|
@@ -38,7 +42,7 @@ async function getRepoOwnerAndNameFromGitRemotes({ accessToken, githubApiBaseUrl
|
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
exports.getRepoOwnerAndNameFromGitRemotes = getRepoOwnerAndNameFromGitRemotes;
|
|
41
|
-
const query =
|
|
45
|
+
const query = (0, graphql_tag_1.default) `
|
|
42
46
|
query RepoOwnerAndName($repoOwner: String!, $repoName: String!) {
|
|
43
47
|
repository(owner: $repoOwner, name: $repoName) {
|
|
44
48
|
isFork
|
|
@@ -9,6 +9,7 @@ exports.commitsByAuthorMock = {
|
|
|
9
9
|
edges: [
|
|
10
10
|
{
|
|
11
11
|
node: {
|
|
12
|
+
remoteConfigHistory: { edges: [] },
|
|
12
13
|
repository: {
|
|
13
14
|
name: 'kibana',
|
|
14
15
|
owner: { login: 'elastic' },
|
|
@@ -23,6 +24,7 @@ exports.commitsByAuthorMock = {
|
|
|
23
24
|
},
|
|
24
25
|
{
|
|
25
26
|
node: {
|
|
27
|
+
remoteConfigHistory: { edges: [] },
|
|
26
28
|
repository: {
|
|
27
29
|
name: 'kibana',
|
|
28
30
|
owner: { login: 'elastic' },
|
|
@@ -55,6 +57,7 @@ exports.commitsByAuthorMock = {
|
|
|
55
57
|
},
|
|
56
58
|
{
|
|
57
59
|
node: {
|
|
60
|
+
remoteConfigHistory: { edges: [] },
|
|
58
61
|
repository: {
|
|
59
62
|
name: 'kibana',
|
|
60
63
|
owner: { login: 'elastic' },
|
|
@@ -120,6 +123,7 @@ exports.commitsByAuthorMock = {
|
|
|
120
123
|
},
|
|
121
124
|
{
|
|
122
125
|
node: {
|
|
126
|
+
remoteConfigHistory: { edges: [] },
|
|
123
127
|
repository: {
|
|
124
128
|
name: 'kibana',
|
|
125
129
|
owner: { login: 'elastic' },
|
|
@@ -134,6 +138,7 @@ exports.commitsByAuthorMock = {
|
|
|
134
138
|
},
|
|
135
139
|
{
|
|
136
140
|
node: {
|
|
141
|
+
remoteConfigHistory: { edges: [] },
|
|
137
142
|
repository: {
|
|
138
143
|
name: 'kibana',
|
|
139
144
|
owner: { login: 'elastic' },
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import winston from 'winston';
|
|
2
2
|
export declare let logger: winston.Logger;
|
|
3
|
+
export declare function initLogger({ ci, accessToken, logFilePath, }: {
|
|
4
|
+
ci: boolean | undefined;
|
|
5
|
+
accessToken?: string;
|
|
6
|
+
logFilePath?: string;
|
|
7
|
+
}): winston.Logger;
|
|
3
8
|
export declare function consoleLog(message: string): void;
|
|
4
9
|
export declare function updateLogger({ accessToken, verbose, }: {
|
|
5
10
|
accessToken: string;
|
|
6
11
|
verbose?: boolean;
|
|
7
12
|
}): void;
|
|
8
|
-
export declare function initLogger({ ci, accessToken, logFilePath, }: {
|
|
9
|
-
ci?: boolean;
|
|
10
|
-
accessToken?: string;
|
|
11
|
-
logFilePath?: string;
|
|
12
|
-
}): winston.Logger;
|
package/dist/services/logger.js
CHANGED
|
@@ -19,18 +19,37 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
22
|
+
exports.updateLogger = exports.consoleLog = exports.initLogger = exports.logger = void 0;
|
|
23
23
|
const winston_1 = __importStar(require("winston"));
|
|
24
24
|
const redact_1 = require("../utils/redact");
|
|
25
25
|
const env_1 = require("./env");
|
|
26
|
+
let _accessToken;
|
|
27
|
+
let _ci;
|
|
28
|
+
function initLogger({ ci, accessToken, logFilePath, }) {
|
|
29
|
+
const fileTransport = getFileTransport({ logFilePath });
|
|
30
|
+
if (accessToken) {
|
|
31
|
+
_accessToken = accessToken;
|
|
32
|
+
}
|
|
33
|
+
_ci = ci;
|
|
34
|
+
exports.logger = winston_1.default.createLogger({
|
|
35
|
+
format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
36
|
+
// Format the metadata object
|
|
37
|
+
winston_1.format.metadata({
|
|
38
|
+
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
39
|
+
})),
|
|
40
|
+
transports: fileTransport,
|
|
41
|
+
});
|
|
42
|
+
return exports.logger;
|
|
43
|
+
}
|
|
44
|
+
exports.initLogger = initLogger;
|
|
26
45
|
// wrapper around console.log
|
|
27
46
|
function consoleLog(message) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
if (!_ci) {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.log(redactAccessToken(message));
|
|
50
|
+
}
|
|
31
51
|
}
|
|
32
52
|
exports.consoleLog = consoleLog;
|
|
33
|
-
let _accessToken;
|
|
34
53
|
function updateLogger({ accessToken, verbose, }) {
|
|
35
54
|
// set access token
|
|
36
55
|
_accessToken = accessToken;
|
|
@@ -45,24 +64,6 @@ function redactAccessToken(str) {
|
|
|
45
64
|
}
|
|
46
65
|
return str;
|
|
47
66
|
}
|
|
48
|
-
function initLogger({ ci, accessToken, logFilePath, }) {
|
|
49
|
-
const fileTransport = getFileTransport({ logFilePath });
|
|
50
|
-
if (accessToken) {
|
|
51
|
-
_accessToken = accessToken;
|
|
52
|
-
}
|
|
53
|
-
exports.logger = winston_1.default.createLogger({
|
|
54
|
-
format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
55
|
-
// Format the metadata object
|
|
56
|
-
winston_1.format.metadata({
|
|
57
|
-
fillExcept: ['message', 'level', 'timestamp', 'label'],
|
|
58
|
-
})),
|
|
59
|
-
transports: ci
|
|
60
|
-
? [fileTransport, new winston_1.default.transports.Console()]
|
|
61
|
-
: [fileTransport],
|
|
62
|
-
});
|
|
63
|
-
return exports.logger;
|
|
64
|
-
}
|
|
65
|
-
exports.initLogger = initLogger;
|
|
66
67
|
function getFileTransport({ logFilePath }) {
|
|
67
68
|
return new winston_1.default.transports.File({
|
|
68
69
|
filename: (0, env_1.getLogfilePath)({ logFilePath }),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ConfigFileOptions } from '../entrypoint.module';
|
|
2
|
+
export declare const RemoteConfigHistoryFragment: import("graphql").DocumentNode;
|
|
3
|
+
export interface RemoteConfig {
|
|
4
|
+
committedDate: string;
|
|
5
|
+
file: {
|
|
6
|
+
object: {
|
|
7
|
+
text: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface RemoteConfigHistory {
|
|
12
|
+
remoteConfigHistory: {
|
|
13
|
+
edges: Array<{
|
|
14
|
+
remoteConfig: RemoteConfig;
|
|
15
|
+
}> | null;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare function parseRemoteConfig(remoteConfig: RemoteConfig): ConfigFileOptions | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
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.parseRemoteConfig = exports.RemoteConfigHistoryFragment = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const readConfigFile_1 = require("../options/config/readConfigFile");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
exports.RemoteConfigHistoryFragment = (0, graphql_tag_1.default) `
|
|
11
|
+
fragment RemoteConfigHistory on Commit {
|
|
12
|
+
remoteConfigHistory: history(first: 1, path: ".backportrc.json") {
|
|
13
|
+
edges {
|
|
14
|
+
remoteConfig: node {
|
|
15
|
+
committedDate
|
|
16
|
+
file(path: ".backportrc.json") {
|
|
17
|
+
... on TreeEntry {
|
|
18
|
+
object {
|
|
19
|
+
... on Blob {
|
|
20
|
+
text
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
function parseRemoteConfig(remoteConfig) {
|
|
31
|
+
try {
|
|
32
|
+
return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(remoteConfig.file.object.text));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
logger_1.logger.info('Parsing remote config failed', e);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.parseRemoteConfig = parseRemoteConfig;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { SourceCommitWithTargetPullRequest } from './parseSourceCommit';
|
|
2
2
|
export declare function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems, }: {
|
|
3
3
|
sourceCommit: {
|
|
4
|
+
remoteConfig?: {
|
|
5
|
+
branchLabelMapping: Record<string, string>;
|
|
6
|
+
committedDate: string;
|
|
7
|
+
};
|
|
4
8
|
sha?: string;
|
|
5
9
|
message: string;
|
|
6
10
|
commitedDate?: string;
|
|
@@ -5,6 +5,24 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
|
|
|
5
5
|
const defaultTargetPullRequestTitle = 'DO NOT USE: Default Pull Request Title';
|
|
6
6
|
const defaultSourceCommitSha = 'DO NOT USE: default-source-commit-sha';
|
|
7
7
|
const baseMockCommit = {
|
|
8
|
+
remoteConfigHistory: sourceCommit.remoteConfig
|
|
9
|
+
? {
|
|
10
|
+
edges: [
|
|
11
|
+
{
|
|
12
|
+
remoteConfig: {
|
|
13
|
+
committedDate: sourceCommit.remoteConfig.committedDate,
|
|
14
|
+
file: {
|
|
15
|
+
object: {
|
|
16
|
+
text: JSON.stringify({
|
|
17
|
+
branchLabelMapping: sourceCommit.remoteConfig.branchLabelMapping,
|
|
18
|
+
}),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
}
|
|
25
|
+
: { edges: [] },
|
|
8
26
|
repository: {
|
|
9
27
|
name: 'kibana',
|
|
10
28
|
owner: { login: 'elastic' },
|
|
@@ -12,14 +30,10 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
|
|
|
12
30
|
committedDate: sourceCommit.commitedDate ?? '2021-12-22T00:00:00Z',
|
|
13
31
|
sha: sourceCommit.sha ?? defaultSourceCommitSha,
|
|
14
32
|
message: sourceCommit.message,
|
|
33
|
+
associatedPullRequests: { edges: null },
|
|
15
34
|
};
|
|
16
35
|
if (!sourcePullRequest) {
|
|
17
|
-
return
|
|
18
|
-
...baseMockCommit,
|
|
19
|
-
associatedPullRequests: {
|
|
20
|
-
edges: null,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
36
|
+
return baseMockCommit;
|
|
23
37
|
}
|
|
24
38
|
return {
|
|
25
39
|
...baseMockCommit,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../options/options';
|
|
2
|
+
import { RemoteConfigHistory } from '../remoteConfig';
|
|
2
3
|
import { ExpectedTargetPullRequest } from './getExpectedTargetPullRequests';
|
|
3
4
|
export interface Commit {
|
|
4
5
|
sourceCommit: {
|
|
@@ -75,6 +76,7 @@ interface TimelineIssueEdge {
|
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
78
|
export declare type SourceCommitWithTargetPullRequest = {
|
|
79
|
+
remoteConfigHistory: RemoteConfigHistory['remoteConfigHistory'];
|
|
78
80
|
repository: {
|
|
79
81
|
name: string;
|
|
80
82
|
owner: {
|
|
@@ -94,11 +96,8 @@ export declare function parseSourceCommit({ sourceCommit, options, }: {
|
|
|
94
96
|
sourceCommit: SourceCommitWithTargetPullRequest;
|
|
95
97
|
options: {
|
|
96
98
|
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
97
|
-
historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
|
|
98
99
|
sourceBranch: string;
|
|
99
100
|
};
|
|
100
101
|
}): Commit;
|
|
101
|
-
export declare const sourceCommitWithTargetPullRequestFragment:
|
|
102
|
-
source: string;
|
|
103
|
-
};
|
|
102
|
+
export declare const sourceCommitWithTargetPullRequestFragment: import("graphql").DocumentNode;
|
|
104
103
|
export {};
|