TxtRepo

TxtRepo is a powerful tool that allows users to interact with GitHub repositories using a simple API. It provides functionality to retrieve an entire codebase as a single text file and convert a similarly formatted text file into a pull request. The project is open-source and available at https://github.com/matan1905/TxtRepo.

Features

How to Use

Getting a Repository Summary

To get a summary of a repository, send a GET request to the /repo endpoint with the repository's Git URL and optional parameters:

GET /repo?git_url=https://github.com/username/repo.git&branch=main&filter_patterns=*.py,*.js&exclude_patterns=*.txt,*.md&case_sensitive=false&suppress_comments=false&line_number=false

The response will include a summary of the repository's contents in a formatted text file.

Creating a Pull Request

To create a pull request, send a POST request to the /repo endpoint with the following JSON body:

{
  "git_url": "https://github.com/username/repo.git",
  "github_token": "your_github_personal_access_token",
  "summary": "# File /path/to/file\nYour code or content here\n# EndFile /path/to/file",
  "branch": "main"
}
    

The summary field should contain the changes you want to make, formatted as follows:

# File /path/to/file
Your code or content here
# EndFile /path/to/file
    

For multiple files, repeat the format. To delete a file, use the "::delete" suffix:

# File /path/to/delete::delete
# EndFile /path/to/delete
    

To inject content at a specific line, use the "::injectAtLine:line-number" suffix:

# File /path/to/file::injectAtLine:5
    Content to be injected
# EndFile /path/to/file
    

Note that when using the "injectAtLine" feature, you need to add spaces at the beginning of each line to match the indentation of the surrounding code.

The response will include the URL of the created pull request.

Demo

Loading...

Note

Make sure to keep your GitHub personal access token secure and never share it publicly.