Last active
November 19, 2015 11:27
-
-
Save fmasuhr/c216a24f15f613c82445 to your computer and use it in GitHub Desktop.
Automated bundle update process and creation of pull request
This file contains 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 = 'gem-updates' | |
COMMIT_MESSAGE = 'Update gems' | |
# 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) | |
# Update gems | |
Bundler::CLI.start([:update]) | |
# Commit changes | |
git.add('Gemfile.lock') | |
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