git-review 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/git-review.rb +75 -35
  2. metadata +7 -7
data/lib/git-review.rb CHANGED
@@ -17,24 +17,27 @@ class GitReview
17
17
  puts ' list [--reverse] List all open requests.'
18
18
  puts ' show <number> [--full] Show details of a single request.'
19
19
  puts ' browse <number> Open a browser window and review a specified request.'
20
+ # puts ' checkout <number> Checkout a specified request\'s changes to your local repository.'
21
+ puts ' accept <number> Accept a specified request by merging it into master.'
22
+ puts ' decline <number> Decline and close a specified request.'
20
23
  puts ' create Create a new request.'
21
- puts ' merge <number> Sign off a specified request by merging it into master.'
22
24
  end
23
25
 
24
26
  # List all open requests.
25
27
  def list
26
- puts "Open Pull Requests for #{@user}/#{@repo}"
28
+ puts "Open requests for '#{source_repo}/#{source_branch}'"
27
29
  option = @args.shift
28
30
  open_requests = get_pull_info
29
31
  open_requests.reverse! if option == '--reverse'
32
+ # TODO: Refactor to get rid of unnecessary variables and computation.
30
33
  count = 0
34
+ puts 'ID Date Comments Title'
31
35
  open_requests.each do |pull|
32
36
  line = []
33
- line << format_text(pull['number'], 4)
34
- line << format_text(Date.parse(pull['created_at']).strftime("%m/%d"), 5)
35
- line << format_text(pull['comments'], 2)
36
- line << format_text(pull['title'], 35)
37
- line << format_text(pull['head']['label'], 20)
37
+ line << format_text(pull['number'], 6)
38
+ line << format_text(Date.parse(pull['created_at']).strftime('%d-%b-%y'), 10)
39
+ line << format_text(pull['comments'], 10)
40
+ line << format_text(pull['title'], 94)
38
41
  sha = pull['head']['sha']
39
42
  if not_merged?(sha)
40
43
  puts line.join ' '
@@ -42,7 +45,7 @@ class GitReview
42
45
  end
43
46
  end
44
47
  if count == 0
45
- puts ' -- no open pull requests --'
48
+ puts ' -- No open requests. --'
46
49
  end
47
50
  end
48
51
 
@@ -76,31 +79,14 @@ class GitReview
76
79
  Launchy.open(@review['html_url']) if review_exists?
77
80
  end
78
81
 
79
- # Create a new request.
80
- def create
81
- # Gather information.
82
- last_review_id = get_pull_info.collect{|review| review['number']}.sort.last
83
- target_repo = "#{@user}/#{@repo}"
84
- target_branch = 'master'
85
- source_branch = git('branch', false).match(/\*(.*)/)[0][2..-1]
86
- title = "Review request: #{github_login} wants to merge changes from '#{source_branch}' into #{target_repo}'s branch '#{target_branch}'."
87
- # TODO: Insert commit messages (that are not yet in master) into body (since this will be displayed inside the mail that is sent out).
88
- body = 'my body'
89
- # Create the actual pull request.
90
- Octokit.create_pull_request(target_repo, target_branch, source_branch, title, body)
91
- # Switch back to target_branch and check for success.
92
- git "co #{target_branch}"
93
- update
94
- potential_new_review = get_pull_info.find{ |review| review['title'] == title}
95
- if potential_new_review['number'] > last_review_id
96
- puts 'Review request successfully created.'
97
- else
98
- puts 'Creating new review request failed.'
99
- end
82
+ # Checkout a specified request's changes to your local repository.
83
+ # TODO: Implement this.
84
+ def checkout
85
+ puts 'Under construction... ;-)'
100
86
  end
101
87
 
102
- # Sign off a specified request by merging it into master.
103
- def merge
88
+ # Accept a specified request by merging it into master.
89
+ def accept
104
90
  return unless review_exists?
105
91
  option = @args.shift
106
92
  if @review['head']['repository']
@@ -118,7 +104,7 @@ class GitReview
118
104
  return false
119
105
  end
120
106
  s = @review['head']['sha']
121
- message = "Merge pull request ##{@review['number']} from #{o}/#{r}\n\n---\n\n"
107
+ message = "Accepting request ##{@review['number']} from #{o}/#{r}\n\n---\n\n"
122
108
  message += @review['body'].gsub("'", '')
123
109
  if option == '--log'
124
110
  message += "\n\n---\n\nMerge Log:\n"
@@ -129,6 +115,31 @@ class GitReview
129
115
  exec(cmd)
130
116
  end
131
117
 
118
+ # Decline and close a specified request.
119
+ def decline
120
+ return unless review_exists?
121
+ Octokit.post("issues/close/#{source_repo}/#{@review['number']}")
122
+ puts "Successfully declined request." unless review_exists?(@review['number'])
123
+ end
124
+
125
+ # Create a new request.
126
+ # TODO: Support creating requests to other repositories and branches (like the original repo, this has been forked from).
127
+ def create
128
+ # TODO: Create and push to a remote branch if necessary.
129
+ # Gather information.
130
+ last_review_id = get_pull_info.collect{|review| review['number']}.sort.last.to_i
131
+ title = "[Review] Request from '#{github_login}' @ '#{source_repo}/#{source_branch}'"
132
+ # TODO: Insert commit messages (that are not yet in master) into body (since this will be displayed inside the mail that is sent out).
133
+ body = "You are requested to review the following changes:"
134
+ # Create the actual pull request.
135
+ Octokit.create_pull_request(target_repo, target_branch, source_branch, title, body)
136
+ # Switch back to target_branch and check for success.
137
+ git "co #{target_branch}"
138
+ update
139
+ potential_new_review = get_pull_info.find{ |review| review['title'] == title}
140
+ puts 'Review request successfully created.' if potential_new_review['number'] > last_review_id
141
+ end
142
+
132
143
  # Start a console session (used for debugging).
133
144
  def console
134
145
  puts 'Entering debug console.'
@@ -165,8 +176,15 @@ class GitReview
165
176
  end
166
177
 
167
178
  # Check existence of specified review and assign @review.
168
- def review_exists?
169
- review_id = @args.shift.to_i
179
+ def review_exists?(review_id = nil)
180
+ # NOTE: If review_id is not set explicitly we might need to update to get the
181
+ # latest changes from GitHub, as this is called from within another method.
182
+ update if review_id.nil?
183
+ review_id ||= @args.shift.to_i
184
+ if review_id == 0
185
+ puts "Please specify a valid ID."
186
+ return false
187
+ end
170
188
  @review = get_pull_info.find{ |review| review['number'] == review_id}
171
189
  puts "Review '#{review_id}' does not exist." unless @review
172
190
  not @review.nil?
@@ -184,6 +202,28 @@ class GitReview
184
202
  info.to_s.gsub("\n", ' ')[0, size].ljust(size)
185
203
  end
186
204
 
205
+ # Returns a string that specifies the source repo.
206
+ def source_repo
207
+ "#{@user}/#{@repo}"
208
+ end
209
+
210
+ # Returns a string that specifies the source branch.
211
+ def source_branch
212
+ git('branch', false).match(/\*(.*)/)[0][2..-1]
213
+ end
214
+
215
+ # Returns a string that specifies the target repo.
216
+ def target_repo
217
+ # TODO: Enable possibility to manually override this and set arbitrary repositories.
218
+ source_repo
219
+ end
220
+
221
+ # Returns a string that specifies the target branch.
222
+ def target_branch
223
+ # TODO: Enable possibility to manually override this and set arbitrary branches.
224
+ 'master'
225
+ end
226
+
187
227
  def fetch_stale_forks
188
228
  pulls = get_pull_info
189
229
  repos = {}
@@ -263,7 +303,7 @@ class GitReview
263
303
  end
264
304
 
265
305
  def cache_pull_info
266
- response = Octokit.pull_requests("#{@user}/#{@repo}")
306
+ response = Octokit.pull_requests(source_repo)
267
307
  save_data({'review' => response}, REVIEW_CACHE_FILE)
268
308
  end
269
309
 
metadata CHANGED
@@ -5,17 +5,17 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
- - Cristian Messel, Dominik Bamberger
13
+ - Dominik Bamberger, Cristian Messel
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-13 00:00:00 +02:00
18
+ date: 2011-07-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -62,7 +62,7 @@ dependencies:
62
62
  version: 0.5.1
63
63
  type: :runtime
64
64
  version_requirements: *id003
65
- description: git-review facilitates github code reviews.
65
+ description: Manage review workflow for projects hosted on GitHub (using pull requests).
66
66
  email: bamberger.dominik@gmail.com
67
67
  executables:
68
68
  - git-review
@@ -107,6 +107,6 @@ rubyforge_project:
107
107
  rubygems_version: 1.5.2
108
108
  signing_key:
109
109
  specification_version: 3
110
- summary: facilitates github code reviews
110
+ summary: facilitates GitHub code reviews
111
111
  test_files: []
112
112