Contents¶
Overview¶
tests | |
---|---|
package | |
docs |
Python client for GitHub API
Installation¶
requires python 3.5+
Yes that is opinionated. Python 2 is near the end of the life and this is a new project.
Note octokit and octokit.py were already taken in the cheese shop
pip install octokitpy
Documentation¶
https://octokitpy.readthedocs.io/en/latest/
Examples¶
REST API:
from octokit import Octokit
repos = Octokit().repos.get_for_org(org='octokit', type='public')
# Make an unauthenticated request for the public repositories of the octokit organization
Webhooks:
from octokit import webhook
webhook.verify(headers, payload, secret, events=['push'])
octokit.py
provides a function to verify webhooks sent to your application.
- headers
- dictionary of request headers
- payload
- string; payload of request
- secret
- string; secret provided to GitHub to sign webhook
- events
- list; events that you want to receive
- verify_user_agent
- boolean; whether or not you want to verify the user agent string of the request
- return_app_id
- boolean; whether or not you want to return the app id from the ping event for GitHub applications. This will only return the
id
if the event is theping
event. Otherwise the return value will be boolean.
Authentication¶
Instatiate a client with the authentication scheme and credentials that you want to use.
basic:
octokit = Octokit(auth='basic', username='myuser', password='mypassword')
octokit.repos.get_for_org(org='octokit', type='private')
token:
response = Octokit(auth='token', token='yak').authorization.get(id=100)
app:
octokit = Octokit(auth='app', app_id='42', private_key=private_key)
app installation:
octokit = Octokit(auth='installation', app_id='42', private_key=private_key)
For applications provide the application id either from the ping webhook or the application’s page on GitHub.
The private_key
is a string of your private key provided for the application.
The app
scheme will use the application id and private key to get a token for the first installation id of the application.
API Schema/Routes/Specifications¶
One can instantiate the Octokit
with routes=specification
where the specification
is one of api.github.com
, ghe-2.15
, etc.
TODOs¶
GitHub APIs¶
[-] REST (see best practices, integration tests, and errors)
[ ] GraphQL client
[x] GitHub Apps
[ ] OAuth Apps
[x] Webhooks
Data¶
The octokit
client based on the available route data and webhook data
[x] Periodically, check if ``routes.json`` has changed and if so fetch and open a PR for it to be merged
[ ] Periodically, check if ``webhook-names.json`` has changed and if so fetch and open a PR for it to be merged
Tests¶
[x] unit tests
[ ] integration tests - need fixtures to assert against
[ ] coverage uploaded to code climate -- not sure why it is not working
Errors¶
[ ] Raise :code:`OctokitValidationError` for param validation error
[ ] Raise :code:`OctokitAuthenticationError` for auth error
[ ] Raise :code:`OctokitRateLimitError` for rate limiting errors
Best Practices¶
[ ] throttling
[ ] handles rate limiting
[x] pagination
Documentation¶
[ ] Auto generated documentation
Deployment¶
[x] Deploy wheels
[ ] Make GitHub releases work
Check box guide
[ ] Incomplete
[-] Partially completed
[x] Completed
Credits¶
Package based on cookiecutter-pylibrary
License¶
MIT
Usage¶
To use octokit.py in a project:
import octokit
Chaining requests¶
issue = Octokit().issues.edit(owner='testUser', repo='testRepo', number=1, state='closed')
# If the previous request had a required url attribute, the next request will use the previous url attribute
# This does not apply attributes that are part of the body of the request on post, patch, etc.
issue.pull_requests.create(head='branch', base='master', title='Title')
# Previous attributes can be overridden
issue.pull_requests.create(owner='differentOwner', head='branch', base='master', title='Title')
Responses¶
Responses are the Octokit instance with state in json
and response
. json
is the result of the Requests response.json()
. response
is the json as a python object.
octokit.json¶
issue = Octokit().issues.get(owner='testUser', repo='testRepo', number=1)
issue.json['title'] # Title of issue
octokit.response¶
issue = Octokit().issues.get(owner='testUser', repo='testRepo', number=1)
issue.response.title # Title of issue
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps.
Bug reports¶
When reporting a bug please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Documentation improvements¶
octokit.py could always use more documentation, whether as part of the official octokit.py docs or even on the web in blog posts, articles, and such.
Feature requests and feedback¶
The best way to send feedback is to file an issue at https://github.com/khornberg/octokit.py/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that code contributions are welcome :)
Development¶
To set up octokit.py for local development:
Fork octokit.py (look for the “Fork” button).
Clone your fork locally:
git clone git@github.com:your_name_here/octokit.py.git
Create a branch for local development:
git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, run all the checks, doc builder and spell checker with tox one command:
tox
Commit your changes using the commit message guide and push your branch to GitHub:
git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Commit Message Guidelines¶
Prefix messages with one of the prefixes below followed by a colon:
Example message:
Style: yapf
- Bug Fix
- A fix for a bug
- Feature
- Something that did not previously exist
- Enhancement
- Something that previously existed, but now works slightly differently in some way
- Doc
- Documentation
- Version
- A new (semver) version number
- Dependency
- Updating the dependencies Updating 3rd party APIs ect
- Refactor
- Improvements to code with no modification of external behavior Include Performance Enhancements
- Test
- New tests or altering old tests without changing any production code Helper code intended to assist ONLY with test creation
- Style
- Linting violations, code formatting, etc
- Peripheral
- Updates to builds, deploys, etc
Pull Request Guidelines¶
If you need some code review or feedback while you’re developing the code just make the pull request.
For merging, you should:
- Include passing tests (run
tox
) [1]. - Update documentation when there’s new API, functionality etc.
- Add yourself to
AUTHORS.rst
.
[1] | If you don’t have all the necessary python versions available locally you can rely on Travis - it will run the tests for each change you add in the pull request. It will be slower though … |
Tips¶
To run a subset of tests:
tox -e envname -- py.test -k test_myfeature
To run all the test environments in parallel (you need to pip install detox
):
detox
Authors¶
- Kyle Hornberg - https://khornberg.github.io