Skip to main content

GitHub Search Using Regex

Saikat Karmakar | 28 Jan:2023


This program allows you to search for a specific pattern within the files of a GitHub repository(Using PyGithub). The program utilizes regular expressions and multithreading to quickly search through the repository's contents and return all files that contain the specified pattern.

Features

  • Search for a specific pattern in the files of a GitHub repository
  • Supports single repository or file containing multiple repository URLs
  • Uses multithreading to improve search performance

Installation

# using pip
pip install git-regex-search

To use this program, you will need to have Python 3 and the PyGithub library installed. You can install PyGithub using pip:

pip3 install -r requirements.txt

You will also need to have a GitHub personal access token. You can create one by going to the GitHub Developer Settings.

Usage

To use the program, you will need to provide a GitHub access token. The token can be passed as an environment variable or in a config.toml file. The program will look for the token in the following order:

  • GITHUB_TOKEN environment variable
  • config.toml file
python3 git_regex_search.py -h                                              
usage: git_regex_search.py [-h] [-u URL] [-r REGEX]

options:
  -h, --help            show this help message and exit
  -u URL, --url URL     URL of the repository (single or file
                        containing URLs)
  -r REGEX, --regex REGEX
                        Regex pattern to search for

For example, to search for the pattern brownie in the repository Aviksaikat/RoadClosed-quillctf-brownie, you would run the following command:

python3 git_regex_search.py -u https://github.com/Aviksaikat/RoadClosed-quillctf-brownie -r "brownie"

The program will then return a list of all files that contain the specified pattern, along with the line number where the pattern was found.

Multithreading

The program utilizes multithreading to search through the repository's contents more quickly. Two threads are created and run simultaneously, each searching through the repository's contents. This allows the program to search through the repository's contents much faster than if it were only using a single thread.

Regular Expressions

The program utilizes regular expressions to search for the specified pattern within the files of the repository. This allows for more powerful and flexible searches, as opposed to simple string matching.

Docker

You can build the image by running the following command in the same directory where the Dockerfile is located:

docker build -t <image-name> .

You can then run the container using the following command:

docker run -e GITHUB_TOKEN=<access_token> <image-name>

Limitations

This program only searches the contents of the files and not the name of the files. For my use I don't need it to search the names.

Additional Features

The program also prints the whole file path where the pattern was found, which is helpful in identifying the location of the pattern.

Conclusion

This program is a powerful tool for quickly searching through the contents of a GitHub repository and finding specific patterns. With the use of regular expressions and multithreading, it is able to search through large repositories quickly and efficiently.

Version 0.3

Published as pip package

Metadata

Release files for git-regex-search 1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-regex-search 1
File Size Uploaded
git_regex_search-1.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for git-regex-search 1
File Interpreter ABI Platform
git_regex_search-1-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / git_regex_search-1.tar.gz

Download URL git_regex_search-1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8a5f0ce4c3e71bbc747f96e946a31d367cd2a591bd165fdeb1a8a2ae5dfdf155
BLAKE2b-256 checksum
How to use checksums
c42cd1c08b27627a4e5dec2eb4472101e65356f44c7b1b7d119d7bce9c29dbb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / git_regex_search-1-py3-none-any.whl

Download URL git_regex_search-1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0735a68a746445e2b7569f5c6efc566ce71ee127ad96f6903db5fb5deff7fa4
BLAKE2b-256 checksum
How to use checksums
19d7a561661fd487abc706d557af496fb20b0a0cd9a0063ed69227f2d8f33439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

1 This release

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page