git_pr 0.0.4 → 0.0.5

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: b845e6d7a05d53f4bc31e91986cd886b56c88cd1
4
- data.tar.gz: 157e6084f4c39dee37322508e0464cf371f07bc7
3
+ metadata.gz: e231910d981e67ad3eede6e7ceb0b64edb8e838c
4
+ data.tar.gz: b0f203c2bd2c920840aa0440fe80f29b8b4185b2
5
5
  SHA512:
6
- metadata.gz: 103b7d80a8719dde69faba086dd9b959d76c08458f083059c8c52ff7ccac99623eb540c9228c8d511f8ddce51f0a9613e38c3780b414882ec847024319343a65
7
- data.tar.gz: f992d1c24326943f34d7568ede54c0fd094337c70ac11a88ccda9263bd230c8e6f1b5b90ed41562f9900a0e544e93190c032b6f9e2a118c8af868c184ea650cc
6
+ metadata.gz: fdeb0d89f3c48faa1b9acbf9735745824b71b3dc2b74a700bad7a747a5cc02edf9c7a1d122afd2d7a4982695d0ac17967afd707f4d634a5fc8e458f26d2b4e68
7
+ data.tar.gz: e59e243ffcc9b8bf6d27c1a87b5486182f6971e0ed541698c89d0b4bcbb85e81ba8228f3c06b1ec2370de0f34935a62a578cfea234e4cca3eb7ae6d68f529e3d
data/bin/git-pr CHANGED
@@ -64,8 +64,9 @@ eos
64
64
  Valid subcommands:
65
65
  diff: Use "git diff" to display a diff for a pull request
66
66
  difftool: Like "diff", but uses "git difftool" instead
67
- merge: Merge and close a pull request
68
67
  list: List open pull requests
68
+ merge: Merge and close a pull request
69
+ open: Open a PR page on the web
69
70
 
70
71
  Run "git pr <subcommand> -h" for help with subcommands.
71
72
 
@@ -110,17 +111,18 @@ eos
110
111
 
111
112
  opts.separator ""
112
113
  end,
113
- # 'open' => OptionParser.new do |opts|
114
- # opts.banner = "Usage: git pr open [options]"
114
+ 'open' => OptionParser.new do |opts|
115
+ opts.banner = "Usage: git pr open [pr_number|branch]"
115
116
 
116
- # opts.separator "\nOpen command options"
117
+ opts.separator <<eos
117
118
 
118
- # opts.on("-r", "--readonly", "Check without prompting") do |v|
119
- # options.open.readonly = true
120
- # end
119
+ Open a pull request page, if one exists, for the passed in PR number or
120
+ branch. Otherwise, open a diff page where a pull request can be created. If no
121
+ argument is passed, open a PR page for the current branch.
121
122
 
122
- # opts.separator ""
123
- # end
123
+ eos
124
+
125
+ end
124
126
  }
125
127
 
126
128
  begin
@@ -183,6 +185,49 @@ when "list"
183
185
  puts "No open pull requests found.".yellow
184
186
  end
185
187
 
188
+ when "open"
189
+
190
+ # Look for an existing pull request that fits. A branch name or PR number can
191
+ # be passed on the command line, or we default to the current branch.
192
+ pulls = Octokit.pulls github_project
193
+ source = options[command].additional_arguments.shift || git.current_branch
194
+ if pulls.any?
195
+ pull = pulls.find { |p| p.head.ref == source || p.number.to_s == source }
196
+ if pull
197
+ `open #{pull.html_url}`
198
+ exit
199
+ end
200
+ end
201
+
202
+ # We didn't find a matching pull request, so let's try to open the "create
203
+ # pull request" page.
204
+ source = source
205
+ if not git.is_local_branch? source
206
+ puts "Unknown branch '#{source}'.".red
207
+ exit -1
208
+ end
209
+ target_repo = Octokit.repo(github_project)
210
+ target = target_repo.default_branch
211
+ if source == target
212
+ puts "Current branch '#{target}' is the default branch for the project '#{github_project}'."
213
+ puts "Can't open pull request page.".yellow
214
+ exit -1
215
+ end
216
+
217
+ # Need to open a diff page. Diff URL looks like:
218
+ # https://github.com/FiftyThree/Studio/compare/FiftyThree:master...floatplane:blobstore
219
+ # So I need to: get the upstream for the named branch. Extract the github project owner.
220
+ github_target_owner, github_target_project = github_project.split "/"
221
+ remote_source_branch = git.branches.remote.find { |b| b.name == source }
222
+ remote_url = remote_source_branch ? remote_source_branch.remote.url : nil
223
+ unless remote_url and remote_url.match /github\.com/
224
+ puts "Branch '#{source}' has never been pushed to GitHub."
225
+ exit -1
226
+ end
227
+ github_source_owner = remote_url.match(/git@github.com:(.*)\//)[1]
228
+ url = "https://github.com/#{github_source_owner}/#{github_target_project}/compare/#{github_target_owner}:#{target}...#{github_source_owner}:#{source}?expand=1"
229
+ `open #{url}`
230
+ exit
186
231
 
187
232
  when "diff", "difftool"
188
233
  pull_request = nil
data/lib/git_pr/merge.rb CHANGED
@@ -59,7 +59,7 @@ module GitPr
59
59
  # same contents as the remote source branch. If not, it must be reconciled
60
60
  # manually.
61
61
  remote_source_branch = "#{source_remote}/#{source_branch}"
62
- if git.is_branch? source_branch and
62
+ if git.is_local_branch? source_branch and
63
63
  git.diff("remotes/#{remote_source_branch}", source_branch).any?
64
64
  puts "Local branch '#{source_branch}' differs from remote branch '#{remote_source_branch}'. Please reconcile before continuing.".red
65
65
  exit -1
@@ -69,7 +69,7 @@ module GitPr
69
69
  # failing if the temporary name already exists.
70
70
  rebase_branch = "#{source_branch}-rebase"
71
71
  puts "Create temporary branch '#{rebase_branch}'"
72
- if git.is_branch? rebase_branch
72
+ if git.is_local_branch? rebase_branch
73
73
  puts "Local rebase branch '#{rebase_branch}' already exists. Please remove before continuing.".red
74
74
  exit -1
75
75
  end
@@ -77,7 +77,7 @@ module GitPr
77
77
 
78
78
  # Add an at_exit handler to blow away the temp branch when we exit
79
79
  at_exit do
80
- if git.is_branch? rebase_branch
80
+ if git.is_local_branch? rebase_branch
81
81
  puts "Removing temporary branch #{rebase_branch}" if $verbose
82
82
  GitPr.run_command "git checkout -q #{target_branch}"
83
83
  GitPr.run_command "git branch -D #{rebase_branch}"
@@ -135,7 +135,7 @@ module GitPr
135
135
  if GitPr.prompt "\nDo you want to delete the feature branch (y/n)? ".cyan
136
136
  source_branch_sha = git.branches["#{source_remote}/#{source_branch}"].gcommit.sha[0..6]
137
137
  GitPr.run_command "git push #{source_remote} :#{source_branch} 2>&1"
138
- if git.is_branch? source_branch
138
+ if git.is_local_branch? source_branch
139
139
  source_branch_sha = git.branches[source_branch].gcommit.sha[0..6]
140
140
  GitPr.run_command "git branch -D #{source_branch}"
141
141
  end
@@ -1,3 +1,3 @@
1
1
  module GitPr
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Sharon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize