-
-
Notifications
You must be signed in to change notification settings - Fork 0
Use Deno as a upload-git-commit-notion language #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| name: 🎽 CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - pre-commit/hooks/**/* | ||
| - .github/workflows/ci.yml | ||
| pull_request: | ||
| paths: | ||
| - pre-commit/hooks/**/* | ||
| - .github/workflows/ci.yml | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| detect: | ||
| name: 🔄 Detect Deno Projects | ||
| runs-on: Ubuntu-Slim | ||
| timeout-minutes: 1 | ||
| outputs: | ||
| projects: ${{ steps.get-directories.outputs.result }} | ||
|
|
||
| steps: | ||
| - name: 🚚 Check out repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: 🔄 Filter changed files | ||
| id: filter | ||
| uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1 | ||
| with: | ||
| filters: | | ||
| hook: | ||
| - added|modified: ["pre-commit/hooks/**/*"] | ||
| ci: [".github/workflows/ci.yml"] | ||
| list-files: json | ||
|
|
||
| - name: 📁 Get directories | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | ||
| id: get-directories | ||
| with: | ||
| script: | | ||
| const path = require("path"); | ||
|
|
||
| if (JSON.parse(process.env.ci)) { | ||
| const globber = await glob.create("pre-commit/hooks/*/deno.json"); | ||
| const files = await globber.glob(); | ||
| return files.map(file => path.relative(process.env.GITHUB_WORKSPACE, path.dirname(file))); | ||
| } | ||
|
|
||
| const files = JSON.parse(process.env.files); | ||
| const dirs = files.map(file => file.match(/^(pre-commit\/hooks\/[^/]+)/)[1]); | ||
| return Array.from(new Set(dirs)); | ||
| env: | ||
| files: ${{ steps.filter.outputs.hook_files }} | ||
| ci: ${{ steps.filter.outputs.ci }} | ||
|
|
||
| lint-check: | ||
| name: 🧹 Lint Check | ||
| needs: detect | ||
| runs-on: Ubuntu-Slim | ||
| defaults: | ||
| run: | ||
| working-directory: ${{ matrix.project }} | ||
| timeout-minutes: 1 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| project: ${{ fromJson(needs.detect.outputs.projects) }} | ||
|
|
||
| steps: | ||
| - name: 🚚 Check out repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: 🦕 Set up Deno | ||
| id: setup-deno | ||
| uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4 | ||
| with: | ||
| cache: true | ||
|
|
||
| - name: 📦 Install dependencies | ||
| if: ${{ steps.setup-deno.outputs.cache-hit != 'true' }} | ||
| run: deno install --frozen | ||
|
|
||
| - name: 🧹 Lint check | ||
| run: deno lint | ||
|
|
||
| format-check: | ||
| name: 📝 Format Check | ||
| needs: detect | ||
| runs-on: Ubuntu-Slim | ||
| defaults: | ||
| run: | ||
| working-directory: ${{ matrix.project }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| project: ${{ fromJson(needs.detect.outputs.projects) }} | ||
| timeout-minutes: 1 | ||
|
|
||
| steps: | ||
| - name: 🚚 Check out repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: 🦕 Set up Deno | ||
| uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4 | ||
|
|
||
| - name: 📝 Format check | ||
| run: deno fmt --check | ||
|
|
||
| type-check: | ||
| name: 🔍 Type Check | ||
| needs: detect | ||
| runs-on: Ubuntu-Slim | ||
| defaults: | ||
| run: | ||
| working-directory: ${{ matrix.project }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| project: ${{ fromJson(needs.detect.outputs.projects) }} | ||
| timeout-minutes: 1 | ||
|
|
||
| steps: | ||
| - name: 🚚 Check out repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: 🦕 Set up Deno | ||
| id: setup-deno | ||
| uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4 | ||
| with: | ||
| cache: true | ||
|
|
||
| - name: 📦 Install dependencies | ||
| if: ${{ steps.setup-deno.outputs.cache-hit != 'true' }} | ||
| run: deno install --frozen | ||
|
|
||
| - name: 🔍 Type check | ||
| run: deno check --doc | ||
|
5ouma marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "permissions": { | ||
| "default": { "net": ["api.notion.com"], "env": true, "run": ["git", "op"] } | ||
| }, | ||
| "imports": { | ||
| "@roka/git": "jsr:@roka/git@0.4.0", | ||
| "git-url-parse": "npm:git-url-parse@16.1.0", | ||
| "@1password/op-js": "npm:@1password/op-js@0.1.13", | ||
| "@notionhq/client": "npm:@notionhq/client@5.20.0" | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env -S deno run -P | ||
|
|
||
| import { git } from "@roka/git"; | ||
| import gitUrlParse from "git-url-parse"; | ||
| import { item } from "@1password/op-js"; | ||
| import { Client } from "@notionhq/client"; | ||
|
|
||
| const range = { | ||
| from: Deno.env.get("PRE_COMMIT_FROM_REF"), | ||
| to: Deno.env.get("PRE_COMMIT_TO_REF"), | ||
| }; | ||
| const url = (() => { | ||
| const remoteUrl = Deno.env.get("PRE_COMMIT_REMOTE_URL"); | ||
| if (!remoteUrl) throw new Error("PRE_COMMIT_REMOTE_URL is not set"); | ||
| const { source, full_name } = gitUrlParse(remoteUrl); | ||
| return `https://${source}/${full_name}`; | ||
| })(); | ||
| const commits = await git().commit.log(range); | ||
|
5ouma marked this conversation as resolved.
|
||
|
|
||
| const [database_id, auth] = (() => { | ||
| const data = item.get("Notion Git Integration", { | ||
| fields: { label: ["database-id", "credential"] }, | ||
| }); | ||
| if (!Array.isArray(data)) throw new Error("Data is not an array"); | ||
| return data.map((field) => field.value); | ||
| })(); | ||
| const client = new Client({ auth }); | ||
|
|
||
| for (const commit of commits) { | ||
| const res = await client.pages.create({ | ||
| parent: { database_id }, | ||
| properties: { | ||
| Message: { title: [{ type: "text", text: { content: commit.subject } }] }, | ||
| ...(commit.body && { | ||
| Description: { | ||
| rich_text: [{ type: "text", text: { content: commit.body } }], | ||
| }, | ||
| }), | ||
| Hash: { rich_text: [{ type: "text", text: { content: commit.short } }] }, | ||
| URL: { url }, | ||
| Date: { date: { start: commit.author.date.toInstant().toString() } }, | ||
| }, | ||
| }); | ||
| console.log(res.id); | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.