pullrequest 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51a50bd60f262b845aba22d34f1e3cbcccfb315d
4
- data.tar.gz: 6a4c6da5da6a65c26c8120e806663c55d94f8316
3
+ metadata.gz: ba700fdf8961d0cf9c3d6002c65abe42ac2dd9ae
4
+ data.tar.gz: ab3e8846ac4962e113e36a3fd5b6ea6b85671811
5
5
  SHA512:
6
- metadata.gz: 48f6154a1b06a34dd1068732f767caacfd1c65b2f06498862d4d8e614616a3323250b450b8e346553527b0d4653c504c9a0ed190cd835b01aa13d8b81c726523
7
- data.tar.gz: f26f73b224862a45fd68c8ac62fb32afb5f2c5589543b53e9818336e7a9650be876a27ebd299c074dd70ef3e41f759b5af9cd4c9191e1118e20f06b535f703a3
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
- no_commands do
14
- def command
15
- @command ||= repo_class.new(self).command
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
- def repo_class
19
- Bitbucket
20
- end
34
+ private
35
+
36
+ def command
37
+ pullrequest.command
21
38
  end
22
39
 
23
- desc "submit", "Submits pull request"
24
- def submit
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
- data # ask these questions first
14
- [
15
- "curl",
16
- "-X POST",
17
- "-H 'Content-Type: application/json'",
18
- "-u #{username}:#{password}",
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(*args)
27
- context.ask *args
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: ask("Title of pull request", required: true),
41
- description: ask("Description of pull request"),
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
- ask("Your Bitbucket password", echo: false, required: true).tap do
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
- ask "Your Bitbucket username", required: true
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
@@ -1,3 +1,3 @@
1
1
  module Pullrequest
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/pullrequest.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.9'
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'pry'
26
27
  end
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.0
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-03 00:00:00.000000000 Z
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