Skip to content
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

[chore] Prepare fiest release #4

Merged
merged 1 commit into from
Nov 4, 2023
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
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/wise-dodos-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ai-craftsman": minor
---

Initial release
7 changes: 4 additions & 3 deletions .github/workflows/ai-review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
GITHUB_EVENT_PATH: ${{ github.event_path }}
LANGUAGE: Japanese
DEBUG: true
# CODING_GUIDE_PATH: GUIDE.md
# CODING_GUIDE_LEVEL: 2
CODING_GUIDE_READER: packages/ai-craftsman/dist/ci/codingGuide.js
CODING_GUIDE_PATH: GUIDE.md
CODING_GUIDE_LEVEL: 2
CODING_GUIDE_ENABLE_PATTERN: "AI Review.*ON"
# CODING_GUIDE_READER: packages/ai-craftsman/dist/ci/codingGuide.js
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Release

on:
push:
branches:
- main

permissions:
contents: write
issues: write
pull-requests: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: prebuild
run: pnpm install --frozen-lockfile

- name: Build
run: cd packages/ai-craftsman && pnpm build

- name: Zip output
run: zip release *.*

- uses: ncipollo/release-action@v1
with:
artifacts: "release.zip"
38 changes: 38 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "AI Craftsman"
description: "Fully customizable AI reviewer"
inputs:
BASE_REF:
description: "Value of github.base_ref"
required: true
OPENAI_API_KEY:
description: "OpenAI API Key"
required: true
GITHUB_TOKEN:
description: "Value of secrets.GITHUB_TOKEN"
required: true
GITHUB_EVENT_PATH:
description: "Value of github.event_path"
required: true
LANGUAGE:
description: "Your preferred language. Example: English"
required: false
default: "English"
DEBUG:
description: "Set true to enable debug mode"
required: false
CODING_GUIDE_PATH:
description: "File path of the coding guide. Relative path from the project root."
required: false
CODING_GUIDE_LEVEL:
description: "Hierarchy of markdowns representing each rule."
required: false
CODING_GUIDE_ENABLE_PATTERN:
description: "Regular expression patterns for rules that enable review by AI."
required: false
default: ".*"
CODING_GUIDE_READER:
description: "File path of the custom script that returns each rule"
required: false
runs:
using: "node20"
main: "packages/ai-craftsman/dist/bin.js"
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"scripts": {
"build": "cd packages/ai-craftsman && pnpm build"
"build": "cd packages/ai-craftsman && pnpm build",
"update:version": "changeset version",
"release": "changeset publish"
},
"keywords": [],
"devDependencies": {
"@changesets/changelog-github": "0.4.8",
"@changesets/cli": "2.26.2",
"@tsconfig/strictest": "2.0.2",
"typescript": "5.2.2",
"vitest": "0.34.6"
Expand Down
9 changes: 6 additions & 3 deletions packages/ai-craftsman/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev": "tsc -d -w",
"build": "tsc -d",
"build": "cd src && tsc -d",
"type:check": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",
Expand All @@ -17,10 +17,13 @@
"license": "MIT",
"devDependencies": {
"@types/node": "20.8.10",
"rollup": "4.3.0",
"tiktoken-node": "0.0.6"
},
"dependencies": {
"@octokit/rest": "^20.0.2",
"openai": "4.14.2"
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@octokit/rest": "20.0.2",
"openai": "4.15.0"
}
}
4 changes: 3 additions & 1 deletion packages/ai-craftsman/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { review } from "./usecase/review.js";

const excludePatterns = [
/.*node_modules/,
/.*bin\//,
/.*pnpm-lock.yaml$/,
/.*yarn.lock$/,
/.*package-lock.json$/,
Expand All @@ -30,7 +31,8 @@ const readCodingRules = async (): Promise<string[]> => {
if (codingGuide.path != null && codingGuide.level != null) {
const markdown = await fs.promises.readFile(codingGuide.path, "utf-8");
const parsed = parseMarkdown(markdown);
return chunkMarkdownByLevel(parsed, codingGuide.level);
const chunked = chunkMarkdownByLevel(parsed, codingGuide.level);
return chunked.filter((chunk) => codingGuide.enablePattern.test(chunk));
Comment on lines 31 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全ての変数、関数の引数、および戻り値には明示的な型またはインターフェースを指定することが必要です。ここでは、markdownparsedchunkedの変数と、chunkMarkdownByLevel関数の引数と戻り値の型が指定されていません。これらに適切な型を指定してください。

Reference: ## 型定義の適用
Meta Content
Level 必須
Link https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
AI Review ON

説明

全ての変数、関数の引数、および戻り値には明示的な型またはインターフェースを指定すること。

理由

型を明示的に宣言することで、コンパイル時の型チェックの恩恵を受けられ、ランタイムエラーのリスクを減らします。また、コードの意図が明確になり、他の開発者がコードを理解しやすくなります。

// 良いコードの例
function add(x: number, y: number): number {
  return x + y;
}

// 悪いコードの例
function add(x, y) {
  return x + y;
}

例外ケース

  • ライブラリが提供する関数や変数の型が any である場合は、適宜型アサーションを使用する。

リファクタリングガイドライン

既存のコードでは、任意の型が使われていた場合、それを具体的な型に置き換えていく。新規コードでは初めから型を適用する。


}

throw new Error(
Expand Down
3 changes: 3 additions & 0 deletions packages/ai-craftsman/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ export const env = {
reader: getEnv("CODING_GUIDE_READER") || undefined,
path: getEnv("CODING_GUIDE_PATH") || undefined,
Comment on lines 29 to 30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

各変数に対して型が明示的に指定されていません。型を明示的に宣言することで、コンパイル時の型チェックの恩恵を受けられ、ランタイムエラーのリスクを減らします。また、コードの意図が明確になり、他の開発者がコードを理解しやすくなります。以下のように修正してください。

reader: string | undefined = getEnv("CODING_GUIDE_READER") || undefined,
path: string | undefined = getEnv("CODING_GUIDE_PATH") || undefined,
level: number | undefined = Number(getEnv("CODING_GUIDE_LEVEL")) || undefined,
enablePattern: RegExp = RegExp(
  getEnv("CODING_GUIDE_ENABLE_PATTERN", { defaultValue: ".*" })
),
Reference: ## 型定義の適用
Meta Content
Level 必須
Link https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
AI Review ON

説明

全ての変数、関数の引数、および戻り値には明示的な型またはインターフェースを指定すること。

理由

型を明示的に宣言することで、コンパイル時の型チェックの恩恵を受けられ、ランタイムエラーのリスクを減らします。また、コードの意図が明確になり、他の開発者がコードを理解しやすくなります。

// 良いコードの例
function add(x: number, y: number): number {
  return x + y;
}

// 悪いコードの例
function add(x, y) {
  return x + y;
}

例外ケース

  • ライブラリが提供する関数や変数の型が any である場合は、適宜型アサーションを使用する。

リファクタリングガイドライン

既存のコードでは、任意の型が使われていた場合、それを具体的な型に置き換えていく。新規コードでは初めから型を適用する。


level: Number(getEnv("CODING_GUIDE_LEVEL")) || undefined,
enablePattern: RegExp(
getEnv("CODING_GUIDE_ENABLE_PATTERN", { defaultValue: ".*" })
),
},
};
3 changes: 2 additions & 1 deletion packages/ai-craftsman/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"outDir": "dist",
"module": "Node16"
},
"exclude": ["node_modules", "dist", "**/*.spec.ts"]
"include": ["src/"],
"exclude": ["node_modules", "dist", "bin", "**/*.spec.ts"]
}
Loading