Class: Action
- Inherits:
-
Object
- Object
- Action
- Defined in:
- lib/action.rb
Constant Summary collapse
- USES_REGEX =
%r{^(?<user>[^/]+)[/](?<repo>[^/]+)[/]?(?<dir>.+)?[@](?<ref>.+)$}.freeze
- TAGS_REGEX =
%r{refs/tags/(.*)$}.freeze
- DOMAIN =
'https://github.com'
- TAG_REJECT_REASONS =
%w[ alpha beta rc ^{} ].freeze
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#ref ⇒ Object
Returns the value of attribute ref.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(uses) ⇒ Action
constructor
A new instance of Action.
- #latest_tag ⇒ Object
- #print ⇒ Object
- #print_without_ref ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(uses) ⇒ Action
Returns a new instance of Action.
30 31 32 33 34 35 36 |
# File 'lib/action.rb', line 30 def initialize(uses) captures = uses.match(USES_REGEX).named_captures @user = captures['user'] @repo = captures['repo'] @dir = captures['dir'] @ref = captures['ref'] end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
6 7 8 |
# File 'lib/action.rb', line 6 def dir @dir end |
#ref ⇒ Object
Returns the value of attribute ref.
6 7 8 |
# File 'lib/action.rb', line 6 def ref @ref end |
#repo ⇒ Object
Returns the value of attribute repo.
6 7 8 |
# File 'lib/action.rb', line 6 def repo @repo end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/action.rb', line 6 def user @user end |
Class Method Details
.array_from_yaml(yaml) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/action.rb', line 18 def self.array_from_yaml(yaml) hash = YAML.safe_load(yaml) useses = hash['jobs'].values.map do |job| job['steps'].map do |step| step['uses'] end end useses.flatten.compact.uniq.map do |uses| new(uses) end end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 |
# File 'lib/action.rb', line 50 def ==(other) to_s == other.to_s end |
#latest_tag ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/action.rb', line 54 def latest_tag url = "#{DOMAIN}/#{@user}/#{@repo}" = `git ls-remote -t #{url}`.scan(TAGS_REGEX).flatten .reject! do |tag| TAG_REJECT_REASONS.any? do |reason| tag.include?(reason) end end .last || @ref end |
#print ⇒ Object
42 43 44 |
# File 'lib/action.rb', line 42 def print "#{@user}/#{@repo}#{@dir ? '/' : ''}#{@dir}#{@ref ? '@' : ''}#{@ref}" end |
#print_without_ref ⇒ Object
46 47 48 |
# File 'lib/action.rb', line 46 def print_without_ref "#{@user}/#{@repo}#{@dir ? '/' : ''}#{@dir}" end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/action.rb', line 38 def to_s print end |