gub 0.1.5 → 0.2.0

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: 8576c0e8367a0d8c054b8b1c0663d897e8212be4
4
- data.tar.gz: a55371c54605d614bb343ae0108875e8e70b48e1
3
+ metadata.gz: 63cc87efc78a3425e09f29cd40ee3cef3daa98a3
4
+ data.tar.gz: 89f6490382d896b46dcf7c534ee39ae253132e7d
5
5
  SHA512:
6
- metadata.gz: bb5f7d5cc4ea0947141a103b0fa4610abada77a82bee4ca3f8b05f41b6daaba21dd10c29d65befced63f6761e2638f8e8ea860b98e7128e5b58561ef07f5da00
7
- data.tar.gz: 924b4d5afa7d1d99e3eebe126969c3d187dde57ea1300a61e80e142deb9b8836a42a277637fd2baee6b3adec81e7d5ecd9563c308c3b788ac8fb8740642ab86f
6
+ metadata.gz: 0c0e6e656618166ea72b59b6a941e8ce271709de66829b307a07a16a470a04fa6190648693dc7174ba4d0ba61bedd5144510dcb49e87a55b2c4f8723041f4b6c
7
+ data.tar.gz: 31e157be199547fbc78c7ec5982c43cca2a7ec217df3bb46bb6802a4c34632ce1b8a50ed5bd19aff37187592462b670be6e05f2f928c051f0bebe59489afc993
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'octokit'
27
27
  spec.add_dependency 'terminal-table'
28
28
  spec.add_dependency 'highline'
29
+ spec.add_dependency 'launchy'
29
30
  end
data/lib/gub.rb CHANGED
@@ -5,12 +5,13 @@ require 'gub/version'
5
5
  require 'gub/clients/git'
6
6
  require 'gub/clients/github'
7
7
  require 'gub/repository'
8
+ require 'gub/issue'
8
9
  require 'gub/cli'
9
10
  require 'gub/config'
10
11
  require 'gub/logger'
11
12
 
12
13
  module Gub
13
- # TODO: Understand this
14
+ # TODO: Understand the following code
14
15
  class << self
15
16
  attr_accessor :debug, :log, :config, :git, :github
16
17
 
@@ -26,5 +27,9 @@ module Gub
26
27
  # Invoke our CLI
27
28
  Gub::CLI.start
28
29
  end
30
+
31
+ def current_user
32
+ @github.user.login
33
+ end
29
34
  end
30
35
  end
@@ -1,4 +1,3 @@
1
- require 'gub/version'
2
1
  require 'thor'
3
2
  require 'terminal-table'
4
3
  require 'highline'
@@ -31,22 +30,51 @@ module Gub
31
30
  puts table
32
31
  rescue Gub::Unauthorized
33
32
  reauthorize
33
+ rescue Gub::Disconnected
34
+ panic 'Unable to connect to Github'
35
+ end
36
+
37
+ desc 'browse', 'Browse current repository'
38
+ def browse
39
+ repository = Gub::Repository.new(origin_name)
40
+ repository.browse
34
41
  end
35
42
 
36
- desc 'issue [id]', 'Show a Github issue'
43
+ desc 'issue [id]', 'Show or edit a Github issue'
44
+ method_option :assign, type: :boolean, aliases: '-i', desc: 'Assign the issue'
45
+ method_option :comment, type: :string, aliases: '-m', desc: 'Add a comment to the issue'
46
+ method_option :close, type: :boolean, aliases: '-c', desc: 'Close the issue'
47
+ method_option :reopen, type: :boolean, aliases: '-r', desc: 'Reopen the issue'
37
48
  def issue(id)
38
- repository = Gub::Repository.new
39
- issue = repository.issue(id)
40
- rows = []
41
- rows << ['Status:', issue.state]
42
- rows << ['Milestone:', issue.milestone.title]
43
- rows << ['Author:', issue.user.login]
44
- rows << ['Assignee:', (issue.assignee.nil? ? '-' : issue.assignee.login)]
45
- rows << ['Description:', word_wrap(issue.body, line_width: 70)]
46
- Gub.log.info "Hint: use 'gub start #{id}' to start working on this issue."
47
- say table rows, ["Issue ##{id}:", issue.title]
49
+ repository = Gub::Repository.new(origin_name)
50
+ if options.comment
51
+ repository.issue(id).comment(options.comment)
52
+ elsif options.close
53
+ repository.issue(id).close
54
+ elsif options.assign
55
+ repository.issue(id).assign
56
+ elsif options.reopen
57
+ repository.issue(id).reopen
58
+ else
59
+ issue = repository.issue(id)
60
+ rows = []
61
+ rows << ['Status:', issue.state]
62
+ rows << ['Milestone:', issue.milestone.title]
63
+ rows << ['Author:', issue.user.login]
64
+ rows << ['Assignee:', (issue.assignee.nil? ? '-' : issue.assignee.login)]
65
+ rows << ['Description:', word_wrap(issue.body, line_width: 70)]
66
+ comments = []
67
+ issue.comments.each do |comment|
68
+ comments << [comment.user.login, "On #{comment.updated_at}: #{comment.body}"]
69
+ end
70
+ Gub.log.info "Hint: use 'gub start #{id}' to start working on this issue."
71
+ puts table rows, ["Issue ##{id}:", issue.title]
72
+ puts table comments, ['', 'Comments']
73
+ end
48
74
  rescue Gub::Unauthorized
49
75
  reauthorize
76
+ rescue Gub::Disconnected
77
+ panic 'Unable to connect to Github'
50
78
  end
51
79
 
52
80
  desc 'issues', 'List Github issues'
@@ -54,7 +82,7 @@ module Gub
54
82
  method_option :mine, type: :boolean, aliases: '-m', desc: 'Only issues assigned to me'
55
83
  def issues
56
84
  args = {}
57
- repository = Gub::Repository.new
85
+ repository = Gub::Repository.new(origin_name)
58
86
  if options.all || repository.full_name.nil?
59
87
  say "Listing all issues:"
60
88
  issues = Gub.github.user_issues
@@ -87,6 +115,8 @@ module Gub
87
115
  end
88
116
  rescue Gub::Unauthorized
89
117
  reauthorize
118
+ rescue Gub::Disconnected
119
+ panic 'Unable to connect to Github'
90
120
  end
91
121
 
92
122
  desc 'start [id]', 'Start working on a Github issue'
@@ -94,18 +124,21 @@ module Gub
94
124
  if id.nil?
95
125
  panic 'Issue ID required.'
96
126
  else
97
- branch = "issue-#{id}"
98
- if Gub.git.branch().include?('issue-111')
99
- Gub.git.checkout(branch)
127
+ repository = Repository.new(origin_name)
128
+ issue = repository.issue(id)
129
+ if repository.branches.include?(issue.branch)
130
+ Gub.git.checkout(issue.branch)
100
131
  else
101
- repository = Repository.new
102
- Gub.git.sync
103
- repository.assign_issue id
104
- Gub.git.checkout('-b', branch)
132
+ repository = Repository.new(origin_name)
133
+ repository.sync
134
+ issue.assign
135
+ Gub.git.checkout('-b', issue.branch)
105
136
  end
106
137
  end
107
138
  rescue Gub::Unauthorized
108
139
  reauthorize
140
+ rescue Gub::Disconnected
141
+ panic 'Unable to connect to Github'
109
142
  end
110
143
 
111
144
  desc 'finish [id]', 'Finish working on a Github issue'
@@ -114,15 +147,18 @@ module Gub
114
147
  if id.nil?
115
148
  panic "Unable to guess issue ID from branch name. You might want to specify it explicitly."
116
149
  else
117
- repository = Repository.new
118
- Gub.log.info 'Pushing branch...'
119
- Gub.git.push('origin', "issue-#{id}")
120
- Gub.log.info "Creating pull-request for issue ##{id}..."
121
- repository.issue_pull_request(id)
150
+ repository = Repository.new(origin_name)
151
+ issue = repository.issue(id)
152
+ say 'Pushing branch...'
153
+ Gub.git.push('origin', issue.branch)
154
+ say "Creating pull-request for issue ##{id}..."
155
+ issue.request_pull
122
156
  Gub.git.checkout('master')
123
157
  end
124
158
  rescue Gub::Unauthorized
125
159
  reauthorize
160
+ rescue Gub::Disconnected
161
+ panic 'Unable to connect to Github'
126
162
  end
127
163
 
128
164
  desc 'clone [repo]', 'Clone a Github repository'
@@ -136,35 +172,43 @@ module Gub
136
172
  Gub.log.info "Cloning from #{url}..."
137
173
  Gub.git.clone(url)
138
174
  `cd #{repo.split('/').last}`
139
- repository = Repository.new
175
+ repository = Gub::Repository.new(origin_name)
140
176
  repository.add_upstream
141
177
  rescue Gub::Unauthorized
142
178
  reauthorize
179
+ rescue Gub::Disconnected
180
+ panic 'Unable to connect to Github'
143
181
  end
144
182
 
145
183
  desc 'add_upstream', 'Add repo upstream'
146
184
  def add_upstream
147
- repository = Repository.new
185
+ repository = Gub::Repository.new(origin_name)
148
186
  repository.add_upstream
149
187
  rescue Gub::Unauthorized
150
188
  reauthorize
189
+ rescue Gub::Disconnected
190
+ panic 'Unable to connect to Github'
151
191
  end
152
192
 
153
193
  desc 'sync', 'Synchronize fork with upstream repository'
154
194
  def sync
155
195
  Gub.log.info 'Synchroizing with upstream...'
156
- Gub.git.sync
196
+ Gub::Repository.new(origin_name).sync
157
197
  rescue Gub::Unauthorized
158
198
  reauthorize
199
+ rescue Gub::Disconnected
200
+ panic 'Unable to connect to Github'
159
201
  end
160
202
 
161
203
  desc 'info', 'Show current respository information'
162
204
  def info
163
- repo = Gub::Repository.new
205
+ repo = Gub::Repository.new(origin_name)
164
206
  say "Github repository: #{repo.full_name}"
165
207
  say "Forked from: #{repo.parent}" if repo.parent
166
208
  rescue Gub::Unauthorized
167
209
  reauthorize
210
+ rescue Gub::Disconnected
211
+ panic 'Unable to connect to Github'
168
212
  end
169
213
 
170
214
  desc 'setup', 'Setup Gub for the first time'
@@ -196,6 +240,10 @@ module Gub
196
240
  end
197
241
 
198
242
  private
243
+ def origin_name
244
+ `git remote -v | grep origin | grep fetch | awk '{print $2}' | cut -d ':' -f 2`.to_s
245
+ end
246
+
199
247
  def table rows, header = []
200
248
  Terminal::Table.new headings: header, rows: rows
201
249
  end
@@ -4,10 +4,10 @@ module Gub
4
4
  class Git
5
5
  attr_accessor :default_options
6
6
 
7
- def sync
7
+ def sync remote
8
8
  self.checkout('master')
9
- self.fetch('upstream')
10
- self.merge('upstream/master')
9
+ self.fetch(remote)
10
+ self.merge("#{remote}/master")
11
11
  self.push('origin', '--all')
12
12
  end
13
13
 
@@ -9,14 +9,21 @@ module Gub
9
9
  @connection = Octokit::Client.new(opts)
10
10
  end
11
11
 
12
+ def url
13
+ 'https://github.com/'
14
+ end
15
+
12
16
  def user
13
17
  @connection.user
14
18
  end
15
19
 
16
20
  def method_missing meth, *args, &block
21
+ Gub.log.debug "Running command #{meth} with arguments #{args}"
17
22
  @connection.send(meth, *args, &block)
18
23
  rescue Octokit::Unauthorized, Octokit::NotFound
19
24
  raise Gub::Unauthorized
25
+ rescue Faraday::Error::ConnectionFailed
26
+ raise Gub::Disconnected
20
27
  end
21
28
  end
22
29
  end
@@ -1,3 +1,4 @@
1
1
  module Gub
2
2
  class Unauthorized < Exception; end
3
+ class Disconnected < Exception; end
3
4
  end
@@ -0,0 +1,53 @@
1
+ module Gub
2
+ class Issue
3
+ attr_accessor :parent, :id, :info
4
+
5
+
6
+ def self.all parent, params = {}
7
+ Gub.github.issues(parent params)
8
+ end
9
+
10
+ def initialize parent, id
11
+ self.parent = parent
12
+ self.id = id
13
+ self.info = Gub.github.issue(self.parent, self.id)
14
+ end
15
+
16
+ def repository
17
+ Gub::Repository.new(self.parent)
18
+ end
19
+
20
+ def reopen
21
+ Gub.github.reopen_issue(self.parent, self.id)
22
+ end
23
+
24
+ def close
25
+ Gub.github.close_issue(self.parent, self.id)
26
+ end
27
+
28
+ def comment body
29
+ Gub.github.add_comment(self.parent, self.id, body)
30
+ end
31
+
32
+ def comments
33
+ Gub.github.issue_comments(self.parent, self.id)
34
+ end
35
+
36
+ def assignee
37
+ self.info[:user]
38
+ end
39
+
40
+ def assign login = nil
41
+ assignee = login || Gub.github.user.login
42
+ Gub.github.update_issue self.parent, self.id, self.info[:title], self.info[:body], { assignee: assignee }
43
+ end
44
+
45
+ def branch
46
+ "issue-#{self.id}"
47
+ end
48
+
49
+ def request_pull
50
+ Gub.github.create_pull_request_for_issue(self.parent, 'master', "#{Gub.current_user}:#{self.branch}", self.id)
51
+ end
52
+ end
53
+ end
@@ -2,12 +2,8 @@ module Gub
2
2
  class Repository
3
3
  attr_accessor :full_name, :info
4
4
 
5
- def initialize full_name = nil
6
- if full_name.nil?
7
- self.full_name = `git remote -v | grep origin | grep fetch | awk '{print $2}' | cut -d ':' -f 2`.to_s.chop
8
- else
9
- self.full_name = full_name
10
- end
5
+ def initialize full_name
6
+ self.full_name = full_name
11
7
  # Strip .git from the name
12
8
  self.full_name = self.full_name.split('.').first
13
9
  if self.full_name.nil? || self.full_name.empty?
@@ -15,12 +11,12 @@ module Gub
15
11
  exit 1
16
12
  else
17
13
  Gub.log.debug "Loading information for #{self.full_name}"
18
- @info = Gub.github.repo(repo: self.full_name)
14
+ self.info = Gub.github.repo(repo: self.full_name)
19
15
  end
20
16
  end
21
17
 
22
18
  def name
23
- @full_name.split('/').last
19
+ self.full_name.split('/').last
24
20
  end
25
21
 
26
22
  def has_issues?
@@ -34,33 +30,13 @@ module Gub
34
30
  issues.flatten!
35
31
  end
36
32
 
37
- def issue id
38
- if self.has_issues?
39
- Gub.github.issue(self.full_name, id)
40
- else
41
- Gub.github.issue(self.parent, id)
42
- end
43
- end
44
-
45
- def assign_issue id, login = nil
46
- issue = self.issue(id)
47
- assignee = login || Gub.github.user.login
33
+ def issue id, action = :fetch, extra_args = nil
48
34
  if self.has_issues?
49
35
  name = self.full_name
50
36
  else
51
37
  name = self.parent
52
38
  end
53
- Gub.github.update_issue name, issue.number, issue.title, issue.body, { assignee: assignee }
54
- end
55
-
56
- def issue_pull_request id
57
- issue = self.issue(id)
58
- if self.has_issues?
59
- repo = self.full_name
60
- else
61
- repo = self.parent
62
- end
63
- Gub.github.create_pull_request_for_issue(repo, 'master', "#{self.owner}:issue-#{id}", id)
39
+ Gub::Issue.new(name, id)
64
40
  end
65
41
 
66
42
  def owner
@@ -82,5 +58,14 @@ module Gub
82
58
  def sync
83
59
  Gub.git.sync('upstream')
84
60
  end
61
+
62
+ def branches
63
+ Gub.git.branch()
64
+ end
65
+
66
+ def browse
67
+ require 'launchy'
68
+ ::Launchy.open("#{Gub.github.url}#{self.full_name}")
69
+ end
85
70
  end
86
71
  end
@@ -1,3 +1,3 @@
1
1
  module Gub
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Omar Abdel-Wahab
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: launchy
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: The missing command line tool for Github
112
126
  email:
113
127
  - owahab@gmail.com
@@ -131,6 +145,7 @@ files:
131
145
  - lib/gub/config.rb
132
146
  - lib/gub/exceptions.rb
133
147
  - lib/gub/extensions.rb
148
+ - lib/gub/issue.rb
134
149
  - lib/gub/logger.rb
135
150
  - lib/gub/repository.rb
136
151
  - lib/gub/setup.rb