git-pr-release 0.0.5 → 0.1.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: 6bc50424a98694a90f526c8685e4ea743a46b9d6
4
- data.tar.gz: 934bf70ff7c35846b4d525023e20593d9dbd2385
3
+ metadata.gz: 0a86a7c2e8b0cef94c0eb162660772b0efa212bf
4
+ data.tar.gz: 81115e65decbf92b726b6218b6fe9cd1cd007f7f
5
5
  SHA512:
6
- metadata.gz: b8110e2381e583f4cdf913d02b85a6b2978cf0344b0b6a5791980e26bcd26bec6bc1f3398d199d93b4dfba1cbaaa312de0985ca04d1cbc16f60aa79a5cfeb8f5
7
- data.tar.gz: 7243843af08eba2a5bacf9f72bdc0b1ffc6a5f6eb598ab0d2b0a7af711b997b95d6e7179adc61ae961029d530365a8888cca0b7018d7bfd7b584b5ad4b8aebce
6
+ metadata.gz: 64cb59550b604a2a0d189b23dfddeca083bd2a21b656ccadc04e4d72294ed99ce9cf05fc98732b28a1e71f7886ec0f75a472afab2868d551990b38133c94f265
7
+ data.tar.gz: 0f9f1f277f6f4ce30e73d7d4c6c4681ea9b5e2541a24e17ad518fc3b7291f04af963464ee15a674f36ddbe51d4b723c321f97db8b058f5d732fcb3e421054198
@@ -4,6 +4,7 @@ require 'uri'
4
4
  require 'erb'
5
5
  require 'open3'
6
6
  require 'tmpdir'
7
+ require 'json'
7
8
  require 'optparse'
8
9
 
9
10
  require 'octokit'
@@ -25,6 +26,10 @@ class PullRequest
25
26
  def html_link
26
27
  pr.rels[:html].href
27
28
  end
29
+
30
+ def to_hash
31
+ { :data => @pr.to_hash }
32
+ end
28
33
  end
29
34
 
30
35
  class DummyPullRequest
@@ -39,6 +44,10 @@ class DummyPullRequest
39
44
  def html_link
40
45
  'http://github.com/DUMMY/DUMMY/issues/?'
41
46
  end
47
+
48
+ def to_hash
49
+ { :data => {} }
50
+ end
42
51
  end
43
52
 
44
53
  def say(message, level)
@@ -59,7 +68,7 @@ def say(message, level)
59
68
  :red
60
69
  end
61
70
 
62
- puts message.colorize(color)
71
+ STDERR.puts message.colorize(color)
63
72
  end
64
73
 
65
74
  def git(*command)
@@ -101,9 +110,9 @@ Release <%= Time.now %>
101
110
  <% end -%>
102
111
  ERB
103
112
 
104
- def build_pr_title_and_body(target_pr, prs)
105
- target_pull_request = target_pr ? PullRequest.new(target_pr) : DummyPullRequest.new
106
- pull_requests = prs.map { |pr| PullRequest.new(pr) }
113
+ def build_pr_title_and_body(release_pr, merged_prs)
114
+ release_pull_request = target_pull_request = release_pr ? PullRequest.new(release_pr) : DummyPullRequest.new
115
+ merged_pull_requests = pull_requests = merged_prs.map { |pr| PullRequest.new(pr) }
107
116
 
108
117
  template = DEFAULT_PR_TEMPLATE
109
118
 
@@ -117,6 +126,13 @@ def build_pr_title_and_body(target_pr, prs)
117
126
  content.split(/\n/, 2)
118
127
  end
119
128
 
129
+ def dump_result_as_json(release_pr, merged_prs)
130
+ puts( {
131
+ :release_pull_request => (release_pr ? PullRequest.new(release_pr) : DummyPullRequest.new).to_hash,
132
+ :merged_pull_requests => merged_prs.map { |pr| PullRequest.new(pr).to_hash }
133
+ }.to_json )
134
+ end
135
+
120
136
  def merge_pr_body(old_body, new_body)
121
137
  # Try to take over checklist statuses
122
138
  pr_body_lines = []
@@ -206,6 +222,9 @@ OptionParser.new do |opts|
206
222
  opts.on('-n', '--dry-run', 'Do not create/update a PR. Just prints out') do |v|
207
223
  @dry_run = v
208
224
  end
225
+ opts.on('--json', 'Show data of target PRs in JSON format') do |v|
226
+ @json = v
227
+ end
209
228
  end.parse!
210
229
 
211
230
  ### Set up configuration
@@ -254,7 +273,7 @@ if merged_pull_request_numbers.empty?
254
273
  exit 1
255
274
  end
256
275
 
257
- pull_requests = merged_pull_request_numbers.map do |nr|
276
+ merged_prs = merged_pull_request_numbers.map do |nr|
258
277
  pr = client.pull_request repository, nr
259
278
  say "To be released: ##{pr.number} #{pr.title}", :notice
260
279
  pr
@@ -263,45 +282,46 @@ end
263
282
  ### Create a release PR
264
283
 
265
284
  say 'Searching for existing release pull requests...', :info
266
- existing_pull_request = client.pull_requests(repository).find do |pr|
285
+ found_release_pr = client.pull_requests(repository).find do |pr|
267
286
  pr.head.ref == staging_branch && pr.base.ref == production_branch
268
287
  end
269
- create_mode = existing_pull_request.nil?
288
+ create_mode = found_release_pr.nil?
270
289
 
271
290
  if @dry_run
272
- pr_title, new_body = build_pr_title_and_body existing_pull_request, pull_requests
273
- pr_body = create_mode ? new_body : merge_pr_body(existing_pull_request.body, new_body)
291
+ pr_title, new_body = build_pr_title_and_body found_release_pr, merged_prs
292
+ pr_body = create_mode ? new_body : merge_pr_body(found_release_pr.body, new_body)
274
293
 
275
294
  say 'Dry-run. Not updating PR', :info
276
295
  say pr_title, :notice
277
296
  say pr_body, :notice
278
- exit
297
+ dump_result_as_json( found_release_pr, merged_prs ) if @json
298
+ exit 0
279
299
  end
280
300
 
281
301
  pr_title, pr_body = nil, nil
282
- target_pull_request = nil
302
+ release_pr = nil
283
303
 
284
304
  if create_mode
285
- created_pull_request = client.create_pull_request(
305
+ created_pr = client.create_pull_request(
286
306
  repository, production_branch, staging_branch, 'Preparing release pull request...', ''
287
307
  )
288
- unless created_pull_request
308
+ unless created_pr
289
309
  say 'Failed to create a new pull request', :error
290
310
  exit 1
291
311
  end
292
- pr_title, pr_body = build_pr_title_and_body created_pull_request, pull_requests
293
- target_pull_request = created_pull_request
312
+ pr_title, pr_body = build_pr_title_and_body created_pr, merged_prs
313
+ release_pr = created_pr
294
314
  else
295
- pr_title, new_body = build_pr_title_and_body existing_pull_request, pull_requests
296
- pr_body = merge_pr_body(existing_pull_request.body, new_body)
297
- target_pull_request = existing_pull_request
315
+ pr_title, new_body = build_pr_title_and_body found_release_pr, merged_prs
316
+ pr_body = merge_pr_body(found_release_pr.body, new_body)
317
+ release_pr = found_release_pr
298
318
  end
299
319
 
300
320
  say 'Pull request body:', :debug
301
321
  say pr_body, :debug
302
322
 
303
323
  updated_pull_request = client.update_pull_request(
304
- repository, target_pull_request.number, :title => pr_title, :body => pr_body
324
+ repository, release_pr.number, :title => pr_title, :body => pr_body
305
325
  )
306
326
 
307
327
  unless updated_pull_request
@@ -310,3 +330,4 @@ unless updated_pull_request
310
330
  end
311
331
 
312
332
  say "#{create_mode ? 'Created' : 'Updated'} pull request: #{updated_pull_request.rels[:html].href}", :notice
333
+ dump_result_as_json( release_pr, merged_prs ) if @json
@@ -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.5'
7
+ spec.version = '0.1.0'
8
8
  spec.authors = ["motemen"]
9
9
  spec.email = ["motemen@gmail.com"]
10
10
  spec.summary = 'Creates a release pull request'
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-pr-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - motemen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: highline
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: colorize
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: diff-lcs
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.2'
69
69
  description: git-pr-release creates a pull request which summarizes feature branches
@@ -75,7 +75,7 @@ executables:
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - .gitignore
78
+ - ".gitignore"
79
79
  - Gemfile
80
80
  - Gemfile.lock
81
81
  - README.md
@@ -92,19 +92,18 @@ require_paths:
92
92
  - lib
93
93
  required_ruby_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '>='
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.0.3
105
+ rubygems_version: 2.2.2
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Creates a release pull request
109
109
  test_files: []
110
- has_rdoc: