Skip to content
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
53 changes: 53 additions & 0 deletions .github/workflows/test_bot_responses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test Bot Responses

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-mock pytest-cov

- name: Run basic tests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
pytest tests/test_response_agent.py -v

- name: Run detailed tests
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pytest tests/test_detailed_responses.py -v

- name: Run all tests with coverage
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pytest tests/ -v --cov=src --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
fail_ci_if_error: false
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --ignore=src/repos
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ pre-commit>=3.5.0
urlextract>=1.0.0
beautifulsoup4>=4.9.3
aider-chat>=0.18.0
pytest>=7.0.0
pytest-mock>=3.10.0
pytest-cov>=4.1.0
codecov>=2.1.13
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file is required to make Python treat the directory as a package.
6 changes: 3 additions & 3 deletions src/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import autogen
import subprocess
from autogen import ConversableAgent, AssistantAgent, UserProxyAgent
import bot_tools
from git_utils import (
from src import bot_tools
from src.git_utils import (
get_github_client,
get_repository,
get_issue_comments,
)
from github.Issue import Issue
import random
import string
import triggers
from src import triggers
from urlextract import URLExtract


Expand Down
94 changes: 94 additions & 0 deletions src/bot_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,97 @@ def search_github(query: str) -> str:
from git_utils import perform_github_search

return perform_github_search(query)

# Testing utilities


def create_mock_issue(
issue_number: int = 1,
title: str = "Test Issue",
body: str = "This is a test issue",
labels: list = None,
user_login: str = "test_user"
) -> dict:
"""
Create a mock issue for testing purposes.

Args:
issue_number: The issue number
title: The issue title
body: The issue body
labels: List of label names
user_login: Username of issue creator

Returns:
A dictionary representing a GitHub issue
"""
if labels is None:
labels = ["blech_bot"]

return {
"number": issue_number,
"title": title,
"body": body,
"labels": [{"name": label} for label in labels],
"user": {"login": user_login},
"comments_url": f"https://api.github.com/repos/test/test/issues/{issue_number}/comments",
"html_url": f"https://github.com/test/test/issues/{issue_number}"
}


def create_mock_comment(
comment_id: int = 1,
body: str = "Test comment",
user_login: str = "test_user",
created_at: str = "2023-01-01T00:00:00Z"
) -> dict:
"""
Create a mock comment for testing purposes.

Args:
comment_id: The comment ID
body: The comment body
user_login: Username of commenter
created_at: Creation timestamp

Returns:
A dictionary representing a GitHub comment
"""
return {
"id": comment_id,
"body": body,
"user": {"login": user_login},
"created_at": created_at,
"html_url": f"https://github.com/test/test/issues/comments/{comment_id}"
}


def create_mock_pull_request(
pr_number: int = 1,
title: str = "Test PR",
body: str = "This is a test PR",
branch: str = "test-branch",
user_login: str = "test_user"
) -> dict:
"""
Create a mock pull request for testing purposes.

Args:
pr_number: The PR number
title: The PR title
body: The PR body
branch: The branch name
user_login: Username of PR creator

Returns:
A dictionary representing a GitHub pull request
"""
return {
"number": pr_number,
"title": title,
"body": body,
"head": {"ref": branch},
"user": {"login": user_login},
"html_url": f"https://github.com/test/test/pull/{pr_number}",
"comments_url": f"https://api.github.com/repos/test/test/issues/{pr_number}/comments"
}
2 changes: 1 addition & 1 deletion src/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import subprocess
import git
from branch_handler import (
from src.branch_handler import (
get_issue_related_branches,
get_current_branch,
checkout_branch,
Expand Down
12 changes: 6 additions & 6 deletions src/response_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

from dotenv import load_dotenv
import string
import triggers
from agents import (
from src import triggers
from src.agents import (
create_user_agent,
create_agent,
generate_prompt,
parse_comments
)
from urlextract import URLExtract
import agents
from src import agents
from autogen import AssistantAgent
import bot_tools
from src import bot_tools
import os

from git_utils import (
from src.git_utils import (
get_github_client,
get_repository,
write_issue_response,
Expand All @@ -35,7 +35,7 @@
from github.Repository import Repository
from github.Issue import Issue
from github.PullRequest import PullRequest
from branch_handler import (
from src.branch_handler import (
checkout_branch,
back_to_master_branch,
delete_branch
Expand Down
4 changes: 2 additions & 2 deletions src/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Functions to check specific conditions
"""
from github import Issue
from git_utils import get_issue_comments
from src.git_utils import get_issue_comments


def has_blech_bot_tag(issue: Issue) -> bool:
Expand Down Expand Up @@ -131,7 +131,7 @@ def has_user_comment_on_pr(issue: Issue) -> bool:
Returns:
True if there is a user comment on a PR that needs processing
"""
from git_utils import has_linked_pr, get_linked_pr
from src.git_utils import has_linked_pr, get_linked_pr

# First check issue comments
comments = get_issue_comments(issue)
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Tests package
# This file is required to make Python treat the directory as a package.
Loading