Skip to content
Merged
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
148 changes: 148 additions & 0 deletions .github/workflows/ci.yml
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
Comment thread
coderabbitai[bot] marked this conversation as resolved.

- 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
Comment thread
5ouma marked this conversation as resolved.
4 changes: 2 additions & 2 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- id: upload-git-commit-notion
name: Upload Git Commits to Notion
description: Upload not pushed Git commits data to Notion database
entry: pre-commit/scripts/upload-git-commit-notion
language: script
entry: pre-commit/hooks/upload-git-commit-notion/main.ts
language: deno
always_run: true
verbose: true
pass_filenames: false
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ repos:
- id: upload-git-commit-notion
```

> [!IMPORTANT]
> You need [prek](https://prek.j178.dev) to run the hooks.

<br />

## 🎨 Renovate
Expand Down
11 changes: 11 additions & 0 deletions pre-commit/hooks/upload-git-commit-notion/deno.json
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"
}
}
124 changes: 124 additions & 0 deletions pre-commit/hooks/upload-git-commit-notion/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions pre-commit/hooks/upload-git-commit-notion/main.ts
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);
Comment thread
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);
}
44 changes: 0 additions & 44 deletions pre-commit/scripts/upload-git-commit-notion

This file was deleted.

Loading