-
Notifications
You must be signed in to change notification settings - Fork 2
add AI-powered GitHub workflows and development agents #234
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: AI Issue Triage | ||
|
|
||
| on: | ||
| issues: | ||
| types: [opened] | ||
|
|
||
| jobs: | ||
| triage: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.10' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| pip install google-generativeai PyGithub | ||
|
|
||
| - name: Run AI Bug Triager | ||
| env: | ||
| GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| python scripts/ai_bug_triager.py | ||
| --repo "${{ github.repository }}" | ||
| --issue "${{ github.event.issue.number }}" | ||
| --github-token "$GITHUB_TOKEN" | ||
| --gemini-api-key "$GEMINI_API_KEY" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import os | ||
| import sys | ||
| import argparse | ||
| import google.generativeai as genai | ||
| from github import Github | ||
|
|
||
| def triage_issue(repo_name, issue_number, github_token, gemini_api_key): | ||
| """ | ||
| AI Bug Triager Agent. | ||
| Analyzes new issues and suggests root causes and fixes. | ||
| """ | ||
| # 1. Setup | ||
| g = Github(github_token) | ||
| repo = g.get_repo(repo_name) | ||
| issue = repo.get_issue(int(issue_number)) | ||
|
|
||
| genai.configure(api_key=gemini_api_key) | ||
| model = genai.GenerativeModel('gemini-1.5-pro') | ||
|
|
||
| # 2. Analyze Issue Content | ||
| print(f"π Triaging Issue #{issue_number}: {issue.title}") | ||
|
|
||
| # Get a list of key files to help the AI map the issue | ||
| # We'll provide a simplified directory structure | ||
| file_structure = """ | ||
| - app.py (Main Entry) | ||
| - services/ (Trading, Auth, Data Services) | ||
| - strategies/ (Trading Strategies) | ||
| - ui/ (Frontend React Code) | ||
| - database/ (Models and Repositories) | ||
| - core/ (Config, Security, WebSockets) | ||
| """ | ||
|
|
||
| prompt = f""" | ||
| You are a Senior Debugging Engineer for an Algorithmic Trading Platform. | ||
| Analyze the following GitHub Issue and suggest a root cause and fix. | ||
|
|
||
| Issue Title: {issue.title} | ||
| Issue Body: {issue.body} | ||
|
|
||
| Codebase Overview: | ||
| {file_structure} | ||
|
|
||
| Tasks: | ||
| 1. Identify the likely files involved. | ||
| 2. If there's a stack trace, explain what the error means. | ||
| 3. Suggest a specific fix or investigation steps. | ||
| 4. Assign a priority (Low, Medium, High, Critical). | ||
|
|
||
| Format your response as: | ||
| ### π΅οΈ AI Diagnosis | ||
| - **Likely Files:** [e.g., services/upstox_service.py] | ||
| - **Root Cause:** [Explain what's happening] | ||
| - **Priority:** [Priority Level] | ||
|
|
||
| ### π οΈ Suggested Fix | ||
| ```python | ||
| # [Your suggested code or investigation steps] | ||
| ``` | ||
| """ | ||
|
|
||
| response = model.generate_content(prompt) | ||
| ai_output = response.text.strip() | ||
|
|
||
| # 3. Post to GitHub | ||
| comment = f"## π€ AI Bug Triager Response | ||
|
|
||
| {ai_output} | ||
|
|
||
| *This is an automated response to help speed up resolution.*" | ||
| issue.create_comment(comment) | ||
|
|
||
| # 4. Add labels based on priority (if AI suggests) | ||
| if "Priority: Critical" in ai_output: | ||
| issue.add_to_labels("critical", "bug") | ||
| elif "Priority: High" in ai_output: | ||
| issue.add_to_labels("high-priority", "bug") | ||
| else: | ||
| issue.add_to_labels("bug") | ||
|
|
||
| print("β Issue triage completed.") | ||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--repo", required=True) | ||
| parser.add_argument("--issue", required=True) | ||
| parser.add_argument("--github-token", required=True) | ||
| parser.add_argument("--gemini-api-key", required=True) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| try: | ||
| triage_issue(args.repo, args.issue, args.github_token, args.gemini_api_key) | ||
| except Exception as e: | ||
| print(f"β Error in Bug Triager: {e}") | ||
| sys.exit(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import os | ||
| import sys | ||
| import argparse | ||
| import google.generativeai as genai | ||
| from github import Github | ||
| from datetime import datetime | ||
|
|
||
| def generate_docs_and_changelog(repo_name, pr_number, github_token, gemini_api_key): | ||
| """ | ||
| AI Documentation & Changelog Agent. | ||
| Analyzes the PR and generates a semantic changelog and doc updates. | ||
| """ | ||
| # 1. Setup | ||
| g = Github(github_token) | ||
| repo = g.get_repo(repo_name) | ||
| pr = repo.get_pull(int(pr_number)) | ||
|
|
||
| genai.configure(api_key=gemini_api_key) | ||
| model = genai.GenerativeModel('gemini-1.5-pro') | ||
|
|
||
| # 2. Analyze PR Diff for Documentation Needs | ||
| print(f"π Analyzing PR #{pr_number} for documentation impact...") | ||
| files = pr.get_files() | ||
| file_list = [f.filename for f in files] | ||
|
|
||
| # Combined diff for better context (limiting size for LLM) | ||
| combined_diff = " | ||
| ".join([f.patch for f in files if f.patch])[:10000] | ||
|
|
||
| prompt = f""" | ||
| You are a Technical Writer and Senior Developer. Review the following Pull Request details and diff. | ||
| PR Title: {pr.title} | ||
| PR Body: {pr.body} | ||
| Changed Files: {', '.join(file_list)} | ||
|
|
||
| Tasks: | ||
| 1. Generate a "Semantic Changelog" entry (What changed? Why? Impact?). | ||
| 2. Identify if any NEW services, strategies, or APIs were added that require new documentation files. | ||
| 3. Suggest updates to the main README.md or existing docs/ files if necessary. | ||
|
|
||
| Diff: | ||
| {combined_diff} | ||
|
|
||
| Format your response as: | ||
| ### π Semantic Changelog | ||
| [A human-readable summary of the changes] | ||
|
|
||
| ### π Documentation Impact | ||
| - [Impact 1: e.g., Update README to include new Upstox endpoint] | ||
| - [Impact 2: e.g., New strategy 'X' added to docs/strategies/] | ||
| """ | ||
|
|
||
| response = model.generate_content(prompt) | ||
| ai_output = response.text.strip() | ||
|
|
||
| # 3. Post to GitHub | ||
| comment = f"## π€ AI Documentation & Changelog Agent | ||
|
|
||
| {ai_output} | ||
|
|
||
| " | ||
| pr.create_issue_comment(comment) | ||
| print("β Documentation & Changelog suggestions posted.") | ||
|
|
||
| # 4. (Optional) Auto-update CHANGELOG.md if in a specific branch/environment | ||
| # For now, we'll just suggest the update to keep it safe. | ||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--repo", required=True) | ||
| parser.add_argument("--pr", required=True) | ||
| parser.add_argument("--github-token", required=True) | ||
| parser.add_argument("--gemini-api-key", required=True) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| try: | ||
| generate_docs_and_changelog(args.repo, args.pr, args.github_token, args.gemini_api_key) | ||
| print("β Docs Agent run completed.") | ||
| except Exception as e: | ||
| print(f"β Error in Docs Agent: {e}") | ||
| sys.exit(1) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 2 months ago
In general, this issue is fixed by adding an explicit
permissionsblock to the workflow (either at the root level or within the specific job) that grants only the minimal scopes the job needs. For an issueβtriage workflow, the likely needs are read access to repository contents plus the ability to read/write issues (e.g., comment, label, close). That suggestscontents: readandissues: writeas a good leastβprivilege baseline instead of inheriting broad default permissions.The best fix here, without changing existing functionality, is to add a
permissionsblock to thetriagejob (or at the workflow root). Since we only see a single job, putting it at the job level keeps the change tightly scoped. Based on the workflowβs purpose (βAI Issue Triageβ) and the fact that it passesGITHUB_TOKENto a script that likely manipulates issues, we will explicitly grantcontents: readandissues: write. This both satisfies CodeQL (by constraining the token) and documents the workflowβs expected permissions. The specific change is to insert, in.github/workflows/issue-triage.yml, apermissions:section undertriage:beforeruns-on: ubuntu-latest. No additional imports, methods, or external definitions are needed, as this is purely a YAML configuration change for GitHub Actions.