Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2a941eb
[feature] Added workflow and script for suggestion bot #524
stktyagi Feb 18, 2026
2d2e164
[fix] Improved suggestion prompt and fixed workflow #524
stktyagi Feb 18, 2026
a32389f
[fix] Improved handling of error messages #524
stktyagi Feb 18, 2026
bd0e2f8
[fix] Move bot token creation upwards #524
stktyagi Feb 18, 2026
2e004a4
[fix] Added base repo to prevent failure #524
stktyagi Feb 18, 2026
ca26d73
[fix] Prevent prompt injection #524
stktyagi Feb 18, 2026
712ef87
[fix] Add dynamic header #524
stktyagi Feb 19, 2026
4091a2f
[fix] Added mention to contributor #524
stktyagi Feb 19, 2026
a42a6a4
[fix] Improve repomix command #524
stktyagi Feb 19, 2026
65a4344
[fix] Add commit hash #524
stktyagi Feb 19, 2026
6ca2fe4
[fix] Improved log handling and repomix command #524
stktyagi Feb 19, 2026
54f19aa
[fix] Use genai sdk retry method #524
stktyagi Feb 21, 2026
2b9fc04
[fix] Added truncations and concurrency #524
stktyagi Feb 21, 2026
cc82b40
[fix] Stick to v2.0.6 #524
stktyagi Feb 21, 2026
47b1572
Merge branch 'master' into issues/524-ci-failure-bot
stktyagi Feb 22, 2026
06e9c51
[fix] Added minor improvements #524
stktyagi Feb 22, 2026
8f14892
[docs] Added documentation #524
stktyagi Feb 22, 2026
dcb8f47
[fix] Shift concurrency to caller #524
stktyagi Feb 22, 2026
d500d1f
[docs] Update docs #524
stktyagi Feb 22, 2026
a82425f
[fix] Allowed graceful fallback #524
stktyagi Feb 23, 2026
16b34dc
[fix] Moved repo context out of ci #524
stktyagi Feb 26, 2026
7fed459
Merge branch 'master' into issues/524-ci-failure-bot
nemesifier Feb 26, 2026
1e47a44
Merge branch 'master' into issues/524-ci-failure-bot
stktyagi Feb 27, 2026
00769cf
[fix] Added tests and improved analyze script #524
stktyagi Feb 27, 2026
d2828d5
[fix] Added tests file #524
stktyagi Feb 27, 2026
aff7857
[ci] Added caller to utils #524
stktyagi Feb 27, 2026
908d910
[fix] Improved system instructions #524
stktyagi Feb 27, 2026
88d677e
Merge branch 'master' into issues/524-ci-failure-bot
stktyagi Feb 27, 2026
da8769d
[fix] Fixed system instructions #524
stktyagi Feb 27, 2026
4510854
Merge branch 'master' into issues/524-ci-failure-bot
stktyagi Feb 27, 2026
0f396a8
[fix] Changed directory structure #524
stktyagi Feb 27, 2026
8180be1
[chores:fix] Fixed discoverability of tests for pytest
nemesifier Mar 3, 2026
5d79296
Merge branch 'master' into issues/524-ci-failure-bot
stktyagi Mar 4, 2026
f1b6481
[fix] Fixed package installation in ci #524
stktyagi Mar 4, 2026
9f5db4f
[fix] Fixed default fallback #524
stktyagi Mar 4, 2026
2808754
[fix] Fallback to correct value #524
stktyagi Mar 4, 2026
78a2c2e
[fix] Addressed minor improvements #524
stktyagi Mar 4, 2026
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
80 changes: 80 additions & 0 deletions .github/scripts/ai_suggest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os

from google import genai
from google.genai import types


def get_error_logs():
log_file = "failed_logs.txt"
if not os.path.exists(log_file):
return "No failed logs found."
try:
with open(log_file, "r") as f:
content = f.read()
return content[-15000:]
except Exception as e:
return f"Error reading logs: {e}"


def main():
api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
print("Skipping: No API Key found.")
return

client = genai.Client(api_key=api_key)

repo_context = "No repository context available."
if os.path.exists("repo_context.xml"):
try:
with open("repo_context.xml", "r") as f:
repo_context = f.read()
except Exception:
pass

error_log = get_error_logs()

system_instruction = """
You are an automated CI Triage Bot for the OpenWISP project.
Your goal is to analyze CI failure logs and provide helpful, actionable feedback.

Categorize the failure into one of these types:
1. **Code Style/QA**: (flake8, isort, black). Remediation: Run `openwisp-qa-format`.
2. **Commit Message**: (checkcommit). Remediation: Propose a correct message.
3. **Test Failure**: (incorrect test, incorrect logic).
- Compare function logic vs test assertion.
- If logic matches name but test is impossible, fix test.
- If logic is wrong, fix code.

Response Format:
- Friendly greeting.
- Clearly state WHAT failed.
- Provide the command to fix it or the code snippet.
- Use Markdown.
"""

prompt = f"""
Fix this failing test.

FAILURE LOGS:
{error_log}

CODE CONTEXT:
{repo_context}
"""

try:
response = client.models.generate_content(
model="gemini-2.5-flash-lite",
contents=prompt,
config=types.GenerateContentConfig(
system_instruction=system_instruction, temperature=0.4
),
)
print(f"## Report\n\n{response.text}")
except Exception as e:
print(f"Generation Failed: {e}")


if __name__ == "__main__":
main()
85 changes: 85 additions & 0 deletions .github/workflows/reusable-ai-triage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: AI Triage

on:
workflow_call:
inputs:
pr_number:
required: true
type: string
head_sha:
required: true
type: string
head_repo:
required: true
type: string
run_id:
required: true
type: string
secrets:
GEMINI_API_KEY:
required: true
APP_ID:
required: true
PRIVATE_KEY:
required: true

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- name: Checkout Reusable Workflow
uses: actions/checkout@v4
with:
repository: ${{ github.action_repository }}
ref: ${{ github.action_ref }}
path: trusted_scripts

- name: Checkout PR Code
uses: actions/checkout@v4
with:
repository: ${{ inputs.head_repo }}
ref: ${{ inputs.head_sha }}
path: pr_code

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Tools
run: |
pip install google-genai
npm install -g repomix

- name: Fetch CI Logs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_ID: ${{ inputs.run_id }}
REPO: ${{ inputs.head_repo }}
run: |
gh run view $RUN_ID --repo $REPO --log-failed > failed_logs.txt

- name: Pack Context
run: |
cd pr_code
repomix --include "**/*" --ignore "**/*.lock,**/*.json" --style xml --output ../repo_context.xml

- name: Generate Bot Token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}

- name: Run AI Analysis
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
python trusted_scripts/.github/scripts/ai_fix.py > solution.md

- name: Post Comment
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
PR_NUM: ${{ inputs.pr_number }}
REPO: ${{ inputs.head_repo }}
run: gh pr comment "$PR_NUM" --repo "$REPO" --body-file solution.md
Loading