Created
December 14, 2015 22:49
-
-
Save fmasuhr/8b7dee8a706f3d431b22 to your computer and use it in GitHub Desktop.
Create GitHub Pull Request for local changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/cli' | |
require 'git' | |
require 'octokit' | |
BRANCH_NAME = 'branch' | |
COMMIT_MESSAGE = 'Commit Message' | |
# ASSIGNEE = 'pengwynn' # update to assing pull request | |
git = Git.open(Dir.pwd) | |
github = Octokit::Client.new(access_token: ENV['GITHUB_ACCESS_TOKEN']) | |
repository = git.remote(:origin).url.split(':')[1].chomp('.git') | |
default_branch = github.repository(repository).default_branch | |
# Checkout new branch and get up to date | |
git.branch(BRANCH_NAME).checkout | |
git.pull(:origin, default_branch) | |
# Commit changes | |
`git add -u` # git.add does not support to only add updated files | |
git.commit(COMMIT_MESSAGE) | |
git.push(:origin, BRANCH_NAME) | |
# Create Github Pull request | |
pull = github.create_pull_request(repository, default_branch, BRANCH_NAME, COMMIT_MESSAGE) | |
# Add assignee | |
github.update_issue(repository, pull.number, assignee: ASSIGNEE) if defined?(ASSIGNEE) && ASSIGNEE | |
# Cleanup branch | |
git.branch('master').checkout | |
git.branch(BRANCH_NAME).delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment