Class: SpreenPr::Application
- Inherits:
-
Object
- Object
- SpreenPr::Application
- Defined in:
- lib/spreen_pr/application.rb,
sig/generated/spreen_pr/application.rbs
Overview
Derives a pull request title and labels from a topic branch name shaped
{user}/{issue}/{category}/{summary}, with the hotfix special case
{user}/{issue}/hotfix/{category}/{summary}.
Constant Summary collapse
- EXPECTED_SHAPE =
: String
'{user}/{issue}/{category}/{summary}'
Instance Attribute Summary collapse
-
#branch_name ⇒ String
readonly
: String.
-
#segments ⇒ Array[String]
readonly
: Array.
Class Method Summary collapse
Instance Method Summary collapse
- #hotfix? ⇒ Boolean
-
#initialize(branch_name:) ⇒ Application
constructor
A new instance of Application.
- #labels ⇒ Array[String]
- #title ⇒ String
- #to_h ⇒ Hash[Symbol, String | Array[String]]
- #topic ⇒ String
- #validate! ⇒ void
Constructor Details
#initialize(branch_name:) ⇒ Application
Returns a new instance of Application.
19 20 21 22 23 |
# File 'lib/spreen_pr/application.rb', line 19 def initialize(branch_name:) @branch_name = branch_name @segments = branch_name.split('/') validate! end |
Instance Attribute Details
#branch_name ⇒ String (readonly)
: String
47 48 49 |
# File 'lib/spreen_pr/application.rb', line 47 def branch_name @branch_name end |
#segments ⇒ Array[String] (readonly)
: Array
48 49 50 |
# File 'lib/spreen_pr/application.rb', line 48 def segments @segments end |
Class Method Details
.run(branch_name:) ⇒ String
13 14 15 |
# File 'lib/spreen_pr/application.rb', line 13 def self.run(branch_name:) new(branch_name:).title end |
Instance Method Details
#hotfix? ⇒ Boolean
51 52 53 |
# File 'lib/spreen_pr/application.rb', line 51 def hotfix? segments[-3] == 'hotfix' end |
#labels ⇒ Array[String]
31 32 33 |
# File 'lib/spreen_pr/application.rb', line 31 def labels hotfix? ? [segments[-3].capitalize, segments[-2]] : [segments[-2]] end |
#title ⇒ String
26 27 28 |
# File 'lib/spreen_pr/application.rb', line 26 def title "#{labels.map { |label| "[#{label}]" }.join} #{topic}" end |
#to_h ⇒ Hash[Symbol, String | Array[String]]
41 42 43 |
# File 'lib/spreen_pr/application.rb', line 41 def to_h { title:, labels: } end |
#topic ⇒ String
36 37 38 |
# File 'lib/spreen_pr/application.rb', line 36 def topic segments.last.split(/[-_]/).map(&:capitalize).join("\s") end |
#validate! ⇒ void
This method returns an undefined value.
56 57 58 59 60 61 |
# File 'lib/spreen_pr/application.rb', line 56 def validate! return if segments.size >= 3 && segments.none?(&:empty?) raise ArgumentError, "Branch name `#{branch_name}` does not match the expected `#{EXPECTED_SHAPE}` shape" end |