purr-pr 0.1.0 → 0.1.1

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: a65c40e37fd950cf219bacece2cdc51969b809c2862d5d36fb78d5fdabc5d951
4
- data.tar.gz: 2466ebf01d0d50a92dab623517a7e905d10d7285041ed71118d05aae0fb93c8f
3
+ metadata.gz: 28591b3924f3804d53524f066a04af979003efce1eedfbd1d5e13334d1dea7b2
4
+ data.tar.gz: c46423434848aee5e6e3b51fdedf478fd8e304306712c8bad844bfe7e1808e86
5
5
  SHA512:
6
- metadata.gz: df76de7cfeb230d9b4b167b3fdcdd26b5db22c55c505921eb1b93ac7368d9ff0b2f2c17b4d73fd1a4568e329b5365903d536c00f518ae7f7f126fdb487de972e
7
- data.tar.gz: ff0708b5124afc6387e1bef121526feb58b7e1f7d767b3a45230c5f1e773aa5f10eb0a723f17a28a38425038c0ca456ffc007682f929c559539d3af362ac24c9
6
+ metadata.gz: 6d61345f1cb00c3bf5d661e49935b5cdc26f0c439cec602cae95fe34e526351788d8a3466b0169ce8b31583a0667835a5d21c44357b7a21d6c3833bb62feb05e
7
+ data.tar.gz: 612463288bc44aee44fb257a368a29fc113535297beca24a3cfc673514afec77b2defefa131f86d4d417ab2ee6c479030d309f33a57b5221e2658b28fbb7d219
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- purr (0.1.0)
4
+ purr-pr (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,7 +33,7 @@ PLATFORMS
33
33
  DEPENDENCIES
34
34
  bundler (~> 2.0)
35
35
  pry
36
- purr!
36
+ purr-pr!
37
37
  rake (~> 13.0)
38
38
  rspec (~> 3.0)
39
39
 
data/bin/console CHANGED
@@ -1,15 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "purr"
4
+ require 'bundler/setup'
5
+ require 'purr_pr'
6
6
 
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
7
+ require 'pry'
8
+ Pry.start
data/bin/purr CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'purr'
4
+ require 'purr_pr'
5
5
 
6
- puts 'foo'
7
- # ARGV[0]
6
+ PurrPr.new.create
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'io/console'
4
4
 
5
- module Purr
5
+ class PurrPr
6
6
  module Actions
7
7
  def ask(message, default: nil, multiline: false, newline: true)
8
8
  puts(message)
@@ -35,7 +35,7 @@ module Purr
35
35
  end
36
36
 
37
37
  def interrupted?
38
- @interrupted
38
+ !!@interrupted
39
39
  end
40
40
 
41
41
  private
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'editor.rb'
4
+
5
+ class PurrPr
6
+ class Config
7
+ attr_reader :title, :body, :assignee
8
+
9
+ def initialize
10
+ # the defaults if the setter is not called
11
+ @maintainer_edit = true
12
+ end
13
+
14
+ def title(&block)
15
+ @title = edit(:title, &block)
16
+ end
17
+
18
+ def body(&block)
19
+ @body = edit(:body, &block)
20
+ end
21
+
22
+ def assignee(assignee)
23
+ @assignee = assignee
24
+ end
25
+
26
+ def self_assign
27
+ assignee('@me')
28
+ end
29
+
30
+ def maintainer_edit(enabled)
31
+ @maintainer_edit = enabled
32
+ end
33
+
34
+ def no_maintainer_edit
35
+ maintainer_edit(false)
36
+ end
37
+
38
+ def base(base_branch)
39
+ @base = base_branch
40
+ end
41
+
42
+ def draft(enabled = true)
43
+ @draft = enabled
44
+ end
45
+
46
+ def labels(labels)
47
+ @labels = labels
48
+ end
49
+
50
+ def reviewers(reviewers)
51
+ @reviewers = reviewers
52
+ end
53
+
54
+ def values
55
+ OpenStruct.new(
56
+ title: @title,
57
+ body: @body,
58
+ assignee: @assignee,
59
+ base: @base,
60
+ draft: @draft,
61
+ reviewers: @reviewers,
62
+ labels: @labels,
63
+ maintainer_edit: @maintainer_edit
64
+ )
65
+ end
66
+
67
+ private
68
+
69
+ def edit(subject, &block)
70
+ editor = Editor.new(subject)
71
+
72
+ catch(:abort) { editor.evaluate(&block) }
73
+
74
+ interrupt if editor.interrupted?
75
+
76
+ editor.content
77
+ end
78
+
79
+ def interrupt
80
+ puts 'aborted'
81
+ exit
82
+ end
83
+ end
84
+ end
@@ -5,7 +5,7 @@ require 'securerandom'
5
5
  require_relative 'text_objects'
6
6
  require_relative 'actions'
7
7
 
8
- module Purr
8
+ class PurrPr
9
9
  class Editor
10
10
  include TextObjects
11
11
  include Actions
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Purr
3
+ class PurrPr
4
4
  module TextObjects
5
5
  def newline(count = 1)
6
6
  "\n" * count
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Purr
4
- VERSION = "0.1.0"
3
+ class PurrPr
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/purr_pr.rb ADDED
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'purr_pr/version'
4
+ require_relative 'purr_pr/editor.rb'
5
+ require_relative 'purr_pr/config.rb'
6
+
7
+ class PurrPr
8
+ attr_reader :config_file_path, :config
9
+
10
+ DEFAULT_CONFIG_FILE_PATH = 'purr.rb'
11
+
12
+ def initialize(config_file_path = DEFAULT_CONFIG_FILE_PATH)
13
+ @config_file_path = config_file_path
14
+ @config = Config.new
15
+ end
16
+
17
+ def create
18
+ config.instance_eval(config_code)
19
+
20
+ command = 'gh pr create'
21
+ command += " --title '#{config.values.title}'" if config.values.title
22
+ command += " --body '#{config.values.body}'"
23
+ command += " --assignee #{config.values.assignee}" if config.values.assignee
24
+ command += " --base #{config.values.base}" if config.values.base
25
+ command += ' --draft' if config.values.draft
26
+ command += ' --no-maintainer-edit' unless config.values.maintainer_edit
27
+
28
+ config.values.labels.each do |label|
29
+ command += " --label #{label}"
30
+ end
31
+
32
+ config.values.reviewers.each do |reviewer|
33
+ command += " --reviewer #{reviewer}"
34
+ end
35
+
36
+ # The later arguments will override the earlier ones,
37
+ # e.g. after `gh pr create --title a --title b` the title will equal 'b',
38
+ # so explicit options will override the config
39
+ command += ARGV.join(' ').prepend(' ')
40
+
41
+ system(command)
42
+ end
43
+
44
+ private
45
+
46
+ def config_code
47
+ File.read(config_file_path)
48
+ end
49
+ end
data/purr_pr.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/purr_pr/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'purr-pr'
7
+ spec.version = PurrPr::VERSION
8
+ spec.author = 'Alexander Teslovskiy'
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'
12
+ spec.homepage = 'https://github.com/ARtoriouSs/purr-pr'
13
+ spec.license = 'MIT'
14
+
15
+ spec.metadata = {
16
+ 'documentation_uri' => 'https://github.com/ARtoriouSs/purr-pr/blob/master/README.md',
17
+ 'bug_tracker_uri' => 'https://github.com/ARtoriouSs/purr-pr/issues',
18
+ 'source_code_uri' => 'https://github.com/ARtoriouSs/purr-pr',
19
+ 'changelog_uri' => 'https://github.com/ARtoriouSs/purr-pr/blob/master/CHANGELOG.md',
20
+ 'wiki_uri' => 'https://github.com/ARtoriouSs/purr-pr/wiki',
21
+ 'homepage_uri' => 'https://github.com/ARtoriouSs/purr-pr'
22
+ }
23
+
24
+ spec.require_paths = ['lib']
25
+ spec.bindir = 'bin'
26
+ spec.executables << 'purr'
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject { |file| file.match(%r{^spec/}) }
29
+ spec.test_files = `git ls-files -- spec`.split("\n")
30
+
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'pry'
35
+ end
data/spec/purr_spec.rb CHANGED
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Purr do
3
+ describe PurrPr do
4
4
  it "has a version number" do
5
- expect(Purr::VERSION).not_to be nil
6
- end
7
-
8
- it "does something useful" do
9
- expect(false).to eq(true)
5
+ expect(PurrPr::VERSION).not_to be nil
10
6
  end
11
7
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "purr"
3
+ require "purr_pr"
4
4
 
5
5
  RSpec.configure do |config|
6
- # Enable flags like --only-failures and --next-failure
7
6
  config.example_status_persistence_file_path = ".rspec_status"
8
-
9
- # Disable RSpec exposing methods globally on `Module` and `main`
10
7
  config.disable_monkey_patching!
11
8
 
12
9
  config.expect_with :rspec do |c|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purr-pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Teslovskiy
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-09 00:00:00.000000000 Z
11
+ date: 2022-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: ''
69
+ description: Purr PR is a tool to automate pull request formatting via GitHub CLI
70
70
  email: artoriousso@gmail.com
71
71
  executables:
72
72
  - purr
@@ -86,25 +86,26 @@ files:
86
86
  - bin/console
87
87
  - bin/purr
88
88
  - bin/setup
89
- - lib/purr.rb
90
- - lib/purr/actions.rb
91
- - lib/purr/editor.rb
92
- - lib/purr/text_objects.rb
93
- - lib/purr/version.rb
94
- - purr.gemspec
89
+ - lib/purr_pr.rb
90
+ - lib/purr_pr/actions.rb
91
+ - lib/purr_pr/config.rb
92
+ - lib/purr_pr/editor.rb
93
+ - lib/purr_pr/text_objects.rb
94
+ - lib/purr_pr/version.rb
95
+ - purr_pr.gemspec
95
96
  - spec/purr_spec.rb
96
97
  - spec/spec_helper.rb
97
- homepage: https://github.com/ARtoriouSs/purr
98
+ homepage: https://github.com/ARtoriouSs/purr-pr
98
99
  licenses:
99
100
  - MIT
100
101
  metadata:
101
- documentation_uri: https://github.com/ARtoriouSs/purr/blob/master/README.md
102
- bug_tracker_uri: https://github.com/ARtoriouSs/purr/issues
103
- source_code_uri: https://github.com/ARtoriouSs/purr
104
- changelog_uri: https://github.com/ARtoriouSs/purr/blob/master/CHANGELOG.md
105
- wiki_uri: https://github.com/ARtoriouSs/purr/wiki
106
- homepage_uri: https://github.com/ARtoriouSs/purr
107
- post_install_message:
102
+ documentation_uri: https://github.com/ARtoriouSs/purr-pr/blob/master/README.md
103
+ bug_tracker_uri: https://github.com/ARtoriouSs/purr-pr/issues
104
+ source_code_uri: https://github.com/ARtoriouSs/purr-pr
105
+ changelog_uri: https://github.com/ARtoriouSs/purr-pr/blob/master/CHANGELOG.md
106
+ wiki_uri: https://github.com/ARtoriouSs/purr-pr/wiki
107
+ homepage_uri: https://github.com/ARtoriouSs/purr-pr
108
+ post_install_message:
108
109
  rdoc_options: []
109
110
  require_paths:
110
111
  - lib
@@ -119,10 +120,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  requirements: []
122
- rubygems_version: 3.1.2
123
- signing_key:
123
+ rubygems_version: 3.2.3
124
+ signing_key:
124
125
  specification_version: 4
125
- summary: ''
126
+ summary: A CLI pull request formatter
126
127
  test_files:
127
128
  - spec/purr_spec.rb
128
129
  - spec/spec_helper.rb
data/lib/purr.rb DELETED
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'purr/version'
4
- require_relative 'purr/editor.rb'
5
-
6
- require 'pry' # TODO
7
-
8
- module Purr
9
- def self.title(&block)
10
- @title = edit(:title, &block)
11
- end
12
-
13
- def self.body(&block)
14
- @body = edit(:body, &block)
15
- end
16
-
17
- def self.assignee(assignee)
18
- @assignee = assignee
19
- end
20
-
21
- def self.self_assign
22
- assignee('@me')
23
- end
24
-
25
- private
26
-
27
- def edit(subject, &block)
28
- editor = Editor.new(subject)
29
-
30
- catch(:abort) { editor.evaluate(&block) }
31
-
32
- interrupt if editor.interrupted?
33
-
34
- editor.content
35
- end
36
-
37
- def interrupt
38
- puts 'aborted'
39
- exit
40
- end
41
- end
data/purr.gemspec DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'purr/version'
6
-
7
- require_relative "lib/purr/version"
8
-
9
- Gem::Specification.new do |spec|
10
- spec.name = 'purr-pr'
11
- spec.version = Purr::VERSION
12
- spec.author = 'Alexander Teslovskiy'
13
- spec.email = 'artoriousso@gmail.com'
14
- spec.summary = ''
15
- spec.description = ''
16
- spec.homepage = 'https://github.com/ARtoriouSs/purr'
17
- spec.license = 'MIT'
18
-
19
- spec.metadata = {
20
- 'documentation_uri' => 'https://github.com/ARtoriouSs/purr/blob/master/README.md',
21
- 'bug_tracker_uri' => 'https://github.com/ARtoriouSs/purr/issues',
22
- 'source_code_uri' => 'https://github.com/ARtoriouSs/purr',
23
- 'changelog_uri' => 'https://github.com/ARtoriouSs/purr/blob/master/CHANGELOG.md',
24
- 'wiki_uri' => 'https://github.com/ARtoriouSs/purr/wiki',
25
- 'homepage_uri' => 'https://github.com/ARtoriouSs/purr'
26
- }
27
-
28
- spec.require_paths = ['lib']
29
- spec.bindir = 'bin'
30
-
31
- spec.files = `git ls-files -z`.split("\x0").reject { |file| file.match(%r{^spec/}) }
32
- spec.test_files = `git ls-files -- spec`.split("\n")
33
- spec.executables << 'purr'
34
-
35
- spec.add_development_dependency 'bundler', '~> 2.0'
36
- spec.add_development_dependency 'rake', '~> 13.0'
37
- spec.add_development_dependency 'rspec', '~> 3.0'
38
- spec.add_development_dependency 'pry'
39
- end