pull_request-create 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 774b339b1d19c13d9d2bc636c71fb2b60ee0798f
4
+ data.tar.gz: e19957ab2442d5437d0331abb64bbc037c5c31e5
5
+ SHA512:
6
+ metadata.gz: 1494bbdd6819a5f06b1b3e1fc033b08ca058bd5cc014e7cf9e8c41bcdad34440d968a9d26964d704332ac19977f171c0350b207e37880f0f279706525ee6590d
7
+ data.tar.gz: 0544647106e011020cf20280d24fee989630fddabd32b49fdd9bedb0d1c55bc934f2fe13c544ae9ff5e4b5642861e69f3244e29b75ef5643b71115569757435c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bundle_bin/*'
4
+ - 'vendor/bundle/**/*'
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/LineLength:
10
+ Max: 100
11
+
12
+ Style/FileName:
13
+ Exclude:
14
+ - exe/*
15
+
16
+ Style/RegexpLiteral:
17
+ MaxSlashes: 0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pull_request-create.gemspec
4
+ gemspec
5
+ gem 'byebug' if RUBY_VERSION >= '2.0.0'
6
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 sanemat
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # PullRequest::Create
2
+
3
+ [![Gem Version](http://img.shields.io/gem/v/pull_request-create.svg?style=flat)](http://badge.fury.io/rb/pull_request-create)
4
+ [![Build Status](http://img.shields.io/travis/packsaddle/ruby-pull_request-create/master.svg?style=flat)](https://travis-ci.org/packsaddle/ruby-pull_request-create)
5
+
6
+ ## Commands
7
+
8
+ ```
9
+ Commands:
10
+ pull-request-create create # Create a pull request
11
+ pull-request-create help [COMMAND] # Describe available commands or one specific command
12
+ pull-request-create version # Show the PullRequest::Create version
13
+
14
+ Usage:
15
+ pull-request-create create
16
+
17
+ Options:
18
+ [--debug], [--no-debug]
19
+ [--verbose], [--no-verbose]
20
+ [--repo=REPO]
21
+ # Default: (YOUR_CURRENT_REPO_SLUG)
22
+ [--base=BASE]
23
+ # Default: master
24
+ [--head=HEAD]
25
+ # Default: (YOUR_CURRENT_BRANCH)
26
+ [--title=TITLE]
27
+ # Default: Request by PullRequest::Create
28
+ [--body=BODY]
29
+ # Default: :hamster::hamster::hamster: by <a href="https://github.com/packsaddle/ruby-pull_request-create">PullRequest::Create</a>
30
+
31
+ Create a pull request
32
+ ```
33
+
34
+ Requires `GITHUB_ACCESS_TOKEN`.
35
+
36
+ ## Installation
37
+
38
+ Add this line to your application's Gemfile:
39
+
40
+ ```ruby
41
+ gem 'pull_request-create'
42
+ ```
43
+
44
+ And then execute:
45
+
46
+ $ bundle
47
+
48
+ Or install it yourself as:
49
+
50
+ $ gem install pull_request-create
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec pull_request-create` to use the code located in this directory, ignoring other installed copies of this gem.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/packsaddle/ruby-pull_request-create/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/test*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pull_request/create'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pull_request/create'
4
+ require 'pull_request/create/cli'
5
+ PullRequest::Create::CLI.start(ARGV)
@@ -0,0 +1,65 @@
1
+ require 'thor'
2
+
3
+ module PullRequest
4
+ module Create
5
+ class CLI < Thor
6
+ def self.exit_on_failure?
7
+ true
8
+ end
9
+
10
+ desc 'version', 'Show the PullRequest::Create version'
11
+ map %w(-v --version) => :version
12
+
13
+ def version
14
+ puts "PullRequest::Create version #{::PullRequest::Create::VERSION}"
15
+ end
16
+
17
+ desc 'create', 'Create a pull request'
18
+ option :debug, type: :boolean, default: false
19
+ option :verbose, type: :boolean, default: false
20
+ option :repo, type: :string
21
+ option :base, type: :string, default: Client::BASE
22
+ option :head, type: :string
23
+ option :title, type: :string, default: Client::TITLE
24
+ option :body, type: :string, default: Client::BODY
25
+ def create
26
+ setup_logger(options)
27
+ params = {
28
+ repo: options[:repo],
29
+ base: options[:base],
30
+ head: options[:head],
31
+ title: options[:title],
32
+ body: options[:body]
33
+ }
34
+ client = Client.new(Repository.new('.'))
35
+ client.create_pull_request(params)
36
+ rescue StandardError => e
37
+ suggest_messages(options)
38
+ raise e
39
+ end
40
+ default_command :create
41
+
42
+ no_commands do
43
+ def logger
44
+ ::PullRequest::Create.logger
45
+ end
46
+
47
+ def setup_logger(options)
48
+ if options[:debug]
49
+ logger.level = Logger::DEBUG
50
+ elsif options[:verbose]
51
+ logger.level = Logger::INFO
52
+ end
53
+ logger.debug(options)
54
+ end
55
+
56
+ def suggest_messages(options)
57
+ logger.error 'Have a question? Please ask us:'
58
+ logger.error ISSUE_URL
59
+ logger.error 'options:'
60
+ logger.error options
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,67 @@
1
+ module PullRequest
2
+ module Create
3
+ class Client
4
+ BASE = 'master'
5
+ TITLE = 'Request by PullRequest::Create'
6
+ BODY = <<-EOL.gsub(/^\s+/, '').gsub("\n", ' ')
7
+ :hamster::hamster::hamster:
8
+ by
9
+ <a href="https://github.com/packsaddle/ruby-pull_request-create">PullRequest::Create</a>
10
+ EOL
11
+
12
+ def initialize(repo)
13
+ @repo = repo
14
+ end
15
+
16
+ def create_pull_request(params)
17
+ logger.debug(params)
18
+
19
+ repo = decide_repo(params[:repo])
20
+ base = decide_base(params[:base])
21
+ head = decide_head(params[:head])
22
+ title = decide_title(params[:title])
23
+ body = decide_body(params[:body])
24
+ options = {}
25
+ logger.debug([repo, base, head, title, body, options])
26
+ resource = client.create_pull_request(repo, base, head, title, body, options)
27
+ logger.debug(resource)
28
+ logger.info("state: #{resource.state}")
29
+ logger.info("title: #{resource.title}")
30
+ logger.info("html_url: #{resource.html_url}")
31
+ resource
32
+ end
33
+
34
+ def decide_repo(repo)
35
+ repo || @repo.slug
36
+ end
37
+
38
+ def decide_base(base)
39
+ base || BASE
40
+ end
41
+
42
+ def decide_head(head)
43
+ head || @repo.current_branch
44
+ end
45
+
46
+ def decide_title(title)
47
+ title || TITLE
48
+ end
49
+
50
+ def decide_body(body)
51
+ body || BODY
52
+ end
53
+
54
+ def logger
55
+ ::PullRequest::Create.logger
56
+ end
57
+
58
+ def client
59
+ @client ||= ::Octokit::Client.new(access_token: access_token)
60
+ end
61
+
62
+ def access_token
63
+ ENV['GITHUB_ACCESS_TOKEN']
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,37 @@
1
+ module PullRequest
2
+ module Create
3
+ class Repository
4
+ def initialize(path, options = {})
5
+ @path = path
6
+ @options = options
7
+ end
8
+
9
+ def logger
10
+ ::PullRequest::Create.logger
11
+ end
12
+
13
+ def git
14
+ @git ||= ::Git.open(@path, @options)
15
+ end
16
+
17
+ def current_branch
18
+ git.current_branch
19
+ end
20
+
21
+ def slug
22
+ slug_regex = %r{\A/(?<slug>.*?)(?:\.git)?\Z}
23
+ remote_urls.map do |url|
24
+ uri = GitCloneUrl.parse(url)
25
+ match = slug_regex.match(uri.path)
26
+ match[:slug] if match
27
+ end.compact.first
28
+ end
29
+
30
+ def remote_urls
31
+ git
32
+ .remotes
33
+ .map(&:url)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module PullRequest
2
+ module Create
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'logger'
2
+ require 'git'
3
+ require 'octokit'
4
+ require 'git_clone_url'
5
+
6
+ require 'pull_request/create/client'
7
+ require 'pull_request/create/repository'
8
+ require 'pull_request/create/version'
9
+
10
+ module PullRequest
11
+ module Create
12
+ ISSUE_URL = 'https://github.com/packsaddle/ruby-pull_request-create/issues/new'
13
+
14
+ def self.default_logger
15
+ logger = Logger.new(STDERR)
16
+ logger.progname = "PullRequest::Create/#{VERSION}"
17
+ logger.level = Logger::WARN
18
+ logger
19
+ end
20
+
21
+ def self.logger
22
+ return @logger if @logger
23
+ @logger = default_logger
24
+ end
25
+
26
+ class << self
27
+ attr_writer :logger
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pull_request/create/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pull_request-create'
8
+ spec.version = PullRequest::Create::VERSION
9
+ spec.authors = ['sanemat']
10
+ spec.email = ['o.gata.ken@gmail.com']
11
+
12
+ spec.summary = 'Create pull request with few configuration.'
13
+ spec.description = 'Create pull request with few configuration.'
14
+ spec.homepage = 'https://github.com/packsaddle/ruby-pull_request-create'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = \
18
+ `git ls-files -z`
19
+ .split("\x0")
20
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ .reject do |f|
22
+ [
23
+ '.travis.yml',
24
+ 'circle.yml',
25
+ '.tachikoma.yml'
26
+ ].include?(f)
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_runtime_dependency 'thor'
33
+ spec.add_runtime_dependency 'git'
34
+ spec.add_runtime_dependency 'octokit'
35
+ spec.add_runtime_dependency 'git_clone_url'
36
+
37
+ spec.add_development_dependency 'bundler', '~> 1.8'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'test-unit'
40
+ spec.add_development_dependency 'mocha'
41
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pull_request-create
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sanemat
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: git_clone_url
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-unit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mocha
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Create pull request with few configuration.
126
+ email:
127
+ - o.gata.ken@gmail.com
128
+ executables:
129
+ - pull-request-create
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rubocop.yml"
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - exe/pull-request-create
143
+ - lib/pull_request/create.rb
144
+ - lib/pull_request/create/cli.rb
145
+ - lib/pull_request/create/client.rb
146
+ - lib/pull_request/create/repository.rb
147
+ - lib/pull_request/create/version.rb
148
+ - pull_request-create.gemspec
149
+ homepage: https://github.com/packsaddle/ruby-pull_request-create
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.5
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Create pull request with few configuration.
173
+ test_files: []