Skip to content

Commit

Permalink
Merge pull request #1 from xonlly/feat-blacklist-extension-file
Browse files Browse the repository at this point in the history
feat(B): add blacklist extensions files
  • Loading branch information
Jean Ducellier authored Jul 20, 2023
2 parents a82f664 + 6774f1c commit 3bcb761
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/aireview.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PR review

on:
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

Expand All @@ -17,5 +17,6 @@ jobs:
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
pr_number: ${{ github.event.number }}
#file_extensions: ".py,.js,.html" # for example
#file_extensions: ".py,.js,.html" # for example whitelist
#exclude_paths: "test/,docs/" # for example
#exclude_file_extensions: ".md" # for example blacklist
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ Perform code review using OpenAI ChatGPT to analyze and provide feedback on your

## Inputs

***token*** - Required. The GitHub token. This token is used to authenticate and access your GitHub repository.
**_token_** - Required. The GitHub token. This token is used to authenticate and access your GitHub repository.

***openai_api_key*** - Required. The OpenAI API key. This key is needed to access OpenAI's ChatGPT API for code review.
**_openai_api_key_** - Required. The OpenAI API key. This key is needed to access OpenAI's ChatGPT API for code review.

***owner*** - Required. The repository owner's username.
**_owner_** - Required. The repository owner's username.

***repo*** - Required. The name of the repository.
**_repo_** - Required. The name of the repository.

***pr_number*** - Required. The pull request number to review.
**_pr_number_** - Required. The pull request number to review.

***file_extensions*** - Optional. A comma-separated list of file extensions to review (e.g., ".py,.js,.html"). If not provided, the action will review all file types.
**_file_extensions_** - Optional. A comma-separated list of file extensions to review (e.g., ".py,.js,.html"). If not provided, the action will review all file types. Do not use with `exclude-file-extensions`

***exclude_paths*** - Optional. A comma-separated list of paths to exclude from the review (e.g., "test/,docs/"). If not provided, the action will review all paths.
**_exclude_paths_** - Optional. A comma-separated list of paths to exclude from the review (e.g., "test/,docs/"). If not provided, the action will review all paths.

**_exclude_file_extensions_** - Optional. A comma-separated list of file extensions to not review (e.g., ".py,.js,.html"). If not provided, the action will review all file types. Do not use with `file-extensions`

## Usage

Expand All @@ -42,18 +44,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: AI Code Review
uses: xonlly/ai-code-review@v0.2.2
with:
token: ${{ secrets.GITHUB_TOKEN }} # or your token with access to PRs, read for files and write for comments
openai_api_key: ${{ secrets.OPENAI_API_KEY }} # You should have access to gpt-4-0613
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
pr_number: ${{ github.event.number }}
#file_extensions: ".py,.js,.html" # for example
#exclude_paths: "test/,docs/" # for example
- name: AI Code Review
uses: xonlly/ai-code-review@v0.2.2
with:
token: ${{ secrets.GITHUB_TOKEN }} # or your token with access to PRs, read for files and write for comments
openai_api_key: ${{ secrets.OPENAI_API_KEY }} # You should have access to gpt-4-0613
owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
pr_number: ${{ github.event.number }}
#file_extensions: ".py,.js,.html" # for example
#exclude_paths: "test/,docs/" # for example
#exclude_file_extensions: ".md" # for example blacklist
```

This action will run on every opened or updated pull request, and it will review only the specified file types and exclude the specified paths.

PS ***Written with GPT 3.5 turbo***
PS **_Written with GPT 3.5 turbo_**
23 changes: 13 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
name: 'AI Code Review'
description: 'Perform code review using OpenAI ChatGPT'
name: "AI Code Review"
description: "Perform code review using OpenAI ChatGPT"

inputs:
token:
description: 'GitHub token'
description: "GitHub token"
required: true
openai_api_key:
description: 'OpenAI API key'
description: "OpenAI API key"
required: true
owner:
description: 'Repository owner'
description: "Repository owner"
required: true
repo:
description: 'Repository name'
description: "Repository name"
required: true
pr_number:
description: 'Pull request number'
description: "Pull request number"
required: true
file_extensions:
description: 'File extensions to review (comma-separated, e.g., ".py,.js,.html")'
required: false
exclude_paths:
description: 'Paths to exclude from review (comma-separated, e.g., "test/,docs/")'
required: false
exclude_file_extensions:
description: 'File extensions to exclude from review (comma-separated, e.g., ".py,.js,.html")'
required: false

runs:
using: 'node16'
pre: 'setup.js'
main: 'index.js'
using: "node16"
pre: "setup.js"
main: "index.js"
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ const core = require("@actions/core");
const GitHubAPI = require("./githubapi");
const OpenAIAPI = require("./openaiapi");

const isFileToReview = (filename, fileExtensions, excludePaths) => {
const isFileToReview = (filename, fileExtensions, excludePaths, excludeFileExtensions) => {
if (fileExtensions) {
const extensions = fileExtensions.split(",").map((ext) => ext.trim());
if (!extensions.some((ext) => filename.endsWith(ext))) {
return false;
}
}

if (excludeFileExtensions) {
const extensions = excludeFileExtensions.split(",").map((ext) => ext.trim());
if (extensions.some((ext) => filename.endsWith(ext))) {
return false;
}
}

if (excludePaths) {
const paths = excludePaths.split(",").map((path) => path.trim());
if (paths.some((path) => filename.startsWith(path))) {
Expand All @@ -20,9 +27,9 @@ const isFileToReview = (filename, fileExtensions, excludePaths) => {
return true;
}

const getFilteredChangedFiles = (changedFiles, fileExtensions, excludePaths) => {
const getFilteredChangedFiles = (changedFiles, fileExtensions, excludePaths, excludeFileExtensions) => {
let filteredFiles = changedFiles;
return filteredFiles.filter((file) => isFileToReview(file.filename, fileExtensions, excludePaths));
return filteredFiles.filter((file) => isFileToReview(file.filename, fileExtensions, excludePaths, excludeFileExtensions));
};

const getApproxMaxSymbols = () => {
Expand Down Expand Up @@ -84,10 +91,12 @@ const main = async () => {
const changedFiles = await githubAPI.listFiles(owner, repo, pullNumber);
const fileExtensions = core.getInput("file_extensions", { required: false });
const excludePaths = core.getInput("exclude_paths", { required: false });
const excludeFileExtensions = core.getInput("exclude_file_extensions", { required: false });
const filteredChangedFiles = getFilteredChangedFiles(
changedFiles,
fileExtensions,
excludePaths
excludePaths,
excludeFileExtensions
);

const allInOneSucess = await processAllInOneStrategy(filteredChangedFiles, openaiAPI, githubAPI, owner, repo, pullNumber);
Expand Down

0 comments on commit 3bcb761

Please sign in to comment.