git-pr-release 0.0.2 → 0.0.3

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: 79571d68044b4b6400cd27b0ea810cc26cc4d009
4
- data.tar.gz: 4a5413b28460e4083c3aa9492d78a429285ba0a5
3
+ metadata.gz: 01b3c946c2a231690f39774716ac1d7a73e8d795
4
+ data.tar.gz: b0be27e932dc56f83e112c53f9a9c74d5ae080b7
5
5
  SHA512:
6
- metadata.gz: 563d365becde236f2bff0b111925b8dff67021f2e6a7cf931dc857671bf198934b671c3823c7996d1d1b4df9cb947cdc762c4d2d63f6fceb2dc5c1edd76a4860
7
- data.tar.gz: 510e8000fcd8a6de989f8366284b7eefbbf7ae44717bb195df3c6d328bef791600b80661586f3ca988ac8429fdadc45fef9e140c6e2f826e71103ed31411f52d
6
+ metadata.gz: 1ca4bb2f17fe20b0d631d65b1c63310cac8251f085e0b7355b8df1a0a8bdc6de396eccf7cc051000b2a0a4e37ca3186285b72ee364fcb26a02672fe58794d6ea
7
+ data.tar.gz: d13dd5e4cafd8d6988add6976afd1677dc11c500ba517197eef8ccabddd8c7bc4adc77785160436d2ff885959ecbdaa4ab2b2ba8040aaebaab957fea157e1aa8
data/README.md CHANGED
@@ -33,3 +33,16 @@ The branch name that the feature branches are merged into and is going to be
33
33
  merged into the "production" branch.
34
34
 
35
35
  Default value: `staging`.
36
+
37
+ ### `pr-release.template`
38
+
39
+ The template file path (relative to the workidir top) for pull requests created. Its first line is used for the PR title, the rest for the body. This is an ERB template.
40
+
41
+ If not specified, the content below is used as the template (embedded in the code):
42
+
43
+ ```erb
44
+ Release <%= Time.now %>
45
+ <% pull_requests.each do |pr| -%>
46
+ <%= pr.to_checklist_item %>
47
+ <% end -%>
48
+ ```
data/bin/git-pr-release CHANGED
@@ -4,6 +4,8 @@ require 'uri'
4
4
  require 'erb'
5
5
  require 'open3'
6
6
  require 'tmpdir'
7
+ require 'optparse'
8
+
7
9
  require 'octokit'
8
10
  require 'colorize'
9
11
  require 'diff/lcs'
@@ -53,13 +55,25 @@ end
53
55
 
54
56
 
55
57
  def git_config(key)
58
+ host, _ = host_and_repository()
59
+
60
+ plain_key = [ 'pr-release', key ].join('.')
61
+ host_aware_key = [ 'pr-release', host, key ].compact.join('.')
62
+
56
63
  begin
57
- git('config', key).first.chomp
64
+ git(:config, '-f', '.git-pr-release', plain_key).first.chomp
58
65
  rescue
59
- nil
66
+ git(:config, host_aware_key).first.chomp rescue nil
60
67
  end
61
68
  end
62
69
 
70
+ def git_config_set(key, value)
71
+ host, _ = host_and_repository()
72
+ host_aware_key = [ 'pr-release', host, key ].compact.join('.')
73
+
74
+ git :config, '--global', host_aware_key, value
75
+ end
76
+
63
77
  # First line will be the title of the PR
64
78
  DEFAULT_PR_TEMPLATE = <<ERB
65
79
  Release <%= Time.now %>
@@ -73,7 +87,7 @@ def build_pr_title_and_body(prs)
73
87
 
74
88
  template = DEFAULT_PR_TEMPLATE
75
89
 
76
- if path = git_config('pr-release.template.path')
90
+ if path = git_config('pr-release.template')
77
91
  template_path = File.join(git('rev-parse', '--show-toplevel').first.chomp, path)
78
92
  template = File.read(template_path)
79
93
  end
@@ -121,11 +135,11 @@ def merge_pr_body(old_body, new_body)
121
135
  end
122
136
 
123
137
  def obtain_token!
124
- token = git_config('pr-release.token')
138
+ token = git_config('token')
125
139
 
126
140
  unless token
127
141
  require 'highline/import'
128
- STDERR.puts 'Could not obtain config variable pr-release.token.'
142
+ STDERR.puts 'Could not obtain GitHub API token.'
129
143
  STDERR.puts 'Trying to generate token...'
130
144
 
131
145
  username = ask('username? ') { |q| q.default = ENV['USER'] }
@@ -135,34 +149,49 @@ def obtain_token!
135
149
 
136
150
  auth = temporary_client.create_authorization({ :scopes => [ 'public_repo', 'repo' ], :note => 'summerize-release' })
137
151
  token = auth.token
138
- git :config, '--global', 'pr-release.token', token
152
+ git_config_set 'token', token
139
153
  end
140
154
 
141
155
  token
142
156
  end
143
157
 
144
- remote = git_config 'remote.origin.url'
145
- unless %r(^\w+://) === remote
146
- remote = "ssh://#{remote.sub(':', '/')}"
158
+ def host_and_repository
159
+ @host_and_repository ||= begin
160
+ remote = git(:config, 'remote.origin.url').first.chomp
161
+ unless %r(^\w+://) === remote
162
+ remote = "ssh://#{remote.sub(':', '/')}"
163
+ end
164
+
165
+ remote_url = URI.parse(remote)
166
+ repository = remote_url.path.sub(%r(^/), '').sub(/\.git$/, '')
167
+
168
+ host = remote_url.host == 'github.com' ? nil : remote_url.host
169
+ [ host, repository ]
170
+ end
147
171
  end
148
172
 
149
- remote_url = URI.parse(remote)
150
- repository = remote_url.path.sub(%r(^/), '').sub(/\.git$/, '')
173
+ host, repository = host_and_repository
151
174
 
152
- if remote_url.host != 'github.com'
175
+ if host
153
176
  # GitHub:Enterprise
154
177
  OpenSSL::SSL.const_set :VERIFY_PEER, OpenSSL::SSL::VERIFY_NONE # XXX
155
178
 
156
179
  Octokit.configure do |c|
157
- c.api_endpoint = "https://#{remote_url.host}/api/v3"
158
- c.web_endpoint = "https://#{remote_url.host}/"
180
+ c.api_endpoint = "https://#{host}/api/v3"
181
+ c.web_endpoint = "https://#{host}/"
159
182
  end
160
183
  end
161
184
 
185
+ OptionParser.new do |opts|
186
+ opts.on('-n', '--dry-run', 'Do not create/update a PR. Just prints out') do |v|
187
+ @dry_run = v
188
+ end
189
+ end.parse!
190
+
162
191
  ### Set up configuration
163
192
 
164
- production_branch = git_config('pr-release.branch.production') || 'master'
165
- staging_branch = git_config('pr-release.branch.staging') || 'staging'
193
+ production_branch = git_config('branch.production') || 'master'
194
+ staging_branch = git_config('branch.staging') || 'staging'
166
195
 
167
196
  say "Repository: #{repository}", :debug
168
197
  say "Production branch: #{production_branch}", :debug
@@ -232,15 +261,30 @@ if existing_release_pr
232
261
 
233
262
  merged_pr_body = merge_pr_body existing_release_pr.body, pr_body
234
263
 
235
- release_pr = client.update_pull_request(
236
- repository, existing_release_pr.number, :title => pr_title, :body => merged_pr_body
237
- )
264
+ if @dry_run
265
+ say 'Dry-run. Not updating PR', :info
266
+ say pr_title, :notice
267
+ say merged_pr_body, :notice
268
+ exit
269
+ else
270
+ release_pr = client.update_pull_request(
271
+ repository, existing_release_pr.number, :title => pr_title, :body => merged_pr_body
272
+ )
273
+ end
238
274
  else
239
275
  say 'Creating release pull request...', :info
240
- release_pr = client.create_pull_request(
241
- repository, production_branch, staging_branch, pr_title, pr_body
242
- )
243
- created = true
276
+
277
+ if @dry_run
278
+ say 'Dry-run. Not creating PR', :info
279
+ say pr_title, :notice
280
+ say pr_body, :notice
281
+ exit
282
+ else
283
+ release_pr = client.create_pull_request(
284
+ repository, production_branch, staging_branch, pr_title, pr_body
285
+ )
286
+ created = true
287
+ end
244
288
  end
245
289
 
246
290
  unless release_pr
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "git-pr-release"
7
- spec.version = '0.0.2'
7
+ spec.version = '0.0.3'
8
8
  spec.authors = ["motemen"]
9
9
  spec.email = ["motemen@gmail.com"]
10
10
  spec.summary = 'Creates a release pull request'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-pr-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - motemen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit