mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-28 20:14:14 +00:00
Merge pull request #6 from cds-snc/feature/include-pattern
Add the `include` Github action parameter to only review matching files
This commit is contained in:
commit
71dac9ec6d
11 changed files with 102 additions and 52 deletions
|
@ -9,5 +9,10 @@
|
|||
// "ghcr.io/guiyomh/features/just:0": {},
|
||||
// "ghcr.io/jungaretti/features/ripgrep:1": {},
|
||||
// "ghcr.io/lukewiwa/features/shellcheck:0": {},
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": ["yzhang.markdown-all-in-one"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
.github/workflows/backstage-catalog-helper.yml
vendored
12
.github/workflows/backstage-catalog-helper.yml
vendored
|
@ -28,10 +28,10 @@ jobs:
|
|||
uses: peter-evans/create-pull-request@v3
|
||||
with:
|
||||
token: ${{ steps.generate_token.outputs.token}}
|
||||
commit-message: 'Add catalog-info.yaml'
|
||||
branch: 'backstage/catalog-info'
|
||||
title: 'Add catalog-info.yaml'
|
||||
body: 'Adding a basic catalog-info.yaml to start populating the backstage catalog with your components.'
|
||||
labels: 'backstage'
|
||||
commit-message: "Add catalog-info.yaml"
|
||||
branch: "backstage/catalog-info"
|
||||
title: "Add catalog-info.yaml"
|
||||
body: "Adding a basic catalog-info.yaml to start populating the backstage catalog with your components."
|
||||
labels: "backstage"
|
||||
add-paths: |
|
||||
catalog-info.yaml
|
||||
catalog-info.yaml
|
||||
|
|
3
.github/workflows/code_review.yml
vendored
3
.github/workflows/code_review.yml
vendored
|
@ -19,4 +19,5 @@ jobs:
|
|||
OPENAI_API_MODEL: ${{ vars.OPENAI_API_MODEL }}
|
||||
OPENAI_API_VERSION: ${{ vars.OPENAI_API_VERSION }}
|
||||
OPENAI_BASE_URL: ${{ vars.OPENAI_BASE_URL }}
|
||||
exclude: "yarn.lock,dist/**"
|
||||
exclude: "*lock*,dist/**,**/*.js,**/*.js.map"
|
||||
include: "**/*.ts,**/*.yml"
|
||||
|
|
49
.github/workflows/s3-backup.yml
vendored
49
.github/workflows/s3-backup.yml
vendored
|
@ -8,32 +8,31 @@ jobs:
|
|||
s3-backup:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||
with:
|
||||
fetch-depth: 0 # retrieve all history
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
||||
with:
|
||||
fetch-depth: 0 # retrieve all history
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_S3_BACKUP_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_S3_BACKUP_SECRET_ACCESS_KEY }}
|
||||
aws-region: ca-central-1
|
||||
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_S3_BACKUP_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_S3_BACKUP_SECRET_ACCESS_KEY }}
|
||||
aws-region: ca-central-1
|
||||
- name: Create ZIP bundle
|
||||
run: |
|
||||
ZIP_FILE=`basename ${{ github.repository }}`-`date '+%Y-%m-%d'`.zip
|
||||
zip -rq "${ZIP_FILE}" .
|
||||
mkdir -p ${{ github.repository }}
|
||||
mv "${ZIP_FILE}" ${{ github.repository }}
|
||||
|
||||
- name: Create ZIP bundle
|
||||
run: |
|
||||
ZIP_FILE=`basename ${{ github.repository }}`-`date '+%Y-%m-%d'`.zip
|
||||
zip -rq "${ZIP_FILE}" .
|
||||
mkdir -p ${{ github.repository }}
|
||||
mv "${ZIP_FILE}" ${{ github.repository }}
|
||||
- name: Upload to S3 bucket
|
||||
run: |
|
||||
aws s3 sync . s3://${{ secrets.AWS_S3_BACKUP_BUCKET }} --exclude='*' --include='${{ github.repository }}/*'
|
||||
|
||||
- name: Upload to S3 bucket
|
||||
run: |
|
||||
aws s3 sync . s3://${{ secrets.AWS_S3_BACKUP_BUCKET }} --exclude='*' --include='${{ github.repository }}/*'
|
||||
|
||||
- name: Notify Slack channel if this job failed
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
json='{"text":"S3 backup failed in <https://github.com/${{ github.repository }}>!"}'
|
||||
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_NOTIFY_WEBHOOK }}
|
||||
- name: Notify Slack channel if this job failed
|
||||
if: ${{ failure() }}
|
||||
run: |
|
||||
json='{"text":"S3 backup failed in <https://github.com/${{ github.repository }}>!"}'
|
||||
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_NOTIFY_WEBHOOK }}
|
||||
|
|
11
README.md
11
README.md
|
@ -16,10 +16,10 @@ review process.
|
|||
1. To use this GitHub Action, you need an OpenAI API key. If you don't have one, sign up for an API key
|
||||
at [OpenAI](https://beta.openai.com/signup).
|
||||
|
||||
2. Add the OpenAI API key as a GitHub Secret in your repository with the name `OPENAI_API_KEY`. You can find more
|
||||
1. Add the OpenAI API key as a GitHub Secret in your repository with the name `OPENAI_API_KEY`. You can find more
|
||||
information about GitHub Secrets [here](https://docs.github.com/en/actions/reference/encrypted-secrets).
|
||||
|
||||
3. Create a `.github/workflows/main.yml` file in your repository and add the following content:
|
||||
1. Create a `.github/workflows/main.yml` file in your repository and add the following content:
|
||||
|
||||
```yaml
|
||||
name: CDS AI Code Reviewer
|
||||
|
@ -44,11 +44,14 @@ jobs:
|
|||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
OPENAI_API_MODEL: "gpt-4" # Optional: defaults to "gpt-4"
|
||||
exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas
|
||||
include: "**/*.ts" # Optional: include patterns separated by commas
|
||||
```
|
||||
|
||||
4. Customize the `exclude` input if you want to ignore certain file patterns from being reviewed.
|
||||
1. Customize the `exclude` input if you want to ignore certain file patterns from being reviewed.
|
||||
|
||||
5. Commit the changes to your repository, and CDS AI Code Reviewer will start working on your future pull requests.
|
||||
1. Customize the `include` input if you want to add only certain file patterns to be reviewed. Any file matching the include and which also matches the `exclude` will favor the latter: `exclude` > `include`.
|
||||
|
||||
1. Commit the changes to your repository, and CDS AI Code Reviewer will start working on your future pull requests.
|
||||
|
||||
## How It Works
|
||||
|
||||
|
|
|
@ -17,7 +17,11 @@ inputs:
|
|||
description: "Base URL to the OpenAI API model (OpenAI or Azure)."
|
||||
required: true
|
||||
exclude:
|
||||
description: "Glob patterns to exclude files from the diff analysis"
|
||||
description: "Glob patterns to exclude files from the diff analysis. This has precedence over the `include` matches."
|
||||
required: false
|
||||
default: ""
|
||||
include:
|
||||
description: "Glob patterns to only include certain files from the diff analysis."
|
||||
required: false
|
||||
default: ""
|
||||
runs:
|
||||
|
|
|
@ -22,4 +22,5 @@ jobs:
|
|||
OPENAI_API_MODEL: ${{ vars.OPENAI_API_MODEL }}
|
||||
OPENAI_API_VERSION: ${{ vars.OPENAI_API_VERSION }}
|
||||
OPENAI_BASE_URL: ${{ vars.OPENAI_BASE_URL }}
|
||||
exclude: "yarn.lock,dist/**"
|
||||
exclude: "*lock*,dist/**,**/*.js,**/*.js.map"
|
||||
include: "**/*.ts,**/*.yml"
|
||||
|
|
|
@ -17,7 +17,11 @@ inputs:
|
|||
description: "Base URL to the OpenAI API model (OpenAI or Azure)."
|
||||
required: true
|
||||
exclude:
|
||||
description: "Glob patterns to exclude files from the diff analysis"
|
||||
description: "Glob patterns to exclude files from the diff analysis. This has precedence over the `include` matches."
|
||||
required: false
|
||||
default: ""
|
||||
include:
|
||||
description: "Glob patterns to only include certain files from the diff analysis."
|
||||
required: false
|
||||
default: ""
|
||||
runs:
|
||||
|
|
35
dist/index.js
vendored
35
dist/index.js
vendored
|
@ -331,15 +331,34 @@ ${chunk.changes
|
|||
const excludePatterns = core
|
||||
.getInput("exclude")
|
||||
.split(",")
|
||||
.map((s) => s.trim());
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.length > 0); // Filter out empty strings;
|
||||
const includePatterns = core
|
||||
.getInput("include")
|
||||
.split(",")
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.length > 0); // Filter out empty strings;
|
||||
const filteredDiff = parsedDiff.filter((file) => {
|
||||
return !excludePatterns.some((pattern) => {
|
||||
var _a;
|
||||
return (0, minimatch_1.default)(
|
||||
(_a = file.to) !== null && _a !== void 0 ? _a : "",
|
||||
pattern
|
||||
);
|
||||
});
|
||||
const excluded =
|
||||
excludePatterns.length > 0 &&
|
||||
excludePatterns.some((pattern) => {
|
||||
var _a;
|
||||
return (0, minimatch_1.default)(
|
||||
(_a = file.to) !== null && _a !== void 0 ? _a : "",
|
||||
pattern
|
||||
);
|
||||
});
|
||||
const included =
|
||||
includePatterns.length === 0 ||
|
||||
includePatterns.some((pattern) => {
|
||||
var _a;
|
||||
return (0, minimatch_1.default)(
|
||||
(_a = file.to) !== null && _a !== void 0 ? _a : "",
|
||||
pattern
|
||||
);
|
||||
});
|
||||
// Excluded patterns take precedence over included patterns.
|
||||
return !excluded && included;
|
||||
});
|
||||
const comments = yield analyzeCode(filteredDiff, prDetails);
|
||||
if (comments.length > 0) {
|
||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
22
src/main.ts
22
src/main.ts
|
@ -247,12 +247,26 @@ async function main() {
|
|||
const excludePatterns = core
|
||||
.getInput("exclude")
|
||||
.split(",")
|
||||
.map((s) => s.trim());
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.length > 0); // Filter out empty strings;
|
||||
|
||||
const includePatterns = core
|
||||
.getInput("include")
|
||||
.split(",")
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.length > 0); // Filter out empty strings;
|
||||
|
||||
const filteredDiff = parsedDiff.filter((file) => {
|
||||
return !excludePatterns.some((pattern) =>
|
||||
minimatch(file.to ?? "", pattern)
|
||||
);
|
||||
const excluded: boolean =
|
||||
excludePatterns.length > 0 &&
|
||||
excludePatterns.some((pattern) => minimatch(file.to ?? "", pattern));
|
||||
|
||||
const included: boolean =
|
||||
includePatterns.length === 0 ||
|
||||
includePatterns.some((pattern) => minimatch(file.to ?? "", pattern));
|
||||
|
||||
// Excluded patterns take precedence over included patterns.
|
||||
return !excluded && included;
|
||||
});
|
||||
|
||||
const comments = await analyzeCode(filteredDiff, prDetails);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue