For our first release in OSD600, I was tasked with building a Repository-Context-Packager command line tool. This tool was developed to help developers share their code with ChatGPT or other LLMs by collecting and organizing repository content in a single, structured text file.
The tool works by scanning a local repository directory, collecting relevant files and information, and outputting a formatted document that includes the basic git information of the repository (such as latest commit hash, author, date), project structure, file contents, and some basic metadata such as total files or file lines.
The language I chose for this project was Python because I have a lot of familiarity with it from my co-op. I wanted to use something more comfortable and easy for me to start since it has been a while since I touched other languages such as C++. I also already had some experience with the argparse
python module, so I had a good jumping off point to start with for a command line tool.
Working on this project was very natural, it felt just like work. I'd get on, write some code, test it, and commit. I was never stuck for too long and could always jump into other coursework and right back to this project with no issue.
I'll go over how I built this project by highlighting some of the components I built and what libraries I used.
For the argument parsing I used the python library argparse
which allowed me to define command-line flags such as --version and --output as well as file paths.
To get the git info from the repository I used the GitPython
library which allowed me to extract the latest commit hash, branch name, author and timestamp easily. This library does require the user to install GitPython manually or via my own requirements installation guide.
I used the os
module to build the directory structure using os.walk to recursively traverse through the directory. I also used os.walk to get a list of all files that were going to be analyzed (ignoring everything listed in .gitignore, which I didn't even realize was one of the optional requirements before implementing. I just didn't like having it listed.).
To manage output formatting, I used the io
library to buffer content in memory. This allows the tool to write results to a file if the --output flag is set or display the results directly in the terminal.
All in all I'm feeling great about this first release, and looking forward to the next challenge as well as refining this tool even further.
Top comments (0)