purr-pr 0.1.4 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 026f27316039a8102929a1346d6ccdd17e819bd8257799e418612438941d93f5
4
- data.tar.gz: 17e9f3e088efc7e7577997880fb49e175ca4c7eca761ef84a6c0de6ec954f5a9
3
+ metadata.gz: 14bece028ed60daba6706c6c6432bb5768cf18c62dcadd03df6225b866a0b631
4
+ data.tar.gz: 59297880679407b4d96be5c4c5ac797f3e6a4feaf2478dbc413f08b38412aa3d
5
5
  SHA512:
6
- metadata.gz: 570c260277fb207740070722bf0b0f164c965e3902128c9c3f0ab2959d76d1f949de39820a145545adf6019104798213451599c78c03b22839ddef2e58a3fe6c
7
- data.tar.gz: f1cb51100aa7cdc84ad51dd06257a9c61e2a5f6ddcc3fd13402f5db1c3929631a0fdf800c60b697ed229ae75d0587d5d9c4b5654ad5df7433485b0d33a77add6
6
+ metadata.gz: b84b4c9ecb3cdd053c23f8c8e7c38ef272d30d41ab6cab4fe25d607722b6c75c0b4685fca73c77cbf6e0fd890ecff9e447f58abd2510ed902296afabe088452c
7
+ data.tar.gz: 30f8172bb8caecd33b812a98a4c9a6d8663bbe3b0b94299fcf8de51c097a50b3ddd843cae6643518b8845214280bd4e90f0493aad324b39d4d30de40b74f92f9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- purr-pr (0.1.0)
4
+ purr-pr (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,7 +32,7 @@ PLATFORMS
32
32
 
33
33
  DEPENDENCIES
34
34
  bundler (~> 2.0)
35
- pry
35
+ pry (~> 0.14.1)
36
36
  purr-pr!
37
37
  rake (~> 13.0)
38
38
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Purr
1
+ # Purr PR
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/purr`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Tired of formatting/writing the same PR text over and over again? Use Purr PR to create a simple formatting script!
6
4
 
7
5
  ## Installation
8
6
 
@@ -14,27 +12,348 @@ gem 'purr'
14
12
 
15
13
  And then execute:
16
14
 
17
- $ bundle install
15
+ ```bash
16
+ bundle install
17
+ ```
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install purr
21
+ ```bash
22
+ gem install purr
23
+ ```
24
+
25
+ ### Dependencies
26
+
27
+ This gem using [GitHub CLI tool](https://github.com/cli/cli) to conveniently create PRs, so you will need to [install it](https://github.com/cli/cli#installation) in order to use Purr PR.
22
28
 
23
29
  ## Usage
24
30
 
25
- TODO: Write usage instructions here
31
+ After installing gem, create a `purr_pr.rb` file in the root of your git project. This file will describe your PRs.
32
+
33
+ ### Configuration
34
+
35
+ Now you can use `purr_pr.rb` file to create your formatting script
36
+
37
+ #### Body
38
+
39
+ As body is the biggest PR part there are a lot of helpers to edit it. The base format is a:
40
+
41
+ ```ruby
42
+ body do
43
+ # your edits
44
+ end
45
+ ```
46
+
47
+ ##### Templates
48
+
49
+ First of all the `use_template` method will simply copy the contents of `.github/pull_request_template.md` to a body buffer.
50
+ To use any other file as a template you can provide the path to it as an argument:
51
+
52
+ ```ruby
53
+ body do
54
+ use_template
55
+ # or use_template '.github/some_other_template.md'
56
+ end
57
+ ```
58
+
59
+ The above code will create a PR with body that has the contents of a PR template file, but this is what GitHub do by default, so then you'll probably want to apply some edits.
60
+
61
+ For the future edits lets say that the contents of `.github/pull_request_template.md` is 'foo-template'
62
+
63
+ To append or prepend some content to the buffer you can use corresponding methods:
64
+
65
+ ```ruby
66
+ body do
67
+ use_template
68
+ append '-postfix'
69
+ prepend '[STORY_NUMBER] '
70
+ end
71
+ ```
72
+
73
+ It will create the next body: '[STORY_NUMBER] foo-template-postfix'.
74
+
75
+ To change some text in a buffer use the `replace` method:
76
+
77
+ ```ruby
78
+ body do
79
+ use_template
80
+ append '-postfix'
81
+ prepend '[STORY_NUMBER] '
82
+ replace '[STORY_NUMBER]', with: 1337
83
+ end
84
+ ```
85
+
86
+ => '[1337] foo-template-postfix'.
87
+
88
+ To remove some text use the `delete` method:
89
+
90
+ ```ruby
91
+ body do
92
+ use_template
93
+ append '-postfix'
94
+ prepend '[STORY_NUMBER] '
95
+ replace '[STORY_NUMBER]', with: 1337
96
+ delete '-postfix'
97
+ end
98
+ ```
99
+
100
+ => '[1337] foo-template'.
101
+
102
+ You can conditionally clear the buffer with the `clear` method:
103
+
104
+ ```ruby
105
+ body do
106
+ use_template
107
+ clear if ARGV.first == '--empty'
108
+ end
109
+ ```
110
+
111
+ The above code will create the PR with empty body if the first argument is '--empty'
112
+
113
+ ##### Manual edits
114
+
115
+ You can also open the `$EDITOR` and manually edit the buffer text with `editor` method:
116
+
117
+ ```ruby
118
+ body do
119
+ use_template
120
+ editor
121
+ end
122
+ ```
123
+
124
+ The above config will allow you to edit your template before creating a PR.
125
+ Optionally you can provide file format to use syntax highlighting (the default is `:md`): `editor format: :html`.
126
+
127
+ ##### Confirmation
128
+
129
+ If you whant to ensure that your edits are correct use `confirm` method, it will display you current buffer and ask Y/N confirmation to continue:
130
+
131
+ ```ruby
132
+ body do
133
+ use_template
134
+ confirm
135
+ end
136
+ ```
137
+
138
+ ##### Helpers
139
+
140
+ There are some syntax sugar and helpers to be used as the arguments of above methods:
141
+
142
+ ```ruby
143
+ body do
144
+ append newline(3) # => '\n\n\n'
145
+ append space # => ' '
146
+ append commits.last # => Latest commit
147
+ append current_branch # => Current git branch
148
+ end
149
+ ```
150
+
151
+ ##### Actions
152
+
153
+ To ask a Y/N question you can use `ask_yn` method:
154
+
155
+ ```ruby
156
+ body do
157
+ ask_yn 'wanna dance? (Y/N)', confirm: -> { append 'yeeesss' }, decline: -> { append 'nope :(' }
158
+ end
159
+ ```
160
+
161
+ The first argument is a message, and `:confirm` and `:decline` arguments are for callbacks.
162
+
163
+ To ask for a custom input use the `ask` method:
164
+
165
+ ```ruby
166
+ body do
167
+ append(ask 'Story number: ', default: 1337)
168
+ end
169
+ ```
170
+
171
+ It will prompt you to enter the story number and then append it to the buffer. If no input is provided the `:default` value will be used.
172
+ To prompt for multiline input use `multiline: true`, it will prompt for the next line untill you input two empty lines in a row.
173
+ Use `newline: true` to append an empty line after the input.
174
+
175
+ To read a file there is a `read_file` method:
176
+
177
+ ```ruby
178
+ body do
179
+ append(read_file('Gemfile'))
180
+ end
181
+ ```
182
+
183
+ The above config will append your Gemfile content to the buffer
184
+
185
+ To conditionally finish the editing and create a PR use `finish`:
186
+
187
+ ```ruby
188
+ body do
189
+ ask_yn 'are you a duck? (Y/N)', confirm: -> { append 'quack' }, decline: -> { finish }
190
+ end
191
+ ```
192
+
193
+ If you want to finish editing and cancel the PR creating you should use `interrupt` instead
194
+
195
+ #### Title
196
+
197
+ For PR title you can use the same block formatting as for the body:
198
+
199
+ ```ruby
200
+ title do
201
+ story_number = "[#{current_branch}]"
202
+
203
+ append story_number
204
+ append ' my aweasome PR: '
205
+ append commits.last
206
+ end
207
+ ```
208
+
209
+ Or simply do:
210
+
211
+ ```ruby
212
+ title 'My static PR title'
213
+ ```
214
+
215
+ The first argument will be the initial title before editing, so:
216
+
217
+ ```ruby
218
+ title 'Story#' do
219
+ append 1337
220
+ end
221
+ ```
222
+
223
+ Will create a title 'Story#1337'
224
+
225
+ #### Assignee
226
+
227
+ To assign someone to a PR use `assignee` or `self_assign` options:
228
+
229
+ ```ruby
230
+ assignee '@JohnDoe'
231
+ assignee '@me' # self-assign
232
+ self_assign # the same as above
233
+ ```
234
+
235
+ #### Base branch
236
+
237
+ If you want to change the default base branch use `base` option:
238
+
239
+ ```ruby
240
+ base 'develop'
241
+ ```
242
+
243
+ #### Draft PRs
244
+
245
+ To create draft PR use `draft` option:
246
+
247
+ ```ruby
248
+ draft
249
+ # or
250
+ draft true
251
+ ```
252
+
253
+ #### Labels
254
+
255
+ To add PR labels use `labels` or `label` options:
256
+
257
+ ```ruby
258
+ labels ['bug', 'duplicate'] # to add as an array
259
+ label 'documentation' # to add a single label
260
+ ```
261
+
262
+ The above code will add `bug`, `duplicate` and `documentation` labels to the PR
263
+
264
+ #### Reviewers
265
+
266
+ To add reviewers use `reviewers` or `reviewer` options:
267
+
268
+ ```ruby
269
+ reviewers ['@JohnDoe', '@BoJackHorseman'] # to add as an array
270
+ reviewer '@FooBar' # to add a single label
271
+ ```
272
+
273
+ The above code will add `@JohnDoe`, `@BoJackHorseman` and `@FooBar` as the reviewers to the PR
274
+
275
+ #### Disabling maintainer edit
276
+
277
+ To disable/reenable edits from maintainer use `maintainer_edit` or `no_maintainer_edit` options:
278
+
279
+ ```ruby
280
+ maintainer_edit false
281
+ no_maintainer_edit # the same as above
282
+ ```
283
+
284
+ ### Finally, create a PR!
285
+
286
+ Simply call `purr` and it will create a PR for you via [GitHub CLI](https://github.com/cli/cli) according to your configuration file. Note that you may need to log in first with `gh auth login`.
287
+ To override any config values you can append them to `purr` as a `gh pr create` [arguments](https://cli.github.com/manual/gh_pr_create), e.g. `purr --body foo` will create a PR with body 'foo' instead of the value from `purr.rb`.
288
+
289
+ #### Scripting is the key
290
+
291
+ The inline edits is pretty simple, but pretty useless as well, so don't forget that you can use any ruby code here to format your buffer.
292
+ A nice example:
293
+
294
+ ```ruby
295
+ title 'Story: ' do
296
+ story_number = current_branch.gsub('/').first
297
+
298
+ append story_number
299
+ append space
300
+
301
+ if commits.count == 1
302
+ append commits.last
303
+ else
304
+ append(ask 'Title: ', default: commits.last)
305
+ end
306
+ end
307
+
308
+ body do
309
+ story_number = current_branch.gsub('/').first
310
+
311
+ use_template
312
+
313
+ # Story number
314
+ replace '<STORY-NUMBER>', with: story_number
315
+
316
+ # PR Title and details
317
+ if commits.count == 1
318
+ replace 'Story Title', with: commits.last
319
+ replace 'Details go here', with: commits.last
320
+ else
321
+ story_title = ask 'Title: ', default: commits.last
322
+ details = ask 'Details: ', default: commits.last
323
+ replace 'Story Title', with: story_title
324
+ replace 'Details go here', with: details
325
+ end
326
+
327
+ # check the PR type checkboxes
328
+ case ARGV.first
329
+ when '--feature'
330
+ replace '- [ ] New feature', with: '- [x] New feature'
331
+ when '--bugfix'
332
+ replace '- [ ] Bug fix', with: '- [x] Bug fix'
333
+ when '--docs'
334
+ replace '- [ ] Documentation', with: '- [x] Documentation'
335
+ end
336
+
337
+ editor # to ensure and fix something
338
+ end
339
+
340
+ draft
341
+ self_assign
342
+ reviewer '@MyTeamLeadReviever'
343
+ label 'bug' if ARGV.first == '--bugfix'
344
+ ```
26
345
 
27
346
  ## Development
28
347
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
348
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
349
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
350
+ To install this gem onto your local machine, run `rake install`. To release a new version, update the version number in [version.rb](lib/purr_pr/version.rb), and then run `rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
351
 
33
352
  ## Contributing
34
353
 
35
354
  Bug reports and pull requests are welcome on GitHub at https://github.com/ARtoriouSs/purr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ARtoriouSs/purr/blob/master/CODE_OF_CONDUCT.md).
36
355
 
37
- ## License
356
+ ## [License](LICENSE.txt)
38
357
 
39
358
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
359
 
data/bin/setup CHANGED
@@ -5,4 +5,6 @@ set -vx
5
5
 
6
6
  bundle install
7
7
 
8
- # Do any other automated setup that you need to do here
8
+ # test config
9
+ touch purr.rb
10
+ echo "title 'foo'" >> purr.rb
@@ -9,16 +9,18 @@ class PurrPr
9
9
  attr_reader :title, :body, :assignee
10
10
 
11
11
  def initialize
12
- # the defaults if the setter is not called
12
+ # defaults - if setter is not called
13
13
  @maintainer_edit = true
14
+ @reviewers = []
15
+ @labels = []
14
16
  end
15
17
 
16
- def title(&block)
17
- @title = edit(:title, &block)
18
+ def title(initial_content = '', &block)
19
+ @title = edit(:title, content: initial_content, &block)
18
20
  end
19
21
 
20
- def body(&block)
21
- @body = edit(:body, &block)
22
+ def body(initial_content = '', &block)
23
+ @body = edit(:body, content: initial_content, &block)
22
24
  end
23
25
 
24
26
  def assignee(assignee)
@@ -46,11 +48,19 @@ class PurrPr
46
48
  end
47
49
 
48
50
  def labels(labels)
49
- @labels = labels
51
+ @labels += labels
52
+ end
53
+
54
+ def label(label)
55
+ @labels << label
50
56
  end
51
57
 
52
58
  def reviewers(reviewers)
53
- @reviewers = reviewers
59
+ @reviewers += reviewers
60
+ end
61
+
62
+ def reviewer(reviewer)
63
+ @reviewers << reviewer
54
64
  end
55
65
 
56
66
  def values
@@ -68,10 +78,10 @@ class PurrPr
68
78
 
69
79
  private
70
80
 
71
- def edit(subject, &block)
72
- editor = Editor.new(subject)
81
+ def edit(subject, content: '', &block)
82
+ editor = Editor.new(subject, content: content)
73
83
 
74
- catch(:abort) { editor.evaluate(&block) }
84
+ catch(:abort) { editor.evaluate(&block) } if block_given?
75
85
 
76
86
  interrupt if editor.interrupted?
77
87
 
@@ -1,19 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'securerandom'
4
+ require 'tempfile'
4
5
 
5
6
  require_relative 'text_objects'
6
7
  require_relative 'actions'
8
+ require_relative 'shell_helpers'
7
9
 
8
10
  class PurrPr
9
11
  class Editor
10
12
  include TextObjects
11
13
  include Actions
14
+ include ShellHelpers
12
15
 
13
16
  attr_reader :content, :subject
14
17
 
15
- def initialize(subject) @subject = subject.to_s
16
- @content = ''
18
+ def initialize(subject, content: '')
19
+ @subject = subject.to_s
20
+ @content = content
17
21
  end
18
22
 
19
23
  def evaluate(&block)
@@ -37,6 +41,14 @@ class PurrPr
37
41
  @content.gsub!(text, with)
38
42
  end
39
43
 
44
+ def delete(text)
45
+ replace(text, with: '')
46
+ end
47
+
48
+ def clear
49
+ @content = ''
50
+ end
51
+
40
52
  def edit(format: :md)
41
53
  name = subject + SecureRandom.hex(8)
42
54
  format = ".#{format}" unless format.nil?
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PurrPr
4
+ module ShellHelpers
5
+ def commits
6
+ `git log --pretty=%B`.split("\n\n").reverse
7
+ end
8
+
9
+ def current_branch
10
+ `git branch --show-current`.chomp
11
+ end
12
+ end
13
+ end
@@ -5,5 +5,9 @@ class PurrPr
5
5
  def newline(count = 1)
6
6
  "\n" * count
7
7
  end
8
+
9
+ def space(count = 1)
10
+ ' ' * count
11
+ end
8
12
  end
9
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PurrPr
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.8'
5
5
  end
data/lib/purr_pr.rb CHANGED
@@ -4,6 +4,8 @@ require_relative 'purr_pr/version'
4
4
  require_relative 'purr_pr/editor.rb'
5
5
  require_relative 'purr_pr/config.rb'
6
6
 
7
+ require 'tempfile'
8
+
7
9
  class PurrPr
8
10
  attr_reader :config_file_path, :config
9
11
 
@@ -17,9 +19,14 @@ class PurrPr
17
19
  def create
18
20
  config.instance_eval(config_code)
19
21
 
22
+ # use file for body to avoid quotes issues
23
+ body_file = Tempfile.new
24
+ body_file.write(config.values.body)
25
+ body_file.rewind
26
+
20
27
  command = 'gh pr create'
21
28
  command += " --title '#{config.values.title}'" if config.values.title
22
- command += " --body '#{config.values.body}'"
29
+ command += " --body-file '#{body_file.path}'"
23
30
  command += " --assignee #{config.values.assignee}" if config.values.assignee
24
31
  command += " --base #{config.values.base}" if config.values.base
25
32
  command += ' --draft' if config.values.draft
@@ -39,6 +46,8 @@ class PurrPr
39
46
  command += ARGV.join(' ').prepend(' ')
40
47
 
41
48
  system(command)
49
+ ensure
50
+ body_file.close
42
51
  end
43
52
 
44
53
  private
data/purr_pr.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
7
7
  spec.version = PurrPr::VERSION
8
8
  spec.author = 'Alexander Teslovskiy'
9
9
  spec.email = 'artoriousso@gmail.com'
10
- spec.summary = 'A CLI pull request formatter'
11
- spec.description = 'Purr PR is a tool to automate pull request formatting via GitHub CLI'
10
+ spec.summary = 'CLI tool for quick pull request formatting'
11
+ spec.description = 'Tired of formatting/writing the same PR text over and over again? Use Purr PR to create a customizable formatting script!'
12
12
  spec.homepage = 'https://github.com/ARtoriouSs/purr-pr'
13
13
  spec.license = 'MIT'
14
14
 
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'bundler', '~> 2.0'
32
32
  spec.add_development_dependency 'rake', '~> 13.0'
33
33
  spec.add_development_dependency 'rspec', '~> 3.0'
34
- spec.add_development_dependency 'pry'
34
+ spec.add_development_dependency 'pry', '~> 0.14.1'
35
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purr-pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Teslovskiy
@@ -56,17 +56,18 @@ dependencies:
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.14.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
69
- description: Purr PR is a tool to automate pull request formatting via GitHub CLI
68
+ version: 0.14.1
69
+ description: Tired of formatting/writing the same PR text over and over again? Use
70
+ Purr PR to create a customizable formatting script!
70
71
  email: artoriousso@gmail.com
71
72
  executables:
72
73
  - purr
@@ -90,6 +91,7 @@ files:
90
91
  - lib/purr_pr/actions.rb
91
92
  - lib/purr_pr/config.rb
92
93
  - lib/purr_pr/editor.rb
94
+ - lib/purr_pr/shell_helpers.rb
93
95
  - lib/purr_pr/text_objects.rb
94
96
  - lib/purr_pr/version.rb
95
97
  - purr_pr.gemspec
@@ -123,7 +125,7 @@ requirements: []
123
125
  rubygems_version: 3.2.3
124
126
  signing_key:
125
127
  specification_version: 4
126
- summary: A CLI pull request formatter
128
+ summary: CLI tool for quick pull request formatting
127
129
  test_files:
128
130
  - spec/purr_spec.rb
129
131
  - spec/spec_helper.rb