backport 7.2.0-beta.2 → 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/entrypoint.cli.private.test.d.ts +1 -0
- package/dist/entrypoint.cli.private.test.js +46 -0
- package/dist/options/cliArgs.test.d.ts +1 -0
- package/dist/options/cliArgs.test.js +182 -0
- package/dist/options/config/config.test.d.ts +1 -0
- package/dist/options/config/config.test.js +32 -0
- package/dist/options/config/globalConfig.test.d.ts +1 -0
- package/dist/options/config/globalConfig.test.js +61 -0
- package/dist/options/config/projectConfig.test.d.ts +1 -0
- package/dist/options/config/projectConfig.test.js +109 -0
- package/dist/options/options.test.d.ts +1 -0
- package/dist/options/options.test.js +384 -0
- package/dist/runSequentially.test.d.ts +1 -0
- package/dist/runSequentially.test.js +243 -0
- package/dist/scripts/postinstall.test.d.ts +1 -0
- package/dist/scripts/postinstall.test.js +53 -0
- package/dist/services/env.test.d.ts +1 -0
- package/dist/services/env.test.js +21 -0
- package/dist/services/git.d.ts +1 -3
- package/dist/services/git.integration.test.d.ts +1 -0
- package/dist/services/git.integration.test.js +320 -0
- package/dist/services/git.js +5 -3
- package/dist/services/git.test.d.ts +1 -0
- package/dist/services/git.test.js +532 -0
- package/dist/services/github/commitFormatters.test.d.ts +1 -0
- package/dist/services/github/commitFormatters.test.js +11 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/addAssigneesToPullRequest.test.js +27 -0
- package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
- package/dist/services/github/v3/createPullRequest.test.js +325 -0
- package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
- package/dist/services/github/v3/createStatusComment.test.js +386 -0
- package/dist/services/github/v4/apiRequestV4.test.d.ts +1 -0
- package/dist/services/github/v4/apiRequestV4.test.js +109 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
- package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchAuthorId.private.test.js +28 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +134 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +116 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +195 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +152 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +102 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +47 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
- package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +117 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +71 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +156 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +87 -0
- package/dist/services/prompt.test.d.ts +1 -0
- package/dist/services/prompt.test.js +134 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
- package/dist/services/sourceCommit/parseSourceCommit.test.js +225 -0
- package/dist/test/ExecError.d.ts +16 -0
- package/dist/test/ExecError.js +15 -0
- package/dist/test/e2e/cli.e2e.private.test.d.ts +1 -0
- package/dist/test/e2e/cli.e2e.private.test.js +433 -0
- package/dist/test/e2e/module.e2e.private.test.d.ts +1 -0
- package/dist/test/e2e/module.e2e.private.test.js +363 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +1 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +55 -0
- package/dist/test/mockConfigFiles.d.ts +5 -0
- package/dist/test/mockConfigFiles.js +21 -0
- package/dist/test/mocks.d.ts +10 -0
- package/dist/test/mocks.js +23 -0
- package/dist/test/nockHelpers.d.ts +16 -0
- package/dist/test/nockHelpers.js +36 -0
- package/dist/test/private/getDevAccessToken.d.ts +2 -0
- package/dist/test/private/getDevAccessToken.js +12 -0
- package/dist/test/sandbox.d.ts +5 -0
- package/dist/test/sandbox.js +43 -0
- package/dist/test/setupFiles/automatic-mocks.d.ts +1 -0
- package/dist/test/setupFiles/automatic-mocks.js +63 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +459 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +311 -0
- package/dist/ui/getTargetBranches.test.d.ts +1 -0
- package/dist/ui/getTargetBranches.test.js +198 -0
- package/dist/ui/maybeSetupRepo.js +7 -3
- package/dist/ui/maybeSetupRepo.test.d.ts +1 -0
- package/dist/ui/maybeSetupRepo.test.js +238 -0
- package/dist/ui/ora.d.ts +1 -1
- package/dist/ui/ora.js +2 -2
- package/dist/utils/excludeUndefined.test.d.ts +1 -0
- package/dist/utils/excludeUndefined.test.js +24 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
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 nock_1 = __importDefault(require("nock"));
|
|
7
|
+
const nockHelpers_1 = require("../../../../test/nockHelpers");
|
|
8
|
+
const commitsByAuthorMock_1 = require("../mocks/commitsByAuthorMock");
|
|
9
|
+
const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
|
|
10
|
+
const defaultOptions = {
|
|
11
|
+
accessToken: 'myAccessToken',
|
|
12
|
+
author: 'sqren',
|
|
13
|
+
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
14
|
+
maxNumber: 10,
|
|
15
|
+
repoName: 'kibana',
|
|
16
|
+
repoOwner: 'elastic',
|
|
17
|
+
sourceBranch: 'source-branch-from-options',
|
|
18
|
+
dateSince: null,
|
|
19
|
+
dateUntil: null,
|
|
20
|
+
};
|
|
21
|
+
const authorIdMockData = { user: { id: 'myUserId' } };
|
|
22
|
+
describe('fetchCommitsByAuthor', () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
jest.clearAllMocks();
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
nock_1.default.cleanAll();
|
|
28
|
+
});
|
|
29
|
+
describe('when commit has an associated pull request', () => {
|
|
30
|
+
let res;
|
|
31
|
+
let authorIdCalls;
|
|
32
|
+
let commitsByAuthorCalls;
|
|
33
|
+
beforeEach(async () => {
|
|
34
|
+
authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
35
|
+
name: 'AuthorId',
|
|
36
|
+
statusCode: 200,
|
|
37
|
+
body: { data: authorIdMockData },
|
|
38
|
+
});
|
|
39
|
+
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
40
|
+
name: 'CommitsByAuthor',
|
|
41
|
+
statusCode: 200,
|
|
42
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
43
|
+
});
|
|
44
|
+
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)(defaultOptions);
|
|
45
|
+
});
|
|
46
|
+
it('should return a list of commits with pullNumber and existing backports', () => {
|
|
47
|
+
const expectedCommits = [
|
|
48
|
+
{
|
|
49
|
+
sourceCommit: {
|
|
50
|
+
committedDate: '2021-12-24T00:00:00Z',
|
|
51
|
+
sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
|
|
52
|
+
message: 'Add 👻',
|
|
53
|
+
},
|
|
54
|
+
expectedTargetPullRequests: [],
|
|
55
|
+
sourceBranch: 'source-branch-from-options',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
sourceCommit: {
|
|
59
|
+
committedDate: '2021-12-23T00:00:00Z',
|
|
60
|
+
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
61
|
+
message: 'Add witch (#85)',
|
|
62
|
+
},
|
|
63
|
+
sourcePullRequest: {
|
|
64
|
+
number: 85,
|
|
65
|
+
url: 'https://github.com/elastic/kibana/pull/85',
|
|
66
|
+
mergeCommit: {
|
|
67
|
+
sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
|
|
68
|
+
message: 'Add witch (#85)',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
expectedTargetPullRequests: [],
|
|
72
|
+
sourceBranch: 'master',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
sourceCommit: {
|
|
76
|
+
committedDate: '2021-12-22T00:00:00Z',
|
|
77
|
+
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
78
|
+
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
79
|
+
},
|
|
80
|
+
sourcePullRequest: {
|
|
81
|
+
number: 80,
|
|
82
|
+
url: 'https://github.com/elastic/kibana/pull/80',
|
|
83
|
+
mergeCommit: {
|
|
84
|
+
sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
|
|
85
|
+
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
expectedTargetPullRequests: [
|
|
89
|
+
{
|
|
90
|
+
branch: '6.3',
|
|
91
|
+
state: 'MERGED',
|
|
92
|
+
number: 99,
|
|
93
|
+
url: 'https://github.com/elastic/kibana/pull/99',
|
|
94
|
+
mergeCommit: {
|
|
95
|
+
message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
|
|
96
|
+
sha: 'target-merge-commit-sha',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
sourceBranch: 'master',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
sourceCommit: {
|
|
104
|
+
committedDate: '2021-12-21T00:00:00Z',
|
|
105
|
+
sha: '3827bbbaf39914eda4f02f6940189844375fd097',
|
|
106
|
+
message: 'Add backport config',
|
|
107
|
+
},
|
|
108
|
+
expectedTargetPullRequests: [],
|
|
109
|
+
sourceBranch: 'source-branch-from-options',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
sourceCommit: {
|
|
113
|
+
committedDate: '2021-12-20T00:00:00Z',
|
|
114
|
+
sha: '5ea0da550ac191029459289d67f99ad7d310812b',
|
|
115
|
+
message: 'Initial commit',
|
|
116
|
+
},
|
|
117
|
+
expectedTargetPullRequests: [],
|
|
118
|
+
sourceBranch: 'source-branch-from-options',
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
expect(res).toEqual(expectedCommits);
|
|
122
|
+
});
|
|
123
|
+
it('should call with correct args to fetch author id', () => {
|
|
124
|
+
expect(authorIdCalls).toMatchSnapshot();
|
|
125
|
+
});
|
|
126
|
+
it('should call with correct args to fetch commits', () => {
|
|
127
|
+
expect(commitsByAuthorCalls).toMatchSnapshot();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('when a custom github api hostname is supplied', () => {
|
|
131
|
+
it('should be used in gql requests', async () => {
|
|
132
|
+
const authorIdCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
133
|
+
name: 'AuthorId',
|
|
134
|
+
statusCode: 200,
|
|
135
|
+
body: { data: authorIdMockData },
|
|
136
|
+
apiBaseUrl: 'http://localhost/my-custom-api',
|
|
137
|
+
});
|
|
138
|
+
const commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
139
|
+
name: 'CommitsByAuthor',
|
|
140
|
+
statusCode: 200,
|
|
141
|
+
body: { data: commitsByAuthorMock_1.commitsByAuthorMock },
|
|
142
|
+
apiBaseUrl: 'http://localhost/my-custom-api',
|
|
143
|
+
});
|
|
144
|
+
await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
145
|
+
...defaultOptions,
|
|
146
|
+
githubApiBaseUrlV4: 'http://localhost/my-custom-api',
|
|
147
|
+
});
|
|
148
|
+
expect(authorIdCalls.length).toBe(1);
|
|
149
|
+
expect(commitsByAuthorCalls.length).toBe(1);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchPullRequestBySearchQuery_1 = require("./fetchPullRequestBySearchQuery");
|
|
5
|
+
describe('fetchPullRequestBySearchQuery', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
describe('when filter does not match any PRs', () => {
|
|
11
|
+
it('throws an error', async () => {
|
|
12
|
+
const options = {
|
|
13
|
+
accessToken: devAccessToken,
|
|
14
|
+
maxNumber: 10,
|
|
15
|
+
prFilter: 'label:non-existing',
|
|
16
|
+
repoName: 'backport-e2e',
|
|
17
|
+
repoOwner: 'backport-org',
|
|
18
|
+
sourceBranch: 'master',
|
|
19
|
+
author: 'sqren',
|
|
20
|
+
};
|
|
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');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('when filter matches PRs', () => {
|
|
25
|
+
it('returns the merge commits for those PRs', async () => {
|
|
26
|
+
const options = {
|
|
27
|
+
accessToken: devAccessToken,
|
|
28
|
+
maxNumber: 10,
|
|
29
|
+
prFilter: 'label:v7.8.0',
|
|
30
|
+
repoName: 'backport-e2e',
|
|
31
|
+
repoOwner: 'backport-org',
|
|
32
|
+
sourceBranch: 'master',
|
|
33
|
+
author: 'sqren',
|
|
34
|
+
};
|
|
35
|
+
const expectedCommits = [
|
|
36
|
+
{
|
|
37
|
+
sourceCommit: {
|
|
38
|
+
committedDate: '2020-08-16T21:44:28Z',
|
|
39
|
+
message: 'Add sheep emoji (#9)',
|
|
40
|
+
sha: 'eebf165c82a4b718d95c11b3877e365b1949ff28',
|
|
41
|
+
},
|
|
42
|
+
sourcePullRequest: {
|
|
43
|
+
number: 9,
|
|
44
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/9',
|
|
45
|
+
mergeCommit: {
|
|
46
|
+
message: 'Add sheep emoji (#9)',
|
|
47
|
+
sha: 'eebf165c82a4b718d95c11b3877e365b1949ff28',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
sourceBranch: 'master',
|
|
51
|
+
expectedTargetPullRequests: [
|
|
52
|
+
{
|
|
53
|
+
branch: '7.8',
|
|
54
|
+
state: 'OPEN',
|
|
55
|
+
number: 10,
|
|
56
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/10',
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
sourceCommit: {
|
|
62
|
+
committedDate: '2020-08-15T12:40:19Z',
|
|
63
|
+
message: 'Add 🍏 emoji (#5)',
|
|
64
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
65
|
+
},
|
|
66
|
+
sourcePullRequest: {
|
|
67
|
+
number: 5,
|
|
68
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/5',
|
|
69
|
+
mergeCommit: {
|
|
70
|
+
message: 'Add 🍏 emoji (#5)',
|
|
71
|
+
sha: 'ee8c492334cef1ca077a56addb79a26f79821d2f',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
sourceBranch: 'master',
|
|
75
|
+
expectedTargetPullRequests: [
|
|
76
|
+
{
|
|
77
|
+
branch: '7.x',
|
|
78
|
+
state: 'MERGED',
|
|
79
|
+
number: 6,
|
|
80
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/6',
|
|
81
|
+
mergeCommit: {
|
|
82
|
+
message: 'Add 🍏 emoji (#5) (#6)',
|
|
83
|
+
sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
branch: '7.8',
|
|
88
|
+
state: 'MERGED',
|
|
89
|
+
number: 7,
|
|
90
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/7',
|
|
91
|
+
mergeCommit: {
|
|
92
|
+
message: 'Add 🍏 emoji (#5) (#7)',
|
|
93
|
+
sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
expect(await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)(options)).toEqual(expectedCommits);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
4
|
+
const fetchExistingPullRequest_1 = require("./fetchExistingPullRequest");
|
|
5
|
+
describe('fetchExistingPullRequest', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
describe('when PR does not exist', () => {
|
|
11
|
+
it('returns undefined', async () => {
|
|
12
|
+
const options = {
|
|
13
|
+
accessToken: devAccessToken,
|
|
14
|
+
};
|
|
15
|
+
const prPayload = {
|
|
16
|
+
owner: 'backport-org',
|
|
17
|
+
repo: 'backport-e2e',
|
|
18
|
+
title: 'My PR title',
|
|
19
|
+
body: 'My PR body',
|
|
20
|
+
head: 'sqren:backport/7.8/pr-foo',
|
|
21
|
+
base: '7.8',
|
|
22
|
+
};
|
|
23
|
+
const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
|
|
24
|
+
expect(res).toBe(undefined);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('when PR exists', () => {
|
|
28
|
+
it('returns the PR number and url', async () => {
|
|
29
|
+
const options = {
|
|
30
|
+
accessToken: devAccessToken,
|
|
31
|
+
};
|
|
32
|
+
const prPayload = {
|
|
33
|
+
owner: 'backport-org',
|
|
34
|
+
repo: 'backport-e2e',
|
|
35
|
+
title: 'My PR title',
|
|
36
|
+
body: 'My PR body',
|
|
37
|
+
head: 'sqren:backport/7.8/pr-9',
|
|
38
|
+
base: '7.8',
|
|
39
|
+
};
|
|
40
|
+
const res = await (0, fetchExistingPullRequest_1.fetchExistingPullRequest)({ options, prPayload });
|
|
41
|
+
expect(res).toEqual({
|
|
42
|
+
url: 'https://github.com/backport-org/backport-e2e/pull/10',
|
|
43
|
+
number: 10,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -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 fetchRemoteProjectConfig_1 = require("./fetchRemoteProjectConfig");
|
|
5
|
+
describe('fetchRemoteProjectConfig', () => {
|
|
6
|
+
let devAccessToken;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
|
+
});
|
|
10
|
+
it('returns the backport config from "main" branch', async () => {
|
|
11
|
+
const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
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, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
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, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
|
|
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,117 @@
|
|
|
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 = (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
|
+
cwd: process.cwd(),
|
|
24
|
+
};
|
|
25
|
+
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');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
describe('is valid', () => {
|
|
29
|
+
it('returns the options', async () => {
|
|
30
|
+
const combinedOptions = {
|
|
31
|
+
author: 'sqren',
|
|
32
|
+
accessToken: devAccessToken,
|
|
33
|
+
repoOwner: 'backport-org',
|
|
34
|
+
repoName: 'backport-e2e',
|
|
35
|
+
cwd: process.cwd(),
|
|
36
|
+
};
|
|
37
|
+
expect(await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).toEqual({
|
|
38
|
+
authenticatedUsername: 'sqren',
|
|
39
|
+
branchLabelMapping: {
|
|
40
|
+
'^v(\\d+).(\\d+).\\d+$': '$1.$2',
|
|
41
|
+
'^v7.9.0$': '7.x',
|
|
42
|
+
'^v8.0.0$': 'master',
|
|
43
|
+
},
|
|
44
|
+
sourceBranch: 'master',
|
|
45
|
+
targetBranchChoices: [
|
|
46
|
+
{ checked: true, name: 'master' },
|
|
47
|
+
{ checked: true, name: '7.x' },
|
|
48
|
+
'7.8',
|
|
49
|
+
],
|
|
50
|
+
targetPRLabels: ['backport'],
|
|
51
|
+
repoOwner: 'backport-org',
|
|
52
|
+
repoName: 'backport-e2e',
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('when `repoOwner` is fork', () => {
|
|
58
|
+
it('returns original repoOwner', async () => {
|
|
59
|
+
const combinedOptions = {
|
|
60
|
+
author: 'sqren',
|
|
61
|
+
accessToken: devAccessToken,
|
|
62
|
+
repoOwner: 'sqren',
|
|
63
|
+
repoName: 'backport-e2e',
|
|
64
|
+
cwd: process.cwd(),
|
|
65
|
+
};
|
|
66
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
67
|
+
await expect(options.repoOwner).toEqual('backport-org');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('sourceBranch', () => {
|
|
71
|
+
describe('when no sourceBranch is specified', () => {
|
|
72
|
+
it('uses the default branch of the repo', async () => {
|
|
73
|
+
const combinedOptions = {
|
|
74
|
+
author: 'sqren',
|
|
75
|
+
accessToken: devAccessToken,
|
|
76
|
+
repoOwner: 'backport-org',
|
|
77
|
+
repoName: 'repo-with-non-standard-main-branch',
|
|
78
|
+
cwd: process.cwd(),
|
|
79
|
+
};
|
|
80
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
81
|
+
await expect(options.sourceBranch).toEqual('my-custom-default-branch');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('when a branch named "backport"', () => {
|
|
86
|
+
describe('exists', () => {
|
|
87
|
+
it('shows a warning', async () => {
|
|
88
|
+
const combinedOptions = {
|
|
89
|
+
author: 'sqren',
|
|
90
|
+
accessToken: devAccessToken,
|
|
91
|
+
repoOwner: 'backport-org',
|
|
92
|
+
repoName: 'repo-with-branch-named-backport',
|
|
93
|
+
cwd: process.cwd(),
|
|
94
|
+
};
|
|
95
|
+
await expect(async () => {
|
|
96
|
+
await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
97
|
+
}).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe('when a backportrc.json config was deleted from repo', () => {
|
|
102
|
+
it('does not throw', async () => {
|
|
103
|
+
const combinedOptions = {
|
|
104
|
+
author: 'sqren',
|
|
105
|
+
accessToken: devAccessToken,
|
|
106
|
+
repoOwner: 'backport-org',
|
|
107
|
+
repoName: 'repo-with-backportrc-removed',
|
|
108
|
+
cwd: process.cwd(),
|
|
109
|
+
};
|
|
110
|
+
const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
|
|
111
|
+
expect(options).toEqual({
|
|
112
|
+
authenticatedUsername: 'sqren',
|
|
113
|
+
sourceBranch: 'main',
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
|
|
23
|
+
const sandbox_1 = require("../../../test/sandbox");
|
|
24
|
+
const childProcess = __importStar(require("../../child-process-promisified"));
|
|
25
|
+
const getRepoOwnerAndNameFromGitRemotes_1 = require("./getRepoOwnerAndNameFromGitRemotes");
|
|
26
|
+
const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
|
|
27
|
+
describe('fetchRemoteProjectConfig', () => {
|
|
28
|
+
let devAccessToken;
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
devAccessToken = (0, getDevAccessToken_1.getDevAccessToken)();
|
|
31
|
+
});
|
|
32
|
+
describe('when the remote is a fork', () => {
|
|
33
|
+
it('retrives the original owner from github', async () => {
|
|
34
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
35
|
+
const execOpts = { cwd: sandboxPath };
|
|
36
|
+
await childProcess.exec(`git init`, execOpts);
|
|
37
|
+
await childProcess.exec(`git remote add sqren git@github.com:sqren/kibana.git`, execOpts);
|
|
38
|
+
expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
|
|
39
|
+
accessToken: devAccessToken,
|
|
40
|
+
cwd: sandboxPath,
|
|
41
|
+
})).toEqual({
|
|
42
|
+
repoName: 'kibana',
|
|
43
|
+
repoOwner: 'elastic',
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('when none of the git remotes are found', () => {
|
|
48
|
+
it('swallows the error and returns empty', async () => {
|
|
49
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
50
|
+
const execOpts = { cwd: sandboxPath };
|
|
51
|
+
await childProcess.exec(`git init`, execOpts);
|
|
52
|
+
await childProcess.exec(`git remote add foo git@github.com:foo/kibana.git`, execOpts);
|
|
53
|
+
await childProcess.exec(`git remote add bar git@github.com:bar/kibana.git`, execOpts);
|
|
54
|
+
expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
|
|
55
|
+
accessToken: devAccessToken,
|
|
56
|
+
cwd: sandboxPath,
|
|
57
|
+
})).toEqual({});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('when there are no git remotes', () => {
|
|
61
|
+
it('returns empty', async () => {
|
|
62
|
+
await (0, sandbox_1.resetSandbox)(sandboxPath);
|
|
63
|
+
const execOpts = { cwd: sandboxPath };
|
|
64
|
+
await childProcess.exec(`git init`, execOpts);
|
|
65
|
+
expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
|
|
66
|
+
accessToken: devAccessToken,
|
|
67
|
+
cwd: sandboxPath,
|
|
68
|
+
})).toEqual({});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|