ehabdevel / octokit-create-pull-request

Octokit plugin to create a pull request with multiple file changes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

octokit-create-pull-request

Octokit plugin to create a pull request with multiple file changes

@latest Build Status Greenkeeper

Features

  • Retrieves the repository’s default branch unless base branch is set
  • Makes multiple file changes using a single commit
  • Creates a fork if the authenticated user does not have write access to the repository
  • See Todos for more cool feature ideas! Pull requests welcome!

Usage

Update or create two files with a single commit

const Octokit = require("@octokit/rest").plugin(
  require("octokit-create-pull-request")
);

const TOKEN = "secret123"; // token needs "repo" scope
const octokit = new Octokit({
  auth: `token ${TOKEN}`
});

// Returns a normal Octokit PR response
// See https://octokit.github.io/rest.js/#octokit-routes-pulls-create
octokit
  .createPullRequest({
    owner: "repo-name",
    repo: "repo-name",
    title: "pull request title",
    body: "pull request description",
    base: "master" /* optional: defaults to default branch */,
    head: "pull-request-branch-name",
    changes: {
      files: {
        "path/to/file1.txt": "Content for file1",
        "path/to/file2.txt": null // deletes file if it exists
      },
      commit: "creating file1.txt & file2.txt"
    }
  })
  .then(pr => console.log(pr.data.number));

You can create a personal access token with the repo scope at https://github.com/settings/tokens/new?scopes=repo

Todos

  • Editing files based on current content
    Add support to pass a function as file content, the function will be called with the current file content, if present.
  • Multiple commits
    Split up changes among multiple edits
  • Binary files
    Allow to create / edit files with binary content

LICENSE

MIT

About

Octokit plugin to create a pull request with multiple file changes

License:MIT License


Languages

Language:JavaScript 100.0%