Class: Gitingest::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/gitingest/generator.rb

Constant Summary collapse

DEFAULT_EXCLUDES =

Default exclusion patterns for common files and directories

[
  # Version control
  '\.git/', '\.github/', '\.gitignore', '\.gitattributes', '\.gitmodules', '\.svn', '\.hg',

  # System files
  '\.DS_Store', 'Thumbs\.db', 'desktop\.ini',

  # Log files
  '.*\.log$', '.*\.bak$', '.*\.swp$', '.*\.tmp$', '.*\.temp$',

  # Images and media
  '.*\.png$', '.*\.jpg$', '.*\.jpeg$', '.*\.gif$', '.*\.svg$', '.*\.ico$',
  '.*\.pdf$', '.*\.mov$', '.*\.mp4$', '.*\.mp3$', '.*\.wav$',

  # Archives
  '.*\.zip$', '.*\.tar\.gz$',

  # Dependency directories
  "node_modules/", "vendor/", "bower_components/", "\.npm/", "\.yarn/", "\.pnpm-store/",
  "\.bundle/", "vendor/bundle", "packages/", "site-packages/",

  # Virtual environments
  "venv/", "\.venv/", "env/", "\.env", "virtualenv/",

  # IDE and editor files
  "\.idea/", "\.vscode/", "\.vs/", "\.settings/", ".*\.sublime-.*",
  "\.project", "\.classpath", "xcuserdata/", ".*\.xcodeproj/", ".*\.xcworkspace/",

  # Lock files
  "package-lock\.json", "yarn\.lock", "poetry\.lock", "Pipfile\.lock",
  "Gemfile\.lock", "Cargo\.lock", "bun\.lock", "bun\.lockb",

  # Build directories and artifacts
  "build/", "dist/", "target/", "out/", "\.gradle/", "\.settings/",
  ".*\.egg-info", ".*\.egg", ".*\.whl", ".*\.so", "bin/", "obj/", "pkg/",

  # Cache directories
  "\.cache/", "\.sass-cache/", "\.eslintcache/", "\.pytest_cache/",
  "\.coverage", "\.tox/", "\.nox/", "\.mypy_cache/", "\.ruff_cache/",
  "\.hypothesis/", "\.terraform/", "\.docusaurus/", "\.next/", "\.nuxt/",

  # Compiled code
  ".*\.pyc$", ".*\.pyo$", ".*\.pyd$", "__pycache__/", ".*\.class$",
  ".*\.jar$", ".*\.war$", ".*\.ear$", ".*\.nar$",
  ".*\.o$", ".*\.obj$", ".*\.dll$", ".*\.dylib$", ".*\.exe$",
  ".*\.lib$", ".*\.out$", ".*\.a$", ".*\.pdb$", ".*\.nupkg$",

  # Language-specific files
  ".*\.min\.js$", ".*\.min\.css$", ".*\.map$", ".*\.tfstate.*",
  ".*\.gem$", ".*\.ruby-version", ".*\.ruby-gemset", ".*\.rvmrc",
  ".*\.rs\.bk$", ".*\.gradle", ".*\.suo", ".*\.user", ".*\.userosscache",
  ".*\.sln\.docstates", "gradle-app\.setting",
  ".*\.pbxuser", ".*\.mode1v3", ".*\.mode2v3", ".*\.perspectivev3", ".*\.xcuserstate",
  "\.swiftpm/", "\.build/"
].freeze
DOT_FILE_PATTERN =

Pattern for dot files/directories

%r{(?-mix:(^\.|/\.))}
MAX_FILES =

Maximum number of files to process to prevent memory overload

1000
BUFFER_SIZE =

Buffer size to reduce I/O operations

250
LOCAL_BUFFER_THRESHOLD =

Thread-local buffer threshold

50
DEFAULT_THREAD_COUNT =

Default threading options

[Concurrent.processor_count, 8].min
DEFAULT_THREAD_TIMEOUT =

seconds

60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Generator

Returns a new instance of Generator.



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gitingest/generator.rb', line 86

def initialize(options = {})
  @options = options
  @repo_files = []
  # @excluded_patterns = [] # This will be set after validate_options
  setup_logger
  validate_options
  configure_client
  # Populate @excluded_patterns with raw patterns after options are validated
  @excluded_patterns = DEFAULT_EXCLUDES + @options.fetch(:exclude, [])
  compile_excluded_patterns
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



84
85
86
# File 'lib/gitingest/generator.rb', line 84

def client
  @client
end

#excluded_patternsObject (readonly)

Returns the value of attribute excluded_patterns.



84
85
86
# File 'lib/gitingest/generator.rb', line 84

def excluded_patterns
  @excluded_patterns
end

#loggerObject (readonly)

Returns the value of attribute logger.



84
85
86
# File 'lib/gitingest/generator.rb', line 84

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



84
85
86
# File 'lib/gitingest/generator.rb', line 84

def options
  @options
end

#repo_filesObject (readonly)

Returns the value of attribute repo_files.



84
85
86
# File 'lib/gitingest/generator.rb', line 84

def repo_files
  @repo_files
end

Instance Method Details

#generate_directory_structureObject



127
128
129
130
131
132
133
134
# File 'lib/gitingest/generator.rb', line 127

def generate_directory_structure
  fetch_repository_contents if @repo_files.empty?
  @logger.info "Generating directory structure for #{@options[:repository]}"
  repo_name = @options[:repository].split("/").last
  structure = DirectoryStructureBuilder.new(repo_name, @repo_files).build
  @logger.info "\n"
  structure
end

#generate_fileObject



107
108
109
110
111
112
113
114
115
# File 'lib/gitingest/generator.rb', line 107

def generate_file
  fetch_repository_contents if @repo_files.empty?
  @logger.info "Generating file for #{@options[:repository]}"
  File.open(@options[:output_file], "w") do |file|
    process_content_to_output(file)
  end
  @logger.info "Prompt generated and saved to #{@options[:output_file]}"
  @options[:output_file]
end

#generate_promptObject



117
118
119
120
121
122
123
124
125
# File 'lib/gitingest/generator.rb', line 117

def generate_prompt
  @logger.info "Generating in-memory prompt for #{@options[:repository]}"
  fetch_repository_contents if @repo_files.empty?
  content = StringIO.new
  process_content_to_output(content)
  result = content.string
  @logger.info "Generated #{result.size} bytes of content in memory"
  result
end

#runObject



98
99
100
101
102
103
104
105
# File 'lib/gitingest/generator.rb', line 98

def run
  fetch_repository_contents
  if @options[:show_structure]
    puts generate_directory_structure
    return
  end
  generate_file
end