py-github-helper
Python Script for interacting with Github API.
Example Code Usage:
from py_github_helper.utils.commands import add_comment
add_comment(
organization="org-not-included",
repository="py-github-helper",
pull_request_id="2",
message="This is an automated message via Github API",
token="my_github_token",
username=None,
password=None,
)
Example CLI Usage:
python3 -m py-github-helper \
-t $GH_TOKEN -o org-not-included -r py-github-helper -l 2 -c add_comment \
-e '{"message": "This is an automated message via Github API"}'
Example Comment:
https://github.com/org-not-included/py-github-helper/pull/2#issuecomment-1236262158
Docs
python3 -m py-github-helper --help
usage: python3 -m py-github-helper [-h] [-o ORGANIZATION] [-r REPOSITORY] [-t TOKEN] [-u USERNAME] [-p PASSWORD] [-l PULL_REQUEST_ID] [-c COMMAND] [-e EXTRAS]
A python script that handles GitHub API calls.
optional arguments:
-h, --help show this help message and exit.
-o ORGANIZATION, --organization ORGANIZATION
Owner of GitHub repository.
-r REPOSITORY, --repository REPOSITORY
Name of the GitHub repository.
-t TOKEN, --token TOKEN
User's GitHub Personal Access Token.
-u USERNAME, --username USERNAME, --user USERNAME
User's GitHub username.
-p PASSWORD, --password PASSWORD, --pass PASSWORD
User's Github password.
-l PULL_REQUEST_ID, --pull_request_id PULL_REQUEST_ID, --pull-request PULL_REQUEST_ID
The issue # of the Pull Request.
-c COMMAND, --command COMMAND
Name of python function associated with API call being made.
-e EXTRAS, --extras EXTRAS
Extra dictionary to allow for more arguments.
-v, --verbose
Log all INFO level messages to console.
-vv --debug, --very_verbose
Log all DEBUG level messages to console.
Expected Syntax:
python3 -m py-github-helper -o <Organization Name> -r <Repository> -t <O-Auth Token> -u <Github username> -p <Github password> -l <PR Number> -c <Github API Command> -e '{"x": "sample", "y": 5, "z": "test}'
Available Commands:
- add_comment:
Adds a single comment for a specified pull request.
Required parameters: organization, repository, token, pull-request, extras[message]
- add_labels:
Adds a set of labels for a specified pull request.
Required parameters: organization, repository, token, pull-request, extras[labels]
- close_issue:
Marks a specified issue as closed.
Required parameters: organization, repository, token, extras[issue]
- delete_labels:
Deletes a set of labels for a specified pull request.
Required parameters: organization, repository, token, pull-request, extras[labels]
- dimiss_single_review:
Dismisses a specific review for a specified pull request.
Required parameters: organization, repository, token, pull-request, extras[review_id]
- dismiss_all_reviews:
Dismisses all reviews for a specified pull request.
Required parameters: organization, repository, token, pull-request
- get_commit_message:
Gets a commit message, using the commit_id.
Required parameters: organization, repository, token, pull-request, extras[commit_id]
- get_deploy_issue_number:
Parses for a Github issue titled 'Deploy Request: YYYY-MM-DD', and returns the associated issue id.
Required parameters: organization, repository, token
- get_files_changed_during_pr:
Gets a PR's details, and filters it for a list of file names
Required parameters: organization, repository, pull-request, token
- get_pr_id_from_commit_id:
Returns a PR number, for an associated commit SHA.
Required parameters: organization, repository, token, extras[commit_id]
- get_prs_to_deploy:
Parses for a Github issue titled 'Deploy Request: YYYY-MM-DD', and generates a list of mentioned PRs (in order of closed_at).
Required parameters: organization, repository, token
- label_merged_pr:
Adds and/or deletes a set of labels to a pull_request merged into develop or release.
Required parameters: organization, repository, token, pull-request, extras[commit_id, labels_to_add, labels_to_delete]
- label_prs_mentioned_in_commits:
Adds and/or deletes a set of labels to all PRs mentioned in the commit messages of specified pull_request.
Required parameters: organization, repository, token, pull-request, extras[commit_id, labels_to_add, labels_to_delete]
- list_commits:
Fetches a list of commits for a specified pull request.
Required parameters: organization, repository, token, pull-request
- list_deleted_files:
Fetches a list of deleted files for a specific commit.
Required parameters: organization, repository, token, extras[commit_id]
- open_pr:
Opens a PR, using the supplied head branch into base branch.
Required parameters: organization, repository, token, extras[head, base, title]
Quick start (4 Steps)
(1/4) Creating a new Repository
- Create a new Github repo
- Create a local folder and push it to the new repository:
mkdir sample-repo
cd sample-repo
echo "# dummy" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/$(git config user.name)/sample-repo.git
git push -u origin main
(2/4) Creating a new Pull Request
- Create a new branch (and push it to Github):
git checkout -b my_new_branch
echo "some sample text" > test.txt
git add test.txt
git commit -m "commit for demo purposes"
git push --set-upstream origin my_new_branch
- Open a Pull request in Github UI:
(3/4) Create a Github Personal Access Token (PAT)
- Create a PAT in Github UI
- Save the PAT somewhere
(4/4) Use py-github-helper to Post a Comment
- Install the PyPi package:
pip install py-github-helper
- Test out the CLI command:
python3 -m py-github-helper \
-t $MY_PAT -o $(git config user.name) -r sample-repo -l 1 -c add_comment \
-e '{"message": "This message was successfully posted via gitub_api."}'
Metadata
Release files for py-github-helper 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_github_helper-0.2.6.tar.gz | 23.5 kB | Without provenance | Details for py_github_helper-0.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_github_helper-0.2.6-py3-none-any.whl | Python 3 | none | any | Details for py_github_helper-0.2.6-py3-none-any.whl |
Total release size: 46.6 kB
Release files / py_github_helper-0.2.6.tar.gz
| Download URL | py_github_helper-0.2.6.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7e48ff02e1397e76bd15a05f5cceda08281293d402f05d347888f622a1db9dd
|
|
BLAKE2b-256 checksum How to use checksums |
2149e62a64b71a652c0fa104332f1105e89cc41ebb6321ec2832c6d3ed4c26c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / py_github_helper-0.2.6-py3-none-any.whl
| Download URL | py_github_helper-0.2.6-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1738713945b0b8a1a509bfc4e0348caf3edee6c6dbd54ed2569bc34f002525a9
|
|
BLAKE2b-256 checksum How to use checksums |
ded723c5daff1247588339a342f5448444d0e6e8c9c426b5f21c2c024007276e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for py-github-helper 0.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.