Class: HustleAndFlow::IssueTrackers::Github::Commands::Start

Inherits:
Object
  • Object
show all
Defined in:
lib/hustle_and_flow/issue_trackers/github/commands/start.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Start

Returns a new instance of Start.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 20

def initialize(**args)
  self.mode     = args[:options][:create]
  self.labels   = args[:options][:type]
  self.statuses = args[:options][:status]
  self.title    = args[:options][:title]
  self.number   = args[:options][:number]
  self.me       = args[:me]
  self.io       = args[:io]
  self.tracker  = Github::Tracker.new(repo: args[:repo])
  self.issues   = Github::Issues.new(tracker:  tracker,
                                     io:       io,
                                     statuses: statuses)
end

Instance Attribute Details

#ioObject

Returns the value of attribute io.



10
11
12
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 10

def io
  @io
end

#issuesObject

Returns the value of attribute issues.



10
11
12
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 10

def issues
  @issues
end

#meObject

Returns the value of attribute me.



10
11
12
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 10

def me
  @me
end

#modeObject

Returns the value of attribute mode.



10
11
12
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 10

def mode
  @mode
end

#numberObject

Returns the value of attribute number.



10
11
12
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 10

def number
  @number
end

#statusesObject

Returns the value of attribute statuses.



10
11
12
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 10

def statuses
  @statuses
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 10

def title
  @title
end

#trackerObject

Returns the value of attribute tracker.



10
11
12
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 10

def tracker
  @tracker
end

Class Method Details

.call(**args) ⇒ Object



56
57
58
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 56

def self.call(**args)
  new(**args).call
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hustle_and_flow/issue_trackers/github/commands/start.rb', line 34

def call
  if !issue_specified? && mode == 'search'
    applicable_issues = issues.filter_by(issue_data)

    io.print_formatted_table \
      data:  Formatters::IssueTableFormatter.new(applicable_issues).to_ary,
      title: 'Available Issues'

    self.number = io.choose_issue until issue_specified?
  end

  if issue_specified?
    issue = issues.find_or_create(issue_data)

    if io.correct_issue?(issue)
      issue.start(me: me)
    end
  else
    fail ArgumentError.new("You must specify both type and a title when starting a new issue")
  end
end