Skip to content

Commit

Permalink
feat: Handle the gitlab MR draft status
Browse files Browse the repository at this point in the history
closes #1160
  • Loading branch information
paolomainardi committed Aug 22, 2024
1 parent cd526a2 commit ffaf5d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pr_agent/servers/gitlab_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,26 @@ async def inner(data: dict):
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))

log_context["sender"] = sender
should_skip_draft = get_settings().get("GITLAB.SKIP_DRAFT_MR", False)
if data.get('object_kind') == 'merge_request' and data['object_attributes'].get('action') in ['open', 'reopen']:
url = data['object_attributes'].get('url')
draft = data['object_attributes'].get('draft')
get_logger().info(f"New merge request: {url}")

if draft and should_skip_draft:
get_logger().info(f"Skipping draft MR: {url}")
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))

await _perform_commands_gitlab("pr_commands", PRAgent(), url, log_context)
elif data.get('object_kind') == 'note' and data.get('event_type') == 'note': # comment on MR
if 'merge_request' in data:
mr = data['merge_request']
url = mr.get('url')
draft = mr.get('draft')
if draft and should_skip_draft:
get_logger().info(f"Skipping draft MR: {url}")
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))

get_logger().info(f"A comment has been added to a merge request: {url}")
body = data.get('object_attributes', {}).get('note')
if data.get('object_attributes', {}).get('type') == 'DiffNote' and '/ask' in body: # /ask_line
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 @@ -230,6 +230,7 @@ push_commands = [
"/describe",
"/review --pr_reviewer.num_code_suggestions=0",
]
skip_draft_mr = false

[bitbucket_app]
pr_commands = [
Expand Down

0 comments on commit ffaf5d5

Please sign in to comment.