backport 7.0.1 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backportRun.d.ts +1 -0
- package/dist/backportRun.js +3 -2
- package/dist/entrypoint.cli.js +12 -1
- package/dist/options/cliArgs.d.ts +1 -1
- package/dist/options/config/readConfigFile.d.ts +1 -1
- package/dist/options/options.d.ts +1 -5
- package/dist/options/options.test.js +26 -28
- package/dist/runSequentially.test.js +0 -1
- package/dist/services/HandledError.js +3 -1
- package/dist/services/git.js +5 -8
- 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/v4/FetchPullRequestId.js +5 -1
- package/dist/services/github/v4/apiRequestV4.d.ts +3 -1
- package/dist/services/github/v4/apiRequestV4.js +7 -7
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +6 -2
- 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 +0 -4
- package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +14 -55
- 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 +5 -0
- package/dist/services/logger.d.ts +5 -5
- package/dist/services/logger.js +24 -23
- package/dist/services/remoteConfig.d.ts +18 -0
- package/dist/services/remoteConfig.js +39 -0
- package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
- package/dist/services/sourceCommit/getMockSourceCommit.js +20 -6
- package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
- package/dist/services/sourceCommit/parseSourceCommit.js +73 -71
- package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
- package/dist/test/nockHelpers.js +6 -2
- package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
- package/dist/ui/getCommits.js +2 -2
- 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 +1 -1
package/dist/backportRun.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export declare type BackportResponse = {
|
|
|
10
10
|
status: 'failure';
|
|
11
11
|
commits: Commit[];
|
|
12
12
|
error: Error | HandledError;
|
|
13
|
+
errorMessage: string;
|
|
13
14
|
};
|
|
14
15
|
export declare function backportRun(processArgs: string[], optionsFromModule?: ConfigFileOptions): Promise<BackportResponse>;
|
package/dist/backportRun.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.backportRun = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const ora_1 = __importDefault(require("ora"));
|
|
9
8
|
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
10
9
|
const options_1 = require("./options/options");
|
|
11
10
|
const runSequentially_1 = require("./runSequentially");
|
|
@@ -16,13 +15,14 @@ const apiRequestV4_1 = require("./services/github/v4/apiRequestV4");
|
|
|
16
15
|
const logger_1 = require("./services/logger");
|
|
17
16
|
const getCommits_1 = require("./ui/getCommits");
|
|
18
17
|
const getTargetBranches_1 = require("./ui/getTargetBranches");
|
|
18
|
+
const ora_1 = require("./ui/ora");
|
|
19
19
|
async function backportRun(processArgs, optionsFromModule = {}) {
|
|
20
20
|
const argv = (0, yargs_parser_1.default)(processArgs);
|
|
21
21
|
const ci = argv.ci ?? optionsFromModule.ci;
|
|
22
22
|
const logFilePath = argv.logFilePath ?? optionsFromModule.logFilePath;
|
|
23
23
|
(0, logger_1.initLogger)({ ci, logFilePath });
|
|
24
24
|
// don't show spinner for yargs commands that exit the process without stopping the spinner first
|
|
25
|
-
const spinner = (0, ora_1.
|
|
25
|
+
const spinner = (0, ora_1.ora)(ci);
|
|
26
26
|
if (!argv.help && !argv.version && !argv.v) {
|
|
27
27
|
spinner.start('Initializing...');
|
|
28
28
|
}
|
|
@@ -55,6 +55,7 @@ async function backportRun(processArgs, optionsFromModule = {}) {
|
|
|
55
55
|
status: 'failure',
|
|
56
56
|
commits,
|
|
57
57
|
error: e,
|
|
58
|
+
errorMessage: e.message,
|
|
58
59
|
};
|
|
59
60
|
if (options) {
|
|
60
61
|
await (0, createStatusComment_1.createStatusComment)({
|
package/dist/entrypoint.cli.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
4
8
|
const backportRun_1 = require("./backportRun");
|
|
5
9
|
const processArgs = process.argv.slice(2);
|
|
6
10
|
// this is the entrypoint when running from command line
|
|
7
|
-
(0, backportRun_1.backportRun)(processArgs)
|
|
11
|
+
(0, backportRun_1.backportRun)(processArgs).then((backportResponse) => {
|
|
12
|
+
const argv = (0, yargs_parser_1.default)(processArgs);
|
|
13
|
+
const ci = argv.ci;
|
|
14
|
+
if (ci) {
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.log(JSON.stringify(backportResponse));
|
|
17
|
+
}
|
|
18
|
+
});
|
|
@@ -5,6 +5,7 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
|
|
|
5
5
|
fork?: boolean | undefined;
|
|
6
6
|
dir?: string | undefined;
|
|
7
7
|
verbose?: boolean | undefined;
|
|
8
|
+
logFilePath?: string | undefined;
|
|
8
9
|
accessToken?: string | undefined;
|
|
9
10
|
author?: string | null | undefined;
|
|
10
11
|
autoAssign?: boolean | undefined;
|
|
@@ -20,7 +21,6 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
|
|
|
20
21
|
gitHostname?: string | undefined;
|
|
21
22
|
githubApiBaseUrlV3?: string | undefined;
|
|
22
23
|
githubApiBaseUrlV4?: string | undefined;
|
|
23
|
-
logFilePath?: string | undefined;
|
|
24
24
|
mainline?: number | undefined;
|
|
25
25
|
maxNumber?: number | undefined;
|
|
26
26
|
multipleBranches?: boolean | undefined;
|
|
@@ -5,6 +5,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
5
5
|
dir?: string | undefined;
|
|
6
6
|
help?: boolean | undefined;
|
|
7
7
|
verbose?: boolean | undefined;
|
|
8
|
+
logFilePath?: string | undefined;
|
|
8
9
|
accessToken?: string | undefined;
|
|
9
10
|
author?: string | null | undefined;
|
|
10
11
|
autoAssign?: boolean | undefined;
|
|
@@ -20,7 +21,6 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
|
|
|
20
21
|
gitHostname?: string | undefined;
|
|
21
22
|
githubApiBaseUrlV3?: string | undefined;
|
|
22
23
|
githubApiBaseUrlV4?: string | undefined;
|
|
23
|
-
logFilePath?: string | undefined;
|
|
24
24
|
maxNumber?: number | undefined;
|
|
25
25
|
multiple?: boolean | undefined;
|
|
26
26
|
multipleBranches?: boolean | undefined;
|
|
@@ -7,6 +7,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
7
7
|
fork: boolean;
|
|
8
8
|
dir?: string | undefined;
|
|
9
9
|
verbose: boolean;
|
|
10
|
+
logFilePath?: string | undefined;
|
|
10
11
|
author: string | null;
|
|
11
12
|
autoAssign: boolean;
|
|
12
13
|
assignees: string[];
|
|
@@ -21,7 +22,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
21
22
|
gitHostname: string;
|
|
22
23
|
githubApiBaseUrlV3?: string | undefined;
|
|
23
24
|
githubApiBaseUrlV4?: string | undefined;
|
|
24
|
-
logFilePath?: string | undefined;
|
|
25
25
|
mainline?: number | undefined;
|
|
26
26
|
maxNumber: number;
|
|
27
27
|
multipleBranches: boolean;
|
|
@@ -44,10 +44,6 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
|
|
|
44
44
|
targetBranches: string[];
|
|
45
45
|
targetPRLabels: string[];
|
|
46
46
|
publishStatusComment: boolean;
|
|
47
|
-
historicalBranchLabelMappings: {
|
|
48
|
-
branchLabelMapping: Record<string, string>;
|
|
49
|
-
committedDate: string;
|
|
50
|
-
}[];
|
|
51
47
|
autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
|
|
52
48
|
files: string[];
|
|
53
49
|
directory: string;
|
|
@@ -126,6 +126,14 @@ describe('getOptions', () => {
|
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
|
+
it('reads options from remote config', async () => {
|
|
130
|
+
mockGithubConfigOptions({ hasRemoteConfig: true });
|
|
131
|
+
const options = await (0, options_1.getOptions)([], {});
|
|
132
|
+
expect(options.branchLabelMapping).toEqual({
|
|
133
|
+
'^v8.2.0$': 'option-from-remote',
|
|
134
|
+
});
|
|
135
|
+
expect(options.autoMergeMethod).toEqual('rebase');
|
|
136
|
+
});
|
|
129
137
|
it('should ensure that "backport" branch does not exist', async () => {
|
|
130
138
|
mockGithubConfigOptions({ hasBackportBranch: true });
|
|
131
139
|
await expect((0, options_1.getOptions)([], {})).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
|
|
@@ -145,12 +153,6 @@ describe('getOptions', () => {
|
|
|
145
153
|
mockGithubConfigOptions({
|
|
146
154
|
viewerLogin: 'john.diller',
|
|
147
155
|
defaultBranchRef: 'default-branch-from-github',
|
|
148
|
-
historicalMappings: [
|
|
149
|
-
{
|
|
150
|
-
committedDate: '2022-01-02T20:52:45.173Z',
|
|
151
|
-
branchLabelMapping: { foo: 'bar' },
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
156
|
});
|
|
155
157
|
const options = await (0, options_1.getOptions)([], {});
|
|
156
158
|
expect(options).toEqual({
|
|
@@ -162,9 +164,6 @@ describe('getOptions', () => {
|
|
|
162
164
|
autoMerge: false,
|
|
163
165
|
autoMergeMethod: 'merge',
|
|
164
166
|
backportBinary: 'backport',
|
|
165
|
-
branchLabelMapping: {
|
|
166
|
-
foo: 'bar',
|
|
167
|
-
},
|
|
168
167
|
cherrypickRef: true,
|
|
169
168
|
ci: false,
|
|
170
169
|
commitPaths: [],
|
|
@@ -176,12 +175,6 @@ describe('getOptions', () => {
|
|
|
176
175
|
fork: true,
|
|
177
176
|
gitHostname: 'github.com',
|
|
178
177
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
179
|
-
historicalBranchLabelMappings: [
|
|
180
|
-
{
|
|
181
|
-
branchLabelMapping: { foo: 'bar' },
|
|
182
|
-
committedDate: '2022-01-02T20:52:45.173Z',
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
178
|
maxNumber: 10,
|
|
186
179
|
multipleBranches: true,
|
|
187
180
|
multipleCommits: false,
|
|
@@ -325,7 +318,7 @@ function mockProjectConfig(projectConfig) {
|
|
|
325
318
|
},
|
|
326
319
|
});
|
|
327
320
|
}
|
|
328
|
-
function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', hasBackportBranch,
|
|
321
|
+
function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBranchRef = 'DO_NOT_USE-default-branch-name', hasBackportBranch, hasRemoteConfig, }) {
|
|
329
322
|
return (0, nockHelpers_1.mockGqlRequest)({
|
|
330
323
|
name: 'GithubConfigOptions',
|
|
331
324
|
statusCode: 200,
|
|
@@ -339,21 +332,26 @@ function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBran
|
|
|
339
332
|
defaultBranchRef: {
|
|
340
333
|
name: defaultBranchRef,
|
|
341
334
|
target: {
|
|
342
|
-
|
|
343
|
-
edges:
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
335
|
+
remoteConfigHistory: {
|
|
336
|
+
edges: hasRemoteConfig
|
|
337
|
+
? [
|
|
338
|
+
{
|
|
339
|
+
remoteConfig: {
|
|
340
|
+
committedDate: '2020-08-15T00:00:00.000Z',
|
|
341
|
+
file: {
|
|
342
|
+
object: {
|
|
343
|
+
text: JSON.stringify({
|
|
344
|
+
autoMergeMethod: 'rebase',
|
|
345
|
+
branchLabelMapping: {
|
|
346
|
+
'^v8.2.0$': 'option-from-remote',
|
|
347
|
+
},
|
|
348
|
+
}),
|
|
349
|
+
},
|
|
352
350
|
},
|
|
353
351
|
},
|
|
354
352
|
},
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
]
|
|
354
|
+
: [],
|
|
357
355
|
},
|
|
358
356
|
},
|
|
359
357
|
},
|
|
@@ -77,7 +77,6 @@ describe('runSequentially', () => {
|
|
|
77
77
|
gitHostname: 'github.com',
|
|
78
78
|
githubApiBaseUrlV3: 'https://api.github.com',
|
|
79
79
|
githubApiBaseUrlV4: 'http://localhost/graphql',
|
|
80
|
-
historicalBranchLabelMappings: [],
|
|
81
80
|
mainline: undefined,
|
|
82
81
|
maxNumber: 10,
|
|
83
82
|
multipleBranches: false,
|
|
@@ -16,9 +16,11 @@ function getMessage(errorContext) {
|
|
|
16
16
|
}
|
|
17
17
|
class HandledError extends Error {
|
|
18
18
|
constructor(errorContext) {
|
|
19
|
-
|
|
19
|
+
const message = getMessage(errorContext);
|
|
20
|
+
super(message);
|
|
20
21
|
Error.captureStackTrace(this, HandledError);
|
|
21
22
|
this.name = 'HandledError';
|
|
23
|
+
this.message = message;
|
|
22
24
|
if (typeof errorContext !== 'string') {
|
|
23
25
|
this.errorContext = errorContext;
|
|
24
26
|
}
|
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
3
|
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;
|
|
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");
|
|
@@ -269,7 +266,7 @@ async function getUnstagedFiles(options) {
|
|
|
269
266
|
}
|
|
270
267
|
exports.getUnstagedFiles = getUnstagedFiles;
|
|
271
268
|
async function setCommitAuthor(options, author) {
|
|
272
|
-
const spinner = (0, ora_1.
|
|
269
|
+
const spinner = (0, ora_1.ora)(options.ci, `Changing author to "${author}"`).start();
|
|
273
270
|
try {
|
|
274
271
|
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
272
|
spinner.succeed();
|
|
@@ -285,7 +282,7 @@ exports.setCommitAuthor = setCommitAuthor;
|
|
|
285
282
|
// ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
|
|
286
283
|
// master -> backport/7.x/pr-1234 -> 7.x
|
|
287
284
|
async function createBackportBranch({ options, targetBranch, backportBranch, }) {
|
|
288
|
-
const spinner = (0, ora_1.
|
|
285
|
+
const spinner = (0, ora_1.ora)(options.ci, 'Pulling latest changes').start();
|
|
289
286
|
try {
|
|
290
287
|
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
288
|
spinner.succeed();
|
|
@@ -303,7 +300,7 @@ async function createBackportBranch({ options, targetBranch, backportBranch, })
|
|
|
303
300
|
}
|
|
304
301
|
exports.createBackportBranch = createBackportBranch;
|
|
305
302
|
async function deleteBackportBranch({ options, backportBranch, }) {
|
|
306
|
-
const spinner = (0, ora_1.
|
|
303
|
+
const spinner = (0, ora_1.ora)(options.ci).start();
|
|
307
304
|
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
305
|
spinner.stop();
|
|
309
306
|
}
|
|
@@ -317,7 +314,7 @@ function getRepoForkOwner(options) {
|
|
|
317
314
|
exports.getRepoForkOwner = getRepoForkOwner;
|
|
318
315
|
async function pushBackportBranch({ options, backportBranch, }) {
|
|
319
316
|
const repoForkOwner = getRepoForkOwner(options);
|
|
320
|
-
const spinner = (0, ora_1.
|
|
317
|
+
const spinner = (0, ora_1.ora)(options.ci, `Pushing branch "${repoForkOwner}:${backportBranch}"`).start();
|
|
321
318
|
try {
|
|
322
319
|
const res = await (0, child_process_promisified_1.exec)(`git push ${repoForkOwner} ${backportBranch}:${backportBranch} --force`, { cwd: (0, env_1.getRepoPath)(options) });
|
|
323
320
|
spinner.succeed();
|
|
@@ -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,
|
|
@@ -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,7 +17,7 @@ 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>;
|
|
@@ -25,4 +26,5 @@ export declare class GithubV4Exception<DataResponse> extends Error {
|
|
|
25
26
|
axiosResponse: AxiosGithubResponse<DataResponse>;
|
|
26
27
|
constructor(message: string, axiosResponse: AxiosGithubResponse<DataResponse>);
|
|
27
28
|
}
|
|
29
|
+
export declare function getQueryName(query: DocumentNode): string;
|
|
28
30
|
export {};
|
|
@@ -3,14 +3,14 @@ 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}`,
|
|
@@ -47,7 +47,7 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
|
|
|
47
47
|
}
|
|
48
48
|
exports.apiRequestV4 = apiRequestV4;
|
|
49
49
|
function addDebugLogs({ githubApiBaseUrlV4, query, variables, axiosResponse, didSucceed, }) {
|
|
50
|
-
const gqlQueryName =
|
|
50
|
+
const gqlQueryName = getQueryName(query);
|
|
51
51
|
logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${axiosResponse.status})`);
|
|
52
52
|
const logMethod = didSucceed ? logger_1.logger.verbose : logger_1.logger.info;
|
|
53
53
|
logMethod(`Query name ${gqlQueryName}`);
|
|
@@ -66,8 +66,8 @@ class GithubV4Exception extends Error {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.GithubV4Exception = GithubV4Exception;
|
|
69
|
-
function
|
|
70
|
-
const ast = (0, graphql_tag_1.default)(query);
|
|
69
|
+
function getQueryName(query) {
|
|
71
70
|
//@ts-expect-error
|
|
72
|
-
return
|
|
71
|
+
return query.definitions[0].name?.value;
|
|
73
72
|
}
|
|
73
|
+
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
|