简体   繁体   中英

How to identify / list all of the GITHUB webhooks (URL) using Python?

I am working with the requests and Github python libraries, basically to build a script to update the webhooks (URL) in github, under certains conditions.

Using the following code, I get some info like GitHub organization, GitHub user and GitHub repositories (just to give some examples):

**from github import Github
import json
import requests
def function_example():
    gh = Github('MY_TOKEN_HERE', base_url='https://MY-GITHUB-DOMAIN/api/v3')
    get_users = gh.get_user().name
    print("USERNAME: ", get_users)
    print(" ")
    # user_repos = gh.repos.list().all()
    user_repos = gh.get_repos()
    print("REPOS: ", user_repos)
    print(" ")
    orgs = gh.get_organization('MY_GITHUB_ORG_HERE')
    print("ORGS: ", orgs)
    print(" ")
if __name__ == '__main__':
    function_example()
# Eof**

However, I need to identify the webhooks URL (located in Github -> Repo -> Setting -> Webhooks), in order to update them with a new domain. The problem is that I haven't found how to get or list all of the webhooks for an specific repository.

I have been reading about a Licenced library called smartsheet , and it looks like that using that library we could handler the webhooks... but I don't have that library installed here :-(

Is it possible to list / identify the URL webhooks, using those python libraries (requests and/or Github) ?

If so, could somebody send me an example ?

I will be really thankful of that !

Jose

There is the GetHooks() call. See https://developer.github.com/v3/repos/hooks/

It looks like there is a Github Webhooks API: https://developer.github.com/v3/repos/hooks/#list-hooks

Using requests, you ought to be able to perform CRUD operations on the webhooks for each of your repos.

The call to list a repo's hooks would look something like this:

import requests
token = "YOUR_OAUTH_OR_PERSONAL_ACCESS_TOKEN"
repo = "connect4"
user = "dreslan"
url = "https://api.github.com/repos/{}/{}/hooks".format(user, repo)
headers = {"Authorization": "token {}".format(token)}
r = requests.get(url, headers=headers)
# r.content will display the result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM