Skip to content

Commit

Permalink
Merge pull request #39 from hrshdhgd/different-ends
Browse files Browse the repository at this point in the history
Different ends
  • Loading branch information
hrshdhgd authored Nov 18, 2022
2 parents 3c2de29 + 8feb0af commit ebcb6f6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "ontobot-change-agent"
version = "0.2.8"
version = "0.2.9"
description = "Update ontologies using change language."

authors = ["Harshad Hegde <[email protected]>"]
Expand Down
33 changes: 23 additions & 10 deletions src/ontobot_change_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,35 @@ def process_issue(input: str, repo: str, label: str, number: int, state: str, ou
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_match = re.match(r"(.*)---", issue_body)
end_index_contenders = []

if begin_match:
begin_index = begin_match.end() - 1
else:
begin_index = 0

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

if output:
new_output = output
Expand Down
20 changes: 19 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_get_labels(self):
result.stderr
self.assertEqual(0, result.exit_code)

def test_process_issues(self):
def test_process_issues_with_end(self):
"""Test process_issue CLI command."""
result = self.runner.invoke(
process_issue,
Expand All @@ -54,6 +54,24 @@ def test_process_issues(self):
result.stderr
self.assertEqual(0, result.exit_code)

def test_process_issues_without_end(self):
"""Test process_issue CLI command."""
result = self.runner.invoke(
process_issue,
[
self.resource,
"--repo",
self.repo_name,
"-n",
38,
"-o",
self.output,
],
)
result.stdout
result.stderr
self.assertEqual(0, result.exit_code)

# def test_process_issues_fail(self):
# """Test process_issue CLI command."""
# result = self.runner.invoke(
Expand Down
12 changes: 6 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ envlist =
docstr-coverage
# docs-test
# the actual tests
py
; py
# always keep coverage-report last
# coverage-report

[testenv]
; [testenv]
# Runs on the "tests" directory by default, or passes the positional
# arguments from `tox -e py <posargs_1> ... <posargs_n>
whitelist_externals =
poetry
commands =
poetry run pytest
; whitelist_externals =
; poetry
; commands =
; poetry run pytest
; commands =
; coverage run -p -m pytest --durations=20 {posargs:tests}
; coverage combine
Expand Down

0 comments on commit ebcb6f6

Please sign in to comment.