From 522f6d374a38802db8005aa1f41f4b5459da3156 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Mon, 21 Nov 2022 12:17:04 -0600 Subject: [PATCH] Check if ontobot is needed or no. --- src/ontobot_change_agent/cli.py | 69 ++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index 3d4acfd..3da6632 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -3,6 +3,7 @@ """Command line interface for :mod:`ontobot_change_agent`.""" import logging +import re from typing import TextIO import click @@ -141,39 +142,43 @@ def process_issue(input: str, repo: str, label: str, number: int, state: str, ou formatted_body = "The following commands were executed:
" for issue in get_issues(repository_name=repo, label=label, number=number, state=state): - bullet_starters = ["* ", "- "] - KGCL_COMMANDS = [] - for bullet in bullet_starters: - - KGCL_COMMANDS.extend( - [ - str(item).replace(bullet, "") - for item in issue[BODY].splitlines() - if item.startswith(bullet) - ] - ) - if output: - new_output = output + # Make sure ontobot_change_agent needs to be triggered or no. + if re.match(r"(.*)ontobot(.*)apply(.*):(.*)\*", issue[BODY]): + bullet_starters = ["* ", "- "] + KGCL_COMMANDS = [] + for bullet in bullet_starters: + + KGCL_COMMANDS.extend( + [ + str(item).replace(bullet, "") + for item in issue[BODY].splitlines() + if item.startswith(bullet) + ] + ) + if output: + new_output = output + else: + new_output = input + + KGCL_COMMANDS = [x.strip() for x in KGCL_COMMANDS] + if issue["number"] == number and len(KGCL_COMMANDS) > 0: # noqa W503 # noqa W503 + process_issue_via_oak( + input=input, + commands=KGCL_COMMANDS, + output=new_output, + ) + + formatted_body += _list_to_markdown(KGCL_COMMANDS) + formatted_body += "
Fixes #" + str(issue["number"]) + + click.echo( + f""" + ::set-output name=PR_BODY::{formatted_body} + ::set-output name=PR_TITLE::{issue[TITLE]} + """ + ) else: - new_output = input - - KGCL_COMMANDS = [x.strip() for x in KGCL_COMMANDS] - if issue["number"] == number and len(KGCL_COMMANDS) > 0: # noqa W503 # noqa W503 - process_issue_via_oak( - input=input, - commands=KGCL_COMMANDS, - output=new_output, - ) - - formatted_body += _list_to_markdown(KGCL_COMMANDS) - formatted_body += "
Fixes #" + str(issue["number"]) - - click.echo( - f""" - ::set-output name=PR_BODY::{formatted_body} - ::set-output name=PR_TITLE::{issue[TITLE]} - """ - ) + click.echo(f"""{issue[TITLE]} does not need ontobot's attention.""") def _list_to_markdown(list: list) -> str: