Skip to content

Commit

Permalink
Merge pull request #1165 from paolomainardi/feature/1160_gitlab_mr_dr…
Browse files Browse the repository at this point in the history
…aft_skip

feat: handle gitlab MR draft status
  • Loading branch information
mrT23 authored Aug 23, 2024
2 parents cd526a2 + 3778cc2 commit 4f1dccf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pr_agent/servers/gitlab_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,23 @@ async def inner(data: dict):
log_context["sender"] = sender
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:
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:
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

0 comments on commit 4f1dccf

Please sign in to comment.