Skip to content
This repository was archived by the owner on Nov 14, 2021. It is now read-only.

narkdown/notion2github

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Notion2Github

Notion2Github

GitHub Action: View on Marketplace Demo: available Version: v1.0.1 license: MIT

Automatic syncronization from Notion to Github


⚠️ NOTE: Narkdown is dependent on notion-py, the unofficial Notion API created by Jamie Alexandre. It can not gurantee it will stay stable. If you need to use in production, I recommend waiting for their official release.


Usage

Using encrypted token_v2 in a workflow

notion2github-image-0

The token_v2 is required to get contents from Notion. The token_v2 of notion is a variable that should not be shared. So you can use encrypted secrets in your repository.

For more information, See "Using encrypted secrets in a workflow"

Parameters

Name Description Required Default
database-url URL of the Notion database to extract. required
docs-directory Directory in which the Notion pages to extract will be stored. "docs"
filter-prop Property of the filter to apply to the notion database. ""
filter-value Value of the filter to apply to the notion database. ""

Database template page for test

Here is an database template page for importing pages from the database. Move to that page, duplicate it, and test it.

notion2github-image-1

Example Workflow

Create workflow in .github/workflows/**.yml

Example 1 (run on push & pull request in main)

name: Notion2Github
on:
  pull_request:
  push:
    branches:
      - main
jobs:
  auto-sync-from-notion-to-github:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Notion2Github
        uses: younho9/notion2github@v1
        with:
          database-url: 'https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad'
          docs-directory: docs/test
          filter-prop: Category
          filter-value: Test
        env:
          NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}

      - name: Format documents
        uses: creyD/prettier_action@v3.1
        with:
          prettier_options: --write ./docs/**/*.md
          commit_message: 'docs: Update docs (auto)'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Example 2 (scheduled)

name: Notion2Github
on:
  schedule:
    - cron: '0 14 * * *'
jobs:
  auto-sync-from-notion-to-github:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Notion2Github
        uses: younho9/notion2github@v1
        with:
          database-url: 'https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad'
          docs-directory: docs/test
          filter-prop: Category
          filter-value: Test
        env:
          NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}

      - name: Format documents
        uses: creyD/prettier_action@v3.1
        with:
          prettier_options: --write ./docs/**/*.md
          commit_message: 'docs: Update docs (auto)'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Useful site for crontab setting

Live examples

Configuring Narkdown

Narkdown provides some configuration for how to extract documents. You can configure Narkdown via narkdown.config.json .

Create narkdown.config.json in root directory of your repository.

For more information on configure your environment, see the document in Nakdown.

// narkdown.config.json
{
  "exportConfig": {
    "recursiveExport": true,
    "createPageDirectory": true,
    "addMetadata": false,
    "lowerPathname": false,
    "lowerFilename": false,
    "lineBreak": false
  },
  "databaseConfig": {
    "categoryColumnName": "Category",
    "tagsColumnName": "Tags",
    "createdTimeColumnName": "Created Time",
    "statusColumnName": "Status",
    "currentStatus": "✅ Completed",
    "nextStatus": "🖨 Published"
  }
}

License

MIT © younho9