Skip to content

Commit 505b2f1

Browse files
authored
Merge pull request #37 from hrshdhgd/end-not-needed
Removed the need of `---` to mark end of commands
2 parents 1e10bab + 9c183a2 commit 505b2f1

File tree

7 files changed

+167
-171
lines changed

7 files changed

+167
-171
lines changed

poetry.lock

Lines changed: 145 additions & 127 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ docs = [
3232
]
3333

3434
[tool.black]
35-
line-length = 79
35+
line-length = 100
3636
target-version = ["py38", "py39", "py310"]
3737

3838
[tool.isort]
3939
profile = "black"
4040
multi_line_output = 3
41-
line_length = 79
41+
line_length = 100
4242
include_trailing_comma = true
4343
reverse_relative = true
4444

src/ontobot_change_agent/api.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
from github import Github
1111
from github.Issue import Issue
1212
from oaklib.cli import query_terms_iterator
13-
from oaklib.implementations import (
14-
ProntoImplementation,
15-
SimpleOboImplementation,
16-
)
13+
from oaklib.implementations import ProntoImplementation, SimpleOboImplementation
1714
from oaklib.interfaces.patcher_interface import PatcherInterface
1815
from oaklib.selector import get_resource_from_shorthand
1916

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

154149
impl_obj.apply_patch(change)

src/ontobot_change_agent/cli.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
import click
1010

1111
from ontobot_change_agent import __version__
12-
from ontobot_change_agent.api import (
13-
get_all_labels_from_repo,
14-
get_issues,
15-
process_issue_via_oak,
16-
)
12+
from ontobot_change_agent.api import get_all_labels_from_repo, get_issues, process_issue_via_oak
1713

1814
__all__ = [
1915
"main",
@@ -136,9 +132,7 @@ def get_labels(repo: str):
136132
@issue_number_option
137133
@state_option
138134
@output_option
139-
def process_issue(
140-
input: str, repo: str, label: str, number: int, state: str, output: str
141-
):
135+
def process_issue(input: str, repo: str, label: str, number: int, state: str, output: str):
142136
"""Run processes based on issue label.
143137
144138
:param repo: GitHub repository name [org/repo_name]
@@ -147,9 +141,7 @@ def process_issue(
147141
"""
148142
formatted_body = "The following commands were executed: </br>"
149143

150-
for issue in get_issues(
151-
repository_name=repo, label=label, number=number, state=state
152-
):
144+
for issue in get_issues(repository_name=repo, label=label, number=number, state=state):
153145
issue_body = issue[BODY].replace("\n", " ")
154146
begin_match = re.match(r"(.*)ontobot(.*)apply(.*):(.*)\*", issue_body)
155147
end_match = re.match(r"(.*)---", issue_body)
@@ -159,10 +151,15 @@ def process_issue(
159151
else:
160152
begin_index = 0
161153

162-
if end_match is not None:
163-
end_index = end_match.end() - 3
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()
164161
else:
165-
end_index = 0
162+
end_index = end_match.end() - 3
166163

167164
if output:
168165
new_output = output
@@ -172,10 +169,7 @@ def process_issue(
172169
if begin_index < end_index:
173170
KGCL_COMMANDS = issue_body[begin_index:end_index].split("* ")[1:]
174171
KGCL_COMMANDS = [x.strip() for x in KGCL_COMMANDS]
175-
if (
176-
issue["number"] == number # noqa W503
177-
and len(KGCL_COMMANDS) > 0 # noqa W503
178-
):
172+
if issue["number"] == number and len(KGCL_COMMANDS) > 0: # noqa W503 # noqa W503
179173
process_issue_via_oak(
180174
input=input,
181175
commands=KGCL_COMMANDS,
@@ -192,9 +186,7 @@ def process_issue(
192186
"""
193187
)
194188
else:
195-
click.echo(
196-
f"""{issue[TITLE]} does not need ontobot's attention."""
197-
)
189+
click.echo(f"""{issue[TITLE]} does not need ontobot's attention.""")
198190

199191

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

tests/test_api.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
from github.Issue import Issue
88

9-
from ontobot_change_agent.api import (
10-
TOKEN,
11-
get_all_labels_from_repo,
12-
get_issues,
13-
)
9+
from ontobot_change_agent.api import TOKEN, get_all_labels_from_repo, get_issues
1410

1511

1612
class TestAPI(unittest.TestCase):
@@ -26,9 +22,7 @@ def setUp(self) -> None:
2622
def test_get_issues_with_label(self):
2723
"""Test if 'get_issues' returns the correct label."""
2824
issues = []
29-
for issue in get_issues(
30-
repository_name=self.repo_name, label=self.label
31-
):
25+
for issue in get_issues(repository_name=self.repo_name, label=self.label):
3226
issues.append(issue)
3327

3428
self.assertEqual(len(issues), 1)
@@ -40,9 +34,7 @@ def test_get_issues_with_label(self):
4034
def test_get_issues_with_title(self):
4135
"""Test if 'get_issues' returns the correct title."""
4236
issues = []
43-
for issue in get_issues(
44-
repository_name=self.repo_name, title_search=self.issue_title
45-
):
37+
for issue in get_issues(repository_name=self.repo_name, title_search=self.issue_title):
4638
issues.append(issue)
4739

4840
self.assertEqual(len(issues), 1)

tests/test_cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def setUp(self):
2424

2525
def test_get_issues(self):
2626
"""Test get_issues CLI command."""
27-
result = self.runner.invoke(
28-
issues, ["--label", "test", "--repo", self.repo_name]
29-
)
27+
result = self.runner.invoke(issues, ["--label", "test", "--repo", self.repo_name])
3028
result.stdout
3129
result.stderr
3230
self.assertEqual(0, result.exit_code)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ ignore =
100100
DAR301 # Missing "Yields" in Docstring: - yield
101101
E111 # indentation is not a multiple of 4
102102
T201 # print found.
103+
max-line-length = 100
103104

104105
# [testenv:pyroma]
105106
# deps =

0 commit comments

Comments
 (0)