Class: GitAuto::Services::HistoryService

Inherits:
Object
  • Object
show all
Defined in:
lib/git_auto/services/history_service.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

HISTORY_FILE =
File.join(Config::Settings::CONFIG_DIR, "commit_history.json")
MAX_HISTORY_ENTRIES =
10

Instance Method Summary collapse

Constructor Details

#initializeHistoryService

Returns a new instance of HistoryService.



14
15
16
17
# File 'lib/git_auto/services/history_service.rb', line 14

def initialize
  @settings = Config::Settings.new
  ensure_history_file
end

Instance Method Details

#analyze_patterns(limit = 50) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/git_auto/services/history_service.rb', line 39

def analyze_patterns(limit = 50)
  history = load_history.take(limit)
  return {} if history.empty?

  {
    styles: analyze_styles(history),
    scopes: analyze_scopes(history),
    types: analyze_types(history),
    common_phrases: analyze_phrases(history)
  }
end

#get_recent_commits(limit = nil) ⇒ Object



34
35
36
37
# File 'lib/git_auto/services/history_service.rb', line 34

def get_recent_commits(limit = nil)
  history = load_history
  limit ? history.take(limit) : history
end

#save_commit(message, metadata = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/git_auto/services/history_service.rb', line 19

def save_commit(message,  = {})
  return unless @settings.get(:save_history)

  history = load_history
  history.unshift({
                    message: message,
                    timestamp: Time.now.iso8601,
                    metadata: 
                  })

  history = history.take(MAX_HISTORY_ENTRIES)

  save_history(history)
end