• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

NiklasRosenstein/python-github-bot-api: API for creating GitHub bots and webhook ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

NiklasRosenstein/python-github-bot-api

开源软件地址:

https://github.com/NiklasRosenstein/python-github-bot-api

开源编程语言:

Python 100.0%

开源软件介绍:

github-bot-api

API for creating GitHub bots and webhooks in Python.

Note: If you want to make use of GithubApp.app_client() or GithubApp.installation_client(), you need to install PyGithub.

Quickstart (Webhook)

  1. Create a new Smee channel on https://smee.io
  2. Install smee-client (e.g. yarn global add smee-client)
  3. Run smee -u <SMEE_CHANNEL_URL> -P /event-handler -p 5000
  4. Create a Python script with the below contents and run it
from github_bot_api import Event, Webhook
from github_bot_api.flask import create_flask_app

def on_any_event(event: Event) -> bool:
  print(event)
  return True

webhook = Webhook(secret=None)
webhook.listen('*', on_any_event)

import os; os.environ['FLASK_ENV'] = 'development'
flask_app = create_flask_app(__name__, webhook)
flask_app.run()

Quickstart (Application)

  1. Create a GitHub App, including a private key
  2. Set the APP_ID and PRIVATE_KEY_FILE environment variables
  3. Run the following Python script
import os
from github_bot_api import GithubApp

with open(os.environ['PRIVATE_KEY_FILE']) as fp:
  private_key = fp.read()

app = GithubApp(
  user_agent='my-bot/0.0.0',
  app_id=int(os.environ['APP_ID']),
  private_key=private_key)

print(app.app_client().get_app().owner)

Combined Example

# ...

app = GithubApp(...)
webhook = Webhook()

@webhook.listen('pull_request')
def on_pull_request(event: Event) -> bool:
  client = app.installation_client(event.payload['installation']['id'])
  repo = client.get_repo(event['repository']['full_name'])
  pr = repo.get_pull(event['pull_request']['number'])
  pr.create_issue_comment('Hello from my own bot!')
  return True

# ...



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap