backport 7.0.1 → 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/backportRun.d.ts +1 -0
- package/dist/backportRun.js +3 -2
- package/dist/entrypoint.cli.js +12 -1
- package/dist/entrypoint.module.d.ts +4 -3
- package/dist/entrypoint.module.js +2 -7
- package/dist/options/ConfigOptions.d.ts +1 -1
- package/dist/options/cliArgs.d.ts +2 -1
- package/dist/options/cliArgs.js +4 -0
- package/dist/options/config/config.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +2 -2
- package/dist/options/options.d.ts +3 -6
- package/dist/options/options.test.js +26 -28
- package/dist/runSequentially.js +1 -0
- package/dist/runSequentially.test.js +55 -30
- package/dist/services/HandledError.js +3 -1
- package/dist/services/git.d.ts +3 -3
- package/dist/services/git.integration.test.js +66 -13
- package/dist/services/git.js +52 -13
- package/dist/services/git.test.js +15 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
- package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
- package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
- package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
- package/dist/services/github/v3/createPullRequest.js +2 -5
- package/dist/services/github/v3/createStatusComment.js +1 -1
- package/dist/services/github/v4/FetchPullRequestId.js +5 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +7 -4
- package/dist/services/github/v4/apiRequestV4.js +22 -21
- package/dist/services/github/v4/apiRequestV4.test.js +38 -11
- package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
- package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
- package/dist/services/github/v4/fetchAuthorId.js +5 -1
- package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -3
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +24 -13
- package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +3 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +24 -13
- package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -11
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +20 -10
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +7 -12
- package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -1
- package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +20 -9
- package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
- package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
- package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -5
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -19
- package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
- package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
- package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
- package/dist/services/github/v4/mocks/commitsByAuthorMock.js +2 -0
- package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
- package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +5 -5
- package/dist/services/logger.d.ts +5 -5
- package/dist/services/logger.js +24 -23
- package/dist/services/remoteConfig.d.ts +20 -0
- package/dist/services/remoteConfig.js +52 -0
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
- package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +73 -39
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +21 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
- package/dist/services/sourceCommit/parseSourceCommit.js +73 -77
- package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
- package/dist/{entrypoint.cli.e2e.private.test.d.ts → test/e2e/cli.e2e.private.test.d.ts} +0 -0
- package/dist/{entrypoint.cli.e2e.private.test.js → test/e2e/cli.e2e.private.test.js} +153 -39
- package/dist/{services/github/v3/index.d.ts → test/e2e/module.e2e.private.test.d.ts} +0 -0
- package/dist/test/e2e/module.e2e.private.test.js +363 -0
- package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -2
- package/dist/test/nockHelpers.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +16 -22
- package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +6 -2
- package/dist/ui/getCommits.js +8 -6
- package/dist/ui/maybeSetupRepo.js +13 -16
- package/dist/ui/maybeSetupRepo.test.js +50 -16
- package/dist/ui/ora.d.ts +9 -0
- package/dist/ui/ora.js +21 -0
- package/dist/utils/packageVersion.d.ts +1 -1
- package/dist/utils/packageVersion.js +1 -1
- package/package.json +10 -10
- package/yarn.lock +121 -114
- package/dist/services/github/v3/index.js +0 -61
- package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
- package/dist/test/backport-e2e.mutation.test.js +0 -347
package/dist/services/git.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRoot = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
|
|
3
|
+
exports.getSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getCommitsInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRoot = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
|
|
7
4
|
const path_1 = require("path");
|
|
8
5
|
const lodash_1 = require("lodash");
|
|
9
|
-
const ora_1 =
|
|
6
|
+
const ora_1 = require("../ui/ora");
|
|
10
7
|
const filterEmpty_1 = require("../utils/filterEmpty");
|
|
11
8
|
const HandledError_1 = require("./HandledError");
|
|
12
9
|
const child_process_promisified_1 = require("./child-process-promisified");
|
|
@@ -102,9 +99,11 @@ async function getRepoInfoFromGitRemotes({ cwd }) {
|
|
|
102
99
|
}
|
|
103
100
|
}
|
|
104
101
|
exports.getRepoInfoFromGitRemotes = getRepoInfoFromGitRemotes;
|
|
105
|
-
async function getGitProjectRoot(
|
|
102
|
+
async function getGitProjectRoot(dir) {
|
|
106
103
|
try {
|
|
107
|
-
const { stdout } = await (0, child_process_promisified_1.exec)('git rev-parse --show-toplevel', {
|
|
104
|
+
const { stdout } = await (0, child_process_promisified_1.exec)('git rev-parse --show-toplevel', {
|
|
105
|
+
cwd: dir,
|
|
106
|
+
});
|
|
108
107
|
return stdout.trim();
|
|
109
108
|
}
|
|
110
109
|
catch (e) {
|
|
@@ -159,10 +158,50 @@ async function fetchBranch(options, branch) {
|
|
|
159
158
|
});
|
|
160
159
|
}
|
|
161
160
|
exports.fetchBranch = fetchBranch;
|
|
161
|
+
async function getIsMergeCommit(options, sha) {
|
|
162
|
+
const res = await (0, child_process_promisified_1.exec)(`git rev-list -1 --merges ${sha}~1..${sha}`, {
|
|
163
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
164
|
+
});
|
|
165
|
+
return res.stdout !== '';
|
|
166
|
+
}
|
|
167
|
+
exports.getIsMergeCommit = getIsMergeCommit;
|
|
168
|
+
async function getCommitsInMergeCommit(options, sha) {
|
|
169
|
+
try {
|
|
170
|
+
const res = await (0, child_process_promisified_1.exec)(`git --no-pager log ${sha}^1..${sha}^2 --pretty=format:"%H"`, {
|
|
171
|
+
cwd: (0, env_1.getRepoPath)(options),
|
|
172
|
+
});
|
|
173
|
+
return res.stdout.split('\n');
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
// swallow error
|
|
177
|
+
if (e.code === 128) {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
throw e;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.getCommitsInMergeCommit = getCommitsInMergeCommit;
|
|
162
184
|
async function cherrypick(options, sha, mergedTargetPullRequest) {
|
|
163
185
|
const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
|
|
164
186
|
const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
|
|
165
|
-
|
|
187
|
+
let shaOrRange = sha;
|
|
188
|
+
if (!options.mainline) {
|
|
189
|
+
try {
|
|
190
|
+
const isMergeCommit = await getIsMergeCommit(options, sha);
|
|
191
|
+
if (isMergeCommit) {
|
|
192
|
+
const shas = await getCommitsInMergeCommit(options, sha);
|
|
193
|
+
shaOrRange = `${(0, lodash_1.last)(shas)}^..${(0, lodash_1.first)(shas)}`;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
// swallow error if it's a known error
|
|
198
|
+
// exit 128 will happen for many things, among others when the cherrypicked commit is empty
|
|
199
|
+
if (e.code !== 128) {
|
|
200
|
+
throw e;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${shaOrRange}`;
|
|
166
205
|
try {
|
|
167
206
|
await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
|
|
168
207
|
return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
|
|
@@ -269,7 +308,7 @@ async function getUnstagedFiles(options) {
|
|
|
269
308
|
}
|
|
270
309
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
271
310
|
async function setCommitAuthor(options, author) {
|
|
272
|
-
const spinner = (0, ora_1.
|
|
311
|
+
const spinner = (0, ora_1.ora)(options.ci, `Changing author to "${author}"`).start();
|
|
273
312
|
try {
|
|
274
313
|
const res = await (0, child_process_promisified_1.exec)(`git commit --amend --no-edit --author "${author} <${author}@users.noreply.github.com>"`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
275
314
|
spinner.succeed();
|
|
@@ -285,7 +324,7 @@ exports.setCommitAuthor = setCommitAuthor;
|
|
|
285
324
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
286
325
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
287
326
|
async function createBackportBranch({ options, targetBranch, backportBranch, }) {
|
|
288
|
-
const spinner = (0, ora_1.
|
|
327
|
+
const spinner = (0, ora_1.ora)(options.ci, 'Pulling latest changes').start();
|
|
289
328
|
try {
|
|
290
329
|
const res = await (0, child_process_promisified_1.exec)(`git reset --hard && git clean -d --force && git fetch ${options.repoOwner} ${targetBranch} && git checkout -B ${backportBranch} ${options.repoOwner}/${targetBranch} --no-track`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
291
330
|
spinner.succeed();
|
|
@@ -303,7 +342,7 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
|
|
|
303
342
|
}
|
|
304
343
|
exports.createBackportBranch = createBackportBranch;
|
|
305
344
|
async function deleteBackportBranch({ options, backportBranch, }) {
|
|
306
|
-
const spinner = (0, ora_1.
|
|
345
|
+
const spinner = (0, ora_1.ora)(options.ci).start();
|
|
307
346
|
await (0, child_process_promisified_1.exec)(`git reset --hard && git checkout ${options.sourceBranch} && git branch -D ${backportBranch}`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
308
347
|
spinner.stop();
|
|
309
348
|
}
|
|
@@ -317,7 +356,7 @@ function getRepoForkOwner(options) {
|
|
|
317
356
|
exports.getRepoForkOwner = getRepoForkOwner;
|
|
318
357
|
async function pushBackportBranch({ options, backportBranch, }) {
|
|
319
358
|
const repoForkOwner = getRepoForkOwner(options);
|
|
320
|
-
const spinner = (0, ora_1.
|
|
359
|
+
const spinner = (0, ora_1.ora)(options.ci, `Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
|
|
321
360
|
try {
|
|
322
361
|
const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
323
362
|
spinner.succeed();
|
|
@@ -338,7 +377,7 @@ async function getSourceRepoPath(options) {
|
|
|
338
377
|
const remoteUrl = getRemoteUrl(options, options.repoOwner);
|
|
339
378
|
const sourcePath = options.repoName === gitRemote.repoName &&
|
|
340
379
|
options.repoOwner === gitRemote.repoOwner
|
|
341
|
-
? (await getGitProjectRoot(options)) ?? remoteUrl
|
|
380
|
+
? (await getGitProjectRoot(options.cwd)) ?? remoteUrl
|
|
342
381
|
: remoteUrl;
|
|
343
382
|
return sourcePath;
|
|
344
383
|
}
|
|
@@ -275,7 +275,9 @@ describe('cherrypick', () => {
|
|
|
275
275
|
it('should return `needsResolving: false` when no errors are encountered', async () => {
|
|
276
276
|
jest
|
|
277
277
|
.spyOn(childProcess, 'exec')
|
|
278
|
-
// mock
|
|
278
|
+
// mock getIsMergeCommit(...)
|
|
279
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
280
|
+
// mock cherrypick(...)
|
|
279
281
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
280
282
|
expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
|
|
281
283
|
conflictingFiles: [],
|
|
@@ -286,6 +288,8 @@ describe('cherrypick', () => {
|
|
|
286
288
|
it('should use mainline option when specified', async () => {
|
|
287
289
|
const execSpy = jest
|
|
288
290
|
.spyOn(childProcess, 'exec')
|
|
291
|
+
// mock getIsMergeCommit(...)
|
|
292
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
289
293
|
// mock cherry pick command
|
|
290
294
|
.mockResolvedValueOnce({ stderr: '', stdout: '' });
|
|
291
295
|
await (0, git_1.cherrypick)({ ...options, mainline: 1 }, 'abcd');
|
|
@@ -294,6 +298,8 @@ describe('cherrypick', () => {
|
|
|
294
298
|
it('should return `needsResolving: true` upon cherrypick error', async () => {
|
|
295
299
|
jest
|
|
296
300
|
.spyOn(childProcess, 'exec')
|
|
301
|
+
// mock getIsMergeCommit(...)
|
|
302
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
297
303
|
// mock cherry pick command
|
|
298
304
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
299
305
|
killed: false,
|
|
@@ -325,6 +331,8 @@ describe('cherrypick', () => {
|
|
|
325
331
|
it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
|
|
326
332
|
jest
|
|
327
333
|
.spyOn(childProcess, 'exec')
|
|
334
|
+
// mock getIsMergeCommit(...)
|
|
335
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
328
336
|
// mock cherry pick command
|
|
329
337
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
330
338
|
killed: false,
|
|
@@ -348,6 +356,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
348
356
|
it('should gracefully handle empty commits', async () => {
|
|
349
357
|
jest
|
|
350
358
|
.spyOn(childProcess, 'exec')
|
|
359
|
+
// mock getIsMergeCommit(...)
|
|
360
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
351
361
|
// mock cherry pick command
|
|
352
362
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
353
363
|
killed: false,
|
|
@@ -362,6 +372,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
362
372
|
it('gracefully handles missing git info', async () => {
|
|
363
373
|
jest
|
|
364
374
|
.spyOn(childProcess, 'exec')
|
|
375
|
+
// mock getIsMergeCommit(...)
|
|
376
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
365
377
|
// mock cherry pick command
|
|
366
378
|
.mockRejectedValueOnce(new ExecError_1.ExecError({
|
|
367
379
|
killed: false,
|
|
@@ -392,6 +404,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
|
|
|
392
404
|
it('should re-throw non-cherrypick errors', async () => {
|
|
393
405
|
jest
|
|
394
406
|
.spyOn(childProcess, 'exec')
|
|
407
|
+
// mock getIsMergeCommit(...)
|
|
408
|
+
.mockResolvedValueOnce({ stderr: '', stdout: '' })
|
|
395
409
|
// mock cherry pick command
|
|
396
410
|
.mockRejectedValueOnce(new Error('non-cherrypick error'))
|
|
397
411
|
// getConflictingFiles
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
|
|
2
|
+
export declare function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, ci, }: ValidConfigOptions, pullNumber: number, assignees: string[]): Promise<void>;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.addAssigneesToPullRequest = void 0;
|
|
7
4
|
const rest_1 = require("@octokit/rest");
|
|
8
|
-
const ora_1 =
|
|
5
|
+
const ora_1 = require("../../../ui/ora");
|
|
9
6
|
const logger_1 = require("../../logger");
|
|
10
|
-
async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }, pullNumber, assignees) {
|
|
7
|
+
async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, ci, }, pullNumber, assignees) {
|
|
11
8
|
const text = autoAssign
|
|
12
9
|
? `Self-assigning to #${pullNumber}`
|
|
13
10
|
: `Adding assignees to #${pullNumber}: ${assignees.join(', ')}`;
|
|
14
11
|
logger_1.logger.info(text);
|
|
15
|
-
const spinner = (0, ora_1.
|
|
12
|
+
const spinner = (0, ora_1.ora)(ci, text).start();
|
|
16
13
|
try {
|
|
17
14
|
const octokit = new rest_1.Octokit({
|
|
18
15
|
auth: accessToken,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
|
|
2
|
+
export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.addLabelsToPullRequest = void 0;
|
|
7
4
|
const rest_1 = require("@octokit/rest");
|
|
8
|
-
const ora_1 =
|
|
5
|
+
const ora_1 = require("../../../ui/ora");
|
|
9
6
|
const logger_1 = require("../../logger");
|
|
10
|
-
async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, labels) {
|
|
7
|
+
async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }, pullNumber, labels) {
|
|
11
8
|
const text = `Adding labels: ${labels.join(', ')}`;
|
|
12
9
|
logger_1.logger.info(text);
|
|
13
|
-
const spinner = (0, ora_1.
|
|
10
|
+
const spinner = (0, ora_1.ora)(ci, text).start();
|
|
14
11
|
try {
|
|
15
12
|
const octokit = new rest_1.Octokit({
|
|
16
13
|
auth: accessToken,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ValidConfigOptions } from '../../../options/options';
|
|
2
|
-
export declare function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, reviewers: string[]): Promise<void>;
|
|
2
|
+
export declare function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }: ValidConfigOptions, pullNumber: number, reviewers: string[]): Promise<void>;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.addReviewersToPullRequest = void 0;
|
|
7
4
|
const rest_1 = require("@octokit/rest");
|
|
8
|
-
const ora_1 =
|
|
5
|
+
const ora_1 = require("../../../ui/ora");
|
|
9
6
|
const logger_1 = require("../../logger");
|
|
10
|
-
async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, reviewers) {
|
|
7
|
+
async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }, pullNumber, reviewers) {
|
|
11
8
|
const text = `Adding reviewers: ${reviewers}`;
|
|
12
9
|
logger_1.logger.info(text);
|
|
13
|
-
const spinner = (0, ora_1.
|
|
10
|
+
const spinner = (0, ora_1.ora)(ci, text).start();
|
|
14
11
|
try {
|
|
15
12
|
const octokit = new rest_1.Octokit({
|
|
16
13
|
auth: accessToken,
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getTitle = exports.getPullRequestBody = exports.createPullRequest = void 0;
|
|
7
4
|
const rest_1 = require("@octokit/rest");
|
|
8
|
-
const ora_1 =
|
|
5
|
+
const ora_1 = require("../../../ui/ora");
|
|
9
6
|
const packageVersion_1 = require("../../../utils/packageVersion");
|
|
10
7
|
const HandledError_1 = require("../../HandledError");
|
|
11
8
|
const logger_1 = require("../../logger");
|
|
@@ -15,7 +12,7 @@ const getGithubV3ErrorMessage_1 = require("./getGithubV3ErrorMessage");
|
|
|
15
12
|
async function createPullRequest({ options, prPayload, }) {
|
|
16
13
|
logger_1.logger.info(`Creating PR with title: "${prPayload.title}". ${prPayload.head} -> ${prPayload.base}`);
|
|
17
14
|
const { accessToken, githubApiBaseUrlV3 } = options;
|
|
18
|
-
const spinner = (0, ora_1.
|
|
15
|
+
const spinner = (0, ora_1.ora)(options.ci, `Creating pull request`).start();
|
|
19
16
|
try {
|
|
20
17
|
const octokit = new rest_1.Octokit({
|
|
21
18
|
auth: accessToken,
|
|
@@ -9,7 +9,7 @@ const logger_1 = require("../../logger");
|
|
|
9
9
|
const commitFormatters_1 = require("../commitFormatters");
|
|
10
10
|
async function createStatusComment({ options, backportResponse, }) {
|
|
11
11
|
const { githubApiBaseUrlV3, repoName, repoOwner, accessToken, publishStatusComment, } = options;
|
|
12
|
-
if (!publishStatusComment) {
|
|
12
|
+
if (!publishStatusComment || options.dryRun) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.fetchPullRequestId = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
4
8
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
9
|
async function fetchPullRequestId(options, pullNumber) {
|
|
6
10
|
const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
|
|
7
|
-
const prQuery =
|
|
11
|
+
const prQuery = (0, graphql_tag_1.default) `
|
|
8
12
|
query PullRequestId(
|
|
9
13
|
$repoOwner: String!
|
|
10
14
|
$repoName: String!
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { DocumentNode } from 'graphql';
|
|
2
3
|
interface GithubError {
|
|
3
4
|
type: string;
|
|
4
5
|
path: string[];
|
|
@@ -16,13 +17,15 @@ declare type Variables = Record<string, string | number | null>;
|
|
|
16
17
|
export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessToken, query, variables, }: {
|
|
17
18
|
githubApiBaseUrlV4?: string;
|
|
18
19
|
accessToken: string;
|
|
19
|
-
query:
|
|
20
|
+
query: DocumentNode;
|
|
20
21
|
variables?: Variables;
|
|
21
22
|
}): Promise<DataResponse>;
|
|
22
23
|
declare type AxiosGithubResponse<DataResponse> = AxiosResponse<GithubV4Response<DataResponse | null>, any>;
|
|
23
24
|
export declare class GithubV4Exception<DataResponse> extends Error {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
githubResponse: AxiosGithubResponse<DataResponse> & {
|
|
26
|
+
request: undefined;
|
|
27
|
+
};
|
|
28
|
+
constructor(githubResponse: AxiosGithubResponse<DataResponse>, errorMessage?: string);
|
|
27
29
|
}
|
|
30
|
+
export declare function getQueryName(query: DocumentNode): string;
|
|
28
31
|
export {};
|
|
@@ -3,30 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GithubV4Exception = exports.apiRequestV4 = void 0;
|
|
6
|
+
exports.getQueryName = exports.GithubV4Exception = exports.apiRequestV4 = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const
|
|
8
|
+
const printer_1 = require("graphql/language/printer");
|
|
9
9
|
const HandledError_1 = require("../../HandledError");
|
|
10
10
|
const logger_1 = require("../../logger");
|
|
11
11
|
async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, }) {
|
|
12
12
|
try {
|
|
13
|
-
const response = await axios_1.default.post(githubApiBaseUrlV4, { query, variables }, {
|
|
13
|
+
const response = await axios_1.default.post(githubApiBaseUrlV4, { query: (0, printer_1.print)(query), variables }, {
|
|
14
14
|
headers: {
|
|
15
15
|
'Content-Type': 'application/json',
|
|
16
16
|
Authorization: `bearer ${accessToken}`,
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
19
|
if (response.data.errors) {
|
|
20
|
-
|
|
21
|
-
.map((error) => error.message)
|
|
22
|
-
.join(',')} (Github API v4)`;
|
|
23
|
-
throw new GithubV4Exception(message, response);
|
|
20
|
+
throw new GithubV4Exception(response);
|
|
24
21
|
}
|
|
25
22
|
addDebugLogs({
|
|
26
23
|
githubApiBaseUrlV4,
|
|
27
24
|
query,
|
|
28
25
|
variables,
|
|
29
|
-
|
|
26
|
+
githubResponse: response,
|
|
30
27
|
didSucceed: false,
|
|
31
28
|
});
|
|
32
29
|
return response.data.data;
|
|
@@ -37,37 +34,41 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
37
34
|
githubApiBaseUrlV4,
|
|
38
35
|
query,
|
|
39
36
|
variables,
|
|
40
|
-
|
|
37
|
+
githubResponse: e.response,
|
|
41
38
|
didSucceed: false,
|
|
42
39
|
});
|
|
43
|
-
throw new GithubV4Exception(
|
|
40
|
+
throw new GithubV4Exception(e.response, e.message);
|
|
44
41
|
}
|
|
45
42
|
throw e;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
exports.apiRequestV4 = apiRequestV4;
|
|
49
|
-
function addDebugLogs({ githubApiBaseUrlV4, query, variables,
|
|
50
|
-
const gqlQueryName =
|
|
51
|
-
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${
|
|
46
|
+
function addDebugLogs({ githubApiBaseUrlV4, query, variables, githubResponse, didSucceed, }) {
|
|
47
|
+
const gqlQueryName = getQueryName(query);
|
|
48
|
+
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${githubResponse.status})`);
|
|
52
49
|
const logMethod = didSucceed ? logger_1.logger.verbose : logger_1.logger.info;
|
|
53
50
|
logMethod(`Query name ${gqlQueryName}`);
|
|
54
51
|
logMethod(`Query: ${query}`);
|
|
55
52
|
logMethod('Variables:', variables);
|
|
56
|
-
logMethod('Response headers:',
|
|
57
|
-
logMethod('Response data:',
|
|
53
|
+
logMethod('Response headers:', githubResponse.headers);
|
|
54
|
+
logMethod('Response data:', githubResponse.data);
|
|
58
55
|
}
|
|
59
56
|
class GithubV4Exception extends Error {
|
|
60
|
-
constructor(
|
|
57
|
+
constructor(githubResponse, errorMessage) {
|
|
58
|
+
const githubMessage = githubResponse.data.errors
|
|
59
|
+
?.map((error) => error.message)
|
|
60
|
+
.join(',');
|
|
61
|
+
const message = `${errorMessage ?? githubMessage ?? 'Unknown error'} (Github API v4)`;
|
|
61
62
|
super(message);
|
|
62
|
-
this.message = message;
|
|
63
|
-
this.axiosResponse = axiosResponse;
|
|
64
63
|
Error.captureStackTrace(this, HandledError_1.HandledError);
|
|
65
64
|
this.name = 'GithubV4Exception';
|
|
65
|
+
this.message = message;
|
|
66
|
+
this.githubResponse = { ...githubResponse, request: undefined };
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
exports.GithubV4Exception = GithubV4Exception;
|
|
69
|
-
function
|
|
70
|
-
const ast = (0, graphql_tag_1.default)(query);
|
|
70
|
+
function getQueryName(query) {
|
|
71
71
|
//@ts-expect-error
|
|
72
|
-
return
|
|
72
|
+
return query.definitions[0].name?.value;
|
|
73
73
|
}
|
|
74
|
+
exports.getQueryName = getQueryName;
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
6
7
|
const nock_1 = __importDefault(require("nock"));
|
|
7
8
|
const nockHelpers_1 = require("../../../test/nockHelpers");
|
|
8
9
|
const HandledError_1 = require("../../HandledError");
|
|
@@ -18,25 +19,39 @@ describe('apiRequestV4', () => {
|
|
|
18
19
|
commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
|
|
19
20
|
name: 'MyQuery',
|
|
20
21
|
statusCode: 200,
|
|
21
|
-
body: { data: {
|
|
22
|
+
body: { data: { viewer: { login: 'sqren' } } },
|
|
22
23
|
});
|
|
23
24
|
res = await (0, apiRequestV4_1.apiRequestV4)({
|
|
24
25
|
accessToken: 'myAccessToken',
|
|
25
26
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
26
|
-
query:
|
|
27
|
+
query: (0, graphql_tag_1.default) `
|
|
28
|
+
query MyQuery {
|
|
29
|
+
viewer {
|
|
30
|
+
login
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
27
34
|
variables: { foo: 'bar' },
|
|
28
35
|
});
|
|
29
36
|
});
|
|
30
37
|
it('should return correct response', async () => {
|
|
31
|
-
expect(res).toEqual({
|
|
38
|
+
expect(res).toEqual({ viewer: { login: 'sqren' } });
|
|
32
39
|
});
|
|
33
40
|
it('should call with correct args', async () => {
|
|
34
|
-
expect(commitsByAuthorCalls).
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
expect(commitsByAuthorCalls).toMatchInlineSnapshot(`
|
|
42
|
+
Array [
|
|
43
|
+
Object {
|
|
44
|
+
"query": "query MyQuery {
|
|
45
|
+
viewer {
|
|
46
|
+
login
|
|
47
|
+
}
|
|
48
|
+
}",
|
|
49
|
+
"variables": Object {
|
|
50
|
+
"foo": "bar",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
]
|
|
54
|
+
`);
|
|
40
55
|
});
|
|
41
56
|
});
|
|
42
57
|
describe('when request fails with error messages', () => {
|
|
@@ -53,7 +68,13 @@ describe('apiRequestV4', () => {
|
|
|
53
68
|
return expect((0, apiRequestV4_1.apiRequestV4)({
|
|
54
69
|
accessToken: 'myAccessToken',
|
|
55
70
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
56
|
-
query:
|
|
71
|
+
query: (0, graphql_tag_1.default) `
|
|
72
|
+
query MyQuery {
|
|
73
|
+
viewer {
|
|
74
|
+
login
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`,
|
|
57
78
|
variables: {
|
|
58
79
|
foo: 'bar',
|
|
59
80
|
},
|
|
@@ -72,7 +93,13 @@ describe('apiRequestV4', () => {
|
|
|
72
93
|
return expect((0, apiRequestV4_1.apiRequestV4)({
|
|
73
94
|
accessToken: 'myAccessToken',
|
|
74
95
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
75
|
-
query:
|
|
96
|
+
query: (0, graphql_tag_1.default) `
|
|
97
|
+
query MyQuery {
|
|
98
|
+
viewer {
|
|
99
|
+
login
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
`,
|
|
76
103
|
variables: {
|
|
77
104
|
foo: 'bar',
|
|
78
105
|
},
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.disablePullRequestAutoMerge = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
4
8
|
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
5
9
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
6
10
|
async function disablePullRequestAutoMerge(options, pullNumber) {
|
|
7
11
|
const { accessToken, githubApiBaseUrlV4 } = options;
|
|
8
12
|
const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, pullNumber);
|
|
9
|
-
const query =
|
|
13
|
+
const query = (0, graphql_tag_1.default) `
|
|
10
14
|
mutation DisablePullRequestAutoMerge($pullRequestId: ID!) {
|
|
11
15
|
disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) {
|
|
12
16
|
pullRequest {
|
|
@@ -4,7 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.enablePullRequestAutoMerge = void 0;
|
|
7
|
-
const
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const ora_1 = require("../../../ui/ora");
|
|
8
9
|
const logger_1 = require("../../logger");
|
|
9
10
|
const FetchPullRequestId_1 = require("./FetchPullRequestId");
|
|
10
11
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
@@ -12,9 +13,9 @@ async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
|
|
|
12
13
|
const { accessToken, githubApiBaseUrlV4, autoMergeMethod = 'merge', } = options;
|
|
13
14
|
const text = `Enabling auto merging via ${options.autoMergeMethod}`;
|
|
14
15
|
logger_1.logger.info(text);
|
|
15
|
-
const spinner = (0, ora_1.
|
|
16
|
+
const spinner = (0, ora_1.ora)(options.ci, text).start();
|
|
16
17
|
const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, targetPullRequestNumber);
|
|
17
|
-
const query =
|
|
18
|
+
const query = (0, graphql_tag_1.default) `
|
|
18
19
|
mutation EnablePullRequestAutoMerge(
|
|
19
20
|
$pullRequestId: ID!
|
|
20
21
|
$mergeMethod: PullRequestMergeMethod!
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.fetchAuthorId = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
4
8
|
const apiRequestV4_1 = require("./apiRequestV4");
|
|
5
9
|
async function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4 = 'https://api.github.com/graphql', }) {
|
|
6
10
|
if (author === null) {
|
|
7
11
|
return null;
|
|
8
12
|
}
|
|
9
|
-
const query =
|
|
13
|
+
const query = (0, graphql_tag_1.default) `
|
|
10
14
|
query AuthorId($author: String!) {
|
|
11
15
|
user(login: $author) {
|
|
12
16
|
id
|
|
@@ -13,7 +13,6 @@ describe('allFetchers', () => {
|
|
|
13
13
|
const commitsByAuthor = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
|
|
14
14
|
accessToken: devAccessToken,
|
|
15
15
|
author: 'sqren',
|
|
16
|
-
historicalBranchLabelMappings: [],
|
|
17
16
|
maxNumber: 1,
|
|
18
17
|
repoName: 'kibana',
|
|
19
18
|
repoOwner: 'elastic',
|
|
@@ -34,7 +33,6 @@ describe('allFetchers', () => {
|
|
|
34
33
|
accessToken: devAccessToken,
|
|
35
34
|
pullNumber: commitByAuthor.sourcePullRequest.number,
|
|
36
35
|
sourceBranch: 'master',
|
|
37
|
-
historicalBranchLabelMappings: [],
|
|
38
36
|
});
|
|
39
37
|
expect(commitByAuthor).toEqual(commitByPullNumber);
|
|
40
38
|
});
|
|
@@ -45,7 +43,6 @@ describe('allFetchers', () => {
|
|
|
45
43
|
accessToken: devAccessToken,
|
|
46
44
|
sha: commitByAuthor.sourceCommit.sha,
|
|
47
45
|
sourceBranch: 'main',
|
|
48
|
-
historicalBranchLabelMappings: [],
|
|
49
46
|
});
|
|
50
47
|
expect(commitByAuthor).toEqual(commitBySha);
|
|
51
48
|
});
|
|
@@ -4,7 +4,6 @@ export declare function fetchCommitByPullNumber(options: {
|
|
|
4
4
|
accessToken: string;
|
|
5
5
|
branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
|
|
6
6
|
githubApiBaseUrlV4?: string;
|
|
7
|
-
historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
|
|
8
7
|
pullNumber: number;
|
|
9
8
|
repoName: string;
|
|
10
9
|
repoOwner: string;
|