backport 7.0.1 → 7.2.0-beta.3
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/dist/backportRun.d.ts +1 -0
- package/dist/backportRun.js +3 -2
- package/dist/entrypoint.cli.js +12 -1
- package/dist/entrypoint.module.d.ts +4 -3
- package/dist/entrypoint.module.js +2 -7
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/cliArgs.d.ts +2 -1
- package/dist/options/cliArgs.js +4 -0
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/options.d.ts +3 -6
- package/dist/options/options.test.js +26 -28
- package/dist/runSequentially.js +1 -0
- package/dist/runSequentially.test.js +55 -30
- package/dist/services/HandledError.js +3 -1
- package/dist/services/git.d.ts +3 -3
- package/dist/services/git.integration.test.js +66 -13
- package/dist/services/git.js +52 -13
- package/dist/services/git.test.js +15 -1
- 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/createStatusComment.js +1 -1
- package/dist/services/github/v4/FetchPullRequestId.js +5 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +7 -4
- package/dist/services/github/v4/apiRequestV4.js +22 -21
- 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 +24 -13
- 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 +24 -13
- 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 +20 -10
- 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 +20 -9
- 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 -5
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
- 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 +2 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
- package/dist/services/logger.d.ts +5 -5
- package/dist/services/logger.js +24 -23
- package/dist/services/remoteConfig.d.ts +20 -0
- package/dist/services/remoteConfig.js +52 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +73 -39
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +21 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
- package/dist/services/sourceCommit/parseSourceCommit.js +73 -77
- package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
- package/dist/{entrypoint.cli.e2e.private.test.d.ts → test/e2e/cli.e2e.private.test.d.ts} +0 -0
- package/dist/{entrypoint.cli.e2e.private.test.js → test/e2e/cli.e2e.private.test.js} +153 -39
- package/dist/{services/github/v3/index.d.ts → test/e2e/module.e2e.private.test.d.ts} +0 -0
- package/dist/test/e2e/module.e2e.private.test.js +363 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -2
- package/dist/test/nockHelpers.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +16 -22
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +6 -2
- package/dist/ui/getCommits.js +8 -6
- package/dist/ui/maybeSetupRepo.js +13 -16
- package/dist/ui/maybeSetupRepo.test.js +50 -16
- 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 +10 -10
- package/yarn.lock +121 -114
- package/dist/services/github/v3/index.js +0 -61
- package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
- package/dist/test/backport-e2e.mutation.test.js +0 -347
|
@@ -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");
|
|
@@ -24,38 +23,31 @@ async function getOptionsFromGithub(options) {
|
|
|
24
23
|
if (!(e instanceof apiRequestV4_1.GithubV4Exception)) {
|
|
25
24
|
throw e;
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
(0,
|
|
29
|
-
res = swallowErrorIfConfigFileIsMissing(error);
|
|
26
|
+
(0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({ error: e, repoName, repoOwner });
|
|
27
|
+
res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
30
28
|
}
|
|
31
29
|
// it is not possible to have a branch named "backport"
|
|
32
30
|
if (res.repository.illegalBackportBranch) {
|
|
33
31
|
throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
34
32
|
}
|
|
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);
|
|
33
|
+
const remoteConfig = await getRemoteConfigFileOptions(res, options.cwd, options.skipRemoteConfig);
|
|
41
34
|
return {
|
|
42
35
|
authenticatedUsername: options.username ?? res.viewer.login,
|
|
43
36
|
sourceBranch: res.repository.defaultBranchRef.name,
|
|
44
37
|
...remoteConfig,
|
|
45
|
-
historicalBranchLabelMappings: skipRemoteConfig
|
|
46
|
-
? []
|
|
47
|
-
: getHistoricalBranchLabelMappings(historicalRemoteConfigs),
|
|
48
38
|
};
|
|
49
39
|
}
|
|
50
40
|
exports.getOptionsFromGithub = getOptionsFromGithub;
|
|
51
|
-
async function
|
|
41
|
+
async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
|
|
52
42
|
if (skipRemoteConfig) {
|
|
53
43
|
logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
|
|
54
|
-
return
|
|
44
|
+
return;
|
|
55
45
|
}
|
|
46
|
+
const remoteConfig = res.repository.defaultBranchRef.target.remoteConfigHistory.edges?.[0]
|
|
47
|
+
?.remoteConfig;
|
|
56
48
|
if (!remoteConfig) {
|
|
57
49
|
logger_1.logger.info("Skipping remote config: remote config doesn't exist");
|
|
58
|
-
return
|
|
50
|
+
return;
|
|
59
51
|
}
|
|
60
52
|
if (cwd) {
|
|
61
53
|
const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
|
|
@@ -65,63 +57,17 @@ async function getSkipRemoteConfigFile(cwd, skipRemoteConfig, remoteConfig) {
|
|
|
65
57
|
]);
|
|
66
58
|
if (isLocalConfigUntracked) {
|
|
67
59
|
logger_1.logger.info('Skipping remote config: local config is new');
|
|
68
|
-
return
|
|
60
|
+
return;
|
|
69
61
|
}
|
|
70
62
|
if (isLocalConfigModified) {
|
|
71
63
|
logger_1.logger.info('Skipping remote config: local config is modified');
|
|
72
|
-
return
|
|
64
|
+
return;
|
|
73
65
|
}
|
|
74
66
|
if (localCommitDate &&
|
|
75
67
|
localCommitDate > Date.parse(remoteConfig.committedDate)) {
|
|
76
68
|
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
69
|
return;
|
|
111
70
|
}
|
|
112
|
-
})
|
|
113
|
-
.filter(filterEmpty_1.filterNil);
|
|
114
|
-
}
|
|
115
|
-
function swallowErrorIfConfigFileIsMissing(error) {
|
|
116
|
-
const { data, errors } = error.axiosResponse.data;
|
|
117
|
-
const wasMissingConfigError = errors?.some((error) => {
|
|
118
|
-
const isMatch = /^repository.defaultBranchRef.target.history.edges.\d+.remoteConfig.file$/.test(error.path.join('.'));
|
|
119
|
-
return isMatch && error.type === 'NOT_FOUND';
|
|
120
|
-
});
|
|
121
|
-
// swallow error if it's just the config file that's missing
|
|
122
|
-
if (wasMissingConfigError && data != null) {
|
|
123
|
-
return data;
|
|
124
71
|
}
|
|
125
|
-
|
|
126
|
-
throw error;
|
|
72
|
+
return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
|
|
127
73
|
}
|
|
@@ -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
|
+
...RemoteConfigHistoryFragment
|
|
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
|
|
@@ -41,6 +41,7 @@ exports.commitsByAuthorMock = {
|
|
|
41
41
|
},
|
|
42
42
|
number: 85,
|
|
43
43
|
mergeCommit: {
|
|
44
|
+
remoteConfigHistory: { edges: [] },
|
|
44
45
|
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
45
46
|
message: 'Add witch (#85)',
|
|
46
47
|
},
|
|
@@ -73,6 +74,7 @@ exports.commitsByAuthorMock = {
|
|
|
73
74
|
baseRefName: 'master',
|
|
74
75
|
number: 80,
|
|
75
76
|
mergeCommit: {
|
|
77
|
+
remoteConfigHistory: { edges: [] },
|
|
76
78
|
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
77
79
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
78
80
|
},
|
|
@@ -12,13 +12,13 @@ function throwOnInvalidAccessToken({ error, repoOwner, repoName, }) {
|
|
|
12
12
|
return matches[1];
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
const statusCode = error.
|
|
15
|
+
const statusCode = error.githubResponse.status;
|
|
16
16
|
switch (statusCode) {
|
|
17
17
|
case 200: {
|
|
18
|
-
const repoNotFound = error.
|
|
19
|
-
const grantedScopes = error.
|
|
20
|
-
const requiredScopes = error.
|
|
21
|
-
const ssoHeader = (0, maybe_1.maybe)(error.
|
|
18
|
+
const repoNotFound = error.githubResponse.data.errors?.some((error) => error.type === 'NOT_FOUND' && error.path.join('.') === 'repository');
|
|
19
|
+
const grantedScopes = error.githubResponse.headers['x-oauth-scopes'] || '';
|
|
20
|
+
const requiredScopes = error.githubResponse.headers['x-accepted-oauth-scopes'] || '';
|
|
21
|
+
const ssoHeader = (0, maybe_1.maybe)(error.githubResponse.headers['x-github-sso']);
|
|
22
22
|
if (repoNotFound) {
|
|
23
23
|
const hasRequiredScopes = (0, lodash_1.isEmpty)((0, lodash_1.difference)(requiredScopes.split(','), grantedScopes.split(',')));
|
|
24
24
|
// user does not have permission to the repo
|
|
@@ -28,7 +28,7 @@ function throwOnInvalidAccessToken({ error, repoOwner, repoName, }) {
|
|
|
28
28
|
// repo does not exist
|
|
29
29
|
throw new HandledError_1.HandledError(`The repository "${repoOwner}/${repoName}" doesn't exist`);
|
|
30
30
|
}
|
|
31
|
-
const repoAccessForbidden = error.
|
|
31
|
+
const repoAccessForbidden = error.githubResponse.data.errors?.some((error) => error.type === 'FORBIDDEN');
|
|
32
32
|
const ssoAuthUrl = getSSOAuthUrl(ssoHeader);
|
|
33
33
|
// user does not have permissions
|
|
34
34
|
if (repoAccessForbidden && ssoAuthUrl) {
|
|
@@ -5,7 +5,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
5
5
|
describe('when status code is', () => {
|
|
6
6
|
it('should handle invalid access token', () => {
|
|
7
7
|
const error = {
|
|
8
|
-
|
|
8
|
+
githubResponse: {
|
|
9
9
|
status: 401,
|
|
10
10
|
headers: {},
|
|
11
11
|
},
|
|
@@ -18,7 +18,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
18
18
|
});
|
|
19
19
|
it('should handle SSO error', () => {
|
|
20
20
|
const error = {
|
|
21
|
-
|
|
21
|
+
githubResponse: {
|
|
22
22
|
status: 200,
|
|
23
23
|
headers: { 'x-github-sso': 'required; url=https://ssourl.com' },
|
|
24
24
|
data: {
|
|
@@ -34,7 +34,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
34
34
|
});
|
|
35
35
|
it('should handle non-existing repo', () => {
|
|
36
36
|
const error = {
|
|
37
|
-
|
|
37
|
+
githubResponse: {
|
|
38
38
|
status: 200,
|
|
39
39
|
headers: {
|
|
40
40
|
'x-oauth-scopes': 'a,b,c',
|
|
@@ -53,7 +53,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
53
53
|
});
|
|
54
54
|
it('should handle insufficient permissions (oauth scopes)', () => {
|
|
55
55
|
const error = {
|
|
56
|
-
|
|
56
|
+
githubResponse: {
|
|
57
57
|
status: 200,
|
|
58
58
|
headers: {
|
|
59
59
|
'x-oauth-scopes': 'a,b',
|
|
@@ -72,7 +72,7 @@ describe('throwOnInvalidAccessToken', () => {
|
|
|
72
72
|
});
|
|
73
73
|
it('should not handle unknown cases', () => {
|
|
74
74
|
const error = {
|
|
75
|
-
|
|
75
|
+
githubResponse: {
|
|
76
76
|
status: 500,
|
|
77
77
|
headers: {},
|
|
78
78
|
},
|
|
@@ -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,20 @@
|
|
|
1
|
+
import { ConfigFileOptions } from '../entrypoint.module';
|
|
2
|
+
import { GithubV4Exception } from './github/v4/apiRequestV4';
|
|
3
|
+
export declare const RemoteConfigHistoryFragment: import("graphql").DocumentNode;
|
|
4
|
+
export interface RemoteConfig {
|
|
5
|
+
committedDate: string;
|
|
6
|
+
file: {
|
|
7
|
+
object: {
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface RemoteConfigHistory {
|
|
13
|
+
remoteConfigHistory: {
|
|
14
|
+
edges: Array<{
|
|
15
|
+
remoteConfig: RemoteConfig;
|
|
16
|
+
}> | null;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare function parseRemoteConfig(remoteConfig: RemoteConfig): ConfigFileOptions | undefined;
|
|
20
|
+
export declare function swallowMissingConfigFileException<T>(error: GithubV4Exception<T>): T;
|
|
@@ -0,0 +1,52 @@
|
|
|
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.swallowMissingConfigFileException = 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 RemoteConfigHistoryFragment 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;
|
|
40
|
+
function swallowMissingConfigFileException(error) {
|
|
41
|
+
const { data, errors } = error.githubResponse.data;
|
|
42
|
+
const missingConfigError = errors?.some((error) => {
|
|
43
|
+
return error.path.includes('remoteConfig') && error.type === 'NOT_FOUND';
|
|
44
|
+
});
|
|
45
|
+
// swallow error if it's just the config file that's missing
|
|
46
|
+
if (missingConfigError && data != null) {
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
// Throw unexpected error
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
exports.swallowMissingConfigFileException = swallowMissingConfigFileException;
|
|
@@ -10,4 +10,7 @@ export declare type ExpectedTargetPullRequest = {
|
|
|
10
10
|
message: string;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
export declare function getExpectedTargetPullRequests(sourceCommit
|
|
13
|
+
export declare function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }: {
|
|
14
|
+
sourceCommit: SourceCommitWithTargetPullRequest;
|
|
15
|
+
latestBranchLabelMapping: ValidConfigOptions['branchLabelMapping'];
|
|
16
|
+
}): ExpectedTargetPullRequest[];
|
|
@@ -4,8 +4,12 @@ exports.getExpectedTargetPullRequests = void 0;
|
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const filterEmpty_1 = require("../../utils/filterEmpty");
|
|
6
6
|
const commitFormatters_1 = require("../github/commitFormatters");
|
|
7
|
-
|
|
7
|
+
const remoteConfig_1 = require("../remoteConfig");
|
|
8
|
+
function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }) {
|
|
8
9
|
const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
|
|
10
|
+
const remoteConfig = sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
|
|
11
|
+
const branchLabelMapping = (remoteConfig && (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping) ??
|
|
12
|
+
latestBranchLabelMapping;
|
|
9
13
|
// if there is no source pull request the commit was pushed directly to the source branch
|
|
10
14
|
// in that case there will be no labels, and thus not possible to deduce the expected target branches
|
|
11
15
|
if (!sourcePullRequest) {
|