Package: ghmate
ghmateA comprehensive Python package for interacting with the GitHub API. This package simplifies GitHub API calls by providing a set of high-level commands encapsulated in easy-to-use classes.PrerequisitesPrerequisitesPython 3.8 or higher (specify other supported versions if applicable)pipfor installing packagesA GitHub account andPersonal Access Token(required for making authenticated API requests)InstallationTo installghmate, ensure you have Python 3.8 or higher and pip installed. Run the following command:pipinstallghmateSetupBefore usingghmate, set up your environment with your GitHub personal access token:exportGITHUB_TOKEN='your_personal_access_token'(Optional) Use a .env file with python-dotenv to load environment variables.
Create a.envfile in your project directory and add your GitHub Personal Access Token, repository owner, and repository name.GITHUB_TOKEN=your_personal_access_token_here
OWNER=repository_owner_here
REPO=repository_name_hereLoad environment variables usingpython-dotenv.importosfromdotenvimportload_dotenv# Load environment variablesload_dotenv()# Get environment variablestoken=os.getenv('GITHUB_TOKEN')owner=os.getenv('OWNER')repo=os.getenv('REPO')UsageInitialize the GitHubClient with your repository owner, name, and token.
Replace owner_name, repository_name, and your_token with your actual GitHub information.To start usingghmate, initialize theGitHubClient:fromghmate.github_clientimportGitHubClientgithub_client=GitHubClient(owner="owner_name",repo="repository_name",token="your_token")Use CoreCommands for basic operations and ActionsCommands for GitHub Actions-related tasks.
Here are some examples:Core CommandsCoreCommandsprovides essential GitHub operations:fromghmate.core_commandsimportCoreCommandscore_commands=CoreCommands(token="your_token",owner="owner_name",repo="repository_name")# Authenticate and get user informationuser_info=core_commands.auth()# Browse topicstopics=core_commands.browse()# Create an issueissue=core_commands.issue(action='create',title='Issue Title',body='Issue description')Actions CommandsActionsCommandsfocuses on GitHub Actions-related tasks:fromghmate.actions_commandsimportActionsCommandsactions_commands=ActionsCommands(owner="owner_name",repo="repository_name",token="your_token")# List artifactsartifacts=actions_commands.list_artifacts()# Cache managementcache_list=actions_commands.cache(action='list')cache_restore=actions_commands.cache(action='restore',key='cache_key')Handle exceptions that may occur during API calls.TestsUnit TestRun tests to ensure the package is working as expected.python-munittestdiscover-stests/unit# ORpython3-munittestdiscover-stests/unitMock external API calls when writing unit tests.
Integration tests will make actual API calls, so ensure you have the correct setup.
When writing unit tests, use theunittest.mockmodule to mock external API calls.For example:fromunittestimportTestCasefromunittest.mockimportpatchfromghmate.actions_commandsimportActionsCommandsclassTestActionsCommandsUnit(TestCase):@patch.object(ActionsCommands,'_make_request')deftest_list_artifacts(self,mock_request):# Your test code herepassIntegration TestsFor integration tests, ensure your .env file contains the necessary environment variables and run:python-munittestdiscover-stests/integrationExamplesExamples
Theexamplesdirectory contains a sample project setup and usage examples.example/
├── .env                 # Storing environment variables
├── using_dotenv.py     # Example script utilizing the ghmate package
└── requirements.txt     # Required packagesContributingContributions are welcome! Please read ourcontributing guidelinesto get started.Licenseghmateis licensed under the MIT License - see theLICENSEfile for details.