git-pr 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97f85e7380c5d21763514b7f134fbdb3ab4edfab
4
+ data.tar.gz: f49dd9ec88c5c315c5919cd53457fd4b3221d065
5
+ SHA512:
6
+ metadata.gz: c60cee0f39408928779a9ab1914dd09e22816f7be41f657050c63a9d9c245cb0994a145aa5940ee527fe7a94fa74489f54169df8ed8b43ce1a77c9ab0e12422f
7
+ data.tar.gz: 92dace3a1b0acb054dac7e07c670f96523b4e47ed66d5aea980fa5e8e70f20558f58871def8e24a1ec52f959d2507d49722c396e377cf9f25691837883ed90b3
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ git-pr
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git-pr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nikolay Sturm
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Git::Pr
2
+
3
+ [![Build Status](https://secure.travis-ci.org/nistude/git-pr.png?branch=master)](http://travis-ci.org/nistude/git-pr)
4
+ [![Dependency Status](https://gemnasium.com/nistude/git-pr.png?travis)](https://gemnasium.com/nistude/git-pr)
5
+ [![Code Climate](https://codeclimate.com/github/nistude/git-pr.png)](https://codeclimate.com/github/nistude/git-pr)
6
+
7
+ `git-pr` facilitates GitHub pull requests.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'git-pr'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install git-pr
22
+
23
+ ## Configuration
24
+
25
+ Setup a [personal access token](https://github.com/settings/applications)
26
+ and configure your git for github:
27
+
28
+ $ git config --global github.user your_github_user_name
29
+ $ git config --global github.token your_github_personal_access_token
30
+
31
+ ## Usage
32
+
33
+ List pull requests:
34
+
35
+ $ git pr list # open pull requests for the active repository
36
+
37
+ You can also configure repository profiles and use those to query multiple
38
+ repositories at once:
39
+
40
+ $ git config --global --add pr.repository_profile.work org/one
41
+ $ git config --global --add pr.repository_profile.work org/two
42
+ $ git pr list --profile work # open pull requests for 'org/one', 'org/two'
43
+
44
+ Submit a pull request for the current branch:
45
+
46
+ $ git pr submit --title "my title" --message "longer description"
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/git-pr ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
+
4
+ require 'git/pr'
5
+
6
+ Git::Pr.run(ARGV)
data/git-pr.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git/pr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'git-pr'
8
+ spec.version = Git::Pr::VERSION
9
+ spec.authors = ['Nikolay Sturm']
10
+ spec.email = ['github@erisiandiscord.de']
11
+ spec.description = %q{git-pr facilitates GitHub pull requests}
12
+ spec.summary = %q{facilitates GitHub pull requests}
13
+ spec.homepage = 'https://github.com/nistude/git-pr'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'pry-debugger'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
25
+
26
+ spec.add_runtime_dependency 'octokit', '~> 2.6'
27
+ spec.add_runtime_dependency 'virtus', '~> 1.0'
28
+ end
@@ -0,0 +1,80 @@
1
+ require 'optparse'
2
+ require 'virtus'
3
+
4
+ module Git
5
+ class Pr
6
+ class CliOptions
7
+ include Virtus.value_object(constructor: false)
8
+
9
+ values do
10
+ attribute :subcommand
11
+ # list
12
+ attribute :mine, Boolean, default: false
13
+ attribute :profile
14
+ # submit
15
+ attribute :title
16
+ attribute :message
17
+ end
18
+
19
+ class Invalid < StandardError; end
20
+
21
+ def self.parse(args)
22
+ new(args).parse
23
+ end
24
+
25
+ def initialize(args)
26
+ @args = args
27
+ end
28
+
29
+ def parse
30
+ self.subcommand = @args.shift or raise(Invalid, 'missing subcommand')
31
+ mandatory = []
32
+
33
+ OptionParser.new do |opts|
34
+ opts.banner = "Usage: git pr #{subcommand} [options]"
35
+ case subcommand
36
+ when 'help', '-h', 'version'
37
+ # no specific options
38
+ when 'list'
39
+ opts.on('-m', '--mine',
40
+ 'Show only my pull requests') do
41
+ self.mine = true
42
+ end
43
+ opts.on('-p', '--profile PROFILE',
44
+ 'Show pull requests for all repositories in profile') do |profile|
45
+ self.profile = profile
46
+ end
47
+ when 'submit'
48
+ mandatory = [:title]
49
+ opts.on('-t', '--title TITLE',
50
+ 'Short description of pull request') do |title|
51
+ self.title = title
52
+ end
53
+ opts.on('-m', '--message MESSAGE',
54
+ 'Longer description of pull request') do |message|
55
+ self.message = message
56
+ end
57
+ else
58
+ raise(Invalid, "unknown subcommand: #{subcommand}")
59
+ end
60
+ opts.on_tail('-h', '--help', 'Show this message') do
61
+ puts opts
62
+ exit
63
+ end
64
+ end.parse!(@args)
65
+ validate_options(mandatory)
66
+
67
+ self
68
+ rescue OptionParser::InvalidOption => e
69
+ raise(Invalid, e.message)
70
+ end
71
+
72
+ private
73
+ def validate_options(mandatory)
74
+ mandatory.each do |arg|
75
+ raise(Invalid, 'missing arguments') if self.send(arg).nil?
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,29 @@
1
+ module Git
2
+ class Pr
3
+ class GitProperties
4
+ def api_token
5
+ `git config --get github.token`.chomp
6
+ end
7
+
8
+ def base_branch
9
+ 'master'
10
+ end
11
+
12
+ def current_branch
13
+ `git symbolic-ref HEAD`.split('/').last.chomp
14
+ end
15
+
16
+ def repository
17
+ `git config --get remote.origin.url`.split(':').last.sub(/\.git/, '').chomp
18
+ end
19
+
20
+ def login
21
+ `git config --get github.user`.chomp
22
+ end
23
+
24
+ def repository_profile(profile)
25
+ `git config --get-all pr.repository_profile.#{profile}`.split(/\n/)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ require 'octokit'
2
+
3
+ module Git
4
+ class Pr
5
+ class GitHub
6
+ class Failed < StandardError; end
7
+
8
+ def initialize(git_properties)
9
+ @git = git_properties
10
+
11
+ Octokit.configure do |c|
12
+ c.login = @git.login
13
+ c.password = @git.api_token
14
+ end
15
+ end
16
+
17
+ def list_pull_requests(profile, mine)
18
+ if profile
19
+ repositories = @git.repository_profile(profile)
20
+ else
21
+ repositories = [@git.repository]
22
+ end
23
+
24
+ [].tap do |prs|
25
+ repositories.flatten.uniq.each do |repo|
26
+ pull_requests = Octokit.pull_requests(repo, 'open')
27
+ if mine
28
+ prs << pull_requests.select { |pr| pr.user.login == @git.login }
29
+ else
30
+ prs << pull_requests
31
+ end
32
+ end
33
+ end.flatten
34
+ end
35
+
36
+ def submit_pull_request(title, message)
37
+ response = Octokit.create_pull_request(@git.repository,
38
+ @git.base_branch,
39
+ @git.current_branch,
40
+ title,
41
+ message)
42
+ response.state == 'open' ? response : raise(Failed, response.state)
43
+ rescue Octokit::UnprocessableEntity => e
44
+ message = e.message.match(/message: (.*)/)[1].sub(/ \/\/.*/, '')
45
+ raise Failed, message
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module Git
2
+ class Pr
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
data/lib/git/pr.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'git/pr/cli_options'
2
+ require 'git/pr/git_properties'
3
+ require 'git/pr/github'
4
+ require 'git/pr/version'
5
+
6
+ module Git
7
+ class Pr
8
+ def self.run(args)
9
+ new(args).run
10
+ end
11
+
12
+ def initialize(args)
13
+ @args = args
14
+ @github = GitHub.new(GitProperties.new)
15
+ end
16
+
17
+ def run
18
+ @options = CliOptions.parse(@args)
19
+ if self.respond_to?(@options.subcommand)
20
+ self.send(@options.subcommand)
21
+ else
22
+ be_helpful
23
+ end
24
+ rescue CliOptions::Invalid => e
25
+ be_helpful(e.message)
26
+ end
27
+
28
+ def list
29
+ prs = @github.list_pull_requests(@options.profile, @options.mine)
30
+ puts formatted(prs)
31
+ end
32
+
33
+ def submit
34
+ pr = @github.submit_pull_request(@options.title, @options.message)
35
+ puts "Opened new pull request to merge #{pr.head.ref} into #{pr.base.repo.full_name}/#{pr.base.ref}"
36
+ rescue GitHub::Failed => e
37
+ $stderr.puts "Failed to open new pull request: #{e.message}"
38
+ exit 1
39
+ end
40
+
41
+ def version
42
+ puts Git::Pr::VERSION
43
+ end
44
+
45
+ private
46
+ def be_helpful(message = nil)
47
+ puts message if message
48
+ puts <<-USAGE
49
+ Usage: git pr list [options]
50
+ or: git pr submit [options]
51
+ or: git pr version
52
+ USAGE
53
+ end
54
+
55
+ def terminal_size
56
+ command_exists?('tput') ? `tput cols`.to_i : 80
57
+ end
58
+
59
+ def command_exists?(command)
60
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir|
61
+ File.exists?(File.join(dir, command))
62
+ end
63
+ end
64
+
65
+ def formatted(prs)
66
+ if prs.empty?
67
+ 'No open pull requests'
68
+ else
69
+ prs.map do |pr|
70
+ message = "#{pr.base.repo.full_name}: #{pr.title} -- (#{pr.user.login})"
71
+ link = " #{pr._links.html.href} ".rjust(terminal_size - message.size)
72
+ message + link
73
+ end.join("\n")
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ require 'git/pr/cli_options'
3
+
4
+ describe Git::Pr::CliOptions do
5
+ context 'when the subcommand is missing' do
6
+ it 'raises an error' do
7
+ expect { Git::Pr::CliOptions.parse([]) }.to \
8
+ raise_error Git::Pr::CliOptions::Invalid, 'missing subcommand'
9
+ end
10
+ end
11
+
12
+ context 'when the subcommand is unknown' do
13
+ it 'raises an error' do
14
+ expect { Git::Pr::CliOptions.parse(['foo']) }.to \
15
+ raise_error Git::Pr::CliOptions::Invalid, 'unknown subcommand: foo'
16
+ end
17
+ end
18
+
19
+ describe 'subcommands' do
20
+ describe 'submit' do
21
+ let(:options) { Git::Pr::CliOptions.parse(['submit',
22
+ '--title', 'my title',
23
+ '--message', 'my message']) }
24
+
25
+ it 'extracts the subcommand from the command line arguments' do
26
+ expect(options.subcommand).to eq 'submit'
27
+ end
28
+
29
+ it 'parses pull request title' do
30
+ expect(options.title).to eq 'my title'
31
+ end
32
+
33
+ it 'parses pull request message' do
34
+ expect(options.message).to eq 'my message'
35
+ end
36
+
37
+ it 'raises an error on unknown arguments' do
38
+ expect { Git::Pr::CliOptions.parse(['submit', '--foo']) }.to \
39
+ raise_error Git::Pr::CliOptions::Invalid, /^invalid option/
40
+ end
41
+
42
+ it 'raises an error for missing arguments' do
43
+ expect { Git::Pr::CliOptions.parse(['submit', '--message', 'foo']) }.to \
44
+ raise_error Git::Pr::CliOptions::Invalid, 'missing arguments'
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'git/pr/git_properties'
3
+
4
+ describe Git::Pr::GitProperties do
5
+ let(:git) { Git::Pr::GitProperties.new }
6
+
7
+ describe '#api_token' do
8
+ it 'returns the user`s GitHub API token' do
9
+ git.stub(:`).with(/github.token/).and_return('foo')
10
+
11
+ expect(git.api_token).to eq 'foo'
12
+ end
13
+ end
14
+
15
+ describe '#current_branch' do
16
+ it 'returns the name of the current branch' do
17
+ git.stub(:`).with(/symbolic-ref/).and_return('refs/heads/foo')
18
+
19
+ expect(git.current_branch).to eq 'foo'
20
+ end
21
+ end
22
+
23
+ describe '#repository' do
24
+ it 'returns the name of the GitHub repository' do
25
+ git.stub(:`).with(/remote.origin.url/).and_return('git@github.com:foo/bar.git')
26
+
27
+ expect(git.repository).to eq 'foo/bar'
28
+ end
29
+ end
30
+
31
+ describe '#login' do
32
+ it 'returns the user`s GitHub login name' do
33
+ git.stub(:`).with(/github.user/).and_return('foo')
34
+
35
+ expect(git.login).to eq 'foo'
36
+ end
37
+ end
38
+
39
+ describe '#repository_profile' do
40
+ it 'returns an array of repositories in the given profile' do
41
+ git.stub(:`).with(/pr.repository_profile.foo/).and_return("repo/one\nrepo/two\n")
42
+
43
+ expect(git.repository_profile('foo')).to eq ['repo/one', 'repo/two']
44
+ end
45
+ end
46
+ end
@@ -0,0 +1 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-pr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Sturm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-debugger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: octokit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: virtus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ description: git-pr facilitates GitHub pull requests
98
+ email:
99
+ - github@erisiandiscord.de
100
+ executables:
101
+ - git-pr
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - .ruby-gemset
108
+ - .ruby-version
109
+ - .travis.yml
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/git-pr
115
+ - git-pr.gemspec
116
+ - lib/git/pr.rb
117
+ - lib/git/pr/cli_options.rb
118
+ - lib/git/pr/git_properties.rb
119
+ - lib/git/pr/github.rb
120
+ - lib/git/pr/version.rb
121
+ - spec/git/pr/cli_options_spec.rb
122
+ - spec/git/pr/git_properties_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: https://github.com/nistude/git-pr
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.0.3
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: facilitates GitHub pull requests
148
+ test_files:
149
+ - spec/git/pr/cli_options_spec.rb
150
+ - spec/git/pr/git_properties_spec.rb
151
+ - spec/spec_helper.rb