Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ ENV/
.mypy_cache/

# IDE settings
.vscode/
.vscode/
.idea/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ pip install -e .
`NOTION_TOKEN_V2` - Can be found in your [browser cookies](https://www.redgregory.com/notion/2020/6/15/9zuzav95gwzwewdu1dspweqbv481s5) for Notion's website.
`NOTION_ROOT_PAGE` - URL for notion page. Repo docs will be a new page under this page.
`NOTION_IGNORE_REGEX` - Regex for paths to ignore.
`NOTION_SEARCH_BY_REGEX` - Regex for pattern for file search.

These environment variables can be set.
```bash
export NOTION_TOKEN_V2=<YOUR_TOKEN>
export NOTION_ROOT_PAGE="https://www.notion.so/..." # Can be in setup.cfg as well
export NOTION_IGNORE_REGEX="models/.*" # Can be in setup.cfg as well
export NOTION_SEARCH_BY_REGEX="**/*.md" # Can be in setup.cfg as well
```

These parameters can be set in the `setup.cfg` for the repo.
```
[git-notion]
ignore_regex = models/.*
notion_root_page = https://www.notion.so/...
search_by_regex = "**/*.md"
```

## Usage
Expand Down
7 changes: 7 additions & 0 deletions feature/friday.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Is it Friday yet?
Everybody wants to know when it's Friday

Scenario: Sunday isn't Friday
Given today is Sunday
When I ask whether it's Friday yet
Then I should be told "Nope"
7 changes: 3 additions & 4 deletions git_notion/git_notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from notion.client import NotionClient
from md2notion.upload import upload


TOKEN = os.getenv("NOTION_TOKEN_V2", "")
_client = None

Expand Down Expand Up @@ -56,13 +55,13 @@ def sync_to_notion(repo_root: str = "."):
os.chdir(repo_root)
config = ConfigParser()
config.read(os.path.join(repo_root, "setup.cfg"))
repo_name = os.path.basename(os.getcwd())

repo_name = os.getenv("NOTION_REPO_NAME") or config.get('git-notion', 'notion_repo_name', fallback=os.path.basename(os.getcwd()))
root_page_url = os.getenv("NOTION_ROOT_PAGE") or config.get('git-notion', 'notion_root_page')
ignore_regex = os.getenv("NOTION_IGNORE_REGEX") or config.get('git-notion', 'ignore_regex', fallback=None)
search_by = os.getenv("NOTION_SEARCH_BY_REGEX") or config.get('git-notion', "search_by_regex", fallback="**/*.md")
root_page = get_client().get_block(root_page_url)
repo_page = get_or_create_page(root_page, repo_name)
for file in glob.glob("**/*.md", recursive=True):
for file in glob.glob(search_by, recursive=True):
if ignore_regex is None or not re.match(ignore_regex, file):
print(file)
upload_file(repo_page, file)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ collect_ignore = ['setup.py']

[git-notion]
notion_root_page = https://www.notion.so/Git-Documents-6cf97b2d7ab64a7d964c7a7bcc42f9aa
search_by_regex = "**/*.feature"
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
description="Syncs Github Mmarkdown files to Notion",
description="Syncs Github Markdown or any files to Notion",
entry_points={
'console_scripts': [
'git-notion=git_notion.cli:main',
Expand All @@ -47,6 +47,6 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/NarekA/git-notion',
version='0.2.4',
version='0.2.5',
zip_safe=False,
)