assayo 0.1.5 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/assayo/index.html +4 -4
  3. data/ruby/assayo +115 -52
  4. metadata +2 -2
data/ruby/assayo CHANGED
@@ -1,61 +1,124 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- def get_save_log_command()
4
- $raw = "--raw --numstat"
5
- if ARGV.include?('--no-file')
6
- $raw = ""
7
- end
8
- return "git --no-pager log #{$raw} --oneline --all --reverse --date=iso-strict --pretty=format:\"%ad>%aN>%aE>%s\""
9
- end
4
+ require 'fileutils'
5
+ require 'etc'
10
6
 
11
- def show_message(message)
12
- if ARGV.include?('--debug')
13
- puts "Assayo: #{message}"
14
- end
15
- end
7
+ module Assayo
8
+ module LoggerMixin
9
+ private
16
10
 
17
- def write_in_file(fileName, content)
18
- File.open(fileName, 'w') do |file|
19
- file.write(content)
20
- end
21
- end
11
+ def debug_enabled?
12
+ ARGV.include?('--debug')
13
+ end
22
14
 
23
- def create_report()
24
- # folder, when library was saved
25
- $SOURCE_DIR = '../assayo'
26
- $SOURCE_PATH = __dir__
27
-
28
- # folder, when user run library
29
- $DIST_DIR = 'assayo'
30
- $DIST_PATH = Dir.pwd
31
-
32
- # 1. Copy folder ./assayo from package to ./assayo in project
33
- $source = File.join($SOURCE_PATH, $SOURCE_DIR)
34
- $target = File.join($DIST_PATH, $DIST_DIR)
35
- $copy_cmd = "cp -r #{$source} #{$target}"
36
- begin
37
- system($copy_cmd) or raise $copy_cmd
38
- rescue => e
39
- puts "Assayo: cant copy files: #{e.message}"
15
+ def debug(message)
16
+ return unless debug_enabled?
17
+ warn "[Assayo][DEBUG] #{message}"
18
+ end
40
19
  end
41
- show_message("directory with HTML report was be created")
42
-
43
- # Run "git log" and save output in file ./assayo/log.txt
44
- show_message("reading git log was be started")
45
- $fileName = File.join(Dir.pwd, $DIST_DIR, "log.txt")
46
- $save_log_cmd = get_save_log_command()
47
- begin
48
- system($save_log_cmd, { out: $fileName }) or raise $save_log_cmd
49
- rescue => e
50
- puts "Assayo: cant create log file: #{e.message}"
51
- end
52
- show_message("the file with git log was be saved")
53
20
 
54
- # 3. Replace symbols in ./assayo/log.txt
55
- $content = IO.read($fileName)
56
- $content = $content.gsub(/`/, "")
57
- $content = $content.gsub(/\$/, "")
58
- write_in_file($fileName, "R(f\`#{$content}\`);")
21
+ class Reporter
22
+ LIB_SOURCE_RELATIVE = '../assayo'.freeze
23
+ DIST_DIR_NAME = 'assayo'.freeze
24
+ TEMP_LOG_FILENAME = 'log.txt'.freeze
25
+
26
+ include LoggerMixin
27
+
28
+ GIT_FORMAT = '%ad>%aN>%aE>%s'.freeze
29
+ DANGEROUS_CHARS = /[\\`$%\x00-\x1f\x7f]/.freeze
30
+
31
+ def initialize
32
+ @script_dir = File.expand_path(__dir__)
33
+ end
34
+
35
+ def run
36
+ copy_library_files
37
+ generate_git_log
38
+ assemble_final_payload
39
+ debug("Report generation finished successfully.")
40
+ rescue StandardError => e
41
+ abort "Assayo: Fatal error — #{e.class}: #{e.message}"
42
+ end
43
+
44
+ private
45
+
46
+ def source_path
47
+ @source_path ||= File.expand_path(LIB_SOURCE_RELATIVE, @script_dir)
48
+ end
49
+
50
+ def dist_path
51
+ @dist_path ||= File.join(Dir.pwd, DIST_DIR_NAME)
52
+ end
53
+
54
+ def log_file_path
55
+ @log_file_path ||= File.join(dist_path, TEMP_LOG_FILENAME)
56
+ end
57
+
58
+ # Копирование ассетов отчета
59
+ def copy_library_files
60
+ raise "Source directory not found at '#{source_path}'" unless Dir.exist?(source_path)
61
+
62
+ FileUtils.mkdir_p(dist_path) unless Dir.exist?(dist_path)
63
+ debug("Copying assets from '#{source_path}' to '#{dist_path}'")
64
+ FileUtils.cp_r("#{source_path}/.", dist_path, remove_destination: true)
65
+ rescue SystemCallError => e
66
+ raise IOError, "Failed to copy library files: #{e.message}"
67
+ end
68
+
69
+ def generate_git_log
70
+ cmd = build_git_command
71
+ debug("Spawning process: #{cmd.shelljoin}")
72
+
73
+ begin
74
+ File.open(log_file_path, 'w') do |file|
75
+ Open3.popen2e(*cmd) do |stdin, stdout_err, wait_thr|
76
+ stdin.close
77
+ stdout_err.each_line { |line| file.write(line) }
78
+
79
+ exit_status = wait_thr.value
80
+ unless exit_status.success?
81
+ raise RuntimeError, "Git exited with code #{exit_status.exitstatus}"
82
+ end
83
+ end
84
+ end
85
+ debug("Raw git log streamed to '#{log_file_path}'")
86
+ rescue Errno::ENOENT
87
+ raise "Executable 'git' not found in PATH."
88
+ end
89
+ end
90
+
91
+ def build_git_command
92
+ base_args = %w[git --no-pager log --oneline --all --reverse --date=iso-strict]
93
+ base_args << '--raw' << '--numstat' unless ARGV.include?('--no-file')
94
+ base_args.concat(%W[--pretty=format:#{GIT_FORMAT}])
95
+ base_args
96
+ end
97
+
98
+ def assemble_final_payload
99
+ debug('Assembling final payload...')
100
+
101
+ output_lines = +'R(f`'
102
+ File.foreach(log_file_path, encoding: 'UTF-8') do |line|
103
+ sanitized = line.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
104
+ .gsub(DANGEROUS_CHARS, '')
105
+ .chomp
106
+ next if sanitized.empty?
107
+
108
+ output_lines << sanitized << "\n"
109
+ end
110
+ output_lines.chomp!
111
+ output_lines << '`)'
112
+
113
+ File.binwrite(log_file_path, output_lines)
114
+ debug('Final payload assembled and written.')
115
+ rescue SystemCallError => e
116
+ raise IOError, "Failed during assembly or write of final payload: #{e.message}"
117
+ end
118
+ end
59
119
  end
60
120
 
61
- create_report()
121
+ if __FILE__ == $PROGRAM_NAME
122
+ reporter = Assayo::Reporter.new
123
+ reporter.run
124
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assayo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Bakhirev
8
8
  autorequire:
9
9
  bindir: ruby
10
10
  cert_chain: []
11
- date: 2026-08-14 00:00:00.000000000 Z
11
+ date: 2026-08-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Visualization and analysis you git log. Creates HTML report about commits
14
14
  statistics, employees and company. Also it parse git log and give a achievements