awesome-notebooks
awesome-notebooks copied to clipboard
Notion - Create Github issues from new items in Notion databases

Notion - Create Github issues from new items in Notion databases
Tags: #notion #github #operations #automation
Author: Firstname Lastname
This notebook is used to create Github Issues when new Notion pages are being created in a database.
We will store Github issues urls as a property in notion pages to know which one we already dealt with.
References :
- Notion driver:
- Github SDK: https://github.com/PyGithub/PyGithub
Input
Import libraries
from naas_drivers import notion
from github import Github
Setup Notion
# Notion token
notion_token = "..."
# Specify database id
notion_database_id = "..."
notion.connect(notion_token)
Setup Github
# Github token
github_token = "..."
# Github repo on which we want to create issues.
github_repo_name = "..."
gh_client = Github(github_token)
Setup Naas
# Schedule your notebook to run ever hours.
naas.scheduler.add(cron="0 * * * *")
#-> Uncomment the line below to remove your scheduler
# naas.scheduler.delete()
Model
Query notion database
The goal here is to query the database and fetch only pages who don’t have a value in the “Github issue url” property.
database = notion.database.get(notion_database_id)
# Query only pages for which we did not created an issue already.
pages = ...
Create Github issues
def create_github_issue(gh_client, repo_name, title, body):
repo = gh_client.get_repo(github_repo_name)
repo.create_issue(title=title, body=body)
...
Output
Create all issues
for page in pages:
...
# Get the content of the Notion page as Markdown.
notion_markdown_content = ...
...
create_github_issue(gh_client, github_repo_name, page.properties['Name'], notion_markdown_content)
print(f'✅ Issue created in github at "{issue_url}"')
🚀 Branch and template have been created and pushed.
You should work on:
Hi @calok64 ! I just moved the card in "In Progress". Let us know if you have any question !
@Dr0p42 is this work completed ? looks like because you have attached a jupyter notebook related the same Can you please confirm ?
Hello @calok64, no it's not done, the notebook was added as guidelines to help the contributor going to take this card :)
@FlorentLvr I know you already did it for us, could you open source when you have time please.