backport 6.0.0 → 6.1.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/README.md +179 -52
- 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 +34 -0
- package/dist/main.js +1 -2
- package/dist/options/ConfigOptions.d.ts +16 -6
- package/dist/options/cliArgs.d.ts +36 -37
- package/dist/options/cliArgs.js +25 -24
- package/dist/options/cliArgs.test.js +6 -10
- package/dist/options/config/config.d.ts +28 -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 +2 -5
- 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 +52 -0
- package/dist/options/config/readConfigFile.js +28 -2
- package/dist/options/options.d.ts +55 -32
- package/dist/options/options.js +101 -7
- package/dist/options/options.test.js +248 -97
- 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 +40 -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 +110 -0
- package/dist/services/github/v3/createStatusComment.js +12 -14
- package/dist/services/github/v3/createStatusComment.test.js +58 -29
- 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 +67 -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 +32 -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 +33 -36
- package/dist/test/integration/integration.private.test.js +114 -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 +80 -28
- package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +13 -48
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +222 -260
- package/dist/ui/getCommits.d.ts +1 -1
- package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
- package/dist/ui/getCommitsWithoutBackports.js +53 -0
- package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
- package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
- 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
|
@@ -5,7 +5,9 @@ const createStatusComment_1 = require("./createStatusComment");
|
|
|
5
5
|
describe('getCommentBody', () => {
|
|
6
6
|
it('when an unknown error occurs', () => {
|
|
7
7
|
expect((0, createStatusComment_1.getCommentBody)({
|
|
8
|
-
options: {
|
|
8
|
+
options: {
|
|
9
|
+
backportBinary: 'node scripts/backport',
|
|
10
|
+
},
|
|
9
11
|
pullNumber: 55,
|
|
10
12
|
backportResponse: {
|
|
11
13
|
status: 'failure',
|
|
@@ -16,9 +18,15 @@ describe('getCommentBody', () => {
|
|
|
16
18
|
The pull request could not be backported due to the following error:
|
|
17
19
|
\`A terrible error occured\`
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
## How to fix
|
|
22
|
+
|
|
23
|
+
Re-run the backport manually:
|
|
24
|
+
\`\`\`
|
|
25
|
+
node scripts/backport --pr 55
|
|
26
|
+
\`\`\`
|
|
27
|
+
|
|
28
|
+
### Questions ?
|
|
29
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
22
30
|
`);
|
|
23
31
|
});
|
|
24
32
|
it('when all backports succeed', () => {
|
|
@@ -50,12 +58,14 @@ describe('getCommentBody', () => {
|
|
|
50
58
|
"## 💚 All backports created successfully
|
|
51
59
|
|
|
52
60
|
| Status | Branch | Result |
|
|
53
|
-
|
|
61
|
+
|:------:|:------:|:------|
|
|
54
62
|
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
|
|
55
63
|
|✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
|
|
56
64
|
|
|
57
65
|
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
58
|
-
|
|
66
|
+
|
|
67
|
+
### Questions ?
|
|
68
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
59
69
|
`);
|
|
60
70
|
});
|
|
61
71
|
it('when all backports fail', () => {
|
|
@@ -64,6 +74,7 @@ describe('getCommentBody', () => {
|
|
|
64
74
|
repoName: 'kibana',
|
|
65
75
|
repoOwner: 'elastic',
|
|
66
76
|
autoMerge: true,
|
|
77
|
+
backportBinary: 'node scripts/backport',
|
|
67
78
|
},
|
|
68
79
|
pullNumber: 55,
|
|
69
80
|
backportResponse: {
|
|
@@ -87,14 +98,19 @@ describe('getCommentBody', () => {
|
|
|
87
98
|
"## 💔 Some backports could not be created
|
|
88
99
|
|
|
89
100
|
| Status | Branch | Result |
|
|
90
|
-
|
|
101
|
+
|:------:|:------:|:------|
|
|
91
102
|
|❌|7.x|My boom error!|
|
|
92
103
|
|❌|7.1|My boom error!|
|
|
93
104
|
|
|
94
|
-
|
|
95
|
-
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
105
|
+
## How to fix
|
|
96
106
|
|
|
97
|
-
|
|
107
|
+
Re-run the backport manually:
|
|
108
|
+
\`\`\`
|
|
109
|
+
node scripts/backport --pr 55
|
|
110
|
+
\`\`\`
|
|
111
|
+
|
|
112
|
+
### Questions ?
|
|
113
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
98
114
|
`);
|
|
99
115
|
});
|
|
100
116
|
it('when some backports fail', () => {
|
|
@@ -103,6 +119,7 @@ describe('getCommentBody', () => {
|
|
|
103
119
|
repoName: 'kibana',
|
|
104
120
|
repoOwner: 'elastic',
|
|
105
121
|
autoMerge: true,
|
|
122
|
+
backportBinary: 'node scripts/backport',
|
|
106
123
|
},
|
|
107
124
|
pullNumber: 55,
|
|
108
125
|
backportResponse: {
|
|
@@ -126,15 +143,20 @@ describe('getCommentBody', () => {
|
|
|
126
143
|
"## 💔 Some backports could not be created
|
|
127
144
|
|
|
128
145
|
| Status | Branch | Result |
|
|
129
|
-
|
|
146
|
+
|:------:|:------:|:------|
|
|
130
147
|
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
131
148
|
|❌|7.1|My boom error!|
|
|
132
149
|
|
|
133
|
-
|
|
134
|
-
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
150
|
+
## How to fix
|
|
135
151
|
|
|
152
|
+
Re-run the backport manually:
|
|
153
|
+
\`\`\`
|
|
154
|
+
node scripts/backport --pr 55
|
|
155
|
+
\`\`\`
|
|
136
156
|
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
137
|
-
|
|
157
|
+
|
|
158
|
+
### Questions ?
|
|
159
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
138
160
|
`);
|
|
139
161
|
});
|
|
140
162
|
it('when some backports fail due to conflicts', () => {
|
|
@@ -143,6 +165,7 @@ describe('getCommentBody', () => {
|
|
|
143
165
|
repoName: 'kibana',
|
|
144
166
|
repoOwner: 'elastic',
|
|
145
167
|
autoMerge: true,
|
|
168
|
+
backportBinary: 'node scripts/backport',
|
|
146
169
|
},
|
|
147
170
|
pullNumber: 55,
|
|
148
171
|
backportResponse: {
|
|
@@ -166,6 +189,15 @@ describe('getCommentBody', () => {
|
|
|
166
189
|
commit: {
|
|
167
190
|
pullNumber: 5,
|
|
168
191
|
pullUrl: 'url-to-pr-5',
|
|
192
|
+
originalMessage: 'New Zealand commit message',
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
//@ts-expect-error
|
|
197
|
+
commit: {
|
|
198
|
+
pullNumber: 44,
|
|
199
|
+
pullUrl: 'url-to-pr-44',
|
|
200
|
+
originalMessage: 'Australia commit',
|
|
169
201
|
},
|
|
170
202
|
},
|
|
171
203
|
],
|
|
@@ -177,15 +209,7 @@ describe('getCommentBody', () => {
|
|
|
177
209
|
errorMessage: 'My boom error!',
|
|
178
210
|
error: new HandledError_1.HandledError('Boom!', {
|
|
179
211
|
type: 'commitsWithoutBackports',
|
|
180
|
-
commitsWithoutBackports: [
|
|
181
|
-
{
|
|
182
|
-
//@ts-expect-error
|
|
183
|
-
commit: {
|
|
184
|
-
sha: 'acdefg',
|
|
185
|
-
originalMessage: 'Some long message\nin multiple lines',
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
],
|
|
212
|
+
commitsWithoutBackports: [],
|
|
189
213
|
}),
|
|
190
214
|
},
|
|
191
215
|
],
|
|
@@ -194,16 +218,21 @@ describe('getCommentBody', () => {
|
|
|
194
218
|
"## 💔 Some backports could not be created
|
|
195
219
|
|
|
196
220
|
| Status | Branch | Result |
|
|
197
|
-
|
|
221
|
+
|:------:|:------:|:------|
|
|
198
222
|
|✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
|
|
199
|
-
|❌|7.1
|
|
200
|
-
|❌|7.2
|
|
223
|
+
|❌|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
|
|
224
|
+
|❌|7.2|**Backport failed because of merge conflicts**|
|
|
201
225
|
|
|
202
|
-
|
|
203
|
-
For more info read the [Backport documentation](https://github.com/sqren/backport#backport)
|
|
226
|
+
## How to fix
|
|
204
227
|
|
|
228
|
+
Re-run the backport manually:
|
|
229
|
+
\`\`\`
|
|
230
|
+
node scripts/backport --pr 55
|
|
231
|
+
\`\`\`
|
|
205
232
|
Note: Successful backport PRs will be merged automatically after passing CI.
|
|
206
|
-
|
|
233
|
+
|
|
234
|
+
### Questions ?
|
|
235
|
+
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
|
|
207
236
|
`);
|
|
208
237
|
});
|
|
209
238
|
});
|
|
@@ -13,7 +13,7 @@ export interface GithubV4Response<DataResponse> {
|
|
|
13
13
|
}[];
|
|
14
14
|
}
|
|
15
15
|
export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessToken, query, variables, handleError, }: {
|
|
16
|
-
githubApiBaseUrlV4
|
|
16
|
+
githubApiBaseUrlV4?: string;
|
|
17
17
|
accessToken: string;
|
|
18
18
|
query: string;
|
|
19
19
|
variables?: {
|
|
@@ -7,7 +7,7 @@ exports.handleGithubV4Error = exports.apiRequestV4 = void 0;
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const HandledError_1 = require("../../HandledError");
|
|
9
9
|
const logger_1 = require("../../logger");
|
|
10
|
-
async function apiRequestV4({ githubApiBaseUrlV4, accessToken, query, variables, handleError = true, }) {
|
|
10
|
+
async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, handleError = true, }) {
|
|
11
11
|
try {
|
|
12
12
|
const response = await axios_1.default.post(githubApiBaseUrlV4, { query, variables }, {
|
|
13
13
|
headers: {
|
|
@@ -9,7 +9,7 @@ const logger_1 = require("../../logger");
|
|
|
9
9
|
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
10
10
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
11
11
|
async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
12
|
-
const { accessToken, githubApiBaseUrlV4, autoMergeMethod } = options;
|
|
12
|
+
const { accessToken, githubApiBaseUrlV4, autoMergeMethod = 'merge', } = options;
|
|
13
13
|
const text = `Enabling auto merging via ${options.autoMergeMethod}`;
|
|
14
14
|
logger_1.logger.info(text);
|
|
15
15
|
const spinner = (0, ora_1.default)(text).start();
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { ValidConfigOptions } from '../../../options/options';
|
|
2
1
|
export interface AuthorIdResponse {
|
|
3
2
|
user: {
|
|
4
3
|
id: string;
|
|
5
4
|
};
|
|
6
5
|
}
|
|
7
|
-
export declare function fetchAuthorId(
|
|
6
|
+
export declare function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4, }: {
|
|
7
|
+
accessToken: string;
|
|
8
|
+
author: string | null;
|
|
9
|
+
githubApiBaseUrlV4?: string;
|
|
10
|
+
}): Promise<string | null>;
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchAuthorId = void 0;
|
|
4
4
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
|
-
async function fetchAuthorId(
|
|
6
|
-
|
|
7
|
-
if (all) {
|
|
5
|
+
async function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4 = 'https://api.github.com/graphql', }) {
|
|
6
|
+
if (author === null) {
|
|
8
7
|
return null;
|
|
9
8
|
}
|
|
10
9
|
const query = /* GraphQL */ `
|
|
11
|
-
query AuthorId($
|
|
12
|
-
user(login: $
|
|
10
|
+
query AuthorId($author: String!) {
|
|
11
|
+
user(login: $author) {
|
|
13
12
|
id
|
|
14
13
|
}
|
|
15
14
|
}
|
|
@@ -18,7 +17,7 @@ async function fetchAuthorId(options) {
|
|
|
18
17
|
githubApiBaseUrlV4,
|
|
19
18
|
accessToken,
|
|
20
19
|
query,
|
|
21
|
-
variables: {
|
|
20
|
+
variables: { author },
|
|
22
21
|
});
|
|
23
22
|
return res.user.id;
|
|
24
23
|
}
|
|
@@ -7,22 +7,19 @@ describe('fetchAuthorId', () => {
|
|
|
7
7
|
beforeAll(async () => {
|
|
8
8
|
devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
|
|
9
9
|
});
|
|
10
|
-
describe('
|
|
10
|
+
describe('author = null', () => {
|
|
11
11
|
it('returns null', async () => {
|
|
12
12
|
const options = {
|
|
13
13
|
accessToken: devAccessToken,
|
|
14
|
-
|
|
15
|
-
all: true,
|
|
14
|
+
author: null,
|
|
16
15
|
};
|
|
17
16
|
expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual(null);
|
|
18
17
|
});
|
|
19
18
|
});
|
|
20
|
-
describe('
|
|
19
|
+
describe('author is "sqren"', () => {
|
|
21
20
|
it('returns author id', async () => {
|
|
22
21
|
const options = {
|
|
23
22
|
accessToken: devAccessToken,
|
|
24
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
25
|
-
all: false,
|
|
26
23
|
author: 'sqren',
|
|
27
24
|
};
|
|
28
25
|
expect(await (0, fetchAuthorId_1.fetchAuthorId)(options)).toEqual('MDQ6VXNlcjIwOTk2Ng==');
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../../options/options';
|
|
2
2
|
import { Commit } from '../../../sourceCommit/parseSourceCommit';
|
|
3
|
-
export declare function fetchCommitByPullNumber(options:
|
|
3
|
+
export declare function fetchCommitByPullNumber(options: {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
6
|
+
githubApiBaseUrlV4?: string;
|
|
7
|
+
historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
|
|
4
8
|
pullNumber: number;
|
|
9
|
+
repoName: string;
|
|
10
|
+
repoOwner: string;
|
|
11
|
+
sourceBranch: string;
|
|
5
12
|
}): Promise<Commit>;
|
|
@@ -5,7 +5,7 @@ const HandledError_1 = require("../../../HandledError");
|
|
|
5
5
|
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
6
6
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
7
7
|
async function fetchCommitByPullNumber(options) {
|
|
8
|
-
const { accessToken, githubApiBaseUrlV4, pullNumber, repoName, repoOwner } = options;
|
|
8
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', pullNumber, repoName, repoOwner, } = options;
|
|
9
9
|
const query = /* GraphQL */ `
|
|
10
10
|
query CommitByPullNumber(
|
|
11
11
|
$repoOwner: String!
|
|
@@ -11,10 +11,11 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
11
11
|
it('is returned', async () => {
|
|
12
12
|
const options = {
|
|
13
13
|
accessToken: devAccessToken,
|
|
14
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
15
14
|
pullNumber: 5,
|
|
16
15
|
repoName: 'backport-e2e',
|
|
17
16
|
repoOwner: 'backport-org',
|
|
17
|
+
sourceBranch: 'main',
|
|
18
|
+
historicalBranchLabelMappings: [],
|
|
18
19
|
};
|
|
19
20
|
expect(await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).toEqual({
|
|
20
21
|
committedDate: '2020-08-15T12:40:19Z',
|
|
@@ -44,10 +45,11 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
44
45
|
it('throws an error', async () => {
|
|
45
46
|
const options = {
|
|
46
47
|
accessToken: devAccessToken,
|
|
47
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
48
48
|
pullNumber: 11,
|
|
49
49
|
repoName: 'backport-e2e',
|
|
50
50
|
repoOwner: 'backport-org',
|
|
51
|
+
sourceBranch: 'main',
|
|
52
|
+
historicalBranchLabelMappings: [],
|
|
51
53
|
};
|
|
52
54
|
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
|
|
53
55
|
});
|
|
@@ -56,10 +58,11 @@ describe('fetchCommitByPullNumber', () => {
|
|
|
56
58
|
it('throws an error', async () => {
|
|
57
59
|
const options = {
|
|
58
60
|
accessToken: devAccessToken,
|
|
59
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
60
61
|
pullNumber: 9999999999999,
|
|
61
62
|
repoName: 'backport-e2e',
|
|
62
63
|
repoOwner: 'backport-org',
|
|
64
|
+
sourceBranch: 'main',
|
|
65
|
+
historicalBranchLabelMappings: [],
|
|
63
66
|
};
|
|
64
67
|
await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Unhandled Github v4 error)`);
|
|
65
68
|
});
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../../options/options';
|
|
2
2
|
import { Commit } from '../../../sourceCommit/parseSourceCommit';
|
|
3
|
-
export declare function fetchCommitBySha(options:
|
|
3
|
+
export declare function fetchCommitBySha(options: {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
6
|
+
githubApiBaseUrlV4?: string;
|
|
7
|
+
historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
|
|
8
|
+
repoName: string;
|
|
9
|
+
repoOwner: string;
|
|
4
10
|
sha: string;
|
|
11
|
+
sourceBranch: string;
|
|
5
12
|
}): Promise<Commit>;
|
|
@@ -5,7 +5,7 @@ const HandledError_1 = require("../../../HandledError");
|
|
|
5
5
|
const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
6
6
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
7
7
|
async function fetchCommitBySha(options) {
|
|
8
|
-
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sha, sourceBranch, } = options;
|
|
8
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
|
|
9
9
|
const query = /* GraphQL */ `
|
|
10
10
|
query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
|
|
11
11
|
repository(owner: $repoOwner, name: $repoName) {
|
|
@@ -13,8 +13,8 @@ describe('fetchCommitBySha', () => {
|
|
|
13
13
|
repoName: 'kibana',
|
|
14
14
|
accessToken: devAccessToken,
|
|
15
15
|
sha: 'cb6fbc0',
|
|
16
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
17
16
|
sourceBranch: 'master',
|
|
17
|
+
historicalBranchLabelMappings: [],
|
|
18
18
|
})).toEqual({
|
|
19
19
|
committedDate: '2020-07-07T20:40:28Z',
|
|
20
20
|
originalMessage: '[APM] Add API tests (#70740)',
|
|
@@ -38,8 +38,8 @@ describe('fetchCommitBySha', () => {
|
|
|
38
38
|
repoName: 'kibana',
|
|
39
39
|
accessToken: devAccessToken,
|
|
40
40
|
sha: 'fc22f59',
|
|
41
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
42
41
|
sourceBranch: 'main',
|
|
42
|
+
historicalBranchLabelMappings: [],
|
|
43
43
|
})).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
|
|
44
44
|
});
|
|
45
45
|
it('throws if sha is invalid', async () => {
|
|
@@ -48,8 +48,8 @@ describe('fetchCommitBySha', () => {
|
|
|
48
48
|
repoName: 'kibana',
|
|
49
49
|
accessToken: devAccessToken,
|
|
50
50
|
sha: 'myCommitSha',
|
|
51
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
52
51
|
sourceBranch: 'main',
|
|
52
|
+
historicalBranchLabelMappings: [],
|
|
53
53
|
})).rejects.toThrowError('No commit found on branch "main" with sha "myCommitSha"');
|
|
54
54
|
});
|
|
55
55
|
});
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../../options/options';
|
|
2
2
|
import { Commit, SourceCommitWithTargetPullRequest } from '../../../sourceCommit/parseSourceCommit';
|
|
3
|
-
export declare function fetchCommitsByAuthor(options:
|
|
3
|
+
export declare function fetchCommitsByAuthor(options: {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
author: string | null;
|
|
6
|
+
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
7
|
+
commitPaths?: string[];
|
|
8
|
+
githubApiBaseUrlV4?: string;
|
|
9
|
+
historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
|
|
10
|
+
maxNumber?: number;
|
|
11
|
+
repoName: string;
|
|
12
|
+
repoOwner: string;
|
|
13
|
+
sourceBranch: string;
|
|
14
|
+
}): Promise<Commit[]>;
|
|
4
15
|
export interface CommitByAuthorResponse {
|
|
5
16
|
repository: {
|
|
6
17
|
ref: {
|
|
@@ -8,7 +8,7 @@ const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
|
|
|
8
8
|
const apiRequestV4_1 = require("../apiRequestV4");
|
|
9
9
|
const fetchAuthorId_1 = require("../fetchAuthorId");
|
|
10
10
|
function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
11
|
-
const { accessToken, githubApiBaseUrlV4, maxNumber, repoName, repoOwner, sourceBranch, } = options;
|
|
11
|
+
const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, } = options;
|
|
12
12
|
const query = /* GraphQL */ `
|
|
13
13
|
query CommitsByAuthor(
|
|
14
14
|
$repoOwner: String!
|
|
@@ -56,7 +56,7 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
async function fetchCommitsByAuthor(options) {
|
|
59
|
-
const { sourceBranch, commitPaths } = options;
|
|
59
|
+
const { sourceBranch, commitPaths = [] } = options;
|
|
60
60
|
const authorId = await (0, fetchAuthorId_1.fetchAuthorId)(options);
|
|
61
61
|
const responses = await Promise.all((0, lodash_1.isEmpty)(commitPaths)
|
|
62
62
|
? [fetchByCommitPath({ options, authorId, commitPath: null })]
|
|
@@ -75,12 +75,10 @@ async function fetchCommitsByAuthor(options) {
|
|
|
75
75
|
.filter(filterEmpty_1.filterNil);
|
|
76
76
|
// terminate if not commits were found
|
|
77
77
|
if ((0, lodash_1.isEmpty)(commits)) {
|
|
78
|
-
const pathText =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
? `There are no commits in this repository${pathText}`
|
|
83
|
-
: `There are no commits by "${options.author}" in this repository${pathText}. Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`;
|
|
78
|
+
const pathText = commitPaths.length > 0 ? ` touching files in path: "${commitPaths}"` : '';
|
|
79
|
+
const errorText = options.author
|
|
80
|
+
? `There are no commits by "${options.author}" in this repository${pathText}. Try with \`--all\` for commits by all users or \`--author=<username>\` for commits from a specific user`
|
|
81
|
+
: `There are no commits in this repository${pathText}`;
|
|
84
82
|
throw new HandledError_1.HandledError(errorText);
|
|
85
83
|
}
|
|
86
84
|
const commitsUnique = (0, lodash_1.uniqBy)(commits, 'sha');
|
|
@@ -9,14 +9,13 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
9
9
|
});
|
|
10
10
|
describe('commitPaths', () => {
|
|
11
11
|
const getOptions = () => ({
|
|
12
|
-
repoOwner: 'backport-org',
|
|
13
|
-
repoName: 'repo-with-different-commit-paths',
|
|
14
|
-
sourceBranch: 'main',
|
|
15
12
|
accessToken: devAccessToken,
|
|
16
|
-
username: 'sqren',
|
|
17
13
|
author: 'sqren',
|
|
14
|
+
historicalBranchLabelMappings: [],
|
|
18
15
|
maxNumber: 10,
|
|
19
|
-
|
|
16
|
+
repoName: 'repo-with-different-commit-paths',
|
|
17
|
+
repoOwner: 'backport-org',
|
|
18
|
+
sourceBranch: 'main',
|
|
20
19
|
});
|
|
21
20
|
const getCommitMessages = (commits) => {
|
|
22
21
|
return commits.map((c) => c.originalMessage.replace(/(\r\n|\n|\r)/gm, ''));
|
|
@@ -83,15 +82,14 @@ describe('fetchCommitsByAuthor', () => {
|
|
|
83
82
|
let res;
|
|
84
83
|
beforeEach(async () => {
|
|
85
84
|
res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
86
|
-
repoOwner: 'backport-org',
|
|
87
|
-
repoName: 'backport-e2e',
|
|
88
|
-
sourceBranch: 'master',
|
|
89
85
|
accessToken: devAccessToken,
|
|
90
|
-
username: 'sqren',
|
|
91
|
-
author: 'sqren',
|
|
92
|
-
maxNumber: 10,
|
|
93
|
-
githubApiBaseUrlV4: 'https://api.github.com/graphql',
|
|
94
86
|
commitPaths: [],
|
|
87
|
+
historicalBranchLabelMappings: [],
|
|
88
|
+
maxNumber: 10,
|
|
89
|
+
repoName: 'backport-e2e',
|
|
90
|
+
repoOwner: 'backport-org',
|
|
91
|
+
sourceBranch: 'master',
|
|
92
|
+
author: null,
|
|
95
93
|
});
|
|
96
94
|
});
|
|
97
95
|
it('returns related OPEN PRs', async () => {
|
|
@@ -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
|
{
|