gitingest 0.1.0
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.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +18 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +12 -0
- data/bin/console +11 -0
- data/bin/gitingest +35 -0
- data/bin/setup +8 -0
- data/lib/gitingest/generator.rb +213 -0
- data/lib/gitingest/version.rb +5 -0
- data/lib/gitingest.rb +9 -0
- data/sig/gitingest.rbs +4 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 472ca8e21d2bb9e48eeeada768679586b002087a9253f966eb164fd6118236d2
|
4
|
+
data.tar.gz: 1dddc890f5c380fb7ca2ca93db050473569dd1dd75c307f2d532857fc0f9ceaa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1105676c81a389ea20a80a7be5ed2ea25c52fa2460c1672b0d5c45e19d2daf92c552a3d551cc71c196a9d0e2cbf96d779dc8e6b04f81965d323b31fff374f66a
|
7
|
+
data.tar.gz: 9b565545bfbfc1f983109cbdf08470b6399471f46dbcb651173ab5ab97a806b5ac992eb5affd1b58f71f2d71788d971aba9fde1aead94f779453636392253684
|
data/.DS_Store
ADDED
Binary file
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
## [0.1.0] - 2025-03-02
|
6
|
+
|
7
|
+
### Added
|
8
|
+
- Initial release of Gitingest
|
9
|
+
- Core functionality to fetch and process GitHub repository files
|
10
|
+
- Command-line interface for easy interaction
|
11
|
+
- Smart file filtering with default exclusions for common non-code files
|
12
|
+
- Concurrent processing for improved performance
|
13
|
+
- Custom exclude patterns support
|
14
|
+
- GitHub authentication via access tokens
|
15
|
+
- Automatic rate limit handling with retry mechanism
|
16
|
+
- Repository prompt generation with file separation markers
|
17
|
+
- Support for custom branch selection
|
18
|
+
- Custom output file naming options
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Davide Santangelo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Gitingest
|
2
|
+
|
3
|
+
Gitingest is a Ruby gem that fetches files from a GitHub repository and generates a consolidated text prompt, which can be used as input for large language models, documentation generation, or other purposes.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
### From RubyGems
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem install gitingest
|
11
|
+
```
|
12
|
+
|
13
|
+
### From Source
|
14
|
+
|
15
|
+
```bash
|
16
|
+
git clone https://github.com/davidesantangelo/gitingest.git
|
17
|
+
cd gitingest
|
18
|
+
bundle install
|
19
|
+
bundle exec rake install
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Command Line
|
25
|
+
|
26
|
+
```bash
|
27
|
+
gitingest --repository username/repo --token YOUR_GITHUB_TOKEN --output output.txt
|
28
|
+
```
|
29
|
+
|
30
|
+
#### Available Options
|
31
|
+
|
32
|
+
- `-r, --repository REPO`: GitHub repository (username/repo) [Required]
|
33
|
+
- `-t, --token TOKEN`: GitHub personal access token [Optional but recommended]
|
34
|
+
- `-o, --output FILE`: Output file for the prompt [Default: reponame_prompt.txt]
|
35
|
+
- `-e, --exclude PATTERN`: File patterns to exclude (comma separated)
|
36
|
+
- `-b, --branch BRANCH`: Repository branch [Default: main]
|
37
|
+
- `-h, --help`: Show help message
|
38
|
+
|
39
|
+
### As a Library
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'gitingest'
|
43
|
+
|
44
|
+
options = {
|
45
|
+
repository: 'davidesantangelo/gitingest',
|
46
|
+
token: 'your_github_token', # Optional
|
47
|
+
output_file: 'output.txt', # Optional
|
48
|
+
branch: 'master', # Optional
|
49
|
+
exclude: ['node_modules', '.*\.png$'] # Optional
|
50
|
+
}
|
51
|
+
|
52
|
+
generator = Gitingest::Generator.new(options)
|
53
|
+
generator.run
|
54
|
+
```
|
55
|
+
|
56
|
+
## Features
|
57
|
+
|
58
|
+
- Fetches all files from a GitHub repository based on the given branch
|
59
|
+
- Automatically excludes common binary files and system files by default
|
60
|
+
- Allows custom exclusion patterns for specific file extensions or directories
|
61
|
+
- Uses concurrent processing for faster downloads
|
62
|
+
- Handles GitHub API rate limiting with automatic retry
|
63
|
+
- Generates a clean, formatted output file with file paths and content
|
64
|
+
|
65
|
+
## Default Exclusion Patterns
|
66
|
+
|
67
|
+
By default, Gitingest excludes the following files and directories:
|
68
|
+
|
69
|
+
- `.git/`, `.github/`, `.gitignore`, `.DS_Store`
|
70
|
+
- Log files: `.*\.log$`
|
71
|
+
- Image files: `.*\.png$`, `.*\.jpg$`, `.*\.jpeg$`, `.*\.gif$`, `.*\.svg$`
|
72
|
+
- Document files: `.*\.pdf$`
|
73
|
+
- Archive files: `.*\.zip$`, `.*\.tar\.gz$`
|
74
|
+
- Dependency directories: `node_modules/`, `vendor/`
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/davidesantangelo/gitingest.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "gitingest"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require "irb"
|
11
|
+
IRB.start(__FILE__)
|
data/bin/gitingest
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "optparse"
|
5
|
+
require "gitingest"
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: gitingest [options]"
|
10
|
+
|
11
|
+
opts.on("-r", "--repository REPO", "GitHub repository (username/repo)") { |repo| options[:repository] = repo }
|
12
|
+
opts.on("-t", "--token TOKEN", "GitHub personal access token") { |token| options[:token] = token }
|
13
|
+
opts.on("-o", "--output FILE", "Output file for the prompt") { |file| options[:output_file] = file }
|
14
|
+
opts.on("-e", "--exclude PATTERN", "File patterns to exclude (comma separated)") do |pattern|
|
15
|
+
options[:exclude] = pattern.split(",").map(&:strip)
|
16
|
+
end
|
17
|
+
opts.on("-b", "--branch BRANCH", "Repository branch (default: main)") { |branch| options[:branch] = branch }
|
18
|
+
opts.on("-h", "--help", "Show this help message") do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
parser.parse!
|
26
|
+
generator = Gitingest::Generator.new(options)
|
27
|
+
generator.run
|
28
|
+
rescue ArgumentError => e
|
29
|
+
puts "Error: #{e.message}"
|
30
|
+
puts parser
|
31
|
+
exit 1
|
32
|
+
rescue StandardError => e
|
33
|
+
puts "Error: #{e.message}"
|
34
|
+
exit 1
|
35
|
+
end
|
data/bin/setup
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "octokit"
|
4
|
+
require "base64"
|
5
|
+
require "fileutils"
|
6
|
+
require "concurrent"
|
7
|
+
|
8
|
+
module Gitingest
|
9
|
+
class Generator
|
10
|
+
# Default exclusion patterns for common files and directories
|
11
|
+
DEFAULT_EXCLUDES = [
|
12
|
+
# Version control
|
13
|
+
'\.git/', '\.github/', '\.gitignore', '\.gitattributes', '\.gitmodules', '\.svn', '\.hg',
|
14
|
+
|
15
|
+
# System files
|
16
|
+
'\.DS_Store', 'Thumbs\.db', 'desktop\.ini',
|
17
|
+
|
18
|
+
# Log files
|
19
|
+
'.*\.log$', '.*\.bak$', '.*\.swp$', '.*\.tmp$', '.*\.temp$',
|
20
|
+
|
21
|
+
# Images and media
|
22
|
+
'.*\.png$', '.*\.jpg$', '.*\.jpeg$', '.*\.gif$', '.*\.svg$', '.*\.ico$',
|
23
|
+
'.*\.pdf$', '.*\.mov$', '.*\.mp4$', '.*\.mp3$', '.*\.wav$',
|
24
|
+
|
25
|
+
# Archives
|
26
|
+
'.*\.zip$', '.*\.tar\.gz$',
|
27
|
+
|
28
|
+
# Dependency directories
|
29
|
+
"node_modules/", "vendor/", "bower_components/", "\.npm/", "\.yarn/", "\.pnpm-store/",
|
30
|
+
"\.bundle/", "vendor/bundle", "packages/", "site-packages/",
|
31
|
+
|
32
|
+
# Virtual environments
|
33
|
+
"venv/", "\.venv/", "env/", "\.env", "virtualenv/",
|
34
|
+
|
35
|
+
# IDE and editor files
|
36
|
+
"\.idea/", "\.vscode/", "\.vs/", "\.settings/", ".*\.sublime-.*",
|
37
|
+
"\.project", "\.classpath", "xcuserdata/", ".*\.xcodeproj/", ".*\.xcworkspace/",
|
38
|
+
|
39
|
+
# Lock files
|
40
|
+
"package-lock\.json", "yarn\.lock", "poetry\.lock", "Pipfile\.lock",
|
41
|
+
"Gemfile\.lock", "Cargo\.lock", "bun\.lock", "bun\.lockb",
|
42
|
+
|
43
|
+
# Build directories and artifacts
|
44
|
+
"build/", "dist/", "target/", "out/", "\.gradle/", "\.settings/",
|
45
|
+
".*\.egg-info", ".*\.egg", ".*\.whl", ".*\.so", "bin/", "obj/", "pkg/",
|
46
|
+
|
47
|
+
# Cache directories
|
48
|
+
"\.cache/", "\.sass-cache/", "\.eslintcache/", "\.pytest_cache/",
|
49
|
+
"\.coverage", "\.tox/", "\.nox/", "\.mypy_cache/", "\.ruff_cache/",
|
50
|
+
"\.hypothesis/", "\.terraform/", "\.docusaurus/", "\.next/", "\.nuxt/",
|
51
|
+
|
52
|
+
# Compiled code
|
53
|
+
".*\.pyc$", ".*\.pyo$", ".*\.pyd$", "__pycache__/", ".*\.class$",
|
54
|
+
".*\.jar$", ".*\.war$", ".*\.ear$", ".*\.nar$",
|
55
|
+
".*\.o$", ".*\.obj$", ".*\.dll$", ".*\.dylib$", ".*\.exe$",
|
56
|
+
".*\.lib$", ".*\.out$", ".*\.a$", ".*\.pdb$", ".*\.nupkg$",
|
57
|
+
|
58
|
+
# Language specific files
|
59
|
+
".*\.min\.js$", ".*\.min\.css$", ".*\.map$", ".*\.tfstate.*",
|
60
|
+
".*\.gem$", ".*\.ruby-version", ".*\.ruby-gemset", ".*\.rvmrc",
|
61
|
+
".*\.rs\.bk$", ".*\.gradle", ".*\.suo", ".*\.user", ".*\.userosscache",
|
62
|
+
".*\.sln\.docstates", "gradle-app\.setting",
|
63
|
+
".*\.pbxuser", ".*\.mode1v3", ".*\.mode2v3", ".*\.perspectivev3", ".*\.xcuserstate",
|
64
|
+
"\.swiftpm/", "\.build/"
|
65
|
+
].freeze
|
66
|
+
|
67
|
+
# Maximum number of files to process to prevent memory overload
|
68
|
+
MAX_FILES = 1000
|
69
|
+
|
70
|
+
attr_reader :options, :client, :repo_files, :excluded_patterns
|
71
|
+
|
72
|
+
def initialize(options = {})
|
73
|
+
@options = options
|
74
|
+
@repo_files = []
|
75
|
+
@excluded_patterns = []
|
76
|
+
validate_options
|
77
|
+
configure_client
|
78
|
+
compile_excluded_patterns
|
79
|
+
end
|
80
|
+
|
81
|
+
### Option Validation
|
82
|
+
def validate_options
|
83
|
+
raise ArgumentError, "Repository is required" unless @options[:repository]
|
84
|
+
|
85
|
+
@options[:output_file] ||= "#{@options[:repository].split("/").last}_prompt.txt"
|
86
|
+
@options[:branch] ||= "main"
|
87
|
+
@options[:exclude] ||= []
|
88
|
+
@excluded_patterns = DEFAULT_EXCLUDES + @options[:exclude]
|
89
|
+
end
|
90
|
+
|
91
|
+
### Client Configuration
|
92
|
+
def configure_client
|
93
|
+
@client = @options[:token] ? Octokit::Client.new(access_token: @options[:token]) : Octokit::Client.new
|
94
|
+
|
95
|
+
if @options[:token]
|
96
|
+
puts "Using provided GitHub token for authentication"
|
97
|
+
else
|
98
|
+
puts "Warning: No token provided. API rate limits will be restricted and private repositories will be inaccessible."
|
99
|
+
puts "For better results, provide a GitHub token with the --token option."
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def compile_excluded_patterns
|
104
|
+
@excluded_patterns = @excluded_patterns.map { |pattern| Regexp.new(pattern) }
|
105
|
+
end
|
106
|
+
|
107
|
+
### Fetch Repository Contents
|
108
|
+
def fetch_repository_contents
|
109
|
+
puts "Fetching repository: #{@options[:repository]} (branch: #{@options[:branch]})"
|
110
|
+
begin
|
111
|
+
# First validate authentication and repository access
|
112
|
+
validate_repository_access
|
113
|
+
|
114
|
+
repo_tree = @client.tree(@options[:repository], @options[:branch], recursive: true)
|
115
|
+
@repo_files = repo_tree.tree.select { |item| item.type == "blob" && !excluded_file?(item.path) }
|
116
|
+
|
117
|
+
if @repo_files.size > MAX_FILES
|
118
|
+
puts "Warning: Found #{@repo_files.size} files, limited to #{MAX_FILES}."
|
119
|
+
@repo_files = @repo_files.first(MAX_FILES)
|
120
|
+
end
|
121
|
+
puts "Found #{@repo_files.size} files after exclusion filters"
|
122
|
+
rescue Octokit::Unauthorized
|
123
|
+
raise "Authentication error: Invalid or expired GitHub token. Please provide a valid token."
|
124
|
+
rescue Octokit::NotFound
|
125
|
+
raise "Repository not found: '#{@options[:repository]}' or branch '#{@options[:branch]}' doesn't exist or is private."
|
126
|
+
rescue Octokit::Error => e
|
127
|
+
raise "Error accessing repository: #{e.message}"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def validate_repository_access
|
132
|
+
# Check if we can access the repository
|
133
|
+
begin
|
134
|
+
@client.repository(@options[:repository])
|
135
|
+
rescue Octokit::Unauthorized
|
136
|
+
raise "Authentication error: Invalid or expired GitHub token"
|
137
|
+
rescue Octokit::NotFound
|
138
|
+
raise "Repository '#{@options[:repository]}' not found or is private. Check the repository name or provide a valid token."
|
139
|
+
end
|
140
|
+
|
141
|
+
# Check if the branch exists
|
142
|
+
begin
|
143
|
+
@client.branch(@options[:repository], @options[:branch])
|
144
|
+
rescue Octokit::NotFound
|
145
|
+
raise "Branch '#{@options[:branch]}' not found in repository '#{@options[:repository]}'"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def excluded_file?(path)
|
150
|
+
return true if path.start_with?(".") || path.split("/").any? { |part| part.start_with?(".") }
|
151
|
+
|
152
|
+
@excluded_patterns.any? { |pattern| path.match?(pattern) }
|
153
|
+
end
|
154
|
+
|
155
|
+
### Generate Prompt
|
156
|
+
def generate_prompt
|
157
|
+
puts "Generating prompt..."
|
158
|
+
Concurrent::Array.new(@repo_files)
|
159
|
+
buffer = []
|
160
|
+
buffer_size = 100 # Write every 100 files to reduce I/O
|
161
|
+
|
162
|
+
# Dynamic thread pool based on core count
|
163
|
+
pool = Concurrent::FixedThreadPool.new([Concurrent.processor_count, 5].max)
|
164
|
+
|
165
|
+
File.open(@options[:output_file], "w") do |file|
|
166
|
+
@repo_files.each_with_index do |repo_file, index|
|
167
|
+
pool.post do
|
168
|
+
content = fetch_file_content_with_retry(repo_file.path)
|
169
|
+
result = <<~TEXT
|
170
|
+
================================================================
|
171
|
+
File: #{repo_file.path}
|
172
|
+
================================================================
|
173
|
+
#{content}
|
174
|
+
|
175
|
+
TEXT
|
176
|
+
buffer << result
|
177
|
+
write_buffer(file, buffer) if buffer.size >= buffer_size
|
178
|
+
print "\rProcessing: #{index + 1}/#{@repo_files.size} files"
|
179
|
+
rescue Octokit::Error => e
|
180
|
+
puts "\nError fetching #{repo_file.path}: #{e.message}"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
pool.shutdown
|
184
|
+
pool.wait_for_termination
|
185
|
+
write_buffer(file, buffer) unless buffer.empty?
|
186
|
+
end
|
187
|
+
puts "\nPrompt generated and saved to #{@options[:output_file]}"
|
188
|
+
end
|
189
|
+
|
190
|
+
def fetch_file_content_with_retry(path, retries = 3)
|
191
|
+
content = @client.contents(@options[:repository], path: path, ref: @options[:branch])
|
192
|
+
Base64.decode64(content.content)
|
193
|
+
rescue Octokit::TooManyRequests
|
194
|
+
raise unless retries.positive?
|
195
|
+
|
196
|
+
sleep_time = 60 / retries
|
197
|
+
puts "Rate limit exceeded, waiting #{sleep_time} seconds..."
|
198
|
+
sleep(sleep_time)
|
199
|
+
fetch_file_content_with_retry(path, retries - 1)
|
200
|
+
end
|
201
|
+
|
202
|
+
def write_buffer(file, buffer)
|
203
|
+
file.puts(buffer.join)
|
204
|
+
buffer.clear
|
205
|
+
end
|
206
|
+
|
207
|
+
### Main Execution
|
208
|
+
def run
|
209
|
+
fetch_repository_contents
|
210
|
+
generate_prompt
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
data/lib/gitingest.rb
ADDED
data/sig/gitingest.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitingest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Davide Santangelo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: octokit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: optparse
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Gitingest is a powerful command-line tool that fetches files from GitHub
|
98
|
+
repositories and generates consolidated text prompts for AI analysis. It features
|
99
|
+
smart file filtering, concurrent processing, custom exclusion patterns, authentication
|
100
|
+
support, and automatic rate limit handling. Perfect for creating context-rich prompts
|
101
|
+
from codebases for AI assistants, documentation generation, or codebase analysis.
|
102
|
+
email:
|
103
|
+
- davide.santangelo@gmail.com
|
104
|
+
executables:
|
105
|
+
- gitingest
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- ".DS_Store"
|
110
|
+
- ".rspec"
|
111
|
+
- ".rubocop.yml"
|
112
|
+
- CHANGELOG.md
|
113
|
+
- CODE_OF_CONDUCT.md
|
114
|
+
- LICENSE.txt
|
115
|
+
- README.md
|
116
|
+
- Rakefile
|
117
|
+
- bin/console
|
118
|
+
- bin/gitingest
|
119
|
+
- bin/setup
|
120
|
+
- lib/gitingest.rb
|
121
|
+
- lib/gitingest/generator.rb
|
122
|
+
- lib/gitingest/version.rb
|
123
|
+
- sig/gitingest.rbs
|
124
|
+
homepage: https://github.com/davidesantangelo/gitingest
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata:
|
128
|
+
homepage_uri: https://github.com/davidesantangelo/gitingest
|
129
|
+
source_code_uri: https://github.com/davidesantangelo/gitingest
|
130
|
+
changelog_uri: https://github.com/davidesantangelo/gitingest/blob/main/CHANGELOG.md
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 3.1.0
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubygems_version: 3.3.26
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Efficiently generate AI prompts from GitHub repositories for code analysis
|
150
|
+
and documentation
|
151
|
+
test_files: []
|