Skip to content

Commit

Permalink
Merge pull request #37 from hrshdhgd/end-not-needed
Browse files Browse the repository at this point in the history
Removed the need of `---` to mark end of commands
  • Loading branch information
hrshdhgd authored Nov 18, 2022
2 parents 1e10bab + 9c183a2 commit 505b2f1
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 171 deletions.
272 changes: 145 additions & 127 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ docs = [
]

[tool.black]
line-length = 79
line-length = 100
target-version = ["py38", "py39", "py310"]

[tool.isort]
profile = "black"
multi_line_output = 3
line_length = 79
line_length = 100
include_trailing_comma = true
reverse_relative = true

Expand Down
9 changes: 2 additions & 7 deletions src/ontobot_change_agent/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
from github import Github
from github.Issue import Issue
from oaklib.cli import query_terms_iterator
from oaklib.implementations import (
ProntoImplementation,
SimpleOboImplementation,
)
from oaklib.implementations import ProntoImplementation, SimpleOboImplementation
from oaklib.interfaces.patcher_interface import PatcherInterface
from oaklib.selector import get_resource_from_shorthand

Expand Down Expand Up @@ -146,9 +143,7 @@ def process_issue_via_oak(input: str, commands: list, output: str = None):
# TODO: There must be a better way to identify label in command.
if ":" not in command and change.about_node is None:
change.about_node = list(
query_terms_iterator(
[change.old_value.strip("'").strip('"')], impl_obj
)
query_terms_iterator([change.old_value.strip("'").strip('"')], impl_obj)
)[0]

impl_obj.apply_patch(change)
Expand Down
34 changes: 13 additions & 21 deletions src/ontobot_change_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import click

from ontobot_change_agent import __version__
from ontobot_change_agent.api import (
get_all_labels_from_repo,
get_issues,
process_issue_via_oak,
)
from ontobot_change_agent.api import get_all_labels_from_repo, get_issues, process_issue_via_oak

__all__ = [
"main",
Expand Down Expand Up @@ -136,9 +132,7 @@ def get_labels(repo: str):
@issue_number_option
@state_option
@output_option
def process_issue(
input: str, repo: str, label: str, number: int, state: str, output: str
):
def process_issue(input: str, repo: str, label: str, number: int, state: str, output: str):
"""Run processes based on issue label.
:param repo: GitHub repository name [org/repo_name]
Expand All @@ -147,9 +141,7 @@ def process_issue(
"""
formatted_body = "The following commands were executed: </br>"

for issue in get_issues(
repository_name=repo, label=label, number=number, state=state
):
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)
Expand All @@ -159,10 +151,15 @@ def process_issue(
else:
begin_index = 0

if end_match is not None:
end_index = end_match.end() - 3
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 = 0
end_index = end_match.end() - 3

if output:
new_output = output
Expand All @@ -172,10 +169,7 @@ def process_issue(
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 # noqa W503
and len(KGCL_COMMANDS) > 0 # noqa W503
):
if issue["number"] == number and len(KGCL_COMMANDS) > 0: # noqa W503 # noqa W503
process_issue_via_oak(
input=input,
commands=KGCL_COMMANDS,
Expand All @@ -192,9 +186,7 @@ def process_issue(
"""
)
else:
click.echo(
f"""{issue[TITLE]} does not need ontobot's attention."""
)
click.echo(f"""{issue[TITLE]} does not need ontobot's attention.""")


def _list_to_markdown(list: list) -> str:
Expand Down
14 changes: 3 additions & 11 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

from github.Issue import Issue

from ontobot_change_agent.api import (
TOKEN,
get_all_labels_from_repo,
get_issues,
)
from ontobot_change_agent.api import TOKEN, get_all_labels_from_repo, get_issues


class TestAPI(unittest.TestCase):
Expand All @@ -26,9 +22,7 @@ def setUp(self) -> None:
def test_get_issues_with_label(self):
"""Test if 'get_issues' returns the correct label."""
issues = []
for issue in get_issues(
repository_name=self.repo_name, label=self.label
):
for issue in get_issues(repository_name=self.repo_name, label=self.label):
issues.append(issue)

self.assertEqual(len(issues), 1)
Expand All @@ -40,9 +34,7 @@ def test_get_issues_with_label(self):
def test_get_issues_with_title(self):
"""Test if 'get_issues' returns the correct title."""
issues = []
for issue in get_issues(
repository_name=self.repo_name, title_search=self.issue_title
):
for issue in get_issues(repository_name=self.repo_name, title_search=self.issue_title):
issues.append(issue)

self.assertEqual(len(issues), 1)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def setUp(self):

def test_get_issues(self):
"""Test get_issues CLI command."""
result = self.runner.invoke(
issues, ["--label", "test", "--repo", self.repo_name]
)
result = self.runner.invoke(issues, ["--label", "test", "--repo", self.repo_name])
result.stdout
result.stderr
self.assertEqual(0, result.exit_code)
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ ignore =
DAR301 # Missing "Yields" in Docstring: - yield
E111 # indentation is not a multiple of 4
T201 # print found.
max-line-length = 100

# [testenv:pyroma]
# deps =
Expand Down

0 comments on commit 505b2f1

Please sign in to comment.