purr-pr 0.1.7 → 0.1.8

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
  SHA256:
3
- metadata.gz: 5c4bbf318a7b60cfa3cd5c57416dd3f66764b99928e78330a7d04f69b7c095ca
4
- data.tar.gz: 8040ce5923ece5149ab563b12b223fad7f3d705d80e37a7c9a71ff82237faa96
3
+ metadata.gz: 14bece028ed60daba6706c6c6432bb5768cf18c62dcadd03df6225b866a0b631
4
+ data.tar.gz: 59297880679407b4d96be5c4c5ac797f3e6a4feaf2478dbc413f08b38412aa3d
5
5
  SHA512:
6
- metadata.gz: 5e2cc29dd764cecbf87bca385874511dd1c0eb677b2bf77a2fb7ee4e415d28f70a6fb98123fa16647d54bde0d94c43a0d59a2004cf8d8abd534404b9c6a1cd7a
7
- data.tar.gz: 5dbeeec11460198a30528260c2e6964d9919669fa8084196b029f9ddbd3fb8e2eb12de87740bf1230db83b3a033610bd9399d0fe1807f107a2f7da256a3ff8ec
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.6)
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
@@ -15,12 +15,12 @@ class PurrPr
15
15
  @labels = []
16
16
  end
17
17
 
18
- def title(text = '', &block)
19
- @title = edit(:title, content: text, &block)
18
+ def title(initial_content = '', &block)
19
+ @title = edit(:title, content: initial_content, &block)
20
20
  end
21
21
 
22
- def body(text = '', &block)
23
- @body = edit(:body, content: text, &block)
22
+ def body(initial_content = '', &block)
23
+ @body = edit(:body, content: initial_content, &block)
24
24
  end
25
25
 
26
26
  def assignee(assignee)
@@ -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.7'
4
+ VERSION = '0.1.8'
5
5
  end
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
 
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Teslovskiy
@@ -66,7 +66,8 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.14.1
69
- description: Purr PR is a tool to automate pull request formatting via GitHub CLI
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
@@ -124,7 +125,7 @@ requirements: []
124
125
  rubygems_version: 3.2.3
125
126
  signing_key:
126
127
  specification_version: 4
127
- summary: A CLI pull request formatter
128
+ summary: CLI tool for quick pull request formatting
128
129
  test_files:
129
130
  - spec/purr_spec.rb
130
131
  - spec/spec_helper.rb