!pip install Notion
import os
from notion.client import NotionClient
# Obtain the `token_v2` value by inspecting your browser cookies on a logged-in (non-guest) session on Notion.so
client = NotionClient(token_v2=os.environ['key'])
# If the token can be associated to multiple emails, we choose the correct one
client.set_user_by_email(os.environ['email '])
database_url = "https://www.notion.so/deepnote/14e4cb5528404d0e8b57cfe687e9355f?v=090f36ef8be94d3988beed2dc550a0d6"
def close_issues_with_pr(pr_link):
collection = client.get_block(database_url).collection
for row in collection.get_rows():
if row.pr == pr_link:
row.status = 'Done'
from github_webhook import Webhook
from flask import Flask
app = Flask(__name__) # Standard Flask app
webhook = Webhook(app, secret="U7L56ddCXr") # Defines '/postreceive' endpoint, with a secret (see below)
# Defines a handler for the 'pull_request' event
def on_pull_request(data):
print("Got push with: {0}".format(data))
if data['action'] == 'closed':
# The PR has been closed or merged, so set the corresponding Notion ticket to Done
number = data['number']
print(f"Closed PR #{number}")
close_issues_with_pr(data['pull_request']['html_url'])
app.run(host="0.0.0.0", port=8080)