code-suggester
Advanced tools
Comparing version 2.0.0-candidate.1 to 2.0.0
@@ -40,2 +40,3 @@ "use strict"; | ||
labels: yargs.argv.labels, | ||
logger: logger_1.logger, | ||
}; | ||
@@ -52,2 +53,3 @@ } | ||
pullNumber: yargs.argv.pullNumber, | ||
logger: logger_1.logger, | ||
}; | ||
@@ -60,3 +62,3 @@ } | ||
const octokit = new rest_1.Octokit({ auth: process.env.ACCESS_TOKEN }); | ||
await __1.createPullRequest(octokit, changes, options, logger_1.logger); | ||
await __1.createPullRequest(octokit, changes, options); | ||
} | ||
@@ -67,3 +69,3 @@ async function reviewCommand() { | ||
const octokit = new rest_1.Octokit({ auth: process.env.ACCESS_TOKEN }); | ||
await __1.reviewPullRequest(octokit, diffContents, reviewOptions, logger_1.logger); | ||
await __1.reviewPullRequest(octokit, diffContents, reviewOptions); | ||
} | ||
@@ -75,3 +77,3 @@ /** | ||
try { | ||
logger_1.setupLogger(); | ||
logger_1.setupLogger(console); | ||
if (!process.env.ACCESS_TOKEN) { | ||
@@ -78,0 +80,0 @@ throw Error('The ACCESS_TOKEN should not be undefined'); |
@@ -1,2 +0,2 @@ | ||
import { Changes, CreatePullRequestUserOptions, FileDiffContent, CreateReviewCommentUserOptions, Logger } from './types'; | ||
import { Changes, CreatePullRequestUserOptions, FileDiffContent, CreateReviewCommentUserOptions } from './types'; | ||
export { Changes } from './types'; | ||
@@ -18,6 +18,5 @@ import { Octokit } from '@octokit/rest'; | ||
* @param options The configuration for interacting with GitHub provided by the user. | ||
* @param loggerOption The logger instance (optional). | ||
* @returns the created review's id number, or null if there are no changes to be made. | ||
*/ | ||
export declare function reviewPullRequest(octokit: Octokit, diffContents: Map<string, FileDiffContent> | string, options: CreateReviewCommentUserOptions, loggerOption?: Logger): Promise<number | null>; | ||
export declare function reviewPullRequest(octokit: Octokit, diffContents: Map<string, FileDiffContent> | string, options: CreateReviewCommentUserOptions): Promise<number | null>; | ||
/** | ||
@@ -43,6 +42,5 @@ * Make a new GitHub Pull Request with a set of changes applied on top of primary branch HEAD. | ||
* @param {CreatePullRequestUserOptions} options The configuration for interacting with GitHub provided by the user. | ||
* @param {Logger} logger The logger instance (optional). | ||
* @returns {Promise<number>} the pull request number. Returns 0 if unsuccessful. | ||
*/ | ||
declare function createPullRequest(octokit: Octokit, changes: Changes | null | undefined, options: CreatePullRequestUserOptions, loggerOption?: Logger): Promise<number>; | ||
declare function createPullRequest(octokit: Octokit, changes: Changes | null | undefined, options: CreatePullRequestUserOptions): Promise<number>; | ||
/** | ||
@@ -49,0 +47,0 @@ * Convert a Map<string,string> or {[path: string]: string}, where the key is the relative file path in the repository, |
@@ -17,3 +17,2 @@ "use strict"; | ||
exports.parseTextFiles = exports.createPullRequest = exports.reviewPullRequest = void 0; | ||
const handler = require("./github-handler"); | ||
const types_1 = require("./types"); | ||
@@ -23,2 +22,8 @@ const logger_1 = require("./logger"); | ||
const retry = require("async-retry"); | ||
const review_pull_request_1 = require("./github/review-pull-request"); | ||
const branch_1 = require("./github/branch"); | ||
const fork_1 = require("./github/fork"); | ||
const commit_and_push_1 = require("./github/commit-and-push"); | ||
const open_pull_request_1 = require("./github/open-pull-request"); | ||
const labels_1 = require("./github/labels"); | ||
/** | ||
@@ -38,7 +43,6 @@ * Given a set of suggestions, make all the multiline inline review comments on a given pull request given | ||
* @param options The configuration for interacting with GitHub provided by the user. | ||
* @param loggerOption The logger instance (optional). | ||
* @returns the created review's id number, or null if there are no changes to be made. | ||
*/ | ||
async function reviewPullRequest(octokit, diffContents, options, loggerOption) { | ||
logger_1.setupLogger(loggerOption); | ||
async function reviewPullRequest(octokit, diffContents, options) { | ||
logger_1.setupLogger(options.logger); | ||
// if null undefined, or the empty map then no changes have been provided. | ||
@@ -57,3 +61,3 @@ // Do not execute GitHub workflow | ||
}; | ||
const reviewNumber = await handler.reviewPullRequest(octokit, remote, gitHubConfigs.pullNumber, gitHubConfigs.pageSize, diffContents); | ||
const reviewNumber = await review_pull_request_1.createPullRequestReview(octokit, remote, gitHubConfigs.pullNumber, gitHubConfigs.pageSize, diffContents); | ||
return reviewNumber; | ||
@@ -82,7 +86,6 @@ } | ||
* @param {CreatePullRequestUserOptions} options The configuration for interacting with GitHub provided by the user. | ||
* @param {Logger} logger The logger instance (optional). | ||
* @returns {Promise<number>} the pull request number. Returns 0 if unsuccessful. | ||
*/ | ||
async function createPullRequest(octokit, changes, options, loggerOption) { | ||
logger_1.setupLogger(loggerOption); | ||
async function createPullRequest(octokit, changes, options) { | ||
logger_1.setupLogger(options.logger); | ||
// if null undefined, or the empty map then no changes have been provided. | ||
@@ -100,3 +103,3 @@ // Do not execute GitHub workflow | ||
}; | ||
const origin = options.fork === false ? upstream : await handler.fork(octokit, upstream); | ||
const origin = options.fork === false ? upstream : await fork_1.fork(octokit, upstream); | ||
const originBranch = { | ||
@@ -108,3 +111,3 @@ ...origin, | ||
options.retry = options.retry === undefined ? 5 : options.retry; | ||
const refHeadSha = await retry(async () => await handler.branch(octokit, origin, upstream, originBranch.branch, gitHubConfigs.primary), { | ||
const refHeadSha = await retry(async () => await branch_1.branch(octokit, origin, upstream, originBranch.branch, gitHubConfigs.primary), { | ||
retries: options.retry, | ||
@@ -120,3 +123,3 @@ factor: 2.8411, | ||
}); | ||
await handler.commitAndPush(octokit, refHeadSha, changes, originBranch, gitHubConfigs.message, gitHubConfigs.force); | ||
await commit_and_push_1.commitAndPush(octokit, refHeadSha, changes, originBranch, gitHubConfigs.message, gitHubConfigs.force); | ||
const description = { | ||
@@ -126,6 +129,6 @@ body: gitHubConfigs.description, | ||
}; | ||
const prNumber = await handler.openPullRequest(octokit, upstream, originBranch, description, gitHubConfigs.maintainersCanModify, gitHubConfigs.primary); | ||
const prNumber = await open_pull_request_1.openPullRequest(octokit, upstream, originBranch, description, gitHubConfigs.maintainersCanModify, gitHubConfigs.primary, options.draft); | ||
logger_1.logger.info(`Successfully opened pull request: ${prNumber}.`); | ||
// addLabels will no-op if options.labels is undefined or empty. | ||
await handler.addLabels(octokit, upstream, originBranch, prNumber, options.labels); | ||
await labels_1.addLabels(octokit, upstream, originBranch, prNumber, options.labels); | ||
return prNumber; | ||
@@ -132,0 +135,0 @@ } |
@@ -64,2 +64,4 @@ export declare type FileMode = '100644' | '100755' | '040000' | '160000' | '120000'; | ||
retry?: number; | ||
draft?: boolean; | ||
logger?: Logger; | ||
} | ||
@@ -88,2 +90,3 @@ /** | ||
pageSize?: number; | ||
logger?: Logger; | ||
} | ||
@@ -90,0 +93,0 @@ /** |
# Changelog | ||
## [2.0.0](https://www.github.com/googleapis/code-suggester/compare/v1.11.0...v2.0.0) (2021-04-26) | ||
### ⚠ BREAKING CHANGES | ||
* This does not actually break any interfaces that are intended to be public (exported in `index.ts`), but would be breaking if you are importing from deeply nested paths which is not intended. | ||
* move custom logger configuration into options (#212) | ||
* cleanup custom logging (#206) | ||
### Features | ||
* cleanup custom logging ([#206](https://www.github.com/googleapis/code-suggester/issues/206)) ([3e4df30](https://www.github.com/googleapis/code-suggester/commit/3e4df304f373eabeb0a3be272be017685a67d90d)), closes [#178](https://www.github.com/googleapis/code-suggester/issues/178) [#183](https://www.github.com/googleapis/code-suggester/issues/183) | ||
### Code Refactoring | ||
* move custom logger configuration into options ([#212](https://www.github.com/googleapis/code-suggester/issues/212)) ([89a1482](https://www.github.com/googleapis/code-suggester/commit/89a1482839e43728e1f1e56d0845058368e9d16c)) | ||
* reorganize source code ([#208](https://www.github.com/googleapis/code-suggester/issues/208)) ([5c2edb1](https://www.github.com/googleapis/code-suggester/commit/5c2edb1a75ef394786575cc57afe09fff77932f0)) | ||
## [1.11.0](https://www.github.com/googleapis/code-suggester/compare/v1.10.0...v1.11.0) (2021-04-22) | ||
### Features | ||
* add optional draft flag to openPullRequest() ([#207](https://www.github.com/googleapis/code-suggester/issues/207)) ([ff9516c](https://www.github.com/googleapis/code-suggester/commit/ff9516ced31a6b8346b56870e54705412b79f52e)) | ||
## [1.10.0](https://www.github.com/googleapis/code-suggester/compare/v1.9.3...v1.10.0) (2021-03-30) | ||
@@ -4,0 +30,0 @@ |
{ | ||
"name": "code-suggester", | ||
"description": "Library to propose code changes", | ||
"version": "2.0.0-candidate.1", | ||
"version": "2.0.0", | ||
"license": "Apache-2.0", | ||
@@ -60,3 +60,2 @@ "author": "Google LLC", | ||
"@types/node": "^14.0.20", | ||
"@types/proxyquire": "^1.3.28", | ||
"@types/sinon": "^10.0.0", | ||
@@ -73,3 +72,2 @@ "c8": "^7.0.1", | ||
"pack-n-play": "^1.0.0-2", | ||
"proxyquire": "^2.1.3", | ||
"sinon": "^10.0.0", | ||
@@ -76,0 +74,0 @@ "ts-loader": "^8.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23
1
174823
49
2205
2