1.0.0 • Published 4 years ago

@google-cloud/code-suggester v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

Code-Suggester: Node.js Client

release level npm version codecov

Description

Code-suggester automates the steps involved in making code changes or code suggestions to your GitHub repository! Code-suggester 1. can be imported as a library, or 2. used as a CLI tool

Core Library

Installation

npm i code-suggester

Example

const suggester = require("code-suggester");

async function main() {
  const octokit = new Octokit({ auth: process.env.ACCESS_TOKEN });
  const changes =
    {
      'baz.txt':
      {
         mode: '100644',
         content: 'hello world!'
      }
    };
  await suggester.createPullRequest(
    changes,
    octokit,
    'Foo-Repo',
    'Bar-Owner',
  )
}

createPullRequest(options)

The createPullRequest() method creates a GitHub Pull request with the files given as input.

Syntax

createPullRequest(octokit, changes, config [, logger])

Parameters

octokit

octokit Required. An authenticated octokit instance.

changes

Map<string, FileData> | null | undefined Required. A set of files with their respective file contents conforming where the key is the file path, and the value is the a FileData object. If it is null, the empty map, or undefined, no changes will be made.

FileData Object | field | type | description | |--- |--- |--- | | mode | '100644' \| '100755' \| '040000' \| '160000' \| '120000' | The file type as specified in the GitHub API. Default is '100644'. From the docs: "The file mode; one of 100644 for file (blob), 100755 for executable (blob), 040000 for subdirectory (tree), 160000 for submodule (commit), or 120000 for a blob that specifies the path of a symlink."| | content | string \| null | Required. The entire file contents. |

options

Pull Request Options Object Required. Descriptive values or enforced rules for pull requests, branching, and commits.

Pull Request Options Object | field | type | description | |--------------- |----------- |------------- | | upstreamRepo | string | Required. The repository to suggest changes to. | | upstreamOwner | string | Required. The owner of the upstream repository. | | description | string | The GitHub Pull Request description. Default is 'code suggestions'. | | title | string | The GitHub Pull Request title. Default is 'chore: code suggestions'. | | branch | string | The branch containing the changes. Default is 'code-suggestions'. | | primary | string | The primary upstream branch to open a PR against. Default is 'master'. | | message | string | The commit message for the changes. Default is 'code suggestions'. We recommend following conventional commits.| | force | boolean | Whether or not to force push the reference even if the ancestor commits differs. Default is false. |

logger

Logger The default logger is Pino. You can plug in any logger that conforms to Pino's interface

Exceptions

The core-library will throw an exception if the GitHub V3 API returns an error response, or if the response data format did not come back as expected.

parseTextFiles(options)

The parseTextFiles() method takes a Map<string, string> or Object<string, string> and outputs the changes object for text files only.

Syntax

parseTextFiles(textFiles)

Parameters

textFiles

Object<string, string> | Map<string, string> Required. The key should be the relative file path in the source code, and the value should be the entire file content.

CLI

Installation

npm i code-suggester -g

code-suggester pr

code-suggester pr - opens a GitHub Pull Request against the upstream primary branch with the provided set of changes.

Syntax

code-suggester pr [options] --upstream-repo=<string> --upstream-owner=<string>

Options

--upstream-repo, -r

string Required. The repository to create the fork off of.

--upstream-owner, -o

string Required. The owner of the upstream repository.

--description, -d

string The GitHub Pull Request description. Default value is: 'code suggestions'.

--title, -t

string The GitHub Pull Request title. Default value is: 'chore: code suggestions'.

--branch, -b

string The GitHub working branch name. Default value is: 'code-suggestions'.

--primary, -p

string The primary upstream branch to open a PR against. Default value is: 'master'.

--message, -m

string The GitHub commit message. Default value is: 'code suggestions'.

--force, -f

boolean Whether or not to force push a reference with different commit history before the remote reference HEAD. Default value is: false.

--git-dir

string Required. The path of a git directory

Example

code-suggester pr -o foo -r bar -d 'description' -t 'title' -m 'message' --git-dir=.

Supported Node.js Versions

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js.

Client libraries targeting some end-of-life versions of Node.js are available, and can be installed via npm dist-tags. The dist-tags follow the naming convention legacy-(version).

Legacy Node.js versions are supported as a best effort:

  • Legacy versions will not be tested in continuous integration.
  • Some security patches may not be able to be backported.
  • Dependencies will not be kept up-to-date, and features will not be backported.

Legacy tags available

  • legacy-8: install client libraries from this dist-tag for versions compatible with Node.js 8.

Versioning

This library follows Semantic Versioning.

This library is considered to be in alpha. This means it is still a work-in-progress and under active development. Any release is subject to backwards-incompatible changes at any time.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

Please note that this README.md, the samples/README.md, and a variety of configuration files in this repository (including .nycrc and tsconfig.json) are generated from a central template. To edit one of these files, make an edit to its template in this directory.

License

Apache Version 2.0

See LICENSE