pullrequest 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +0 -7
- data/exe/pullrequest +25 -15
- data/lib/pullrequest/bitbucket.rb +74 -15
- data/lib/pullrequest/version.rb +1 -1
- data/pullrequest.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba700fdf8961d0cf9c3d6002c65abe42ac2dd9ae
|
4
|
+
data.tar.gz: ab3e8846ac4962e113e36a3fd5b6ea6b85671811
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc997522583e766cfe9923500db0333c2d68ee0fc7dd061d602da1f0edc4fb5db9fb5352fadf81bab3df9db42fd58a7db9e3170cd448d369676574b9b27ae922
|
7
|
+
data.tar.gz: 3707adafefdc5ad7ad5081e381e639a9e5b8d5b1853f37f63c0c0bdceb17011250a26ac7b401ba109f8fb13c756f50d3842c06fafb334cd5bf1afee4d32c4f8f
|
data/README.md
CHANGED
@@ -13,13 +13,6 @@ CLI for submitting Bitbucket pull requests
|
|
13
13
|
You will be prompted to enter details for your pull request.
|
14
14
|
The command will be shown before asking confirmation to execute it.
|
15
15
|
|
16
|
-
## TODO
|
17
|
-
|
18
|
-
* Add `pullrequest` to path
|
19
|
-
* Add review option at confirmation (start again with previous answers as defaults).
|
20
|
-
* Optionally cache Bitbucket credentials.
|
21
|
-
* Add GitHub support.
|
22
|
-
|
23
16
|
## Contributing
|
24
17
|
|
25
18
|
1. Fork it ( https://github.com/zubin/pullrequest/fork )
|
data/exe/pullrequest
CHANGED
@@ -9,26 +9,36 @@ require 'pullrequest/thor'
|
|
9
9
|
module Pullrequest
|
10
10
|
class CLI < Thor
|
11
11
|
include Pullrequest::Shell
|
12
|
+
Aborted = Class.new(StandardError)
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
desc "submit", "Submits Bitbucket pull request"
|
15
|
+
def submit
|
16
|
+
begin
|
17
|
+
command
|
18
|
+
if yes? "Print command?"
|
19
|
+
$stdout.puts command
|
20
|
+
end
|
21
|
+
if yes? "Proceed?"
|
22
|
+
execute command
|
23
|
+
else
|
24
|
+
raise Aborted
|
25
|
+
end
|
26
|
+
rescue Aborted
|
27
|
+
if yes? "Review?"
|
28
|
+
pullrequest.review
|
29
|
+
retry
|
30
|
+
end
|
16
31
|
end
|
32
|
+
end
|
17
33
|
|
18
|
-
|
19
|
-
|
20
|
-
|
34
|
+
private
|
35
|
+
|
36
|
+
def command
|
37
|
+
pullrequest.command
|
21
38
|
end
|
22
39
|
|
23
|
-
|
24
|
-
|
25
|
-
command
|
26
|
-
if yes? "Print command?"
|
27
|
-
$stdout.puts command
|
28
|
-
end
|
29
|
-
if yes? "Proceed?"
|
30
|
-
execute command
|
31
|
-
end
|
40
|
+
def pullrequest
|
41
|
+
@pullrequest ||= Bitbucket.new(self)
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'fileutils'
|
1
2
|
require 'json'
|
2
3
|
require 'thor'
|
4
|
+
require 'yaml'
|
3
5
|
|
4
6
|
module Pullrequest
|
5
7
|
class Bitbucket
|
@@ -10,21 +12,28 @@ module Pullrequest
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def command
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
"https://bitbucket.org/api/2.0/repositories/#{dest_repo}/pullrequests",
|
20
|
-
"-d '#{data.to_json}'",
|
21
|
-
].join(' ')
|
15
|
+
@command ||= generate_command
|
16
|
+
end
|
17
|
+
|
18
|
+
def review
|
19
|
+
@data = nil
|
20
|
+
@command = nil
|
22
21
|
end
|
23
22
|
|
24
23
|
private
|
25
24
|
|
26
|
-
def ask(
|
27
|
-
|
25
|
+
def ask(question, options = {})
|
26
|
+
cache_key = question.dup
|
27
|
+
if cached_answers[cache_key]
|
28
|
+
options.merge! default: cached_answers[cache_key]
|
29
|
+
end
|
30
|
+
context.ask(question, options).tap do |answer|
|
31
|
+
cached_answers[cache_key] = answer
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def cached_answers
|
36
|
+
@cached_answers ||= {}
|
28
37
|
end
|
29
38
|
|
30
39
|
def current_branch
|
@@ -37,8 +46,8 @@ module Pullrequest
|
|
37
46
|
|
38
47
|
def data
|
39
48
|
@data ||= {
|
40
|
-
title:
|
41
|
-
description:
|
49
|
+
title: title,
|
50
|
+
description: description,
|
42
51
|
source: {
|
43
52
|
repository: {full_name: source_repo},
|
44
53
|
branch: {name: source_branch},
|
@@ -52,6 +61,10 @@ module Pullrequest
|
|
52
61
|
}
|
53
62
|
end
|
54
63
|
|
64
|
+
def description
|
65
|
+
ask("Description of pull request")
|
66
|
+
end
|
67
|
+
|
55
68
|
def dest_branch
|
56
69
|
ask("Destination branch", default: 'master', required: true)
|
57
70
|
end
|
@@ -60,9 +73,26 @@ module Pullrequest
|
|
60
73
|
ask("Destination Bitbucket repo (account_name/report_name)", default: current_repo, required: true)
|
61
74
|
end
|
62
75
|
|
76
|
+
def generate_command
|
77
|
+
data # ask these questions first
|
78
|
+
[
|
79
|
+
"curl",
|
80
|
+
"-X POST",
|
81
|
+
"-H 'Content-Type: application/json'",
|
82
|
+
"-u #{username}:#{password}",
|
83
|
+
"https://bitbucket.org/api/2.0/repositories/#{dest_repo}/pullrequests",
|
84
|
+
"-d '#{data.to_json}'",
|
85
|
+
].join(' ')
|
86
|
+
end
|
87
|
+
|
63
88
|
def password
|
64
|
-
|
89
|
+
return stored_credentials[:password] if stored_credentials?
|
90
|
+
ask("Your Bitbucket password", echo: false, required: true).tap do |password|
|
65
91
|
$stdout.puts # force newline
|
92
|
+
if yes? "Store credentials for next time? (in #{stored_credentials_path})"
|
93
|
+
@password = password
|
94
|
+
write_credentials
|
95
|
+
end
|
66
96
|
end
|
67
97
|
end
|
68
98
|
|
@@ -74,12 +104,41 @@ module Pullrequest
|
|
74
104
|
current_repo
|
75
105
|
end
|
76
106
|
|
107
|
+
def stored_credentials
|
108
|
+
return {} unless File.exists?(stored_credentials_path)
|
109
|
+
@stored_credentials ||= YAML.load(File.read(stored_credentials_path))
|
110
|
+
end
|
111
|
+
|
112
|
+
def stored_credentials?
|
113
|
+
stored_credentials.key?(:username) && stored_credentials.key?(:password)
|
114
|
+
end
|
115
|
+
|
116
|
+
def stored_credentials_path
|
117
|
+
File.join(Dir.home, '.config/pullrequest/bitbucket.yml')
|
118
|
+
end
|
119
|
+
|
120
|
+
def title
|
121
|
+
ask("Title of pull request", required: true)
|
122
|
+
end
|
123
|
+
|
77
124
|
def reviewer_usernames
|
78
125
|
ask("Reviewers (enter comma-separated usernames)", default: "<none>").split(',').map(&:strip).reject { |u| u == '' }
|
79
126
|
end
|
80
127
|
|
81
128
|
def username
|
82
|
-
|
129
|
+
return stored_credentials[:username] if stored_credentials?
|
130
|
+
@username = ask("Your Bitbucket username", required: true)
|
131
|
+
end
|
132
|
+
|
133
|
+
def write_credentials
|
134
|
+
FileUtils.mkdir_p(File.dirname(stored_credentials_path))
|
135
|
+
File.open(stored_credentials_path, 'w', 0600) do |f|
|
136
|
+
f.write({username: @username, password: @password}.to_yaml)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def yes?(*args)
|
141
|
+
context.yes? *args
|
83
142
|
end
|
84
143
|
end
|
85
144
|
end
|
data/lib/pullrequest/version.rb
CHANGED
data/pullrequest.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pullrequest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zubin Henner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description:
|
70
84
|
email:
|
71
85
|
- zubin@rubidium.com.au
|