awesome-notebooks icon indicating copy to clipboard operation
awesome-notebooks copied to clipboard

Notion - Create Github issues from new items in Notion databases

Open Dr0p42 opened this issue 2 years ago • 5 comments

Naas

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 :

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}"')

Dr0p42 avatar Mar 31 '22 13:03 Dr0p42

🚀 Branch and template have been created and pushed.

You should work on:

Dr0p42 avatar Mar 31 '22 14:03 Dr0p42

Hi @calok64 ! I just moved the card in "In Progress". Let us know if you have any question !

FlorentLvr avatar Apr 15 '22 12:04 FlorentLvr

@Dr0p42 is this work completed ? looks like because you have attached a jupyter notebook related the same Can you please confirm ?

calok64 avatar Apr 16 '22 05:04 calok64

Hello @calok64, no it's not done, the notebook was added as guidelines to help the contributor going to take this card :)

Dr0p42 avatar Apr 16 '22 06:04 Dr0p42

@FlorentLvr I know you already did it for us, could you open source when you have time please.

Dr0p42 avatar May 11 '22 14:05 Dr0p42