Class: FlashFlow::Merge::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/flash_flow/merge/status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issue_tracker_config, branches_config, branch_info_file, git_config, opts = {}) ⇒ Status

Returns a new instance of Status.



8
9
10
11
# File 'lib/flash_flow/merge/status.rb', line 8

def initialize(issue_tracker_config, branches_config, branch_info_file, git_config, opts={})
  @issue_tracker = IssueTracker::Base.new(issue_tracker_config)
  @collection = Data::Base.new(branches_config, branch_info_file, ShadowGit.new(git_config)).collection
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



6
7
8
# File 'lib/flash_flow/merge/status.rb', line 6

def collection
  @collection
end

#issue_trackerObject (readonly)

Returns the value of attribute issue_tracker.



6
7
8
# File 'lib/flash_flow/merge/status.rb', line 6

def issue_tracker
  @issue_tracker
end

#releasesObject (readonly)

Returns the value of attribute releases.



6
7
8
# File 'lib/flash_flow/merge/status.rb', line 6

def releases
  @releases
end

#storiesObject (readonly)

Returns the value of attribute stories.



6
7
8
# File 'lib/flash_flow/merge/status.rb', line 6

def stories
  @stories
end

Instance Method Details

#branchesObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/flash_flow/merge/status.rb', line 45

def branches
  g = ReleaseGraph.build(collection.current_branches, issue_tracker)

  branch_hash = {}
  collection.current_branches.each_with_index do |branch, i|
    connected_branches = g.connected_branches(branch.ref)
    connected_stories = g.connected_stories(branch.ref)
    connected_releases = g.connected_releases(branch.ref)
    add_stories(connected_stories)
    add_releases(connected_releases)
    sub_g = ReleaseGraph.build(connected_branches, issue_tracker)
    graph_file = sub_g.output("/tmp/graph-#{i}.png")

    branch_hash[branch] =
        Hash.new.tap do |hash|
          hash[:name] = branch.ref
          hash[:branch_url] = collection.branch_link(branch)
          hash[:code_reviewed?] = collection.code_reviewed?(branch)
          hash[:can_ship?] = collection.can_ship?(branch)
          hash[:connected_branches] = connected_branches
          hash[:image] = graph_file
          hash[:my_stories] = branch.stories.to_a
          hash[:stories] = connected_stories
          hash[:releases] = connected_releases
        end
  end

  mark_as_shippable(branch_hash)
  branch_hash
end

#statusObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flash_flow/merge/status.rb', line 13

def status
  filename = File.dirname(__FILE__) + '/merge_status.csv'
  checkmark = "\u2713".encode('utf-8')

  CSV.open(filename, 'w') do |f|
    f << ['Ready', 'Branch', 'Stories', 'Review', 'Can ship?']
    branches.each do |_, branch_hash|
      f << [
        branch_hash[:shippable?] ? checkmark : 'x',
        branch_hash[:name],
        unshippable_stories(branch_hash[:stories]).empty? ? checkmark : 'x',
        branch_hash[:code_reviewed?] ? checkmark : 'x',
        branch_hash[:can_ship?] ? checkmark : 'x'
      ]
    end
  end

  CSV.foreach(filename) { |row| puts '%-10s %-70s %-10s %-10s %-10s' % row }
end

#status_html(filename = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/flash_flow/merge/status.rb', line 33

def status_html(filename=nil)
  filename = File.dirname(__FILE__) + '/merge_status.html'
  @branches = branches

  template = ERB.new File.read(File.dirname(__FILE__) + '/merge_status.html.erb')
  html = template.result(binding)
  File.open(filename, 'w') do |f|
    f.puts html
  end
  `open #{filename}`
end