Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama committed Nov 5, 2023
1 parent 2c9269f commit 9421478
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 200 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ai-review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_EVENT_PATH: ${{ github.event_path }}
LANGUAGE: Japanese
DEBUG: true
CODING_GUIDE_PATH: GUIDE.md
CODING_GUIDE_LEVEL: 2
CODING_GUIDE_ENABLE_PATTERN: "AI Review.*ON"
CODING_GUIDE_PATH: ExampleOfCodigRules.md
# CODING_GUIDE_READER: packages/ai-craftsman/dist/ci/codingGuide.js
DEBUG: true
59 changes: 59 additions & 0 deletions ExampleOfCodigRules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Sample Coding Rules for AI Review Flex

The following are sample coding rules that `AI Review Flex`. These rules are written in markdown and should be placed in a file (e.g., `coding_guide.md`) within your repository.

## Use camelCase for variable names

Ensure that all your variable names are in camelCase. For example, use `employeeList` instead of `EmployeeList` or `employee_list`.

- File Pattern: \.(js|ts|jsx|tsx)$
- AI Review: ON

## Functions should have descriptive names

Function names should clearly describe what the function does using verb-noun pairs when applicable, such as `calculateTotal` or `getUserInfo`.

- File Pattern: \.(js|ts)$
- AI Review: ON

## Constants should be in uppercase

All constants should be declared using uppercase letters and underscore separators, like `MAX_RETRY_COUNT`.

- File Pattern: \.(js|ts|jsx|tsx)$
- AI Review: ON

## Comment public methods and classes

All public methods and classes should have JSDoc comments describing their purpose, parameters, and return values.

- File Pattern: \.(js|ts)$
- AI Review: ON

## Avoid 'any' type in TypeScript

The use of `any` type should be avoided in TypeScript files. Instead, use specific types or generics for better type safety.

- File Pattern: \.ts$
- AI Review: ON

## No console logs in production code

Remove all `console.log` statements from the production code to avoid leaking information and cluttering the output.

- File Pattern: \.(js|ts|jsx|tsx)$
- AI Review: ON

## SQL Naming Conventions

Use snake*case for all SQL identifiers, including table names and column names. Prefix tables with `tbl*`and views with`view\_`.

- File Pattern: `\.(sql)$`
- AI Review: ON

## Commit Messages

All commit messages should follow the conventional commit format for consistency and clarity.

- File Pattern: `\.(md|txt|docx)$`
- AI Review: OFF
176 changes: 0 additions & 176 deletions GUIDE.md

This file was deleted.

89 changes: 83 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,88 @@
# AI Craftman
# AI Review Flex

AI reviewer configurable for you.
`AI Review Flex` is a versatile GitHub Action that employs AI to review code against project-specific guidelines. By interpreting markdown coding guides, it delivers tailored feedback for each pull request to uphold your coding standards.

## What is this
## Prerequisites

Fully configurable AI reviewers that review according to project-specific coding conventions.
To use `AI Review Flex`, make sure you have:

---
- A GitHub repository.
- An OpenAI API Key.

The rest of the README is WIP
## Setup

Incorporate this action in your workflow (`.github/workflows/main.yml`) with the required settings:

```yaml
- name: AI Review Flex
uses: baseballyama/ai-review-flex@main
with:
BASE_REF: ${{ github.base_ref }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_EVENT_PATH: ${{ github.event_path }}
LANGUAGE: "English"
CODING_GUIDE_PATH: "path/to/guide.md"
CODING_GUIDE_LEVEL: 2
CODING_GUIDE_ENABLE_PATTERN: "AI Review.*ON"
CODING_GUIDE_FILE_PATTERN: "File Pattern:\\s*`?(.+)`?$"
CODING_GUIDE_READER: "path/to/custom_reader.js"
DEBUG: false
```
## Customizing Coding Rules
Configure these parameters in the workflow for tailored coding standard reviews:
| Parameter | Description | Required | Default |
| ----------------------------- | -------------------------------------------- | -------- | --------------------------- |
| `CODING_GUIDE_PATH` | Path to markdown coding rules. | No | - |
| `CODING_GUIDE_LEVEL` | Markdown level to interpret as rules. | No | `2` |
| `CODING_GUIDE_ENABLE_PATTERN` | Regex pattern to match reviewed rules. | No | `AI Review.*ON` |
| `CODING_GUIDE_FILE_PATTERN` | Regex for file paths to apply rules. | No | `File Pattern:\s*/?(.+)/?$` |
| `CODING_GUIDE_READER` | Path to a `.js` custom rule reader function. | No | - |
| `LANGUAGE` | Language preference for reviews. | No | "English" |
| `DEBUG` | Enable debug mode for detailed logs. | No | `false` |

Example custom rule reader function:

```javascript
import * as fs from "node:fs";
export default async (): Promise<{ rule: string, filePattern: RegExp }[]> => {
const markdown = await fs.promises.readFile("GUIDE.md", "utf-8");
return markdown
.split("## ")
.map((rule) => `## ${rule}`)
.filter(() => {
/** some filter process */
return true;
})
.map((rule) => {
const [, filePattern = ".*"] = rule.match(/File Pattern: (\S+)$/m) ?? [];
return { rule, filePattern: RegExp(filePattern) };
});
};
```

Set the custom reader in your workflow as:

```yaml
CODING_GUIDE_READER: "path/to/your/rules-reader.js"
```
## Example of Coding Rules
Please see [ExampleOfCodigRules.md](./ExampleOfCodigRules.md) to check example of coding rules.
## Usage
Configure the action, and it will automatically review PRs based on your rules.
## Contributing
Suggestions and contributions are appreciated! Feel free to submit issues or pull requests.
## License
Distributed under the MIT License.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ inputs:
description: "Hierarchy of markdowns representing each rule."
required: false
CODING_GUIDE_ENABLE_PATTERN:
description: "Regular expression patterns for rules that enable review by AI."
description: "Regex patterns for rules that enable review by AI."
required: false
default: "AI Review.*ON"
CODING_GUIDE_FILE_PATTERN:
description: "Regex pattern to match file path that the rules should apply to."
required: false
default: ".*"
CODING_GUIDE_READER:
Expand Down
Loading

0 comments on commit 9421478

Please sign in to comment.