|
3 | 3 | """Command line interface for :mod:`ontobot_change_agent`.""" |
4 | 4 |
|
5 | 5 | import logging |
6 | | -import re |
7 | 6 | from typing import TextIO |
8 | 7 |
|
9 | 8 | import click |
@@ -142,64 +141,31 @@ def process_issue(input: str, repo: str, label: str, number: int, state: str, ou |
142 | 141 | formatted_body = "The following commands were executed: </br>" |
143 | 142 |
|
144 | 143 | 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 | + ] |
177 | 147 | if output: |
178 | 148 | new_output = output |
179 | 149 | else: |
180 | 150 | new_output = input |
181 | 151 |
|
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 | + ) |
203 | 169 |
|
204 | 170 |
|
205 | 171 | def _list_to_markdown(list: list) -> str: |
|
0 commit comments