Git Product home page Git Product logo

octokit.py's Introduction

Overview

tests | CodeClimate Quality Status Test Coverage
package
docs

Python client for GitHub API

Installation

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.list_for_user(username="octokit")
for repo in repos.json:
    print(repo["name"])
# Make an unauthenticated request for octokit's public repositories

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 the ping event. Otherwise the return value will be boolean.

Note that webhook names are available at from octokit_routes import webhook_names

Authentication

Instantiate a client with the authentication scheme and credentials that you want to use.

basic:

octokit = Octokit(auth='basic', username='myuser', password='mypassword')

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.

Data

The octokit client based on the available route data and webhook data

TODOs

GitHub APIs

[-] REST (see best practices, integration tests, and errors)

[ ] GraphQL client

[x] GitHub Apps

[ ] OAuth Apps

[x] Webhooks

Tests

[x] unit tests

[ ] integration tests - need fixtures to assert against

[x] coverage uploaded to code climate

Errors

[ ] Raise `OctokitValidationError` for param validation error

[ ] Raise `OctokitAuthenticationError` for auth error

[ ] Raise `OctokitRateLimitError` for rate limiting errors

Best Practices

[ ] throttling

[ ] handles rate limiting

[x] pagination

Generated Documentation

[ ] Auto generated documentation

Deployment

[x] Deploy wheels

[ ] GitHub releases

Check box guide

[ ] Incomplete

[-] Partially completed

[x] Completed

Development

To run the all tests run:

tox

Contributing

Pull requests are very welcome!

Please see CONTRIBUTING.md for more information.

Credits

Package based on cookiecutter-pylibrary

License

MIT

octokit.py's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

octokit.py's Issues

Validate fails with nested objects

This is slightly related to #51 as it's validating an optional parameter but the exception is worth looking into. The parameter comments contains a list object which the validation breaks on.

pulls = Octokit(auth='installation', app_id=APP_ID, private_key=private_key).pulls
pulls.create_a_pull_request_review(owner='Foo', repo='demo', number=1, body='hello world', event='COMMENT')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/ahmed/pyenvchatback/lib/python3.6/site-packages/octokit/__init__.py", line 192, in _api_call
    self._validate(kwargs, parameter_map)
  File "/Users/ahmed/pyenv/chatback/lib/python3.6/site-packages/octokit/__init__.py", line 30, in _validate
    self._validate_required_params(required_params, cached_kwargs)
  File "/Users/ahmed/pyenv/chatback/lib/python3.6/site-packages/octokit/__init__.py", line 38, in _validate_required_params
    utils.walk_path(cached_kwargs, p.split('.'))
  File "/Users/ahmed/pyenv/chatback/lib/python3.6/site-packages/octokit/utils.py", line 24, in walk_path
    walk_path(obj[path[0]], path[1:])
KeyError: 'comments[]'

Error handling

I just ran into this... I got rate limited and the error message seemed fairly cryptic (since it essentially failed silently)

o = Octokit(auth='token', token="mykey")
repo = o.repos.get(owner="myowner", repo="myrepo")
repo.response # is <class 'octokit.ResponseData'>
repo.response.message # is "API rate limit exceeded for user ID XXXXX"

In my case what ended up happening was that I was trying to do something like

o = Octokit(auth='token', token="mykey")
repo = o.repos.get(owner="myowner", repo="myrepo")
repo.response.name # do something with this...

and I ended up getting an AttributeError

AttributeError: type object 'ResponseData' has no attribute 'name'

I'm not sure exactly what the behavior should be.... I assume there should be some exceptions raised in there when non-successful status codes are encountered... maybe? Thoughts?

param_value no present

def _validate_params(self, param_value, kwarg, value, required_params):

If the param_value is None then the data for that function indicates that the parameter is unknown. This is likely a user error.

Perhaps the error can be more helpful in saying such

installation id

"installation": {
    "id": 12345	
  }

Use that from the webhook to do things authorized as an app?

Determine how to know when a release occurs

When octokitpy-routes has a minor version change
add a minor version here

When octokitpy-routes has a major version change
add a major version here

Ad-hoc others when the version changes in the file

Tie this to git tags?

flow?

if version not in git tags
create tag
create release
deploy to pypi

would need to look at the PR from dependabot in an action and change the version and add a commit

Required parameters of optional parameters are still required

example is creating a check run.

output is optional but the parameters if one uses output are still required

This is because the validation of required parameters is not taking into consideration of whether or not the whole path is currently in use.

The data has output.title as required. This is only true if output is a parameter.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/pull_request.yml
  • actions/setup-python v2
.github/workflows/push.yml
  • actions/setup-python v2
pip_requirements
docs/requirements.txt
  • sphinx ==4.5.0
  • sphinx-rtd-theme ==0.5.2
requirements.txt
  • python-jose ==3.3.0
  • requests ==2.27.1
  • octokitpy-routes ==2.5.0

  • Check this box to trigger a request for Renovate to run again on this repository

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6024723: character maps to <undefined>

After fresh install on Windows using conda, following the example in the docs, I did:

from octokit import Octokit

and then I got:

>>> from octokit import Octokit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\josee\Documents\mag\tesis\dev\env_github_app\lib\site-packages\octokit\__init__.py", line 6, in <module>
    from octokit_routes import specifications
  File "C:\Users\josee\Documents\mag\tesis\dev\env_github_app\lib\site-packages\octokit_routes\__init__.py", line 31, in <module>
    specifications = {spec.replace(".json", ""): _load_spec(spec) for spec in specs}
  File "C:\Users\josee\Documents\mag\tesis\dev\env_github_app\lib\site-packages\octokit_routes\__init__.py", line 31, in <dictcomp>
    specifications = {spec.replace(".json", ""): _load_spec(spec) for spec in specs}
  File "C:\Users\josee\Documents\mag\tesis\dev\env_github_app\lib\site-packages\octokit_routes\__init__.py", line 21, in _load_spec
    return _load_json(os.path.join(__location__, "routes", spec_name))
  File "C:\Users\josee\Documents\mag\tesis\dev\env_github_app\lib\site-packages\octokit_routes\__init__.py", line 9, in _load_json
    return json.load(f)
  File "C:\devel\conda\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\devel\conda\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6024723: character maps to <undefined>

I did a quick fix replacing:

with open(path, "r") as f:

with:

with open(path, "r", encoding="utf8") as f:

at line 9 in ...\site-packages\octokit_routes_init_.py inside the virtual enviroment

Thanks for this great library

Bests, José.-

boolean types

When trying to create a repo passing has_issues =False does not seem to work but has_issues='false' does

Make the python boolean work

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.