backport 7.2.0-beta.1 → 7.2.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/dist/entrypoint.cli.js +0 -0
- 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 +1 -0
- package/dist/options/cliArgs.js +4 -0
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +2 -1
- package/dist/runSequentially.test.js +54 -30
- package/dist/services/git.d.ts +1 -3
- package/dist/services/git.js +5 -3
- package/dist/services/github/v3/createStatusComment.js +1 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +2 -3
- package/dist/services/github/v4/apiRequestV4.js +15 -14
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +2 -2
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +1 -1
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.js +1 -1
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +2 -5
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
- package/dist/services/remoteConfig.js +2 -2
- 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.js +19 -18
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +2 -2
- package/dist/services/sourceCommit/parseSourceCommit.js +9 -15
- 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} +85 -38
- package/dist/test/{backport-e2e.mutation.test.d.ts → 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/ui/cherrypickAndCreateTargetPullRequest.js +12 -18
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +2 -2
- package/dist/ui/getCommits.js +6 -4
- package/dist/ui/maybeSetupRepo.js +13 -16
- package/dist/ui/maybeSetupRepo.test.js +50 -16
- package/dist/ui/ora.d.ts +1 -1
- package/dist/ui/ora.js +2 -2
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +9 -9
- package/yarn.lock +121 -114
- package/dist/test/backport-e2e.mutation.test.js +0 -347
package/dist/entrypoint.cli.js
CHANGED
|
File without changes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ConfigFileOptions } from './options/ConfigOptions';
|
|
2
2
|
import { ValidConfigOptions } from './options/options';
|
|
3
|
+
import { Commit } from './services/sourceCommit/parseSourceCommit';
|
|
3
4
|
export { BackportResponse } from './backportRun';
|
|
4
5
|
export { ConfigFileOptions } from './options/ConfigOptions';
|
|
5
|
-
export { Commit }
|
|
6
|
+
export { Commit };
|
|
6
7
|
export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './services/github/v4/fetchRemoteProjectConfig';
|
|
7
8
|
export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
|
|
8
9
|
export declare function backportRun(options: ConfigFileOptions, processArgs?: string[]): Promise<import("./backportRun").BackportResponse>;
|
|
@@ -14,9 +15,9 @@ export declare function getCommits(options: {
|
|
|
14
15
|
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
15
16
|
githubApiBaseUrlV4?: string;
|
|
16
17
|
pullNumber?: number;
|
|
17
|
-
sha?: string;
|
|
18
|
+
sha?: string | string[];
|
|
18
19
|
skipRemoteConfig?: boolean;
|
|
19
20
|
sourceBranch?: string;
|
|
20
21
|
dateUntil?: string;
|
|
21
22
|
dateSince?: string;
|
|
22
|
-
}): Promise<
|
|
23
|
+
}): Promise<Commit[]>;
|
|
@@ -37,13 +37,8 @@ async function getCommits(options) {
|
|
|
37
37
|
];
|
|
38
38
|
}
|
|
39
39
|
if (options.sha) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
...optionsFromGithub,
|
|
43
|
-
...options,
|
|
44
|
-
sha: options.sha,
|
|
45
|
-
}),
|
|
46
|
-
];
|
|
40
|
+
const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
|
|
41
|
+
return Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...optionsFromGithub, ...options, sha })));
|
|
47
42
|
}
|
|
48
43
|
return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
49
44
|
...optionsFromGithub,
|
|
@@ -16,6 +16,7 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
|
|
|
16
16
|
cherrypickRef?: boolean | undefined;
|
|
17
17
|
configFile?: string | undefined;
|
|
18
18
|
details?: boolean | undefined;
|
|
19
|
+
dryRun?: boolean | undefined;
|
|
19
20
|
editor?: string | undefined;
|
|
20
21
|
skipRemoteConfig?: boolean | undefined;
|
|
21
22
|
gitHostname?: string | undefined;
|
package/dist/options/cliArgs.js
CHANGED
|
@@ -83,6 +83,10 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
|
|
|
83
83
|
.option('details', {
|
|
84
84
|
description: 'Show details about each commit',
|
|
85
85
|
type: 'boolean',
|
|
86
|
+
})
|
|
87
|
+
.option('dryRun', {
|
|
88
|
+
description: 'Run backport locally without pushing to Github',
|
|
89
|
+
type: 'boolean',
|
|
86
90
|
})
|
|
87
91
|
.option('editor', {
|
|
88
92
|
description: 'Editor to be opened during conflict resolution',
|
|
@@ -45,7 +45,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
|
|
|
45
45
|
repoOwner?: string | undefined;
|
|
46
46
|
resetAuthor?: boolean | undefined;
|
|
47
47
|
reviewers?: string[] | undefined;
|
|
48
|
-
sha?: string | undefined;
|
|
48
|
+
sha?: string | string[] | undefined;
|
|
49
49
|
skipRemoteConfig?: boolean | undefined;
|
|
50
50
|
sourceBranch?: string | undefined;
|
|
51
51
|
sourcePRLabels?: string[] | undefined;
|
|
@@ -30,7 +30,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
30
30
|
prTitle?: string | undefined;
|
|
31
31
|
prFilter?: string | undefined;
|
|
32
32
|
pullNumber?: number | undefined;
|
|
33
|
-
sha?: string | undefined;
|
|
33
|
+
sha?: string | string[] | undefined;
|
|
34
34
|
resetAuthor?: boolean | undefined;
|
|
35
35
|
repoOwner?: string | undefined;
|
|
36
36
|
repoName?: string | undefined;
|
|
@@ -17,6 +17,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
17
17
|
cherrypickRef: boolean;
|
|
18
18
|
configFile?: string | undefined;
|
|
19
19
|
details: boolean;
|
|
20
|
+
dryRun?: boolean | undefined;
|
|
20
21
|
editor?: string | undefined;
|
|
21
22
|
skipRemoteConfig?: boolean | undefined;
|
|
22
23
|
gitHostname: string;
|
|
@@ -31,7 +32,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
31
32
|
prTitle?: string | undefined;
|
|
32
33
|
prFilter?: string | undefined;
|
|
33
34
|
pullNumber?: number | undefined;
|
|
34
|
-
sha?: string | undefined;
|
|
35
|
+
sha?: string | string[] | undefined;
|
|
35
36
|
resetAuthor: boolean;
|
|
36
37
|
sourceBranch: string;
|
|
37
38
|
username?: string | undefined;
|
|
@@ -169,37 +169,61 @@ describe('runSequentially', () => {
|
|
|
169
169
|
]
|
|
170
170
|
`);
|
|
171
171
|
});
|
|
172
|
-
it('should run
|
|
172
|
+
it('should run commands in correct folders', () => {
|
|
173
173
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
174
|
-
expect(rpcExecMock.mock.calls.map(([cmd,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
174
|
+
expect(rpcExecMock.mock.calls.map(([cmd, { cwd }]) => ({ cmd, cwd }))).toEqual([
|
|
175
|
+
{
|
|
176
|
+
cmd: 'git rev-parse --show-toplevel',
|
|
177
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
cmd: 'git remote --verbose',
|
|
181
|
+
cwd: '/path/to/source/repo',
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
cmd: 'git remote rm origin',
|
|
185
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
cmd: 'git remote rm sqren_authenticated',
|
|
189
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
cmd: 'git remote add sqren_authenticated https://x-access-token:myAccessToken@github.com/sqren_authenticated/kibana.git',
|
|
193
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
cmd: 'git remote rm elastic',
|
|
197
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
cmd: 'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
|
|
201
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
cmd: 'git reset --hard && git clean -d --force && git fetch elastic 7.x && git checkout -B backport/7.x/pr-55 elastic/7.x --no-track',
|
|
205
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
cmd: 'git fetch elastic master:master --force',
|
|
209
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
cmd: 'git rev-list -1 --merges abcd~1..abcd',
|
|
213
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
cmd: 'git cherry-pick -x abcd',
|
|
217
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
cmd: 'git push sqren_authenticated backport/7.x/pr-55:backport/7.x/pr-55 --force',
|
|
221
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
cmd: 'git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55',
|
|
225
|
+
cwd: '/myHomeDir/.backport/repositories/elastic/kibana',
|
|
226
|
+
},
|
|
203
227
|
]);
|
|
204
228
|
});
|
|
205
229
|
it('git clone should be called with correct args', () => {
|
package/dist/services/git.d.ts
CHANGED
|
@@ -21,9 +21,7 @@ export declare function getRepoInfoFromGitRemotes({ cwd }: {
|
|
|
21
21
|
repoOwner: string;
|
|
22
22
|
repoName: string;
|
|
23
23
|
}[]>;
|
|
24
|
-
export declare function getGitProjectRoot(
|
|
25
|
-
cwd: string;
|
|
26
|
-
}): Promise<string | undefined>;
|
|
24
|
+
export declare function getGitProjectRoot(dir: string): Promise<string | undefined>;
|
|
27
25
|
export declare function getIsCommitInBranch(options: ValidConfigOptions, commitSha: string): Promise<boolean>;
|
|
28
26
|
export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
|
29
27
|
export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
|
package/dist/services/git.js
CHANGED
|
@@ -99,9 +99,11 @@ async function getRepoInfoFromGitRemotes({ cwd }) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
exports.getRepoInfoFromGitRemotes = getRepoInfoFromGitRemotes;
|
|
102
|
-
async function getGitProjectRoot(
|
|
102
|
+
async function getGitProjectRoot(dir) {
|
|
103
103
|
try {
|
|
104
|
-
const { stdout } = await (0, child_process_promisified_1.exec)('git rev-parse --show-toplevel', {
|
|
104
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git rev-parse --show-toplevel', {
|
|
105
|
+
cwd: dir,
|
|
106
|
+
});
|
|
105
107
|
return stdout.trim();
|
|
106
108
|
}
|
|
107
109
|
catch (e) {
|
|
@@ -375,7 +377,7 @@ async function getSourceRepoPath(options) {
|
|
|
375
377
|
const remoteUrl = getRemoteUrl(options, options.repoOwner);
|
|
376
378
|
const sourcePath = options.repoName === gitRemote.repoName &&
|
|
377
379
|
options.repoOwner === gitRemote.repoOwner
|
|
378
|
-
? (await getGitProjectRoot(options)) ?? remoteUrl
|
|
380
|
+
? (await getGitProjectRoot(options.cwd)) ?? remoteUrl
|
|
379
381
|
: remoteUrl;
|
|
380
382
|
return sourcePath;
|
|
381
383
|
}
|
|
@@ -9,7 +9,7 @@ const logger_1 = require("../../logger");
|
|
|
9
9
|
const commitFormatters_1 = require("../commitFormatters");
|
|
10
10
|
async function createStatusComment({ options, backportResponse, }) {
|
|
11
11
|
const { githubApiBaseUrlV3, repoName, repoOwner, accessToken, publishStatusComment, } = options;
|
|
12
|
-
if (!publishStatusComment) {
|
|
12
|
+
if (!publishStatusComment || options.dryRun) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
@@ -22,11 +22,10 @@ export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessT
|
|
|
22
22
|
}): Promise<DataResponse>;
|
|
23
23
|
declare type AxiosGithubResponse<DataResponse> = AxiosResponse<GithubV4Response<DataResponse | null>, any>;
|
|
24
24
|
export declare class GithubV4Exception<DataResponse> extends Error {
|
|
25
|
-
|
|
26
|
-
axiosResponse: AxiosGithubResponse<DataResponse> & {
|
|
25
|
+
githubResponse: AxiosGithubResponse<DataResponse> & {
|
|
27
26
|
request: undefined;
|
|
28
27
|
};
|
|
29
|
-
constructor(
|
|
28
|
+
constructor(githubResponse: AxiosGithubResponse<DataResponse>, errorMessage?: string);
|
|
30
29
|
}
|
|
31
30
|
export declare function getQueryName(query: DocumentNode): string;
|
|
32
31
|
export {};
|
|
@@ -17,16 +17,13 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
19
|
if (response.data.errors) {
|
|
20
|
-
|
|
21
|
-
.map((error) => error.message)
|
|
22
|
-
.join(',')} (Github API v4)`;
|
|
23
|
-
throw new GithubV4Exception(message, response);
|
|
20
|
+
throw new GithubV4Exception(response);
|
|
24
21
|
}
|
|
25
22
|
addDebugLogs({
|
|
26
23
|
githubApiBaseUrlV4,
|
|
27
24
|
query,
|
|
28
25
|
variables,
|
|
29
|
-
|
|
26
|
+
githubResponse: response,
|
|
30
27
|
didSucceed: false,
|
|
31
28
|
});
|
|
32
29
|
return response.data.data;
|
|
@@ -37,32 +34,36 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
37
34
|
githubApiBaseUrlV4,
|
|
38
35
|
query,
|
|
39
36
|
variables,
|
|
40
|
-
|
|
37
|
+
githubResponse: e.response,
|
|
41
38
|
didSucceed: false,
|
|
42
39
|
});
|
|
43
|
-
throw new GithubV4Exception(
|
|
40
|
+
throw new GithubV4Exception(e.response, e.message);
|
|
44
41
|
}
|
|
45
42
|
throw e;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
exports.apiRequestV4 = apiRequestV4;
|
|
49
|
-
function addDebugLogs({ githubApiBaseUrlV4, query, variables,
|
|
46
|
+
function addDebugLogs({ githubApiBaseUrlV4, query, variables, githubResponse, didSucceed, }) {
|
|
50
47
|
const gqlQueryName = getQueryName(query);
|
|
51
|
-
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${
|
|
48
|
+
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${githubResponse.status})`);
|
|
52
49
|
const logMethod = didSucceed ? logger_1.logger.verbose : logger_1.logger.info;
|
|
53
50
|
logMethod(`Query name ${gqlQueryName}`);
|
|
54
51
|
logMethod(`Query: ${query}`);
|
|
55
52
|
logMethod('Variables:', variables);
|
|
56
|
-
logMethod('Response headers:',
|
|
57
|
-
logMethod('Response data:',
|
|
53
|
+
logMethod('Response headers:', githubResponse.headers);
|
|
54
|
+
logMethod('Response data:', githubResponse.data);
|
|
58
55
|
}
|
|
59
56
|
class GithubV4Exception extends Error {
|
|
60
|
-
constructor(
|
|
57
|
+
constructor(githubResponse, errorMessage) {
|
|
58
|
+
const githubMessage = githubResponse.data.errors
|
|
59
|
+
?.map((error) => error.message)
|
|
60
|
+
.join(',');
|
|
61
|
+
const message = `${errorMessage ?? githubMessage ?? 'Unknown error'} (Github API v4)`;
|
|
61
62
|
super(message);
|
|
62
|
-
this.message = message;
|
|
63
63
|
Error.captureStackTrace(this, HandledError_1.HandledError);
|
|
64
64
|
this.name = 'GithubV4Exception';
|
|
65
|
-
this.
|
|
65
|
+
this.message = message;
|
|
66
|
+
this.githubResponse = { ...githubResponse, request: undefined };
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
exports.GithubV4Exception = GithubV4Exception;
|
|
@@ -20,13 +20,13 @@ async function fetchCommitByPullNumber(options) {
|
|
|
20
20
|
repository(owner: $repoOwner, name: $repoName) {
|
|
21
21
|
pullRequest(number: $pullNumber) {
|
|
22
22
|
mergeCommit {
|
|
23
|
-
...
|
|
23
|
+
...SourceCommitWithTargetPullRequestFragment
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
${parseSourceCommit_1.
|
|
29
|
+
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
30
30
|
`;
|
|
31
31
|
let res;
|
|
32
32
|
try {
|
|
@@ -15,12 +15,12 @@ async function fetchCommitBySha(options) {
|
|
|
15
15
|
query CommitsBySha($repoOwner: String!, $repoName: String!, $sha: String!) {
|
|
16
16
|
repository(owner: $repoOwner, name: $repoName) {
|
|
17
17
|
object(expression: $sha) {
|
|
18
|
-
...
|
|
18
|
+
...SourceCommitWithTargetPullRequestFragment
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
${parseSourceCommit_1.
|
|
23
|
+
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
24
24
|
`;
|
|
25
25
|
let res;
|
|
26
26
|
try {
|
|
@@ -38,7 +38,7 @@ async function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
|
38
38
|
) {
|
|
39
39
|
edges {
|
|
40
40
|
node {
|
|
41
|
-
...
|
|
41
|
+
...SourceCommitWithTargetPullRequestFragment
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -48,7 +48,7 @@ async function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
${parseSourceCommit_1.
|
|
51
|
+
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
52
52
|
`;
|
|
53
53
|
const variables = {
|
|
54
54
|
repoOwner,
|
|
@@ -18,14 +18,14 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
18
18
|
nodes {
|
|
19
19
|
... on PullRequest {
|
|
20
20
|
mergeCommit {
|
|
21
|
-
...
|
|
21
|
+
...SourceCommitWithTargetPullRequestFragment
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
${parseSourceCommit_1.
|
|
28
|
+
${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
|
|
29
29
|
`;
|
|
30
30
|
const authorFilter = author ? ` author:${author}` : '';
|
|
31
31
|
const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter} ${prFilter} base:${sourceBranch}`;
|
|
@@ -47,7 +47,7 @@ export declare function getOptionsFromGithub(options: {
|
|
|
47
47
|
repoOwner?: string | undefined;
|
|
48
48
|
resetAuthor?: boolean | undefined;
|
|
49
49
|
reviewers?: string[] | undefined;
|
|
50
|
-
sha?: string | undefined;
|
|
50
|
+
sha?: string | string[] | undefined;
|
|
51
51
|
skipRemoteConfig?: boolean | undefined;
|
|
52
52
|
sourceBranch: string;
|
|
53
53
|
sourcePRLabels?: string[] | undefined;
|
|
@@ -9,7 +9,6 @@ exports.commitsByAuthorMock = {
|
|
|
9
9
|
edges: [
|
|
10
10
|
{
|
|
11
11
|
node: {
|
|
12
|
-
remoteConfigHistory: { edges: [] },
|
|
13
12
|
repository: {
|
|
14
13
|
name: 'kibana',
|
|
15
14
|
owner: { login: 'elastic' },
|
|
@@ -24,7 +23,6 @@ exports.commitsByAuthorMock = {
|
|
|
24
23
|
},
|
|
25
24
|
{
|
|
26
25
|
node: {
|
|
27
|
-
remoteConfigHistory: { edges: [] },
|
|
28
26
|
repository: {
|
|
29
27
|
name: 'kibana',
|
|
30
28
|
owner: { login: 'elastic' },
|
|
@@ -43,6 +41,7 @@ exports.commitsByAuthorMock = {
|
|
|
43
41
|
},
|
|
44
42
|
number: 85,
|
|
45
43
|
mergeCommit: {
|
|
44
|
+
remoteConfigHistory: { edges: [] },
|
|
46
45
|
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
47
46
|
message: 'Add witch (#85)',
|
|
48
47
|
},
|
|
@@ -57,7 +56,6 @@ exports.commitsByAuthorMock = {
|
|
|
57
56
|
},
|
|
58
57
|
{
|
|
59
58
|
node: {
|
|
60
|
-
remoteConfigHistory: { edges: [] },
|
|
61
59
|
repository: {
|
|
62
60
|
name: 'kibana',
|
|
63
61
|
owner: { login: 'elastic' },
|
|
@@ -76,6 +74,7 @@ exports.commitsByAuthorMock = {
|
|
|
76
74
|
baseRefName: 'master',
|
|
77
75
|
number: 80,
|
|
78
76
|
mergeCommit: {
|
|
77
|
+
remoteConfigHistory: { edges: [] },
|
|
79
78
|
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
80
79
|
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
81
80
|
},
|
|
@@ -123,7 +122,6 @@ exports.commitsByAuthorMock = {
|
|
|
123
122
|
},
|
|
124
123
|
{
|
|
125
124
|
node: {
|
|
126
|
-
remoteConfigHistory: { edges: [] },
|
|
127
125
|
repository: {
|
|
128
126
|
name: 'kibana',
|
|
129
127
|
owner: { login: 'elastic' },
|
|
@@ -138,7 +136,6 @@ exports.commitsByAuthorMock = {
|
|
|
138
136
|
},
|
|
139
137
|
{
|
|
140
138
|
node: {
|
|
141
|
-
remoteConfigHistory: { edges: [] },
|
|
142
139
|
repository: {
|
|
143
140
|
name: 'kibana',
|
|
144
141
|
owner: { login: 'elastic' },
|
|
@@ -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
|
},
|
|
@@ -8,7 +8,7 @@ const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
|
8
8
|
const readConfigFile_1 = require("../options/config/readConfigFile");
|
|
9
9
|
const logger_1 = require("./logger");
|
|
10
10
|
exports.RemoteConfigHistoryFragment = (0, graphql_tag_1.default) `
|
|
11
|
-
fragment
|
|
11
|
+
fragment RemoteConfigHistoryFragment on Commit {
|
|
12
12
|
remoteConfigHistory: history(first: 1, path: ".backportrc.json") {
|
|
13
13
|
edges {
|
|
14
14
|
remoteConfig: node {
|
|
@@ -38,7 +38,7 @@ function parseRemoteConfig(remoteConfig) {
|
|
|
38
38
|
}
|
|
39
39
|
exports.parseRemoteConfig = parseRemoteConfig;
|
|
40
40
|
function swallowMissingConfigFileException(error) {
|
|
41
|
-
const { data, errors } = error.
|
|
41
|
+
const { data, errors } = error.githubResponse.data;
|
|
42
42
|
const missingConfigError = errors?.some((error) => {
|
|
43
43
|
return error.path.includes('remoteConfig') && error.type === 'NOT_FOUND';
|
|
44
44
|
});
|
|
@@ -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) {
|