bitbucket-pr-post 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/bit_bucket_pr_post +11 -0
- data/bitbucket-pr-post.gemspec +23 -0
- data/lib/bitbucket/pr/post.rb +183 -0
- data/lib/bitbucket/pr/post/version.rb +7 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 943269ec183d90dba52b893078d88acc08f025d8
|
4
|
+
data.tar.gz: 6d0fc2d93b6ed42a3670752a810cd7e6d2f3f4a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6cc3f6c2f43c5bc566d59cf8dcf9a88b3e1898809a06acf2c74fcab0273475d4b05533bc0ba3b8dcb6e66e82cc912eca0a60984cd9755f68ff6913c64260d443
|
7
|
+
data.tar.gz: ddec92729f5d1145d9823f80708c9fc331876d16c4be0850ac9511191d9e0bece209457a5964aedcd32d39830b1ea5a18e640df22ea9a3d2ccff5510662f6986
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 hiroshi kobayashi
|
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,31 @@
|
|
1
|
+
# Bitbucket::Pr::Post
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bitbucket-pr-post'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bitbucket-pr-post
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/bitbucket-pr-post/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# require 'bitbucket/'
|
3
|
+
# require './lib/bitbucket/pr/post/version'
|
4
|
+
|
5
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
6
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
7
|
+
|
8
|
+
require 'bitbucket/pr/post'
|
9
|
+
Bitbucket::Pr::Post.new.request ARGV
|
10
|
+
|
11
|
+
#vim: ft=ruby
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bitbucket/pr/post/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bitbucket-pr-post"
|
8
|
+
spec.version = Bitbucket::Pr::Post::VERSION
|
9
|
+
spec.authors = ["hiroshi kobayashi"]
|
10
|
+
spec.email = ["kobayashi@ans-web.co.jp"]
|
11
|
+
spec.summary = %q{Create Pull Request on Bitbucket.}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require "bitbucket/pr/post/version"
|
2
|
+
require 'json'
|
3
|
+
require 'optparse'
|
4
|
+
require 'io/console'
|
5
|
+
|
6
|
+
|
7
|
+
module Bitbucket
|
8
|
+
module Pr
|
9
|
+
class Post
|
10
|
+
DOMAIN = 'bitbucket.org'
|
11
|
+
def request(argv)
|
12
|
+
set_opts argv
|
13
|
+
confirm
|
14
|
+
print_result post
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def set_opts(argv)
|
20
|
+
@opts = {}
|
21
|
+
o = OptionParser.new
|
22
|
+
o.on('-p', '--pass=Bitbucket Password'){|v| @opts[:pass] = v }
|
23
|
+
o.on('-t', '--title=PR Title'){|v| @opts[:title] = v }
|
24
|
+
o.on('-s', '--slug=SLUG(Repository Name)'){|v| @opts[:slug] = v }
|
25
|
+
o.on('-u', '--user=Bitbucket User'){|v| @opts[:user] = v }
|
26
|
+
o.on('-d', '--debug'){|v| @opts[:debug] = v }
|
27
|
+
o.on('-y', '--yes'){|v| @opts[:yes] = v }
|
28
|
+
o.on('-o', '--open-diff-url'){|v| @opts[:open_diff_url] = v}
|
29
|
+
o.on('-b', '--dst-branch=Destination Branch'){|v| @opts[:dst_branch] = v}
|
30
|
+
o.on('-U', '--update'){|v| @opts[:update] = v}
|
31
|
+
|
32
|
+
o.parse!(argv)
|
33
|
+
|
34
|
+
url = {}
|
35
|
+
`git remote -v`.split("\n").each do |remote|
|
36
|
+
if remote =~ /pub.*push/
|
37
|
+
url[:pub] = remote.split(" ")[1]
|
38
|
+
elsif remote =~ /origin.*push/
|
39
|
+
url[:master] = remote.split(" ")[1]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if url[:pub]
|
44
|
+
dummy,domain,@user,@slug = url[:pub].split /[@:\/]/
|
45
|
+
end
|
46
|
+
|
47
|
+
if url[:master]
|
48
|
+
dummy,domain,@user,@slug = url[:master].split /[@:\/]/
|
49
|
+
@dst_user = @user
|
50
|
+
end
|
51
|
+
|
52
|
+
if @opts[:pass]
|
53
|
+
@pass = @opts[:pass]
|
54
|
+
else
|
55
|
+
@pass = [(print "Password for #{DOMAIN}: "), STDIN.noecho(&:gets).rstrip][1]
|
56
|
+
puts
|
57
|
+
end
|
58
|
+
|
59
|
+
@user = @opts[:user] || @user
|
60
|
+
@slug = @opts[:slug] || @slug.sub('.git', '')
|
61
|
+
@branch = @opts[:branch] || `git branch | grep '*'`.split(" ")[1]
|
62
|
+
@dst_branch = @opts[:dst_branch] || 'master'
|
63
|
+
|
64
|
+
if @branch == 'master'
|
65
|
+
puts "Current Branch is master!"
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
|
69
|
+
if @opts[:title]
|
70
|
+
@title = @opts[:title]
|
71
|
+
@notice = ''
|
72
|
+
else
|
73
|
+
@title = `git log --summary --shortstat -1 --format="%s" --no-color --no-notes | head -1`.strip
|
74
|
+
@notice = "\n ^ This is Last Commit Mesasge. Use Option `--title` If You Want Change."
|
75
|
+
end
|
76
|
+
@description = @opts[:description] || ''
|
77
|
+
|
78
|
+
debug_print @opts
|
79
|
+
end
|
80
|
+
|
81
|
+
def confirm
|
82
|
+
puts <<-CONFIRM
|
83
|
+
title: #{@title}#{@notice}
|
84
|
+
description: #{@description}
|
85
|
+
src: #{@user}/#{@slug}/#{@branch}
|
86
|
+
v v v
|
87
|
+
v v v
|
88
|
+
dst: #{@dst_user}/#{@slug}/#{@dst_branch}
|
89
|
+
|
90
|
+
CONFIRM
|
91
|
+
|
92
|
+
unless @opts[:yes]
|
93
|
+
# Confirm
|
94
|
+
input = [(print "#{method} PR to #{DOMAIN}? [Y/n] "), gets.rstrip][1]
|
95
|
+
if input !~ /y(es)?/i or input == ''
|
96
|
+
puts "canceled."
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def request_data
|
103
|
+
data = {
|
104
|
+
title: @title.gsub("'", "\'"),
|
105
|
+
description: @description,
|
106
|
+
source: {
|
107
|
+
branch: { name: @branch },
|
108
|
+
repository: { full_name: "#{@user}/#{@slug}" }
|
109
|
+
},
|
110
|
+
destination: {
|
111
|
+
branch: { name: "master" },
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
debug_print(JSON.pretty_generate data)
|
116
|
+
JSON.generate data
|
117
|
+
end
|
118
|
+
|
119
|
+
def method
|
120
|
+
@opts[:update] ? 'PUT' : 'POST'
|
121
|
+
end
|
122
|
+
|
123
|
+
def post
|
124
|
+
curl = %W{
|
125
|
+
curl
|
126
|
+
--silent
|
127
|
+
-X #{method}
|
128
|
+
-H "Content-Type: application/json"
|
129
|
+
-u #{@user}:#{@pass}
|
130
|
+
https://api.bitbucket.org/2.0/repositories/#{@dst_user}/#{@slug}/pullrequests/
|
131
|
+
-d '#{request_data}'
|
132
|
+
}
|
133
|
+
cmd = curl.join " "
|
134
|
+
debug_print cmd
|
135
|
+
print 'send PR...'
|
136
|
+
`#{cmd}`
|
137
|
+
end
|
138
|
+
|
139
|
+
def print_result(result)
|
140
|
+
if result == ''
|
141
|
+
puts "Nothing Responce. Maybe, already created pull request."
|
142
|
+
else
|
143
|
+
begin
|
144
|
+
debug_print result
|
145
|
+
result_json = JSON.load(result)
|
146
|
+
debug_print result_json
|
147
|
+
|
148
|
+
if e = result_json['error']
|
149
|
+
print_response_error(e)
|
150
|
+
else
|
151
|
+
url = result_json['links']['diff']['href']
|
152
|
+
puts 'OK!'
|
153
|
+
if @opts[:open_diff_url]
|
154
|
+
puts "Open Browser..."
|
155
|
+
`open #{url}`
|
156
|
+
else
|
157
|
+
puts "Diff URL: #{url}"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
rescue => e
|
161
|
+
puts e.message
|
162
|
+
puts "Responce is Not JSON ( or Broken ). Use Debug Option `-d`."
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def print_response_error(e)
|
168
|
+
puts "Response Error: #{e['message']}"
|
169
|
+
if e['fields']
|
170
|
+
e['fields'].each do|col, v|
|
171
|
+
puts " col"
|
172
|
+
puts " #{v.join(". ")}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def debug_print(str)
|
178
|
+
puts "DEBUG: #{str}" if @opts[:debug]
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitbucket-pr-post
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hiroshi kobayashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-20 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- kobayashi@ans-web.co.jp
|
44
|
+
executables:
|
45
|
+
- bit_bucket_pr_post
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/bit_bucket_pr_post
|
55
|
+
- bitbucket-pr-post.gemspec
|
56
|
+
- lib/bitbucket/pr/post.rb
|
57
|
+
- lib/bitbucket/pr/post/version.rb
|
58
|
+
homepage: ''
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Create Pull Request on Bitbucket.
|
82
|
+
test_files: []
|