Skip to content

Commit

Permalink
feat: paginate (#5)
Browse files Browse the repository at this point in the history
* feat(pr): handle more than 30 files pull request

* feat(pr): remove comment on changed files

* chore: format
  • Loading branch information
Klaitos authored Jul 19, 2024
1 parent 7489ebc commit b9d3e04
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@ The bot will create and try to update (if existing) a comment with OpenAI result
timeout-minutes: 3
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
- name: 'Checkout code'
uses: actions/checkout@v4
- name: Generate prompt
run: |
echo -e "Given a large dataset Postgres database version $POSTGRES_VERSION, for each distinct SQL query at the end of my prompt, knowing that they will be executed into a single transaction.
Please precise if each query will locks the table, which type of postgres lock it will uses and if it will prevents other transactions from reading or writing to the table.
Answer with suggestions and recommendations for how to avoid it (do not include NOWAIT option). Include indexes suggestions if you think he can speed up any query.
Your answer should follow the following format :
## Query 1:
\`\`\`sql
<SQL Query>
\`\`\`
Locking Analysis:
- <start with a warning emoji if this lock the database, then detailed analysis with bold result of the locking result>
Suggestions/Alternatives:
- <Detailed suggestions>
## Query 2:
\`\`\`sql
<SQL Query>
\`\`\`
Locking Analysis:
- <start with a warning emoji if this lock the database, then detailed analysis with bold result of the locking result>
Suggestions/Alternatives:
- <Detailed suggestions>" >> prompt.txt
echo OPENAI_PROMPT=$(cat prompt.txt) >> $GITHUB_ENV
echo OPENAI_SYSTEM_MESSAGE="You are a SQL expert and knowledgeable about large datasets in Postgres version $POSTGRES_VERSION."
env:
Expand All @@ -55,9 +55,9 @@ The bot will create and try to update (if existing) a comment with OpenAI result
with:
prompt: ${{ env.OPENAI_PROMPT }}
openai_system_message: ${{ env.OPENAI_SYSTEM_MESSAGE }}
openai_model: "gpt-4"
openai_model: 'gpt-4'
openai_temperature: 0.1
files_path: "path/to/your/migrations/folders"
files_path: 'path/to/your/migrations/folders'
github_token: ${{ secrets.AI_PR_REVIEW_GITHUB_TOKEN }}
github_pr_id: ${{ github.event.pull_request.number }}
env:
Expand Down
8 changes: 6 additions & 2 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class OctokitClient {
}

async listFiles(): Promise<{ filename: string; patch?: string | undefined }[]> {
const { data: files } = await this.octokit.rest.pulls.listFiles({
const files = await this.octokit.paginate(this.octokit.rest.pulls.listFiles, {
owner: this.owner,
repo: this.repo,
pull_number: this.pullRequestId,
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export async function run(): Promise<void> {
)
)
.forEach(modifiedFile => {
concatenatedFilesContent += modifiedFile.patch?.replace(/@@(.*)+@@/, '').trim()
concatenatedFilesContent += modifiedFile.patch
?.replace(/@@(.*)+@@/, '')
.replace(/\*[\s\S]*?\*/, '')
.replace('No newline at end of file', '')
.trim()
})

if (!concatenatedFilesContent) {
Expand Down

0 comments on commit b9d3e04

Please sign in to comment.