From b3aec84b87c0f3361d9cad7bb70797a9f5a6ac25 Mon Sep 17 00:00:00 2001 From: Narek Amirbekian Date: Tue, 21 Jun 2022 11:45:48 -0700 Subject: [PATCH 1/2] added feature --- .gitignore | 3 ++- README.md | 3 +++ docs/feature/invoice.feature | 0 git_notion/git_notion.py | 5 ++--- setup.cfg | 1 + setup.py | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 docs/feature/invoice.feature diff --git a/.gitignore b/.gitignore index 43091aa..ba59ce5 100644 --- a/.gitignore +++ b/.gitignore @@ -102,4 +102,5 @@ ENV/ .mypy_cache/ # IDE settings -.vscode/ \ No newline at end of file +.vscode/ +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 9bc2e33..9eb7dec 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,14 @@ 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= 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. @@ -38,6 +40,7 @@ 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 diff --git a/docs/feature/invoice.feature b/docs/feature/invoice.feature new file mode 100644 index 0000000..e69de29 diff --git a/git_notion/git_notion.py b/git_notion/git_notion.py index 6bbbfe1..d750ac3 100644 --- a/git_notion/git_notion.py +++ b/git_notion/git_notion.py @@ -10,7 +10,6 @@ from notion.client import NotionClient from md2notion.upload import upload - TOKEN = os.getenv("NOTION_TOKEN_V2", "") _client = None @@ -57,12 +56,12 @@ def sync_to_notion(repo_root: str = "."): config = ConfigParser() config.read(os.path.join(repo_root, "setup.cfg")) repo_name = 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) diff --git a/setup.cfg b/setup.cfg index d9f80e1..55f095f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,3 +25,4 @@ collect_ignore = ['setup.py'] [git-notion] notion_root_page = https://www.notion.so/Git-Documents-6cf97b2d7ab64a7d964c7a7bcc42f9aa +search_by_regex = "**/*.feature" diff --git a/setup.py b/setup.py index c37726b..ccbe6f1 100644 --- a/setup.py +++ b/setup.py @@ -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, ) From 019ad63a23d9592b702c52e503d9df7f9c74c4b2 Mon Sep 17 00:00:00 2001 From: Giulio De donato Date: Tue, 13 Dec 2022 18:40:49 +0100 Subject: [PATCH 2/2] added path as variable --- docs/feature/invoice.feature | 0 feature/friday.feature | 7 +++++++ git_notion/git_notion.py | 2 +- setup.py | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) delete mode 100644 docs/feature/invoice.feature create mode 100644 feature/friday.feature diff --git a/docs/feature/invoice.feature b/docs/feature/invoice.feature deleted file mode 100644 index e69de29..0000000 diff --git a/feature/friday.feature b/feature/friday.feature new file mode 100644 index 0000000..3786d9f --- /dev/null +++ b/feature/friday.feature @@ -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" \ No newline at end of file diff --git a/git_notion/git_notion.py b/git_notion/git_notion.py index d750ac3..dac61b2 100644 --- a/git_notion/git_notion.py +++ b/git_notion/git_notion.py @@ -55,7 +55,7 @@ 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") diff --git a/setup.py b/setup.py index ccbe6f1..9f4bcbe 100644 --- a/setup.py +++ b/setup.py @@ -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',