Class: Git::Blames::Pending

Inherits:
Object
  • Object
show all
Includes:
Git::Blames
Defined in:
lib/blames/pending.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Git::Blames

#blame, #stdout

Methods included from Emails

#load_configuration, #send_gmail

Constructor Details

#initialize(options = nil) ⇒ Pending

Returns a new instance of Pending.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/blames/pending.rb', line 6

def initialize options = nil
  if options.nil? || options[:root].nil? && !options[:rspec] && !options[:log]
    @root = "#{File.dirname(__FILE__)}/logs"
  elsif options[:log]
    find_pending_specs_by_logfile_name( options[:log] )
  elsif options[:rspec]
    find_pending_specs_by_rspec_results( rspec_results )
  else
    @root = options[:root]
    find_pending_specs_by_logfile_name( "#{@root}/#{find_last_logfile_name}" )
  end
  find_contributors
end

Instance Attribute Details

#rspec_resultsObject

Returns the value of attribute rspec_results.



2
3
4
# File 'lib/blames/pending.rb', line 2

def rspec_results
  @rspec_results
end

#tasksObject

Returns the value of attribute tasks.



2
3
4
# File 'lib/blames/pending.rb', line 2

def tasks
  @tasks
end

Instance Method Details

#find_contributorsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/blames/pending.rb', line 25

def find_contributors
  # @tasks = Git::Blames::Pending.new.tasks
  @tasks.each_pair do |key, attributes|
    contributors = []
    `git blame "#{attributes[:spec_file]}"`.each do |blame|
      contributor = blame.split(")")[0].split("(")[1]
      contributor = contributor.split(/\s+\d/)[0]
      contributors.push( contributor )
    end
    @tasks[key][:contributors] = contributors.uniq
    @tasks[key][:contributors].reject!{ |contributor| contributor == 'Not Committed Yet'}
  end
  @tasks
end

#find_last_logfile_nameObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/blames/pending.rb', line 52

def find_last_logfile_name
  begin
    files = Dir.new @root
  rescue => e 
    begin
    Dir.mkdir @root
    files = Dir.new @root
    rescue
      puts e
    end
  end
  file_name = files.to_a.select { |log| log.match /\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}/ }.sort.last
  "#{file_name}/log"
end

#find_pending_specs_by_logfile_name(logfile_name) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/blames/pending.rb', line 95

def find_pending_specs_by_logfile_name logfile_name
  logfile = File.new( logfile_name )
  status = ''
  @tasks = {}
  task = {}

  logfile.readlines.each do |line|

    if found_pending_marker line
      status = 'start'
      
    elsif found_new_spec_marker line, status
      status = 'found new pending spec'  
      task = {}
      task[:name] = line.chomp
      task[:details] = []

    elsif found_spec_details_marker line, status
      status = 'updating spec data'
      if line.match /(spec.*)[:](\d+)/
        task[:spec_file] = $1
        task[:line_number] = $2
      else
        task[:details].push line.chomp
      end
      @tasks[task[:name]] = task
    end
  end
end

#find_pending_specs_by_rspec_results(spec_output) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/blames/pending.rb', line 67

def find_pending_specs_by_rspec_results spec_output
  status = ''
  @tasks = {}
  task = {}

  spec_output.each do |line|
    if found_pending_marker line
      status = 'start'
      
    elsif found_new_spec_marker line, status
      status = 'found new pending spec'  
      task = {}
      task[:name] = line.chomp
      task[:details] = []

    elsif found_spec_details_marker line, status
      status = 'updating spec data'
      if line.match /(spec.*)[:](\d+)/
        task[:spec_file] = $1
        task[:line_number] = $2
      else
        task[:details].push line.chomp
      end
      @tasks[task[:name]] = task
    end
  end
end

#found_new_spec_marker(line, status) ⇒ Object



44
45
46
# File 'lib/blames/pending.rb', line 44

def found_new_spec_marker line, status
  ( status == 'start' || status == 'updating spec data' ) && !line.match( /^[\s\t]*#/ )
end

#found_pending_marker(line) ⇒ Object



40
41
42
# File 'lib/blames/pending.rb', line 40

def found_pending_marker line
  line.match( /^[\s\t]*Pending:/ )
end

#found_spec_details_marker(line, status) ⇒ Object



48
49
50
# File 'lib/blames/pending.rb', line 48

def found_spec_details_marker line, status
  ( status == 'found new pending spec' || status == 'updating spec data' ) && line.match( /^[\s\t]*\#/ )
end

#tasks_by_collaboratorObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/blames/pending.rb', line 125

def tasks_by_collaborator
  load_configuration
  consolidated_emails = {}
  @email_mappings.each_key do |contributor|
    consolidated_emails[contributor] = []
    @tasks.each do |object|
      key = object[0]
      values = object[1]
      if values[:contributors].include?( contributor )
        message = "\n" +
          "  Spec:          #{values[:spec_file]}:#{values[:line_number]}\n" +
          "    Collaborators: #{values[:contributors].join(',')}\n" +
          "    Title:         #{values[:name]}\n" +
          "    Details:       #{values[:details].join('\n')}"
        consolidated_emails[contributor].push( message )
      end
    end
    consolidated_emails[contributor] = consolidated_emails[contributor].join(
      "\n\n"
    )
  end
  consolidated_emails
end