From a0ee6699754a8d7cc1eadd80f3094d25c117f1d7 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Fri, 18 Nov 2022 12:43:35 -0600 Subject: [PATCH 1/2] New way of extracting commands using`splitlines()` --- src/ontobot_change_agent/api.py | 2 +- src/ontobot_change_agent/cli.py | 74 +++++++++------------------------ 2 files changed, 21 insertions(+), 55 deletions(-) diff --git a/src/ontobot_change_agent/api.py b/src/ontobot_change_agent/api.py index a68080f..21fe731 100644 --- a/src/ontobot_change_agent/api.py +++ b/src/ontobot_change_agent/api.py @@ -104,7 +104,7 @@ def _make_sense_of_body(body: str) -> str: # return ( # body.lstrip(bullet).replace("<", "").replace(">", "").split(splitter) # ) - return body.replace("<", "").replace(">", "").replace("\r\n", "") + return body.replace("<", "").replace(">", "") def get_all_labels_from_repo(repository_name: str) -> dict: diff --git a/src/ontobot_change_agent/cli.py b/src/ontobot_change_agent/cli.py index 08a8cc1..92da522 100644 --- a/src/ontobot_change_agent/cli.py +++ b/src/ontobot_change_agent/cli.py @@ -3,7 +3,6 @@ """Command line interface for :mod:`ontobot_change_agent`.""" import logging -import re from typing import TextIO import click @@ -142,64 +141,31 @@ 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): - issue_body = issue[BODY].replace("\n", " ") - begin_match = re.match(r"(.*)ontobot(.*)apply(.*):(.*)\*", issue_body) - end_index_contenders = [] - - if begin_match: - begin_index = begin_match.end() - 1 - else: - begin_index = 0 - - # if issue has `---` as command end indicator - dash_end_match = re.match(r"(.*)---", issue_body) - end_index_contenders.append(dash_end_match.end() - 3 if dash_end_match is not None else 0) - - # if issue has no command end indicator and ends with a CURIE - colon_end_match = re.match(r"(.*):\d+", issue_body) - end_index_contenders.append(colon_end_match.end() if colon_end_match is not None else 0) - - # if issue has no command end indicator and ends with a URI - underscore_end_match = re.match(r"(.*)_\d+", issue_body) - end_index_contenders.append( - underscore_end_match.end() if underscore_end_match is not None else 0 - ) - - # if issue has no command end indicator and ends with a label - quote_end_match = re.match(r"(.*)\'", issue_body) - end_index_contenders.append(quote_end_match.end() if quote_end_match is not None else 0) - - end_index = max(end_index_contenders) - - if end_index == 0: - click.echo(f"""Cannot find end of command: {issue_body[begin_index:]}""") - + KGCL_COMMANDS = [ + str(item).replace("* ", "") for item in issue[BODY].splitlines() if item.startswith("*") + ] if output: new_output = output else: new_output = input - if begin_index < end_index: - KGCL_COMMANDS = issue_body[begin_index:end_index].split("* ")[1:] - 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: - click.echo(f"""{issue[TITLE]} does not need ontobot's attention.""") + 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]} + """ + ) def _list_to_markdown(list: list) -> str: From 245f669d5450382a73023f007ecec0d214b8baac Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Fri, 18 Nov 2022 12:45:33 -0600 Subject: [PATCH 2/2] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4a61df4..5ee6f77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "ontobot-change-agent" -version = "0.2.9" +version = "0.3.0" description = "Update ontologies using change language." authors = ["Harshad Hegde "]