Class: Drone::Builds::Parser
- Inherits:
-
Object
- Object
- Drone::Builds::Parser
- Defined in:
- lib/drone/builds/parser.rb
Constant Summary collapse
- STATUS_COLORS =
{ success: :light_green, running: :light_blue, failure: :light_red, killed: :light_white, pending: :light_yellow }.freeze
- MESSAGE_MAX_WIDTH =
45
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(client) ⇒ Parser
constructor
A new instance of Parser.
- #parse_author(author) ⇒ Object
- #parse_build(build) ⇒ Object
- #parse_builds(builds) ⇒ Object
- #parse_message(message) ⇒ Object
- #parse_number(number) ⇒ Object
- #parse_ref(ref) ⇒ Object
- #parse_status(status) ⇒ Object
- #table(data, fields) ⇒ Object
Constructor Details
#initialize(client) ⇒ Parser
Returns a new instance of Parser.
17 18 19 |
# File 'lib/drone/builds/parser.rb', line 17 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/drone/builds/parser.rb', line 5 def client @client end |
Instance Method Details
#parse_author(author) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/drone/builds/parser.rb', line 43 def () current_github_user = HOME_ENV[:GITHUB_USER] if == current_github_user .colorize(:light_white) else end end |
#parse_build(build) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/drone/builds/parser.rb', line 25 def parse_build(build) { number: parse_number(build['number']), status: parse_status(build['status']), author: (build['author']), ref: parse_ref(build['ref']), message: (build['message']) } end |
#parse_builds(builds) ⇒ Object
21 22 23 |
# File 'lib/drone/builds/parser.rb', line 21 def parse_builds(builds) builds.map { |build| parse_build(build) } end |
#parse_message(message) ⇒ Object
56 57 58 59 60 |
# File 'lib/drone/builds/parser.rb', line 56 def () = .to_s.lines.first.to_s = .gsub("of github.com:#{client.owner}/#{client.name}", '') [0..MESSAGE_MAX_WIDTH] end |
#parse_number(number) ⇒ Object
35 36 37 |
# File 'lib/drone/builds/parser.rb', line 35 def parse_number(number) number.to_s end |
#parse_ref(ref) ⇒ Object
52 53 54 |
# File 'lib/drone/builds/parser.rb', line 52 def parse_ref(ref) ref.gsub('refs/heads/', '').gsub('/head', '').gsub('refs/pull/', '#') end |
#parse_status(status) ⇒ Object
39 40 41 |
# File 'lib/drone/builds/parser.rb', line 39 def parse_status(status) status.colorize(STATUS_COLORS[status.to_sym]) end |
#table(data, fields) ⇒ Object
62 63 64 |
# File 'lib/drone/builds/parser.rb', line 62 def table(data, fields) Terminal::Table.new(rows: [fields, :separator] + data.map(&:values)) end |