Skip to content

Instantly share code, notes, and snippets.

@eduard-un
Last active July 31, 2024 05:56
Show Gist options
  • Save eduard-un/911a30ec29f9efb7065e6aa064a480c1 to your computer and use it in GitHub Desktop.
Save eduard-un/911a30ec29f9efb7065e6aa064a480c1 to your computer and use it in GitHub Desktop.
Github Check

Instalation

  1. Install Python
  2. Open your terminal and type pip install requests
  3. Create a new file and call it check.py and save it inside a folder of your choice
  4. Paste this code
import requests
import os

def search_github_issues(repos, issue_title):
    token = os.getenv('GITHUB_TOKEN')
    if not token:
        print("GITHUB_TOKEN environment variable not set.")
        return

    headers = {'Authorization': f'token {token}'}
    all_found_issues = {}
    search_query = issue_title

    for repo in repos:
        search_url = f'https://api.github.com/search/issues?q={search_query}+repo:{repo}+label:"Divi Dash"+is:issue'
        print(f"Searching URL: {search_url}")  # Debugging line
        response = requests.get(search_url, headers=headers)

        if response.status_code == 200:
            issues = response.json().get('items', [])
            if issues:
                repo_issues = []
                for issue in issues:
                    repo_issues.append(issue['html_url'])
                if repo_issues:
                    all_found_issues[repo] = repo_issues
            else:
                print(f"No issues found in {repo}.")
        else:
            print(f"Failed to search issues in {repo}. Status code: {response.status_code}")
            print(response.json())  # Debugging line

    if all_found_issues:
        for index, (repo, issues) in enumerate(all_found_issues.items()):
            if index > 0:
                print("\n--------------------------------\n")
            print(f"Issues found in {repo}:")
            for issue in issues:
                print(issue)
    else:
        print("No issues found in any repository.")

if __name__ == "__main__":
    repos = ['elegantthemes/Divi', 'elegantthemes/build-laravel']  # Replace with your repository names
    issue_title = input("Enter the issue title to search for: ")
    search_github_issues(repos, issue_title)

Authentificate Github

  1. Login to your Github account
  2. Click on your profile picture (upper-right corner) and choose Settings from the dropdown menu
  3. In the left sidebar, scroll down and click on Developer settings
  4. Click on Tokens (classic)
  5. Click on Generate new Tokens(classic)
  6. Give your Token a descriptive name
  7. Under Scope select Repo (full controll)
  8. Scroll down and click on Generate Token
  9. Copy the Token to your clipboard

Set the Token as an Environment Variable

  • On Unix/Linux/Mac type the below command in your terminal:
export GITHUB_TOKEN=your_github_token

To make this permanent, add the above line to your shell configuration file (~/.bashrc, ~/.zshrc, etc.).

  • On Windows (Command Prompt) type the below command in your terminal
set GITHUB_TOKEN=your_github_token
  • On Windows (PowerShell) type the below command in your terminal
$env:GITHUB_TOKEN="your_github_token"

Run the script

  1. Open your terminal and cd intro the the folder containing the check.py file
  2. Type this command python check.py

Note

If you are using Python3, instead of running python check.py please use python3 check.py

Demonstration

[video recording here]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment