Python Script for interacting with Github API
Project description
github_api
Python Script for interacting with Github API.
Example
python3 -m py-github-helper \
-t $GH_TOKEN -o org-not-included -r sample-repo -l 1 -c add_comment \
-e '{"message": "This message was successfully posted via gitub_api."}'
Quick start
- 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
- Install this PyPi package:
pip install py-github-helper
- Create a new branch (and push it to Github):
git checkout -b new_branch
echo "some sample text" > test.txt
git add test.txt
git commit -m "commit for demo purposes"
git push --set-upstream origin new_branch
- Open a Pull request:
- Create a PAT (and save it somewhere):
- Test out
py-github-helper
:
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."}'
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.
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_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]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py-github-helper-0.1.4.tar.gz
(9.1 kB
view hashes)
Built Distribution
Close
Hashes for py_github_helper-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0bd944d4ab533c06c14249d74de38a808d4807caa733f79a01f74ec82c6e47f |
|
MD5 | dbda03364f4e891413c34f8b542b9cfe |
|
BLAKE2b-256 | e88b539958646fcc39d9b2d5e8e9659a933b62e30342cc3bc0e9160346f513fc |