backport 7.0.1-beta.1 → 7.2.0-beta.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/dist/backportRun.d.ts +1 -0
- package/dist/backportRun.js +3 -2
- package/dist/entrypoint.cli.e2e.private.test.js +74 -7
- package/dist/entrypoint.cli.js +12 -1
- package/dist/options/cliArgs.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +1 -5
- package/dist/options/options.test.js +26 -28
- package/dist/runSequentially.js +1 -0
- package/dist/runSequentially.test.js +3 -2
- package/dist/services/HandledError.js +3 -1
- package/dist/services/git.d.ts +2 -0
- package/dist/services/git.integration.test.js +66 -13
- package/dist/services/git.js +47 -10
- 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/v4/FetchPullRequestId.js +5 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +6 -2
- package/dist/services/github/v4/apiRequestV4.js +8 -8
- 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 +23 -12
- 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 +23 -12
- 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 +19 -9
- 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 +19 -8
- 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 +0 -4
- 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 +5 -0
- 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/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/nockHelpers.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +4 -0
- 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 +3 -3
- package/dist/services/github/v3/index.d.ts +0 -1
- package/dist/services/github/v3/index.js +0 -61
|
@@ -1,15 +1,20 @@
|
|
|
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.fetchCommitsByAuthor = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
4
8
|
const lodash_1 = require("lodash");
|
|
5
9
|
const filterEmpty_1 = require("../../../../utils/filterEmpty");
|
|
6
10
|
const HandledError_1 = require("../../../HandledError");
|
|
11
|
+
const remoteConfig_1 = require("../../../remoteConfig");
|
|
7
12
|
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
8
13
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
9
14
|
const fetchAuthorId_1 = require("../fetchAuthorId");
|
|
10
|
-
function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
15
|
+
async function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
11
16
|
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, dateSince, dateUntil, } = options;
|
|
12
|
-
const query =
|
|
17
|
+
const query = (0, graphql_tag_1.default) `
|
|
13
18
|
query CommitsByAuthor(
|
|
14
19
|
$repoOwner: String!
|
|
15
20
|
$repoName: String!
|
|
@@ -43,7 +48,7 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment
|
|
51
|
+
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
|
|
47
52
|
`;
|
|
48
53
|
const variables = {
|
|
49
54
|
repoOwner,
|
|
@@ -55,12 +60,17 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
|
55
60
|
dateSince,
|
|
56
61
|
dateUntil,
|
|
57
62
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
try {
|
|
64
|
+
return await (0, apiRequestV4_1.apiRequestV4)({
|
|
65
|
+
githubApiBaseUrlV4,
|
|
66
|
+
accessToken,
|
|
67
|
+
query,
|
|
68
|
+
variables,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
return (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
75
|
async function fetchCommitsByAuthor(options) {
|
|
66
76
|
const { sourceBranch, commitPaths = [] } = options;
|
|
@@ -18,11 +18,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const
|
|
22
|
+
const graphql_1 = require("graphql");
|
|
26
23
|
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
27
24
|
const apiRequestV4Module = __importStar(require("../apiRequestV4"));
|
|
28
25
|
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
@@ -39,7 +36,6 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
39
36
|
commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
40
37
|
accessToken: devAccessToken,
|
|
41
38
|
author: 'sqren',
|
|
42
|
-
historicalBranchLabelMappings: [],
|
|
43
39
|
maxNumber: 10,
|
|
44
40
|
repoName: 'kibana',
|
|
45
41
|
repoOwner: 'elastic',
|
|
@@ -52,10 +48,9 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
52
48
|
it('makes the right queries', () => {
|
|
53
49
|
const queries = spy.mock.calls.reduce((acc, call) => {
|
|
54
50
|
const query = call[0].query;
|
|
55
|
-
const ast = (0, graphql_tag_1.default)(query);
|
|
56
51
|
//@ts-expect-error
|
|
57
|
-
const name =
|
|
58
|
-
return { ...acc, [name]: query };
|
|
52
|
+
const name = query.definitions[0].name.value;
|
|
53
|
+
return { ...acc, [name]: (0, graphql_1.print)(query) };
|
|
59
54
|
}, {});
|
|
60
55
|
const queryNames = Object.keys(queries);
|
|
61
56
|
expect(queryNames).toEqual(['AuthorId', 'CommitsByAuthor']);
|
|
@@ -71,7 +66,6 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
71
66
|
const getOptions = () => ({
|
|
72
67
|
accessToken: devAccessToken,
|
|
73
68
|
author: 'sqren',
|
|
74
|
-
historicalBranchLabelMappings: [],
|
|
75
69
|
maxNumber: 10,
|
|
76
70
|
repoName: 'repo-with-different-commit-paths',
|
|
77
71
|
repoOwner: 'backport-org',
|
|
@@ -146,7 +140,6 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
146
140
|
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
147
141
|
accessToken: devAccessToken,
|
|
148
142
|
commitPaths: [],
|
|
149
|
-
historicalBranchLabelMappings: [],
|
|
150
143
|
maxNumber: 10,
|
|
151
144
|
repoName: 'backport-e2e',
|
|
152
145
|
repoOwner: 'backport-org',
|
|
@@ -192,9 +185,11 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
192
185
|
},
|
|
193
186
|
]);
|
|
194
187
|
});
|
|
195
|
-
it('returns
|
|
188
|
+
it('returns missing pull requests', async () => {
|
|
196
189
|
const commitWithoutPRs = res.find((commit) => commit.sourcePullRequest?.number === 8);
|
|
197
|
-
expect(commitWithoutPRs?.expectedTargetPullRequests).toEqual([
|
|
190
|
+
expect(commitWithoutPRs?.expectedTargetPullRequests).toEqual([
|
|
191
|
+
{ branch: '7.x', state: 'MISSING' },
|
|
192
|
+
]);
|
|
198
193
|
});
|
|
199
194
|
});
|
|
200
195
|
});
|
|
@@ -1,13 +1,18 @@
|
|
|
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");
|
|
10
|
+
const remoteConfig_1 = require("../../../remoteConfig");
|
|
6
11
|
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
7
12
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
8
13
|
async function fetchPullRequestBySearchQuery(options) {
|
|
9
14
|
const { accessToken, githubApiBaseUrlV4, maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, author, } = options;
|
|
10
|
-
const query =
|
|
15
|
+
const query = (0, graphql_tag_1.default) `
|
|
11
16
|
query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
|
|
12
17
|
search(query: $query, type: ISSUE, first: $maxNumber) {
|
|
13
18
|
nodes {
|
|
@@ -20,7 +25,7 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment
|
|
28
|
+
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
|
|
24
29
|
`;
|
|
25
30
|
const authorFilter = author ? ` author:${author}` : '';
|
|
26
31
|
const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter} ${prFilter} base:${sourceBranch}`;
|
|
@@ -28,12 +33,18 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
28
33
|
query: searchQuery,
|
|
29
34
|
maxNumber: maxNumber,
|
|
30
35
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
let res;
|
|
37
|
+
try {
|
|
38
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
39
|
+
githubApiBaseUrlV4,
|
|
40
|
+
accessToken,
|
|
41
|
+
query,
|
|
42
|
+
variables,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
|
|
47
|
+
}
|
|
37
48
|
const commits = res.search.nodes.map((pullRequestNode) => {
|
|
38
49
|
const sourceCommit = pullRequestNode.mergeCommit;
|
|
39
50
|
return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
|
|
@@ -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;
|
|
@@ -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
|
+
...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;
|