backport 6.0.0 → 6.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 +158 -42
- package/dist/entrypoint.cli.js +2 -0
- package/dist/entrypoint.module.d.ts +16 -4
- package/dist/entrypoint.module.js +41 -13
- package/dist/entrypoint.module.private.test.d.ts +1 -0
- package/dist/entrypoint.module.private.test.js +33 -0
- package/dist/main.js +1 -2
- package/dist/options/ConfigOptions.d.ts +15 -6
- package/dist/options/cliArgs.d.ts +33 -34
- package/dist/options/cliArgs.js +19 -19
- package/dist/options/cliArgs.test.js +8 -5
- package/dist/options/config/config.d.ts +27 -52
- package/dist/options/config/config.js +2 -36
- package/dist/options/config/config.test.js +10 -27
- package/dist/options/config/getOptionsFromGit.d.ts +3 -2
- package/dist/options/config/getOptionsFromGit.js +1 -3
- package/dist/options/config/globalConfig.js +1 -4
- package/dist/options/config/globalConfig.test.js +0 -2
- package/dist/options/config/projectConfig.test.js +51 -14
- package/dist/options/config/readConfigFile.d.ts +51 -0
- package/dist/options/config/readConfigFile.js +28 -2
- package/dist/options/options.d.ts +52 -33
- package/dist/options/options.js +98 -7
- package/dist/options/options.test.js +180 -73
- package/dist/options/parseRequiredOptions.d.ts +3 -3
- package/dist/options/parseRequiredOptions.js +2 -4
- package/dist/options/parseRequiredOptions.test.js +6 -11
- package/dist/runSequentially.test.js +35 -78
- package/dist/services/git.d.ts +5 -2
- package/dist/services/git.js +11 -10
- package/dist/services/git.test.js +12 -9
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +2 -3
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +4 -5
- package/dist/services/github/v3/createPullRequest.js +10 -13
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +78 -0
- package/dist/services/github/v4/apiRequestV4.d.ts +1 -1
- package/dist/services/github/v4/apiRequestV4.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +1 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -1
- package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
- package/dist/services/github/v4/fetchAuthorId.js +5 -6
- package/dist/services/github/v4/fetchAuthorId.private.test.js +3 -6
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +6 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +8 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +1 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +12 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -8
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +10 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +5 -7
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
- package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +5 -5
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +2 -6
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -2
- package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
- package/dist/services/github/v4/fetchProjectConfig.js +56 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
- package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +66 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
- package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +3 -1
- package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +22 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +4 -1
- package/dist/services/github/v4/getOptionsFromGithub/query.js +3 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +15 -15
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +5 -1
- package/dist/services/sourceCommit/parseSourceCommit.js +2 -2
- package/dist/services/sourceCommit/parseSourceCommit.test.js +120 -5
- package/dist/test/inquirer.private.test.js +42 -34
- package/dist/test/integration/integration.private.test.js +104 -95
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +37 -0
- package/dist/test/nockHelpers.d.ts +1 -1
- package/dist/test/nockHelpers.js +4 -4
- package/dist/test/private/getDevAccessToken.js +1 -1
- package/dist/test/setupFiles/automatic-mocks.js +1 -29
- package/dist/ui/cherrypickAndCreatePullRequest.test.js +67 -28
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +6 -3
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getTargetBranches.d.ts +2 -1
- package/dist/ui/getTargetBranches.js +17 -1
- package/dist/ui/maybeSetupRepo.js +4 -3
- package/dist/ui/maybeSetupRepo.test.js +49 -3
- package/dist/utils/excludeUndefined.d.ts +6 -0
- package/dist/utils/excludeUndefined.js +7 -0
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/package.json +9 -8
- package/yarn.lock +98 -77
|
@@ -8,16 +8,14 @@ const nockHelpers_1 = require("../../../../test/nockHelpers");
|
|
|
8
8
|
const commitsByAuthorMock_1 = require("../mocks/commitsByAuthorMock");
|
|
9
9
|
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
10
10
|
const defaultOptions = {
|
|
11
|
-
repoOwner: 'elastic',
|
|
12
|
-
repoName: 'kibana',
|
|
13
|
-
sourceBranch: 'source-branch-from-options',
|
|
14
11
|
accessToken: 'myAccessToken',
|
|
15
|
-
username: 'sqren',
|
|
16
12
|
author: 'sqren',
|
|
17
|
-
maxNumber: 10,
|
|
18
|
-
githubApiBaseUrlV3: 'https://api.github.com',
|
|
19
13
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
20
|
-
|
|
14
|
+
historicalBranchLabelMappings: [],
|
|
15
|
+
maxNumber: 10,
|
|
16
|
+
repoName: 'kibana',
|
|
17
|
+
repoOwner: 'elastic',
|
|
18
|
+
sourceBranch: 'source-branch-from-options',
|
|
21
19
|
};
|
|
22
20
|
const authorIdMockData = { user: { id: 'myUserId' } };
|
|
23
21
|
describe('fetchCommitsByAuthor', () => {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchProjectConfig = void 0;
|
|
4
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
5
|
+
async function fetchProjectConfig(options) {
|
|
6
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
|
|
7
|
+
const query = /* GraphQL */ `
|
|
8
|
+
query ProjectConfig(
|
|
9
|
+
$repoOwner: String!
|
|
10
|
+
$repoName: String!
|
|
11
|
+
$sourceBranch: String!
|
|
12
|
+
) {
|
|
13
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
14
|
+
ref(qualifiedName: $sourceBranch) {
|
|
15
|
+
target {
|
|
16
|
+
... on Commit {
|
|
17
|
+
history(first: 1, path: ".backportrc.json") {
|
|
18
|
+
edges {
|
|
19
|
+
remoteConfig: node {
|
|
20
|
+
file(path: ".backportrc.json") {
|
|
21
|
+
... on TreeEntry {
|
|
22
|
+
object {
|
|
23
|
+
... on Blob {
|
|
24
|
+
text
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
39
|
+
githubApiBaseUrlV4,
|
|
40
|
+
accessToken,
|
|
41
|
+
query,
|
|
42
|
+
variables: {
|
|
43
|
+
repoOwner,
|
|
44
|
+
repoName,
|
|
45
|
+
sourceBranch,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(res.repository.ref.target.history.edges[0].remoteConfig.file.object.text);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
throw new Error('Project config does not exist');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.fetchProjectConfig = fetchProjectConfig;
|
|
@@ -6,7 +6,7 @@ const HandledError_1 = require("../../../HandledError");
|
|
|
6
6
|
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
7
7
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
8
8
|
async function fetchPullRequestBySearchQuery(options) {
|
|
9
|
-
const { accessToken,
|
|
9
|
+
const { accessToken, githubApiBaseUrlV4, maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, author, } = options;
|
|
10
10
|
const query = /* GraphQL */ `
|
|
11
11
|
query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
|
|
12
12
|
search(query: $query, type: ISSUE, first: $maxNumber) {
|
|
@@ -22,7 +22,7 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
22
22
|
|
|
23
23
|
${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
|
|
24
24
|
`;
|
|
25
|
-
const authorFilter =
|
|
25
|
+
const authorFilter = author ? `author:${author}` : '';
|
|
26
26
|
const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName} ${authorFilter} ${prFilter} base:${sourceBranch}`;
|
|
27
27
|
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
28
28
|
githubApiBaseUrlV4,
|
|
@@ -39,9 +39,9 @@ async function fetchPullRequestBySearchQuery(options) {
|
|
|
39
39
|
});
|
|
40
40
|
// terminate if not commits were found
|
|
41
41
|
if ((0, lodash_1.isEmpty)(commits)) {
|
|
42
|
-
const errorText = options.
|
|
43
|
-
? `There are no
|
|
44
|
-
: `There are no
|
|
42
|
+
const errorText = options.author
|
|
43
|
+
? `There are no commits by "${options.author}" matching the filter "${prFilter}". Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`
|
|
44
|
+
: `There are no pull requests matching the filter "${prFilter}"`;
|
|
45
45
|
throw new HandledError_1.HandledError(errorText);
|
|
46
46
|
}
|
|
47
47
|
return commits;
|
|
@@ -11,14 +11,12 @@ describe('fetchPullRequestBySearchQuery', () => {
|
|
|
11
11
|
it('throws an error', async () => {
|
|
12
12
|
const options = {
|
|
13
13
|
accessToken: devAccessToken,
|
|
14
|
-
all: false,
|
|
15
|
-
author: 'sqren',
|
|
16
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
17
14
|
maxNumber: 10,
|
|
18
15
|
prFilter: 'label:non-existing',
|
|
19
16
|
repoName: 'backport-e2e',
|
|
20
17
|
repoOwner: 'backport-org',
|
|
21
18
|
sourceBranch: 'master',
|
|
19
|
+
author: 'sqren',
|
|
22
20
|
};
|
|
23
21
|
await expect((0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).rejects.toThrowError('There are no commits by "sqren" matching the filter "label:non-existing". Try with `--all` for commits by all users or `--author=<username>` for commits from a specific user');
|
|
24
22
|
});
|
|
@@ -27,14 +25,12 @@ describe('fetchPullRequestBySearchQuery', () => {
|
|
|
27
25
|
it('returns the merge commits for those PRs', async () => {
|
|
28
26
|
const options = {
|
|
29
27
|
accessToken: devAccessToken,
|
|
30
|
-
all: false,
|
|
31
|
-
author: 'sqren',
|
|
32
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
33
28
|
maxNumber: 10,
|
|
34
29
|
prFilter: 'label:v7.8.0',
|
|
35
30
|
repoName: 'backport-e2e',
|
|
36
31
|
repoOwner: 'backport-org',
|
|
37
32
|
sourceBranch: 'master',
|
|
33
|
+
author: 'sqren',
|
|
38
34
|
};
|
|
39
35
|
expect(await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).toEqual([
|
|
40
36
|
{
|
|
@@ -11,7 +11,6 @@ describe('fetchExistingPullRequest', () => {
|
|
|
11
11
|
it('returns undefined', async () => {
|
|
12
12
|
const options = {
|
|
13
13
|
accessToken: devAccessToken,
|
|
14
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
15
14
|
};
|
|
16
15
|
const prPayload = {
|
|
17
16
|
owner: 'backport-org',
|
|
@@ -29,7 +28,6 @@ describe('fetchExistingPullRequest', () => {
|
|
|
29
28
|
it('returns the PR number and url', async () => {
|
|
30
29
|
const options = {
|
|
31
30
|
accessToken: devAccessToken,
|
|
32
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
33
31
|
};
|
|
34
32
|
const prPayload = {
|
|
35
33
|
owner: 'backport-org',
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConfigFileOptions } from '../../../entrypoint.module';
|
|
2
|
+
export declare function fetchProjectConfig(options: {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
githubApiBaseUrlV4?: string;
|
|
5
|
+
repoName: string;
|
|
6
|
+
repoOwner: string;
|
|
7
|
+
sourceBranch: string;
|
|
8
|
+
}): Promise<ConfigFileOptions>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchProjectConfig = void 0;
|
|
4
|
+
const readConfigFile_1 = require("../../../options/config/readConfigFile");
|
|
5
|
+
const apiRequestV4_1 = require("./apiRequestV4");
|
|
6
|
+
async function fetchProjectConfig(options) {
|
|
7
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
|
|
8
|
+
const query = /* GraphQL */ `
|
|
9
|
+
query ProjectConfig(
|
|
10
|
+
$repoOwner: String!
|
|
11
|
+
$repoName: String!
|
|
12
|
+
$sourceBranch: String!
|
|
13
|
+
) {
|
|
14
|
+
repository(owner: $repoOwner, name: $repoName) {
|
|
15
|
+
ref(qualifiedName: $sourceBranch) {
|
|
16
|
+
target {
|
|
17
|
+
... on Commit {
|
|
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
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
try {
|
|
40
|
+
const res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
41
|
+
githubApiBaseUrlV4,
|
|
42
|
+
accessToken,
|
|
43
|
+
query,
|
|
44
|
+
variables: {
|
|
45
|
+
repoOwner,
|
|
46
|
+
repoName,
|
|
47
|
+
sourceBranch,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(res.repository.ref.target.history.edges[0].remoteConfig.file.object.text));
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
throw new Error('Project config does not exist');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.fetchProjectConfig = fetchProjectConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchProjectConfig_1 = require("./fetchProjectConfig");
|
|
5
|
+
describe('fetchProjectConfig', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
it('returns the backport config from "main" branch', async () => {
|
|
11
|
+
const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
|
|
12
|
+
repoOwner: 'backport-org',
|
|
13
|
+
repoName: 'repo-with-project-config',
|
|
14
|
+
accessToken: devAccessToken,
|
|
15
|
+
sourceBranch: 'main',
|
|
16
|
+
});
|
|
17
|
+
expect(projectConfig).toEqual({
|
|
18
|
+
autoMerge: true,
|
|
19
|
+
autoMergeMethod: 'squash',
|
|
20
|
+
branchLabelMapping: {
|
|
21
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
22
|
+
'^v8.1.0$': 'main',
|
|
23
|
+
},
|
|
24
|
+
targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
|
|
25
|
+
targetPRLabels: ['backport'],
|
|
26
|
+
repoOwner: 'backport-org',
|
|
27
|
+
repoName: 'repo-with-project-config',
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it('returns the backport config from "branch-with-legacy-config" branch', async () => {
|
|
31
|
+
const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
|
|
32
|
+
repoOwner: 'backport-org',
|
|
33
|
+
repoName: 'repo-with-project-config',
|
|
34
|
+
accessToken: devAccessToken,
|
|
35
|
+
sourceBranch: 'branch-with-legacy-config',
|
|
36
|
+
});
|
|
37
|
+
expect(projectConfig).toEqual({
|
|
38
|
+
targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
|
|
39
|
+
repoOwner: 'backport-org',
|
|
40
|
+
repoName: 'repo-with-project-config',
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('throws an error if config does not exist', async () => {
|
|
44
|
+
const promise = (0, fetchProjectConfig_1.fetchProjectConfig)({
|
|
45
|
+
repoOwner: 'backport-org',
|
|
46
|
+
repoName: 'repo-with-project-config',
|
|
47
|
+
accessToken: devAccessToken,
|
|
48
|
+
sourceBranch: 'branch-with-no-config',
|
|
49
|
+
});
|
|
50
|
+
await expect(promise).rejects.toThrowError('Project config does not exist');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchProjectConfig_1 = require("./fetchProjectConfig");
|
|
5
|
+
describe('fetchProjectConfig', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
it('returns the backport config from "main" branch', async () => {
|
|
11
|
+
const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
|
|
12
|
+
repoOwner: 'backport-org',
|
|
13
|
+
repoName: 'repo-with-project-config',
|
|
14
|
+
accessToken: devAccessToken,
|
|
15
|
+
sourceBranch: 'main',
|
|
16
|
+
});
|
|
17
|
+
expect(projectConfig).toEqual();
|
|
18
|
+
});
|
|
19
|
+
it('returns the backport config from "branch-with-minimal-config" branch', async () => {
|
|
20
|
+
const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
|
|
21
|
+
repoOwner: 'backport-org',
|
|
22
|
+
repoName: 'repo-with-project-config',
|
|
23
|
+
accessToken: devAccessToken,
|
|
24
|
+
sourceBranch: 'branch-with-minimal-config',
|
|
25
|
+
});
|
|
26
|
+
expect(projectConfig).toEqual();
|
|
27
|
+
});
|
|
28
|
+
it('throws an error if config does not exist', async () => {
|
|
29
|
+
const promise = (0, fetchProjectConfig_1.fetchProjectConfig)({
|
|
30
|
+
repoOwner: 'backport-org',
|
|
31
|
+
repoName: 'repo-with-project-config',
|
|
32
|
+
accessToken: devAccessToken,
|
|
33
|
+
sourceBranch: 'branch-with-no-config',
|
|
34
|
+
});
|
|
35
|
+
await expect(promise).rejects.toThrowError('something...');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export declare type OptionsFromGithub = Awaited<ReturnType<typeof getOptionsFromGithub>>;
|
|
2
|
+
export declare function getOptionsFromGithub(options: {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
githubApiBaseUrlV4?: string;
|
|
5
|
+
repoName: string;
|
|
6
|
+
repoOwner: string;
|
|
7
|
+
skipRemoteConfig?: boolean;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
historicalBranchLabelMappings: {
|
|
10
|
+
branchLabelMapping: Record<string, string>;
|
|
11
|
+
committedDate: string;
|
|
12
|
+
}[];
|
|
13
|
+
accessToken?: string | undefined;
|
|
14
|
+
assignees?: string[] | undefined;
|
|
15
|
+
author?: string | null | undefined;
|
|
16
|
+
autoAssign?: boolean | undefined;
|
|
17
|
+
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
18
|
+
files: string[];
|
|
19
|
+
directory: string;
|
|
20
|
+
logger: {
|
|
21
|
+
error: (message: string, meta?: unknown) => void;
|
|
22
|
+
warn: (message: string, meta?: unknown) => void;
|
|
23
|
+
info: (message: string, meta?: unknown) => void;
|
|
24
|
+
verbose: (message: string, meta?: unknown) => void;
|
|
25
|
+
debug: (message: string, meta?: unknown) => void;
|
|
26
|
+
};
|
|
27
|
+
targetBranch: string;
|
|
28
|
+
}) => boolean | Promise<boolean>) | undefined;
|
|
29
|
+
autoMerge?: boolean | undefined;
|
|
30
|
+
autoMergeMethod?: string | undefined;
|
|
31
|
+
cherrypickRef?: boolean | undefined;
|
|
32
|
+
ci?: boolean | undefined;
|
|
33
|
+
commitPaths?: string[] | undefined;
|
|
34
|
+
details?: boolean | undefined;
|
|
35
|
+
editor?: string | undefined;
|
|
36
|
+
fork?: boolean | undefined;
|
|
37
|
+
gitHostname?: string | undefined;
|
|
38
|
+
githubApiBaseUrlV3?: string | undefined;
|
|
39
|
+
githubApiBaseUrlV4?: string | undefined;
|
|
40
|
+
maxNumber?: number | undefined;
|
|
41
|
+
multiple?: boolean | undefined;
|
|
42
|
+
multipleBranches?: boolean | undefined;
|
|
43
|
+
multipleCommits?: boolean | undefined;
|
|
44
|
+
noVerify?: boolean | undefined;
|
|
45
|
+
prDescription?: string | undefined;
|
|
46
|
+
prFilter?: string | undefined;
|
|
47
|
+
prTitle?: string | undefined;
|
|
48
|
+
pullNumber?: number | undefined;
|
|
49
|
+
repoName?: string | undefined;
|
|
50
|
+
repoOwner?: string | undefined;
|
|
51
|
+
resetAuthor?: boolean | undefined;
|
|
52
|
+
reviewers?: string[] | undefined;
|
|
53
|
+
sha?: string | undefined;
|
|
54
|
+
skipRemoteConfig?: boolean | undefined;
|
|
55
|
+
sourceBranch: string;
|
|
56
|
+
sourcePRLabels?: string[] | undefined;
|
|
57
|
+
targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
58
|
+
targetBranches?: string[] | undefined;
|
|
59
|
+
targetPRLabels?: string[] | undefined;
|
|
60
|
+
verbose?: boolean | undefined;
|
|
61
|
+
branchLabelMapping?: Record<string, string> | undefined;
|
|
62
|
+
upstream?: string | undefined;
|
|
63
|
+
branches?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
|
|
64
|
+
labels?: string[] | undefined;
|
|
65
|
+
authenticatedUsername: string;
|
|
66
|
+
}>;
|
|
@@ -0,0 +1,130 @@
|
|
|
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.getOptionsFromGithub = void 0;
|
|
7
|
+
const ora_1 = __importDefault(require("ora"));
|
|
8
|
+
const readConfigFile_1 = require("../../../../options/config/readConfigFile");
|
|
9
|
+
const filterEmpty_1 = require("../../../../utils/filterEmpty");
|
|
10
|
+
const HandledError_1 = require("../../../HandledError");
|
|
11
|
+
const git_1 = require("../../../git");
|
|
12
|
+
const logger_1 = require("../../../logger");
|
|
13
|
+
const apiRequestV4_1 = require("../apiRequestV4");
|
|
14
|
+
const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
|
|
15
|
+
const query_1 = require("./query");
|
|
16
|
+
async function getOptionsFromGithub(options) {
|
|
17
|
+
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
18
|
+
let res;
|
|
19
|
+
const spinner = (0, ora_1.default)().start('Initializing...');
|
|
20
|
+
try {
|
|
21
|
+
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
22
|
+
githubApiBaseUrlV4,
|
|
23
|
+
accessToken,
|
|
24
|
+
query: query_1.query,
|
|
25
|
+
variables: { repoOwner, repoName },
|
|
26
|
+
handleError: false,
|
|
27
|
+
});
|
|
28
|
+
spinner.stop();
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
spinner.stop();
|
|
32
|
+
const error = e;
|
|
33
|
+
(0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
|
|
34
|
+
error,
|
|
35
|
+
repoName,
|
|
36
|
+
repoOwner,
|
|
37
|
+
});
|
|
38
|
+
res = handleMissingConfigFile(error);
|
|
39
|
+
}
|
|
40
|
+
// get the original repo (not the fork)
|
|
41
|
+
const repo = res.repository.isFork ? res.repository.parent : res.repository;
|
|
42
|
+
// it is not possible to have a branch named "backport"
|
|
43
|
+
if (repo.ref?.name === 'backport') {
|
|
44
|
+
throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
45
|
+
}
|
|
46
|
+
const historicalRemoteConfigs = repo.defaultBranchRef.target.history.edges;
|
|
47
|
+
const latestRemoteConfig = historicalRemoteConfigs[0]?.remoteConfig;
|
|
48
|
+
const skipRemoteConfig = await getSkipRemoteConfigFile(options.skipRemoteConfig, latestRemoteConfig);
|
|
49
|
+
return {
|
|
50
|
+
authenticatedUsername: res.viewer.login,
|
|
51
|
+
sourceBranch: repo.defaultBranchRef.name,
|
|
52
|
+
...(skipRemoteConfig ? {} : parseRemoteConfig(latestRemoteConfig)),
|
|
53
|
+
historicalBranchLabelMappings: skipRemoteConfig
|
|
54
|
+
? []
|
|
55
|
+
: getHistoricalBranchLabelMappings(historicalRemoteConfigs),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.getOptionsFromGithub = getOptionsFromGithub;
|
|
59
|
+
async function getSkipRemoteConfigFile(skipRemoteConfig, remoteConfig) {
|
|
60
|
+
if (skipRemoteConfig) {
|
|
61
|
+
logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (!remoteConfig) {
|
|
65
|
+
logger_1.logger.info("Skipping remote config: remote config doesn't exist");
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
|
|
69
|
+
(0, git_1.isLocalConfigFileModified)(),
|
|
70
|
+
(0, git_1.isLocalConfigFileUntracked)(),
|
|
71
|
+
(0, git_1.getLocalConfigFileCommitDate)(),
|
|
72
|
+
]);
|
|
73
|
+
if (isLocalConfigUntracked) {
|
|
74
|
+
logger_1.logger.info('Skipping remote config: local config is new');
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (isLocalConfigModified) {
|
|
78
|
+
logger_1.logger.info('Skipping remote config: local config is modified');
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (localCommitDate &&
|
|
82
|
+
localCommitDate > Date.parse(remoteConfig.committedDate)) {
|
|
83
|
+
logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
function parseRemoteConfig(remoteConfig) {
|
|
89
|
+
if (!remoteConfig) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
logger_1.logger.info('Using remote config');
|
|
94
|
+
return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(remoteConfig.file.object.text));
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
logger_1.logger.info('Parsing remote config failed', e);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getHistoricalBranchLabelMappings(historicalRemoteConfigs) {
|
|
102
|
+
return historicalRemoteConfigs
|
|
103
|
+
.map((edge) => {
|
|
104
|
+
try {
|
|
105
|
+
const remoteConfig = JSON.parse(edge.remoteConfig.file.object.text);
|
|
106
|
+
if (!remoteConfig.branchLabelMapping) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
branchLabelMapping: remoteConfig.branchLabelMapping,
|
|
111
|
+
committedDate: edge.remoteConfig.committedDate,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
logger_1.logger.info('Could not get historical remote config', e);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
.filter(filterEmpty_1.filterNil);
|
|
120
|
+
}
|
|
121
|
+
function handleMissingConfigFile(error) {
|
|
122
|
+
const wasMissingConfigError = error.response?.data.errors?.some((error) => error.type === 'NOT_FOUND' &&
|
|
123
|
+
error.path.join('.') ===
|
|
124
|
+
'repository.defaultBranchRef.target.history.edges.0.remoteConfig.file');
|
|
125
|
+
// Throw unexpected error
|
|
126
|
+
if (!wasMissingConfigError || !error.response?.data.data) {
|
|
127
|
+
throw (0, apiRequestV4_1.handleGithubV4Error)(error);
|
|
128
|
+
}
|
|
129
|
+
return error.response.data.data;
|
|
130
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
const os_1 = __importDefault(require("os"));
|
|
7
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
8
|
+
const getOptionsFromGithub_1 = require("./getOptionsFromGithub");
|
|
9
|
+
describe('getOptionsFromGithub', () => {
|
|
10
|
+
let devAccessToken;
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
13
|
+
jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
|
|
14
|
+
});
|
|
15
|
+
describe('access token', () => {
|
|
16
|
+
describe('is invalid', () => {
|
|
17
|
+
it('throws an error', async () => {
|
|
18
|
+
const combinedOptions = {
|
|
19
|
+
author: 'sqren',
|
|
20
|
+
accessToken: 'foo',
|
|
21
|
+
repoOwner: 'backport-org',
|
|
22
|
+
repoName: 'backport-e2e',
|
|
23
|
+
};
|
|
24
|
+
await expect((0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('is valid', () => {
|
|
28
|
+
it('returns the options', async () => {
|
|
29
|
+
const combinedOptions = {
|
|
30
|
+
author: 'sqren',
|
|
31
|
+
accessToken: devAccessToken,
|
|
32
|
+
repoOwner: 'backport-org',
|
|
33
|
+
repoName: 'backport-e2e',
|
|
34
|
+
};
|
|
35
|
+
expect(await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).toEqual({
|
|
36
|
+
authenticatedUsername: 'sqren',
|
|
37
|
+
branchLabelMapping: {
|
|
38
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
39
|
+
'^v7.9.0$': '7.x',
|
|
40
|
+
'^v8.0.0$': 'master',
|
|
41
|
+
},
|
|
42
|
+
historicalBranchLabelMappings: [
|
|
43
|
+
{
|
|
44
|
+
branchLabelMapping: {
|
|
45
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
46
|
+
'^v7.9.0$': '7.x',
|
|
47
|
+
'^v8.0.0$': 'master',
|
|
48
|
+
},
|
|
49
|
+
committedDate: '2020-08-15T10:33:06Z',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
|
|
53
|
+
committedDate: '2020-08-15T10:20:23Z',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
|
|
57
|
+
committedDate: '2020-08-15T10:17:57Z',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
sourceBranch: 'master',
|
|
61
|
+
targetBranchChoices: [
|
|
62
|
+
{ checked: true, name: 'master' },
|
|
63
|
+
{ checked: true, name: '7.x' },
|
|
64
|
+
'7.8',
|
|
65
|
+
],
|
|
66
|
+
targetPRLabels: ['backport'],
|
|
67
|
+
repoOwner: 'backport-org',
|
|
68
|
+
repoName: 'backport-e2e',
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('when `repoOwner` is fork', () => {
|
|
74
|
+
it('returns original repoOwner', async () => {
|
|
75
|
+
const combinedOptions = {
|
|
76
|
+
author: 'sqren',
|
|
77
|
+
accessToken: devAccessToken,
|
|
78
|
+
repoOwner: 'sqren',
|
|
79
|
+
repoName: 'backport-e2e',
|
|
80
|
+
};
|
|
81
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
82
|
+
await expect(options.repoOwner).toEqual('backport-org');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('sourceBranch', () => {
|
|
86
|
+
describe('when no sourceBranch is specified', () => {
|
|
87
|
+
it('uses the default branch of the repo', async () => {
|
|
88
|
+
const combinedOptions = {
|
|
89
|
+
author: 'sqren',
|
|
90
|
+
accessToken: devAccessToken,
|
|
91
|
+
repoOwner: 'backport-org',
|
|
92
|
+
repoName: 'repo-with-non-standard-main-branch',
|
|
93
|
+
};
|
|
94
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
95
|
+
await expect(options.sourceBranch).toEqual('my-custom-default-branch');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('when a branch named "backport"', () => {
|
|
100
|
+
describe('exists', () => {
|
|
101
|
+
it('shows a warning', async () => {
|
|
102
|
+
const combinedOptions = {
|
|
103
|
+
author: 'sqren',
|
|
104
|
+
accessToken: devAccessToken,
|
|
105
|
+
repoOwner: 'backport-org',
|
|
106
|
+
repoName: 'repo-with-branch-named-backport',
|
|
107
|
+
};
|
|
108
|
+
await expect(async () => {
|
|
109
|
+
await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
110
|
+
}).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe('when a backportrc.json config was deleted from repo', () => {
|
|
115
|
+
it('does not throw', async () => {
|
|
116
|
+
const combinedOptions = {
|
|
117
|
+
author: 'sqren',
|
|
118
|
+
accessToken: devAccessToken,
|
|
119
|
+
repoOwner: 'backport-org',
|
|
120
|
+
repoName: 'repo-with-backportrc-removed',
|
|
121
|
+
};
|
|
122
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
123
|
+
expect(options).toEqual({
|
|
124
|
+
authenticatedUsername: 'sqren',
|
|
125
|
+
sourceBranch: 'main',
|
|
126
|
+
historicalBranchLabelMappings: [],
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|