Skip to content

Commit ebcb6f6

Browse files
authored
Merge pull request #39 from hrshdhgd/different-ends
Different ends
2 parents 3c2de29 + 8feb0af commit ebcb6f6

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
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.8"
4+
version = "0.2.9"
55
description = "Update ontologies using change language."
66

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

src/ontobot_change_agent/cli.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,35 @@ def process_issue(input: str, repo: str, label: str, number: int, state: str, ou
144144
for issue in get_issues(repository_name=repo, label=label, number=number, state=state):
145145
issue_body = issue[BODY].replace("\n", " ")
146146
begin_match = re.match(r"(.*)ontobot(.*)apply(.*):(.*)\*", issue_body)
147-
end_match = re.match(r"(.*)---", issue_body)
147+
end_index_contenders = []
148148

149149
if begin_match:
150150
begin_index = begin_match.end() - 1
151151
else:
152152
begin_index = 0
153153

154-
if end_match is None:
155-
end_match = re.match(r"(.*):\d+", issue_body)
156-
if end_match is None:
157-
end_index = 0
158-
click.echo(f"""Cannot find end of command: {issue_body[begin_index:]}""")
159-
else:
160-
end_index = end_match.end()
161-
else:
162-
end_index = end_match.end() - 3
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:]}""")
163176

164177
if output:
165178
new_output = output

tests/test_cli.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_get_labels(self):
3636
result.stderr
3737
self.assertEqual(0, result.exit_code)
3838

39-
def test_process_issues(self):
39+
def test_process_issues_with_end(self):
4040
"""Test process_issue CLI command."""
4141
result = self.runner.invoke(
4242
process_issue,
@@ -54,6 +54,24 @@ def test_process_issues(self):
5454
result.stderr
5555
self.assertEqual(0, result.exit_code)
5656

57+
def test_process_issues_without_end(self):
58+
"""Test process_issue CLI command."""
59+
result = self.runner.invoke(
60+
process_issue,
61+
[
62+
self.resource,
63+
"--repo",
64+
self.repo_name,
65+
"-n",
66+
38,
67+
"-o",
68+
self.output,
69+
],
70+
)
71+
result.stdout
72+
result.stderr
73+
self.assertEqual(0, result.exit_code)
74+
5775
# def test_process_issues_fail(self):
5876
# """Test process_issue CLI command."""
5977
# result = self.runner.invoke(

tox.ini

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ envlist =
2323
docstr-coverage
2424
# docs-test
2525
# the actual tests
26-
py
26+
; py
2727
# always keep coverage-report last
2828
# coverage-report
2929

30-
[testenv]
30+
; [testenv]
3131
# Runs on the "tests" directory by default, or passes the positional
3232
# arguments from `tox -e py <posargs_1> ... <posargs_n>
33-
whitelist_externals =
34-
poetry
35-
commands =
36-
poetry run pytest
33+
; whitelist_externals =
34+
; poetry
35+
; commands =
36+
; poetry run pytest
3737
; commands =
3838
; coverage run -p -m pytest --durations=20 {posargs:tests}
3939
; coverage combine

0 commit comments

Comments
 (0)