Class: HustleAndFlow::IssueTrackers::Github::Issue

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject

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

#ioObject

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

#trackerObject

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

Returns:

  • (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

Returns:

  • (Boolean)


83
84
85
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 83

def assigned_to?(other)
  assignee == other
end

#bodyObject



110
111
112
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 110

def body
  data[:body]
end

#categoryObject



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

Returns:

  • (Boolean)


75
76
77
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 75

def closed?
  status == 'closed'
end

#contactObject



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_atObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

#numberObject



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

#statusObject



122
123
124
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 122

def status
  data[:state]
end

#titleObject



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

Returns:

  • (Boolean)


79
80
81
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 79

def unassigned?
  assigned_to? 'unassigned'
end

#urlObject



118
119
120
# File 'lib/hustle_and_flow/issue_trackers/github/issue.rb', line 118

def url
  data[:html_url]
end