Skip to content

Commit

Permalink
Merge pull request #800 from koid/feature/ignore-bot-pr-on-github-app
Browse files Browse the repository at this point in the history
Added `ignore_bot_pr` option
  • Loading branch information
mrT23 authored Mar 21, 2024
2 parents 6323ff2 + cae0b96 commit b4b2c7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pr_agent/servers/github_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,15 @@ async def handle_new_pr_opened(body: Dict[str, Any],
event: str,
sender: str,
sender_id: str,
sender_type: str,
action: str,
log_context: Dict[str, Any],
agent: PRAgent):
# logic to ignore PRs opened by bot
if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender_type == "Bot":
get_logger().info(f"Ignoring PR from '{sender=}' due to github_app.ignore_bot_pr setting")
return {}

title = body.get("pull_request", {}).get("title", "")

# logic to ignore PRs with specific titles (e.g. "[Auto] ...")
Expand Down Expand Up @@ -224,9 +230,11 @@ def handle_closed_pr(body, event, action, log_context):
def get_log_context(body, event, action, build_number):
sender = ""
sender_id = ""
sender_type = ""
try:
sender = body.get("sender", {}).get("login")
sender_id = body.get("sender", {}).get("id")
sender_type = body.get("sender", {}).get("type")
repo = body.get("repository", {}).get("full_name", "")
git_org = body.get("organization", {}).get("login", "")
app_name = get_settings().get("CONFIG.APP_NAME", "Unknown")
Expand All @@ -236,7 +244,7 @@ def get_log_context(body, event, action, build_number):
except Exception as e:
get_logger().error("Failed to get log context", e)
log_context = {}
return log_context, sender, sender_id
return log_context, sender, sender_id, sender_type


async def handle_request(body: Dict[str, Any], event: str):
Expand All @@ -251,7 +259,7 @@ async def handle_request(body: Dict[str, Any], event: str):
if not action:
return {}
agent = PRAgent()
log_context, sender, sender_id = get_log_context(body, event, action, build_number)
log_context, sender, sender_id, sender_type = get_log_context(body, event, action, build_number)

# handle comments on PRs
if action == 'created':
Expand All @@ -260,7 +268,7 @@ async def handle_request(body: Dict[str, Any], event: str):
# handle new PRs
elif event == 'pull_request' and action != 'synchronize' and action != 'closed':
get_logger().debug(f'Request body', artifact=body, event=event)
await handle_new_pr_opened(body, event, sender, sender_id, action, log_context, agent)
await handle_new_pr_opened(body, event, sender, sender_id, sender_type, action, log_context, agent)
# handle pull_request event with synchronize action - "push trigger" for new commits
elif event == 'pull_request' and action == 'synchronize':
get_logger().debug(f'Request body', artifact=body, event=event)
Expand Down
1 change: 1 addition & 0 deletions pr_agent/settings/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ push_commands = [
"/review --pr_reviewer.num_code_suggestions=0",
]
ignore_pr_title = []
ignore_bot_pr = false

[gitlab]
url = "https://gitlab.com" # URL to the gitlab service
Expand Down

0 comments on commit b4b2c7c

Please sign in to comment.