Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 4088008f6f7dca5f1fbf513cb3a4808deb088951 0 parents
@gabebw authored
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
4 Gemfile
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in pull.gemspec
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Gabe Berke-Williams
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 README.md
@@ -0,0 +1,44 @@
+# Pull
+
+Creates Github pull requests from the command line.
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'pull'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install pull
+
+## Usage
+
+The gem assumes that you have a Github remote named "origin".
+
+ # This breaks if your branch isn't on Github.
+ $ git push origin your-branch
+ $ pull
+ Making a pull request for your-branch!
+
+ https://github.com/USER/REPO/pull/1
+
+Voila.
+
+## Thanks
+
+Thanks to Nick Quaranto ([qrush](https://github.com/qrush)) for writing the
+first version of this script and leaving a version of it in every project he
+touched.
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
2  Rakefile
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
64 bin/pull
@@ -0,0 +1,64 @@
+#!/usr/bin/env ruby
+
+require 'json'
+require 'net/https'
+
+def api_uri
+ # This uses the deprecated V2 API because that lets you use your token instead
+ # of entering your password all the time.
+ remote_url = `git remote show -n origin`.split("\n").grep(/Push/).first.split.grep(/github/)[0]
+ user_and_repo = remote_url.split(':')[1].sub(/\.git$/, '')
+ URI.parse("https://github.com/api/v2/json/pulls/#{user_and_repo}")
+end
+
+def current_branch
+ `git symbolic-ref HEAD`.strip.sub("refs/heads/", "")
+end
+
+def current_branch_sha
+ `git show-ref HEAD -s`
+end
+
+def current_user
+ `git config github.user`.strip
+end
+
+def current_token
+ `git config github.token`.strip
+end
+
+def ensure_github_token_is_set
+ if current_token.empty?
+ puts "Please set github.token: git config --global github.token <TOKEN>"
+ exit 1
+ end
+end
+
+ensure_github_token_is_set
+
+puts "Making a pull request for #{current_branch}!"
+puts
+
+def try_to_create_pull_request
+ post = Net::HTTP::Post.new(api_uri.request_uri)
+ post.basic_auth("#{current_user}/token", current_token)
+ post.set_form_data("pull[base]" => "master",
+ "pull[head]" => current_branch,
+ "pull[title]" => current_branch)
+
+ http = Net::HTTP.new(api_uri.host, api_uri.port)
+ http.use_ssl = true
+ response = http.request(post)
+ response.body
+end
+
+json = JSON.parse(try_to_create_pull_request)
+
+if json.key?('error')
+ puts "ERROR:"
+ puts [json['error']].flatten.join("\n")
+ exit 1
+else
+ pull_url = json['pull']['html_url']
+ puts pull_url
+end
4 lib/pull.rb
@@ -0,0 +1,4 @@
+require "pull/version"
+
+module Pull
+end
3  lib/pull/version.rb
@@ -0,0 +1,3 @@
+module Pull
+ VERSION = "0.0.1"
+end
19 pull.gemspec
@@ -0,0 +1,19 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/pull/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Gabe Berke-Williams"]
+ gem.email = ["gabe@thoughtbot.com"]
+ gem.description = %q{Easily create Github pull requests from the command line.}
+ gem.summary = %q{Easily create Github pull requests from the command line.}
+ gem.homepage = "https://github.com/gabebw/pull"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "pull"
+ gem.require_paths = ["lib"]
+ gem.version = Pull::VERSION
+
+ gem.add_development_dependency("json")
+end
Please sign in to comment.
Something went wrong with that request. Please try again.