Module: GitExtractor

Defined in:
lib/git_extractor.rb

Overview

Classe d’extraction des informations de Git Author: Vincent Dubois Date: 19 fevrier 2009

Class Method Summary collapse

Class Method Details

.extract_changelog(scm_current_version, file_name) ⇒ Object

Methode qui permet de fabriquer le flux HTML a partir des informations presentes dans le referentiel



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/git_extractor.rb', line 10

def self.extract_changelog scm_current_version, file_name
  git_revisions = Utils.run_command("git log").split(/$/).select{ |l| l =~ /^commit / }.collect { |l| l[8..(l.length-1)] }
  revision = git_revisions[0]
  begin
    git_url = File.read(".git/config").split(/$/).select {|l| l =~ /url = /}[0].split(/url = /)[1]
    puts " Computing changelog for #{git_url}..."
  rescue
    puts " Computing changelog, from commit #{scm_current_version} to revision #{revision}..."
  end
  i = 0
  html = "<table class='bodyTable'><thead><th>Commit</th><th>Date</th><th>Author</th><th>File(s)</th><th>Comment</th></thead><tbody>"
  commits = Utils.run_command("git log --name-status").split(/^commit/)
  commits.delete_at(0)
  commits.each_with_index do |commit, index|
    commit_details = commit.split(/$/)
    puts " Changelog for commit #{commit_details[0].strip}..."
    html = html + "<tr class='#{ index % 2 == 0 ? 'a' : 'b'}'><td><strong>#{commit_details[0].strip}</strong></td>"
    html = html + "<td>#{commit_details[2].strip.split(/Date:   /)[1]}</td><td>#{commit_details[1].strip.split(/Author: /)[1]}</td><td>"
    (6..(commit_details.length - 3)).to_a.each do |file_detail|
      file_status = "added"
      if commit_details[file_detail].strip.at(0) == 'A'
        file_status = "added"
      elsif commit_details[file_detail].strip.at(0) == 'M'
        file_status = "modified"
      elsif commit_details[file_detail].strip.at(0) == 'D'
        file_status = "deleted"
      end
      html = html + "<img src='images/#{file_status}.png' align='absmiddle'/>&#160;#{commit_details[file_detail].strip.split(Regexp.new("\t"))[1]}<br/>"
    end
    html = html + "</td><td>#{commit_details[4].strip}</td></tr>"
  end
  html = html + "</tbody></table>"
  changelog_file = File.open(file_name,"w")
  changelog_file.write(html)
  changelog_file.close
  return revision
end