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

Dummy commit to trigger the query reviewer workflow #105

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
77 changes: 56 additions & 21 deletions .github/workflows/query_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,35 @@ name: Query Review Bot
on:
pull_request:
types:
- labeled
workflow_dispatch: # Allows manual triggering from GitHub UI
- labeled # Runs when the 'question' label is added
workflow_dispatch: # Allows manual execution from GitHub UI

permissions:
pull-requests: write
contents: read

jobs:
review-query:
if: |
github.ref == 'refs/heads/main' || github.ref == 'refs/heads/test-github-actions'
runs-on: ubuntu-latest
steps:
- name: Checkout PR Code
- name: Checkout PR Branch
uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.head_ref }} # Ensures workflow runs from the PR branch

- name: Debug Git Info
run: |
BASE_BRANCH=${{ github.base_ref }}
if [[ -z "$BASE_BRANCH" ]]; then
BASE_BRANCH="main" # Fallback to main if GitHub doesn't provide a base branch
fi

echo "Base branch: $BASE_BRANCH"
echo "Current branch: ${{ github.head_ref }}"

git fetch --no-tags --depth=1 origin $BASE_BRANCH
echo "Git diff output:"
git diff --name-only origin/$BASE_BRANCH HEAD || echo "❌ No changes detected"

- name: Set up Python
uses: actions/setup-python@v4
Expand All @@ -34,44 +46,67 @@ jobs:
- name: Get Modified queries.md Files
id: get_files
run: |
git fetch --no-tags --depth=1 origin ${{ github.event.pull_request.base.ref }}
MODIFIED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}..HEAD | grep 'queries.md' || echo "")
BASE_BRANCH=${{ github.base_ref }}
if [[ -z "$BASE_BRANCH" ]]; then
BASE_BRANCH="main"
fi
git fetch --no-tags --depth=1 origin $BASE_BRANCH

MODIFIED_FILES=$(git diff --name-only origin/$BASE_BRANCH HEAD | grep 'queries.md' || echo "")

echo "Modified files detected: $MODIFIED_FILES"

if [[ -z "$MODIFIED_FILES" ]]; then
MODIFIED_FILES=$(git diff --name-only HEAD~1 HEAD | grep 'queries.md' || echo "")
echo "❌ No queries.md files found."
exit 0
fi

echo "Modified files: $MODIFIED_FILES"
echo "files=$MODIFIED_FILES" >> $GITHUB_ENV

- name: Evaluate Queries
id: evaluate_queries
run: |
if [[ -z "${{ env.files }}" ]]; then
echo "No queries.md files found."
echo "No queries.md files found."
exit 0
fi

OUTPUT=""
for FILE in ${{ env.files }}; do
echo "Processing file: $FILE"
RESULT=$(python scripts/evaluate_sql.py "$FILE")
echo "🔍 Processing file: $FILE"

# Run the evaluation script and capture output
RESULT=$(python scripts/evaluate_sql.py "$FILE" || echo "⚠️ Error processing file: $FILE")

# Ensure result is not empty
if [[ -z "$RESULT" ]]; then
RESULT="⚠️ No output generated for $FILE"
fi

OUTPUT+="\n\n#### Review for $FILE\n$RESULT"
done


# Store multi-line output in a file and append to GITHUB_ENV safely
echo -e "$OUTPUT" > review_output.txt
echo "review_output=$(cat review_output.txt)" >> $GITHUB_ENV
{
echo "review_output<<EOF"
cat review_output.txt
echo "EOF"
} >> "$GITHUB_ENV"


- name: Comment on PR
run: |
if [[ -z "${{ env.review_output }}" ]]; then
echo "No AI suggestions to post."
echo "ℹ️ No AI suggestions to post."
exit 0
fi

COMMENT="### 🤖 SQL Query Review\n${{ env.review_output }}"
echo "$COMMENT" > pr_comment.txt

echo "### 🤖 SQL Query Review" > pr_comment.txt
echo "${{ env.review_output }}" >> pr_comment.txt
gh pr comment ${{ github.event.pull_request.html_url }} --body-file pr_comment.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}


2 changes: 1 addition & 1 deletion docs/tables/aws_s3_server_access_log/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ group by
key
order by
requests desc
limit 10;
limit 20;
```

### Top 10 requester IP addresses
Expand Down
Loading