Top Level Namespace

Defined Under Namespace

Modules: GitLog

Instance Method Summary collapse

Instance Method Details

#authorObject



204
205
206
207
# File 'lib/gitlog/log.rb', line 204

def author()
  author = `git config user.email`
  return author
end

#git_format_selectorsObject



3
4
5
6
7
8
# File 'lib/gitlog/log.rb', line 3

def git_format_selectors()
  git_format_selectors = {
    'message' => '%s',
  }
  return git_format_selectors
end

#git_formatted_log(logs, log_style, dev = true) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/gitlog/log.rb', line 83

def git_formatted_log(logs, log_style, dev = true)

  # print_log('Raw Logs', logs)

  return "No Changelogs \n" unless logs && !logs.empty?

  categorized_line_info = {}
  logs.each_line { |line|
    line_info = {}
    line = line.strip.split("\t")
    $git_format_info.each_with_index { |value, index|
      line_info[value] = line[index]
    }

    message_format_regex = /([^\(:]+)(?:\(([^\)]*)\))?[[:space:]]*:?[[:space:]]*(.*)/
    match_data = line_info['message'].match(message_format_regex)
    if match_data
      if match_data[3].empty?
        $type_keywords.each { |key, value|
          if line_info['message'].downcase.include? key
            line_info['type'] = key
            break
          end
        }
      else
        line_info['type'] = match_data[1]
        line_info['scope'] = match_data[2]
        line_info['message'] = match_data[3]
      end
    end

    line_info['type'] = (line_info['type'] || '').downcase

    unless $type_keywords[line_info['type']]
      line_info['type'] = $other_type
    end

    line_info['message'] = (line_info['message'][0, 1].upcase + line_info['message'][1..-1]).chomp(".")

    style = 'type'
    case log_style
     when :type_wise
       style = 'type'
     when :scope_wise
       style = 'scope'
    end

    categorized_line_info[line_info[style]] ||= []
    categorized_line_info[line_info[style]] << line_info
  }

    case log_style
     when :type_wise
      return git_formatted_log_type(categorized_line_info)
     when :scope_wise
      return git_formatted_log_scope(categorized_line_info)
    end
end

#git_formatted_log_scope(categorized_line_info, dev = true) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/gitlog/log.rb', line 182

def git_formatted_log_scope(categorized_line_info, dev = true)
    categorized_line_info = categorized_line_info.sort_by { |key, value| $type_keywords_index_helper.index(key)}

    # print_log('categorized_line_info', categorized_line_info)

    changelog_lines = []
    categorized_line_info.each { |key, value|   
      changelog_lines << key
      value.each { |line_info|
        changelog_lines << "- #{$type_keywords[line_info['type']][:name]}: #{line_info['message']}"
      }
      changelog_lines << ''
    }
    return changelog_lines.join("\n")
end

#git_formatted_log_type(categorized_line_info, dev = true) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/gitlog/log.rb', line 163

def git_formatted_log_type(categorized_line_info, dev = true)
  categorized_line_info = categorized_line_info.sort_by { |key, value| $type_keywords_index_helper.index(key) || $type_keywords_index_helper.index($other_type) }

  # print_log('categorized_line_info', categorized_line_info)

  changelog_lines = []
  categorized_line_info.each { |key, value|
    next if $type_keywords[key][:dev] && !dev
    changelog_lines << "#{$type_keywords[key][:name]}"
    value.each { |line_info|
      scope_string = (dev && line_info['scope']) ? " #{line_info['scope']}" : ''
      dev_string = dev ?  (scope_string.empty? ? '' : "-#{scope_string}: ") : ''
      changelog_lines << "#{dev_string}#{line_info['message']}"
    }
    changelog_lines << ''
  }
  return changelog_lines.join("\n")
end

#git_formatted_log_type_markdown(categorized_line_info, dev = true) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/gitlog/log.rb', line 142

def git_formatted_log_type_markdown(categorized_line_info, dev = true)
  categorized_line_info = categorized_line_info.sort_by { |key, value| $type_keywords_index_helper.index(key) || $type_keywords_index_helper.index($other_type) }

  # print_log('categorized_line_info', categorized_line_info)

  changelog_lines = []
  categorized_line_info.each { |key, value|
    next if $type_keywords[key][:dev] && !dev
    changelog_lines << "#### #{$type_keywords[key][:name]}"
    changelog_lines << ''
    value.each { |line_info|
      scope_string = (dev && line_info['scope']) ? " #{line_info['scope']}" : ''
      dev_string = dev ?  (scope_string.empty? ? '' : "**-#{scope_string}:** ") : ''
      changelog_lines << "#{dev_string}#{line_info['message']}"
      changelog_lines << ''
    }
    changelog_lines << ''
  }
  return changelog_lines.join("\n")
end

#git_log_between_commits(from, to, author = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gitlog/log.rb', line 69

def git_log_between_commits(from, to, author = nil)
  command = Array['git log --branches']
  command << "--pretty=\"%s\""
  command << "--author=\"#{author.chomp}\"" if author
  # command << '--ancestry-path'
  command << "#{from.chomp} ^#{to.chomp}^"
  command << "--no-merges"
  puts command.compact.join(' ')
  return `#{command.compact.join(' ')}`
  rescue
  nil
end

#git_log_on_date(specific_date = nil, author = nil, current_branch_only = false) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gitlog/log.rb', line 56

def git_log_on_date(specific_date = nil, author = nil, current_branch_only = false)
  command = Array["git log"]
  command << "--pretty=\"%s\""
  command << "--all" if !current_branch_only
  command << "--author=\"#{author.chomp}\"" if author
  command << "--after=\"#{specific_date.chomp} 00:00\" --before=\"#{specific_date.chomp} 23:59\"" if specific_date
  command << "--no-merges"
  # puts command.compact.join(' ')
  return `#{command.compact.join(' ')}`
  rescue
  nil
end


198
199
200
201
202
# File 'lib/gitlog/log.rb', line 198

def print_log(key, value)
  print "\n\n #{key}: \n"
  print value
  print "\n\n"
end

#type_keywordsObject



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
47
# File 'lib/gitlog/log.rb', line 10

def type_keywords()
  type_keywords = {
    'feat' => {
      name: 'New Features',
    },
    'fix' => {
      name: 'Bug Fixes',
    },
    'perf' => {
      name: 'Performance Enhancements',
    },
    'refactor' => {
      name: 'Refactorings',
      dev: true,
    },
    'docs' => {
      name: 'Documentation Changes',
      dev: true,
    },
    'test' => {
      name: 'Test Changes',
      dev: true,
    },
    'style' => {
      name: 'Style Changes',
      dev: true,
    },
    'chore' => {
      name: 'Configuration Updates',
      dev: true,
    },
    $other_type => {
      name: 'Other Changes',
      dev: true,
    }
  }
  return type_keywords
end