Skip to content

Commit 7e04e4f

Browse files
authored
Merge pull request #40 from hrshdhgd/new-command-extraction-stratgy
New way of extracting commands using `splitlines()`
2 parents ebcb6f6 + 245f669 commit 7e04e4f

File tree

3 files changed

+22
-56
lines changed

3 files changed

+22
-56
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22

33
name = "ontobot-change-agent"
4-
version = "0.2.9"
4+
version = "0.3.0"
55
description = "Update ontologies using change language."
66

77
authors = ["Harshad Hegde <[email protected]>"]

src/ontobot_change_agent/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _make_sense_of_body(body: str) -> str:
104104
# return (
105105
# body.lstrip(bullet).replace("<", "").replace(">", "").split(splitter)
106106
# )
107-
return body.replace("<", "").replace(">", "").replace("\r\n", "")
107+
return body.replace("<", "").replace(">", "")
108108

109109

110110
def get_all_labels_from_repo(repository_name: str) -> dict:

src/ontobot_change_agent/cli.py

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""Command line interface for :mod:`ontobot_change_agent`."""
44

55
import logging
6-
import re
76
from typing import TextIO
87

98
import click
@@ -142,64 +141,31 @@ def process_issue(input: str, repo: str, label: str, number: int, state: str, ou
142141
formatted_body = "The following commands were executed: </br>"
143142

144143
for issue in get_issues(repository_name=repo, label=label, number=number, state=state):
145-
issue_body = issue[BODY].replace("\n", " ")
146-
begin_match = re.match(r"(.*)ontobot(.*)apply(.*):(.*)\*", issue_body)
147-
end_index_contenders = []
148-
149-
if begin_match:
150-
begin_index = begin_match.end() - 1
151-
else:
152-
begin_index = 0
153-
154-
# if issue has `---` as command end indicator
155-
dash_end_match = re.match(r"(.*)---", issue_body)
156-
end_index_contenders.append(dash_end_match.end() - 3 if dash_end_match is not None else 0)
157-
158-
# if issue has no command end indicator and ends with a CURIE
159-
colon_end_match = re.match(r"(.*):\d+", issue_body)
160-
end_index_contenders.append(colon_end_match.end() if colon_end_match is not None else 0)
161-
162-
# if issue has no command end indicator and ends with a URI
163-
underscore_end_match = re.match(r"(.*)_\d+", issue_body)
164-
end_index_contenders.append(
165-
underscore_end_match.end() if underscore_end_match is not None else 0
166-
)
167-
168-
# if issue has no command end indicator and ends with a label
169-
quote_end_match = re.match(r"(.*)\'", issue_body)
170-
end_index_contenders.append(quote_end_match.end() if quote_end_match is not None else 0)
171-
172-
end_index = max(end_index_contenders)
173-
174-
if end_index == 0:
175-
click.echo(f"""Cannot find end of command: {issue_body[begin_index:]}""")
176-
144+
KGCL_COMMANDS = [
145+
str(item).replace("* ", "") for item in issue[BODY].splitlines() if item.startswith("*")
146+
]
177147
if output:
178148
new_output = output
179149
else:
180150
new_output = input
181151

182-
if begin_index < end_index:
183-
KGCL_COMMANDS = issue_body[begin_index:end_index].split("* ")[1:]
184-
KGCL_COMMANDS = [x.strip() for x in KGCL_COMMANDS]
185-
if issue["number"] == number and len(KGCL_COMMANDS) > 0: # noqa W503 # noqa W503
186-
process_issue_via_oak(
187-
input=input,
188-
commands=KGCL_COMMANDS,
189-
output=new_output,
190-
)
191-
192-
formatted_body += _list_to_markdown(KGCL_COMMANDS)
193-
formatted_body += "</br>Fixes #" + str(issue["number"])
194-
195-
click.echo(
196-
f"""
197-
::set-output name=PR_BODY::{formatted_body}
198-
::set-output name=PR_TITLE::{issue[TITLE]}
199-
"""
200-
)
201-
else:
202-
click.echo(f"""{issue[TITLE]} does not need ontobot's attention.""")
152+
KGCL_COMMANDS = [x.strip() for x in KGCL_COMMANDS]
153+
if issue["number"] == number and len(KGCL_COMMANDS) > 0: # noqa W503 # noqa W503
154+
process_issue_via_oak(
155+
input=input,
156+
commands=KGCL_COMMANDS,
157+
output=new_output,
158+
)
159+
160+
formatted_body += _list_to_markdown(KGCL_COMMANDS)
161+
formatted_body += "</br>Fixes #" + str(issue["number"])
162+
163+
click.echo(
164+
f"""
165+
::set-output name=PR_BODY::{formatted_body}
166+
::set-output name=PR_TITLE::{issue[TITLE]}
167+
"""
168+
)
203169

204170

205171
def _list_to_markdown(list: list) -> str:

0 commit comments

Comments
 (0)