Pygithub: Support for github apps

Created on 26 Jun 2018  路  5Comments  路  Source: PyGithub/PyGithub

I am trying to perform oauth using my github app and then read authenticated users repository and organization. However for queries related to "list installations for user", "list repositories accessible to the user for installation" and many other endpoints, I am not able to get the pygithub apis for the same.

ref link : http://pygithub.readthedocs.io/en/latest/apis.html

PS. Previously I was using oauth app and was able to perform the flow, now since I also require to listen to events for which I needed to subscribe to webhooks, so I switched to github app.

Hacktoberfest feature request

Most helpful comment

Would like to work on it.

All 5 comments

Would like to work on it.

this feature would be very helpful :+1:

This is covered in #1021 but is awaiting approval/merge, @sfdye can we get eyes on it?

To get auth_token:

`
installations_url = "https://github.com/api/v3/app/installations"
installations_response = requests.get(installations_url, headers=headers, auth=CustomJWTAuth())
installations_response.raise_for_status()

for item in installations_response.json():
    installation_id = item['id']
    #print (installation_id)
    access_tokens_url = "https://github.com/api/v3/app/installations/{installation_id}/access_tokens".format(
        installation_id=installation_id)
    access_tokens_response = requests.post(access_tokens_url, headers=headers, auth=CustomJWTAuth())
    access_tokens_response.raise_for_status()
    #print (access_tokens_response.json())


    token = access_tokens_response.json()['token']
    #print (token)
    #return github3.login(token=token)
    return token

raise Exception("No app installations")

`

Check out https://pypi.org/project/github-bot-api/, it uses provides you with a PyGithub client for the GitHub app and its installations. (Disclaimer: I am the author of that package)

Was this page helpful?
0 / 5 - 0 ratings