Skip to content

Commit

Permalink
feat: optionally strip body and text
Browse files Browse the repository at this point in the history
If `cut_body_after` or `cut_body_before` is in use, setting this option
to `true` also removes the text itself.
  • Loading branch information
jbergstroem committed Dec 20, 2021
1 parent 852e345 commit ee488ef
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 412 deletions.
1 change: 1 addition & 0 deletions bot/kodiak/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MergeMessage(BaseModel):
include_pull_request_url: bool = False
cut_body_before: str = ""
cut_body_after: str = ""
cut_body_and_text: bool = False


# this pattern indicates that the user has the field unset.
Expand Down
7 changes: 7 additions & 0 deletions bot/kodiak/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,24 @@ def get_body_content(
strip_html_comments: bool,
cut_body_before: str,
cut_body_after: str,
cut_body_and_text: bool,
pull_request: PullRequest,
) -> str:
if body_type is BodyText.markdown:
body = pull_request.body
# TODO(jbergstroem): This could probably be made faster by just cutting the string differently
if cut_body_before != "":
start_index = body.find(cut_body_before)
if start_index != -1:
body = body[start_index:]
if cut_body_and_text:
body = body.replace(cut_body_before, "", 1)
if cut_body_after != "":
end_index = body.find(cut_body_after)
if end_index != -1:
body = body[: end_index + len(cut_body_after)]
if cut_body_and_text:
body = body.replace(cut_body_after, "", 1)
if strip_html_comments:
return strip_html_comments_from_markdown(body)
return body
Expand Down Expand Up @@ -182,6 +188,7 @@ def get_merge_body(
body = get_body_content(
body_type=config.merge.message.body_type,
strip_html_comments=config.merge.message.strip_html_comments,
cut_body_and_text=config.merge.message.cut_body_and_text,
cut_body_before=config.merge.message.cut_body_before,
cut_body_after=config.merge.message.cut_body_after,
pull_request=pull_request,
Expand Down
Loading

0 comments on commit ee488ef

Please sign in to comment.