Class: HustleAndFlow::IssueTrackers::Github::Issue
- Inherits:
-
Object
- Object
- HustleAndFlow::IssueTrackers::Github::Issue
- Defined in:
- lib/hustle_and_flow/issue_trackers/github/issue.rb
Constant Summary collapse
- DEFAULT_CATEGORY_LABELS =
%w{feature bug refactor test style chore docs spike}
- ISSUE_ACTIONS =
%w{closes references fixes}
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#io ⇒ Object
Returns the value of attribute io.
-
#tracker ⇒ Object
Returns the value of attribute tracker.
Class Method Summary collapse
Instance Method Summary collapse
- #assign(to:) ⇒ Object
- #assign_issue?(to:) ⇒ Boolean
- #assigned_to?(other) ⇒ Boolean
- #body ⇒ Object
- #category ⇒ Object
- #closed? ⇒ Boolean
- #contact ⇒ Object
- #created_at ⇒ Object
- #has_body? ⇒ Boolean
- #has_label?(other = []) ⇒ Boolean
-
#initialize(tracker:, io: nil, data:) ⇒ Issue
constructor
A new instance of Issue.
- #match?(labels: nil, **args) ⇒ Boolean
- #new? ⇒ Boolean
- #number ⇒ Object
- #start(me: nil) ⇒ Object
- #status ⇒ Object
- #title ⇒ Object
- #to_branch_name(action: 'closes', version: 1) ⇒ Object
- #unassigned? ⇒ Boolean
- #url ⇒ Object
Constructor Details
#initialize(tracker:, io: nil, data:) ⇒ Issue
Returns a new instance of Issue.
16 17 18 19 20 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 16 def initialize(tracker:, io: nil, data:) self.tracker = tracker self.io = io || HustleAndFlow::Io::Shell.new self.data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
12 13 14 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 12 def data @data end |
#io ⇒ Object
Returns the value of attribute io.
12 13 14 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 12 def io @io end |
#tracker ⇒ Object
Returns the value of attribute tracker.
12 13 14 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 12 def tracker @tracker end |
Class Method Details
.create(tracker: nil, io: nil, title:, body: '', **args) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 22 def self.create(tracker: nil, io: nil, title:, body: '', **args) new(io: io, tracker: tracker, data: tracker.client.create_issue(tracker.repo_name, title, body, args)) end |
Instance Method Details
#assign(to:) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 36 def assign(to:) reassigned_issue_data = client.update_issue(tracker.repo_name, number, title, body, assignee: to) Issue.new(tracker: tracker, data: reassigned_issue_data) end |
#assign_issue?(to:) ⇒ Boolean
69 70 71 72 73 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 69 def assign_issue?(to:) return self unless needs_reassignment?(assignee_to_assign_to: to) assign to: to end |
#assigned_to?(other) ⇒ Boolean
83 84 85 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 83 def assigned_to?(other) assignee == other end |
#body ⇒ Object
110 111 112 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 110 def body data[:body] end |
#category ⇒ Object
47 48 49 50 51 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 47 def category @category ||= labels.find do |label| DEFAULT_CATEGORY_LABELS.include? label end end |
#closed? ⇒ Boolean
75 76 77 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 75 def closed? status == 'closed' end |
#contact ⇒ Object
98 99 100 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 98 def contact assignee_data[:login] || user_data[:login] end |
#created_at ⇒ Object
114 115 116 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 114 def created_at data[:created_at] end |
#has_body? ⇒ Boolean
65 66 67 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 65 def has_body? !(body.nil? || body.empty?) end |
#has_label?(other = []) ⇒ Boolean
59 60 61 62 63 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 59 def has_label?(other = []) other = !other.is_a?(Array) ? [other] : other (labels & other).any? end |
#match?(labels: nil, **args) ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 87 def match?(labels: nil, **args) result = true conditions = args conditions.each do |key, value| result &&= public_send(key) == value end result &&= labels ? has_label?(labels) : true end |
#new? ⇒ Boolean
53 54 55 56 57 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 53 def new? five_minutes_ago = Time.now.utc - (5 * 60) five_minutes_ago <= created_at end |
#number ⇒ Object
106 107 108 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 106 def number data[:number] end |
#start(me: nil) ⇒ Object
31 32 33 34 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 31 def start(me: nil) reopen. assign_issue? to: me end |
#status ⇒ Object
122 123 124 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 122 def status data[:state] end |
#title ⇒ Object
102 103 104 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 102 def title data[:title] end |
#to_branch_name(action: 'closes', version: 1) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 126 def to_branch_name(action: 'closes', version: 1) branch_name = [] branch_name << category branch_name << base_branch_name(action: action, version: version) branch_name.compact! branch_name.join('/') end |
#unassigned? ⇒ Boolean
79 80 81 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 79 def unassigned? assigned_to? 'unassigned' end |
#url ⇒ Object
118 119 120 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 118 def url data[:html_url] end |