Commit
·
1cd87bb
1
Parent(s):
a47d2f1
fixes to search tool
Browse files
app.py
CHANGED
|
@@ -848,7 +848,13 @@ def reply_and_close_issue(
|
|
| 848 |
|
| 849 |
|
| 850 |
def search_issues(
|
| 851 |
-
repo_url: str,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
) -> list | dict:
|
| 853 |
"""
|
| 854 |
Searches for issues in the database based on multiple criteria.
|
|
@@ -858,15 +864,16 @@ def search_issues(
|
|
| 858 |
repo_url (str): The full repository URL.
|
| 859 |
query (str, optional): Text to search in title or body (e.g., "chatbot error").
|
| 860 |
issue_number (int, optional): Specific issue ID to find. If provided, ignores query.
|
| 861 |
-
status (str, optional): GitHub state ('open', 'closed'). Defaults to 'open'.
|
| 862 |
verdict (str, optional): AI Analysis Verdict ('resolved', 'duplicate', 'unresolved').
|
|
|
|
| 863 |
limit (int, optional): Max results to return. Defaults to 5.
|
| 864 |
|
| 865 |
Returns:
|
| 866 |
-
|
| 867 |
"""
|
| 868 |
if not repo_url:
|
| 869 |
-
return "
|
| 870 |
|
| 871 |
try:
|
| 872 |
repo_slug = repo_url.replace("https://github.com/", "").strip("/")
|
|
@@ -902,7 +909,7 @@ def search_issues(
|
|
| 902 |
params.append(issue_number)
|
| 903 |
else:
|
| 904 |
# 2. Status Filter
|
| 905 |
-
if status:
|
| 906 |
sql += " AND i.state = %s"
|
| 907 |
params.append(status)
|
| 908 |
|
|
@@ -914,8 +921,13 @@ def search_issues(
|
|
| 914 |
# If filtering by verdict, we assume user wants analyzed issues
|
| 915 |
sql += " AND r.verdict = %s"
|
| 916 |
params.append(verdict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 917 |
|
| 918 |
-
#
|
| 919 |
if query:
|
| 920 |
sql += " AND (i.title ILIKE %s OR i.body ILIKE %s)"
|
| 921 |
wildcard = f"%{query}%"
|
|
@@ -931,27 +943,23 @@ def search_issues(
|
|
| 931 |
if not rows:
|
| 932 |
return {"error": "No issues found matching criteria."}
|
| 933 |
|
| 934 |
-
# Convert to list of dicts
|
| 935 |
-
result =
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
],
|
| 947 |
-
indent=2,
|
| 948 |
-
default=str,
|
| 949 |
-
)
|
| 950 |
|
| 951 |
return result
|
| 952 |
|
| 953 |
except Exception as e:
|
| 954 |
-
return f"Database Error: {str(e)}"
|
| 955 |
|
| 956 |
|
| 957 |
def get_issue_report(repo_url: str, issue_number: int) -> dict:
|
|
@@ -971,7 +979,7 @@ def get_issue_report(repo_url: str, issue_number: int) -> dict:
|
|
| 971 |
cursor = conn.cursor()
|
| 972 |
|
| 973 |
# Check Report Table
|
| 974 |
-
cursor.execute("SELECT analysis_body, proposed_action, verdict FROM issue_reports WHERE issue_number = %s AND repo_url = %s", (issue_number, repo_url))
|
| 975 |
row = cursor.fetchone()
|
| 976 |
conn.close()
|
| 977 |
|
|
@@ -982,6 +990,7 @@ def get_issue_report(repo_url: str, issue_number: int) -> dict:
|
|
| 982 |
{
|
| 983 |
"issue": issue_number,
|
| 984 |
"verdict": row["verdict"],
|
|
|
|
| 985 |
"report": row["analysis_body"], # Full Markdown
|
| 986 |
"action": row["proposed_action"], # JSON
|
| 987 |
},
|
|
@@ -1536,7 +1545,9 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css, head=THEME_JS, title="GitRepo I
|
|
| 1536 |
with gr.Row():
|
| 1537 |
db_search_q = gr.Textbox(label="Query")
|
| 1538 |
db_search_id = gr.Number(label="Issue ID (Optional)")
|
|
|
|
| 1539 |
db_search_verdict = gr.Dropdown(["None", "resolved", "possibly_resolved", "duplicate", "unresolved", "error"], label="Verdict")
|
|
|
|
| 1540 |
db_search_btn = gr.Button("Search DB")
|
| 1541 |
|
| 1542 |
db_out = gr.JSON(label="Results")
|
|
@@ -1717,7 +1728,16 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css, head=THEME_JS, title="GitRepo I
|
|
| 1717 |
|
| 1718 |
# Tool 7: DB Search
|
| 1719 |
db_search_btn.click(
|
| 1720 |
-
fn=search_issues, inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1721 |
)
|
| 1722 |
|
| 1723 |
# Tool 8: Get Report
|
|
@@ -1794,4 +1814,4 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css, head=THEME_JS, title="GitRepo I
|
|
| 1794 |
# endregion
|
| 1795 |
if __name__ == "__main__":
|
| 1796 |
app.allowed_paths = ["."]
|
| 1797 |
-
app.launch(mcp_server=True, share=True, show_error=True, server_port=7860)
|
|
|
|
| 848 |
|
| 849 |
|
| 850 |
def search_issues(
|
| 851 |
+
repo_url: str,
|
| 852 |
+
query: str = "",
|
| 853 |
+
issue_number: int | None = None,
|
| 854 |
+
status: str = "open",
|
| 855 |
+
verdict: str | None = None,
|
| 856 |
+
author: str | None = None, # Added author parameter
|
| 857 |
+
limit: int = 5
|
| 858 |
) -> list | dict:
|
| 859 |
"""
|
| 860 |
Searches for issues in the database based on multiple criteria.
|
|
|
|
| 864 |
repo_url (str): The full repository URL.
|
| 865 |
query (str, optional): Text to search in title or body (e.g., "chatbot error").
|
| 866 |
issue_number (int, optional): Specific issue ID to find. If provided, ignores query.
|
| 867 |
+
status (str, optional): GitHub state ('open', 'closed', 'all'). Defaults to 'open'.
|
| 868 |
verdict (str, optional): AI Analysis Verdict ('resolved', 'duplicate', 'unresolved').
|
| 869 |
+
author (str, optional): Filter by issue creator's username (e.g., 'abidlabs').
|
| 870 |
limit (int, optional): Max results to return. Defaults to 5.
|
| 871 |
|
| 872 |
Returns:
|
| 873 |
+
list | dict: A list of dictionaries representing matching issues, or an error dict.
|
| 874 |
"""
|
| 875 |
if not repo_url:
|
| 876 |
+
return {"error": "Repo URL required."}
|
| 877 |
|
| 878 |
try:
|
| 879 |
repo_slug = repo_url.replace("https://github.com/", "").strip("/")
|
|
|
|
| 909 |
params.append(issue_number)
|
| 910 |
else:
|
| 911 |
# 2. Status Filter
|
| 912 |
+
if status and status.lower() not in ["all", "none", ""]:
|
| 913 |
sql += " AND i.state = %s"
|
| 914 |
params.append(status)
|
| 915 |
|
|
|
|
| 921 |
# If filtering by verdict, we assume user wants analyzed issues
|
| 922 |
sql += " AND r.verdict = %s"
|
| 923 |
params.append(verdict)
|
| 924 |
+
|
| 925 |
+
# 4. Author Filter (New)
|
| 926 |
+
if author:
|
| 927 |
+
sql += " AND i.user_login = %s"
|
| 928 |
+
params.append(author)
|
| 929 |
|
| 930 |
+
# 5. Text Search
|
| 931 |
if query:
|
| 932 |
sql += " AND (i.title ILIKE %s OR i.body ILIKE %s)"
|
| 933 |
wildcard = f"%{query}%"
|
|
|
|
| 943 |
if not rows:
|
| 944 |
return {"error": "No issues found matching criteria."}
|
| 945 |
|
| 946 |
+
# Convert to list of dicts (Return Python object, let Gradio handle JSON serialization)
|
| 947 |
+
result = [
|
| 948 |
+
{
|
| 949 |
+
"id": row["number"],
|
| 950 |
+
"title": row["title"],
|
| 951 |
+
"author": row["user_login"],
|
| 952 |
+
"snippet": row["snippet"] + "..." if row["snippet"] else "",
|
| 953 |
+
"state": row["github_state"],
|
| 954 |
+
"verdict": row["ai_verdict"],
|
| 955 |
+
}
|
| 956 |
+
for row in rows
|
| 957 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 958 |
|
| 959 |
return result
|
| 960 |
|
| 961 |
except Exception as e:
|
| 962 |
+
return {"error": f"Database Error: {str(e)}"}
|
| 963 |
|
| 964 |
|
| 965 |
def get_issue_report(repo_url: str, issue_number: int) -> dict:
|
|
|
|
| 979 |
cursor = conn.cursor()
|
| 980 |
|
| 981 |
# Check Report Table
|
| 982 |
+
cursor.execute("SELECT analysis_body, proposed_action, verdict, thought_process FROM issue_reports WHERE issue_number = %s AND repo_url = %s", (issue_number, repo_url))
|
| 983 |
row = cursor.fetchone()
|
| 984 |
conn.close()
|
| 985 |
|
|
|
|
| 990 |
{
|
| 991 |
"issue": issue_number,
|
| 992 |
"verdict": row["verdict"],
|
| 993 |
+
"thought": row["thought_process"],
|
| 994 |
"report": row["analysis_body"], # Full Markdown
|
| 995 |
"action": row["proposed_action"], # JSON
|
| 996 |
},
|
|
|
|
| 1545 |
with gr.Row():
|
| 1546 |
db_search_q = gr.Textbox(label="Query")
|
| 1547 |
db_search_id = gr.Number(label="Issue ID (Optional)")
|
| 1548 |
+
db_search_author = gr.Textbox(label="Author (User Login)", placeholder="e.g. abidlabs")
|
| 1549 |
db_search_verdict = gr.Dropdown(["None", "resolved", "possibly_resolved", "duplicate", "unresolved", "error"], label="Verdict")
|
| 1550 |
+
db_search_status = gr.Dropdown(["open", "closed"], label="GitHub Status")
|
| 1551 |
db_search_btn = gr.Button("Search DB")
|
| 1552 |
|
| 1553 |
db_out = gr.JSON(label="Results")
|
|
|
|
| 1728 |
|
| 1729 |
# Tool 7: DB Search
|
| 1730 |
db_search_btn.click(
|
| 1731 |
+
fn=search_issues, inputs=[
|
| 1732 |
+
sync_repo_url,
|
| 1733 |
+
db_search_q,
|
| 1734 |
+
db_search_id,
|
| 1735 |
+
db_search_status,
|
| 1736 |
+
db_search_verdict,
|
| 1737 |
+
db_search_author
|
| 1738 |
+
],
|
| 1739 |
+
outputs=[db_out],
|
| 1740 |
+
api_name="search_issues"
|
| 1741 |
)
|
| 1742 |
|
| 1743 |
# Tool 8: Get Report
|
|
|
|
| 1814 |
# endregion
|
| 1815 |
if __name__ == "__main__":
|
| 1816 |
app.allowed_paths = ["."]
|
| 1817 |
+
app.launch(mcp_server=True, share=True, show_error=True, server_port=7860, enable_monitoring=False)
|