Skip to main content

Modules for interacting with GitHub API.

Project description

The best way to interact with GitHub API.

Note: This module is useful for the GitHub API
Your URL should look like this https://api.github.com This is working module with your PAT Token

Prerequisites

from github_module import GitHubHelper

Getting Started

Connectivity to GitHub

To initialize a connection to GitHub, instantiate the GitHubHelper class with your GitHub URL, ORG, and Personal API Token:

github_helper = GitHubHelper(GITHUB_API, API_TOKEN)


1. Get the Current PAT API Rate Limit

  • Purpose:
    • Fetches the current rate limit from the GitHub API.
  • Parameters:
    • None (The method relies on the instance's github_api and headers)
  • Output:
    • The number of remaining API requests allowed before hitting the rate limit.
  • Return:
    • int: The remaining rate limit.
    • -1: If there was an error retrieving the rate limit.
remaining_requests = github_helper.get_rate_limit()
print(f"Remaining rate limit: {remaining_requests}")

2. Check if the Repository exist

  • Purpose:
    • Checks if a GitHub repository exists and handles various error scenarios.
  • Parameters:
    • owner (str): The username or organization that owns the repository.
    • repo (str): The name of the repository.
  • Output:
    • A dictionary with the status of the repository check.
  • Return:
    • dict:
      • "status" (str): Indicates the result of the check. Possible values are "exists", "not_found", "forbidden", "rate_limit_exceeded", and "error".
      • "message" (str): A message providing details about the result.
result = github_helper.check_repository(owner="octocat", repo="Hello-World")
print(result["status"])  # e.g., "exists"
print(result["message"])  # e.g., "Repository exists."

3. Check if the Repository Read-Only

  • Purpose:
    • Determines whether a GitHub repository is read-only for the authenticated user.
  • Parameters:
    • owner (str): The username or organization that owns the repository.
    • repo (str): The name of the repository.
  • Output:
    • A boolean indicating whether the repository is read-only.
  • Return:
    • True: If the repository is read-only.
    • False: If the repository is writable.
    • None: If there was an error checking the repository (e.g., rate limit too low, repository not found).

4. Get the number of days that PAT is about to expire

  • Purpose:
    • Determines the number of days that PAT is about to expire
  • Parameters:
    • PAT (str): The PAT token to check expiry.
  • Output:
    • The number of remaining days of PAT token.
  • Return:
    • int: The remaining number of days.
    • -1: If there is no expiry of the PAT token.
    • -2: If there was an error retrieving the number of days.
expiry_days = github_helper.get_token_expiry_days()
print(expiry_days)
if expiry_days >= 0:
    print(f"Token expires in {expiry_days} days.")
elif expiry_days == -1:
    print("Token has no expiration (infinite).")
else:
    print("An error occurred while checking the token expiration.")


Data Privacy Note

🔒 We respect your privacy: This module does not store any of your data anywhere. It simply interacts with the GitHub API to perform the requested operations. Ensure you manage your connection details securely.

Release Notes

  • Renaming github_module to github_modules

Old Releases

Latest Release 0.4.1 (21 Aug 2024)

  • Changing README.md structure for Release Notes
  • Updated get_token_expiry_days use case code in README.md

Latest Release: 0.4 (21 Aug 2024)

  • We’ve implemented the get_token_expiry_days function to determine the number of days remaining on the PAT token. Occasionally, our automation fails due to the use of PATs with limited expiry. To prevent this, we’ve added a check to ensure the token’s validity.

Latest Release: 0.3 (05 Aug 2024)

  • Implemented the is_repo_read_only function to determine whether a repository is read-only, helping users avoid unauthorized write operations.

Latest Release: 0.2 (05 Aug 2024)

  • Added the check_repository function to verify if a GitHub repository exists and handle various error scenarios such as permissions issues and rate limit exhaustion.

Latest Release: 0.1 (05 Aug 2024)

  • Introduced the get_rate_limit function to fetch the current rate limit from the GitHub API, ensuring users can manage their API request limits effectively.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

github_modules-0.4.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

github_modules-0.4.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file github_modules-0.4.2.tar.gz.

File metadata

  • Download URL: github_modules-0.4.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.6

File hashes

Hashes for github_modules-0.4.2.tar.gz
Algorithm Hash digest
SHA256 582adcd9f448364881077b71e99a0e2c04d25618df2879efbad216012ffdf008
MD5 28c845ca79000aca42c17702b0e23deb
BLAKE2b-256 7f47bd9b386c0bc9f6b1ef8254f319fa606032ada111a5466978b1a6b8eff219

See more details on using hashes here.

File details

Details for the file github_modules-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for github_modules-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eaed6e63c6944a80e2867d80b9ce4b9596df178fc6e1b177aea8a5bd78aa8561
MD5 c3e366d4a51e46f282a0215c29f9a9a2
BLAKE2b-256 5b3f37594fa2e38b1d985f5a8e4dbf28c923f1f4c936b37c2bd78d272f24a569

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page