The github-api-ps-module
is a PowerShell module designed to simplify interactions with the GitHub API. It provides a collection of cmdlets to perform various operations, such as managing repositories, organizations, and interacting with GitHub's REST and GraphQL APIs. This module is ideal for developers and administrators who want to automate GitHub workflows.
- GitHub API Integration: Seamlessly interact with GitHub's REST and GraphQL APIs.
- Rate Limiting Management: Handle GitHub API rate limits effectively.
- JWT Authentication: Generate and use JSON Web Tokens (JWT) for GitHub App authentication.
- Pagination Support: Easily handle paginated API responses.
- Markdown Utilities: Create and manipulate Markdown content.
- Temporary Directories: Manage temporary directories for intermediate operations.
- PowerShell 6 or later
- A GitHub account
- GitHub App credentials (if using JWT authentication)
GITHUB_TOKEN
: Required for authenticating with the GitHub API when not using JWT.
GITHUB_APP_ID
: Required for generating JWTs for GitHub App authentication.GITHUB_PRIVATE_KEY
: The private key string for JWT generation (optional).GITHUB_PRIVATE_KEY_PATH
: Path to the private key file for JWT generation (alternative toGITHUB_PRIVATE_KEY
).
Ensure these variables are set in your environment before running the module.
- Clone this repository:
git clone https://github.com/your-repo/github-api-ps-module.git
- Import the module:
Import-Module ./GitHubRestModule.psd1
To authenticate with the GitHub API, ensure your environment variables are properly set up (e.g., GITHUB_TOKEN
for personal access token authentication). Then, call the Update-GitHubToken
cmdlet:
Update-GitHubToken
This will authenticate your session and allow you to interact with the GitHub API.
Use the Invoke-GitHubApiRoute
cmdlet to perform simple API actions. For example:
# Get repository details
Invoke-GitHubApiRoute -Method GET -Route "/repos/my-org/my-repo"
# Create a new issue
Invoke-GitHubApiRoute -Method POST -Route "/repos/my-org/my-repo/issues" -Body @{ title = "New Issue"; body = "Issue description" }
Leverage the Invoke-PaginatedGitHubApiRoute
cmdlet to handle paginated API responses automatically:
# List all repositories in an organization
Invoke-PaginatedGitHubApiRoute -Method GET -Route "/orgs/my-org/repos"
Use the Invoke-GitHubGraphql
cmdlet to execute GraphQL queries:
# Example GraphQL query
$query = @"
{
repository(owner: \"my-org\", name: \"my-repo\") {
issues(last: 5) {
edges {
node {
title
url
}
}
}
}
}
"@
Invoke-GitHubGraphql -Query $query
For paginated GraphQL queries, use the Invoke-GitHubGraphqlQuery
cmdlet:
# Example paginated GraphQL query
$query = @"
{
repository(owner: \"my-org\", name: \"my-repo\") {
issues(first: 5, after: $cursor) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
title
url
}
}
}
}
}
"@
Invoke-GitHubGraphqlQuery -Query $query
When an API endpoint returns a 202 status code due to data loading, use the Invoke-GitHubApiRouteRetryOn202
cmdlet to handle retries automatically:
Invoke-GitHubApiRouteRetryOn202 -Method GET -Route "/repos/my-org/my-repo/insights"
This module automatically handles rate limits and throttling. To explicitly check rate limits, use the Assert-GitHubRateLimits
cmdlet:
Assert-GitHubRateLimits
If you prefer using the GitHub CLI (gh
), this module integrates seamlessly and provides rate limit protection out of the box.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request with a detailed description of your changes.
This project is licensed under the MIT License. See the LICENSE
file for details.
If you encounter any issues or have questions, feel free to open an issue in this repository.