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
- .create(tracker: nil, io: nil, title:, body: '', **args) ⇒ Object
- .from_branch_name(branch_name) ⇒ Object
Instance Method Summary collapse
- #assign(to:) ⇒ Object
- #assign_issue?(to:) ⇒ Boolean
- #assigned_to?(other) ⇒ Boolean
- #body ⇒ Object
- #category ⇒ Object
- #closed? ⇒ Boolean
- #contact ⇒ Object
- #convert_to_pull_request(branch: branch) ⇒ 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.
17 18 19 20 21 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 17 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.
13 14 15 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 13 def data @data end |
#io ⇒ Object
Returns the value of attribute io.
13 14 15 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 13 def io @io end |
#tracker ⇒ Object
Returns the value of attribute tracker.
13 14 15 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 13 def tracker @tracker end |
Class Method Details
.create(tracker: nil, io: nil, title:, body: '', **args) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 23 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 |
.from_branch_name(branch_name) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 151 def self.from_branch_name(branch_name) branch_name = branch_name.dup branch_data = {} version_pattern = /\-v(\d+)\z/ number_pattern = /\-(\d+)\z/ action_pattern = /\-(closes|references|fixes)\z/ type_pattern = %r{\A(\w+)/} title_pattern = /([\w\-]+)\z/ branch_data[:version] = branch_name[version_pattern, 1] and branch_name.sub!(version_pattern, '') branch_data[:number] = branch_name[number_pattern, 1] and branch_name.sub!(number_pattern, '') branch_data[:action] = branch_name[action_pattern, 1] and branch_name.sub!(action_pattern, '') branch_data[:type] = branch_name[type_pattern, 1] and branch_name.sub!(type_pattern, '') branch_data[:title] = branch_name[title_pattern, 1] and branch_name.sub!(title_pattern, '') branch_data end |
Instance Method Details
#assign(to:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 37 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
70 71 72 73 74 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 70 def assign_issue?(to:) return self unless needs_reassignment?(assignee_to_assign_to: to) assign to: to end |
#assigned_to?(other) ⇒ Boolean
84 85 86 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 84 def assigned_to?(other) assignee == other end |
#body ⇒ Object
117 118 119 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 117 def body data[:body] end |
#category ⇒ Object
48 49 50 51 52 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 48 def category @category ||= labels.find do |label| DEFAULT_CATEGORY_LABELS.include? label end end |
#closed? ⇒ Boolean
76 77 78 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 76 def closed? status == 'closed' end |
#contact ⇒ Object
105 106 107 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 105 def contact assignee_data[:login] || user_data[:login] end |
#convert_to_pull_request(branch: branch) ⇒ Object
145 146 147 148 149 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 145 def convert_to_pull_request(branch: branch) pr_data = client.create_pull_request_for_issue(tracker.repo_name, 'master', branch, number) PullRequest.new(tracker: tracker, data: pr_data) end |
#created_at ⇒ Object
121 122 123 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 121 def created_at data[:created_at] end |
#has_body? ⇒ Boolean
66 67 68 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 66 def has_body? !(body.nil? || body.empty?) end |
#has_label?(other = []) ⇒ Boolean
60 61 62 63 64 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 60 def has_label?(other = []) other = !other.is_a?(Array) ? [other] : other (labels & other).any? end |
#match?(labels: nil, **args) ⇒ Boolean
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 88 def match?(labels: nil, **args) result = true conditions = args args.delete(:version) if title = args.delete(:title) sanitize(title) == sanitize(self.title) end conditions.each do |key, value| result &&= public_send(key) == value end result &&= labels ? has_label?(labels) : true end |
#new? ⇒ Boolean
54 55 56 57 58 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 54 def new? five_minutes_ago = Time.now.utc - (5 * 60) five_minutes_ago <= created_at end |
#number ⇒ Object
113 114 115 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 113 def number data[:number] end |
#start(me: nil) ⇒ Object
32 33 34 35 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 32 def start(me: nil) reopen. assign_issue? to: me end |
#status ⇒ Object
129 130 131 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 129 def status data[:state] end |
#title ⇒ Object
109 110 111 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 109 def title data[:title] end |
#to_branch_name(action: 'closes', version: 1) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 133 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
80 81 82 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 80 def unassigned? assigned_to? 'unassigned' end |
#url ⇒ Object
125 126 127 |
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 125 def url data[:html_url] end |