pr_comet 0.2.1 → 0.3.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
  SHA256:
3
- metadata.gz: 4c89befe4fe216196ff74e572a7c0661e7ebd30c914ee8e805ea6abd12b5f37e
4
- data.tar.gz: 1f74020285bc9816f5b015c78d23309c2136f40e854d07b745c0eadf3a378471
3
+ metadata.gz: 85cd89906ec3936b19baf0285df362c1c85e174b3e629b3561606ce2603da969
4
+ data.tar.gz: 315b3d930e793c616a3e141acf8c1cbf21212b4ac18f22515588b4e3a00e8457
5
5
  SHA512:
6
- metadata.gz: 44c3a4cc2a2970b8940421158971fb4936edb9317496dc835a173274f6ef627837f74b79744c900b28383d6c9144fada4b7ab9a72c27724108cc87639a3a20a2
7
- data.tar.gz: a4a1bb1b077668648d5e4926fbb21341e0a98f4b9fe948bbcd0a8e118c109f77b8f7a03526dbac5840cd254efe01117727077865ef238e4caa2e7d578e5638a2
6
+ metadata.gz: a6ec85517c9fae4c6fd3bef6bdfeeae6616d8e9737eef41e1901f7e483e1f92572dff967c2f8202d58df4c99a648a6291cd5d104c532762d80e48b67590060ab
7
+ data.tar.gz: 625ac832cb54b16f2d868c47c3453c7e0fd826c056cf8912259f5ffadb1fdcf1daaa39f3487434e4a963cc62131678776cc6b96bf38fd8b0cd47c2878c713569
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pr_comet (0.2.1)
4
+ pr_comet (0.3.0)
5
5
  octokit
6
6
  rainbow
7
7
 
data/bin/release CHANGED
@@ -8,14 +8,15 @@ require 'pr_comet'
8
8
 
9
9
  VERSION_FORMAT = /\A\d+\.\d+\.\d+(\.(pre|beta|rc)\d?)?\z/.freeze
10
10
  version = ARGV[0]
11
- pr_comet = PrComet.new(base: 'master', branch: "update/v#{version}")
11
+ update_pr = PrComet.new(base: 'master', branch: "update/v#{version}")
12
+ release_pr = PrComet.new(base: 'production', branch: 'master')
12
13
 
13
14
  # Verifying
14
15
  abort 'usage: bin/release VERSION' if version.nil?
15
16
  abort 'A version must be like a `1.2.3`' unless version =~ VERSION_FORMAT
16
17
 
17
18
  # Modify a version file
18
- pr_comet.commit ':comet: Update version' do
19
+ update_pr.commit ':comet: Update version' do
19
20
  File.write('lib/pr_comet/version.rb', <<~VERSION)
20
21
  # frozen_string_literal: true
21
22
 
@@ -26,9 +27,10 @@ pr_comet.commit ':comet: Update version' do
26
27
  end
27
28
 
28
29
  # Bundle Update
29
- pr_comet.commit ':comet: Run $ bundle update' do
30
+ update_pr.commit ':comet: Run $ bundle update' do
30
31
  `bundle update`
31
32
  end
32
33
 
33
34
  # Create a pull request
34
- pr_comet.create!(title: "Update v#{version}", body: '')
35
+ update_pr.create!(title: "Update v#{version}", body: '')
36
+ release_pr.create!(title: "Release v#{version}", body: '', validate: false)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PrComet
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/pr_comet.rb CHANGED
@@ -42,44 +42,67 @@ class PrComet
42
42
  result
43
43
  end
44
44
 
45
- # Create a pull request
46
- # You should call #commit before calling this method
45
+ # Create a pull request. You should call #commit before calling this method.
46
+ # If you want to create a blank PR, you can do it with `validate: false`
47
+ # option.
47
48
  #
48
- # @param title [String] Title for the pull request
49
- # @param body [String] The body for the pull request
50
- # @param labels [Array<String>]
49
+ # @param options [Hash]
50
+ # Options for the PR creation.
51
+ # @option title [String]
52
+ # The title for the pull request
53
+ # @option body [String]
54
+ # The body for the pull request
55
+ # @option labels [Array<String>]
51
56
  # List of labels. It is a optional parameter. You can add labels to the
52
57
  # created PR.
53
- # @param project_column_name [String]
58
+ # @option project_column_name [String]
54
59
  # A project column name. It is a optional parameter. You can add the created
55
60
  # PR to the GitHub project.
56
- # @param project_id [Integer]
61
+ # @option project_id [Integer]
57
62
  # A target project ID. It is a optional parameter. If does not supplied,
58
63
  # this method will find a project which associated the repository.
59
- # When the repository has multiple projects, you should supply this.
60
- # @return [Boolean] Return true if it is successed.
61
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
62
- def create!(title:, body:, labels: nil, project_column_name: nil, project_id: nil)
63
- return false unless git_condition_valid?
64
+ # When the repository is associated with multiple projects, you should
65
+ # supply this.
66
+ # @option validate [Boolean]
67
+ # Verifies the branch has commits and checkout to the topic branch. If you
68
+ # want to create a blank PR, set "false" to this option. default: true.
69
+ # @return [Boolean]
70
+ # Return true if it is successed.
71
+ # rubocop:disable Metrics/AbcSize
72
+ def create!(**options)
73
+ options[:validate] = true if options[:validate].nil?
74
+ return false if options[:validate] && !git_condition_valid?
64
75
 
65
76
  git.push(github_token_url, topic_branch)
66
- pr_number = github.create_pull_request(
67
- base: base_branch, head: topic_branch, title: title, body: body
68
- )
69
- github.add_labels(pr_number, *labels) unless labels.nil?
70
- unless project_column_name.nil?
71
- github.add_to_project(
72
- pr_number, column_name: project_column_name, project_id: project_id
73
- )
77
+ pr_number = github.create_pull_request(generate_create_pr_options(options))
78
+ github.add_labels(pr_number, *options[:labels]) unless options[:labels].nil?
79
+ unless options[:project_column_name].nil?
80
+ github.add_to_project(pr_number, generate_add_to_project_options(options))
74
81
  end
75
82
  true
76
83
  end
77
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
84
+ # rubocop:enable Metrics/AbcSize
78
85
 
79
86
  private
80
87
 
81
88
  attr_reader :git, :github, :base_branch, :topic_branch, :initial_sha1
82
89
 
90
+ def generate_create_pr_options(**options)
91
+ {
92
+ base: base_branch,
93
+ head: topic_branch,
94
+ title: options[:title],
95
+ body: options[:body]
96
+ }
97
+ end
98
+
99
+ def generate_add_to_project_options(**options)
100
+ {
101
+ column_name: options[:project_column_name],
102
+ project_id: options[:project_id]
103
+ }
104
+ end
105
+
83
106
  def git_condition_valid?
84
107
  !git.current_sha1?(initial_sha1) && git.current_branch?(topic_branch)
85
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pr_comet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryz310