Compare commits

..

No commits in common. "d5e7767841342aeb1186a11ac419345a22fe35dd" and "b0cd7b6b094d636098bf9d4ad88d57e12d9e4651" have entirely different histories.

1 changed files with 25 additions and 39 deletions

View File

@ -39,51 +39,37 @@ def cli():
pass pass
def parse(input_text: str = ""): def parse_text(input_text: str = ""):
"""Parses text for Jira or Bugzilla issue numbers and creates entries from them""" """Parses text for Jira or Bugzilla issue numbers and creates entries from them"""
if input_text == "": if input_text == "":
logging.error("No text provided for parsing.") click.echo("No text provided for parsing.")
match input_text: for line in input_text:
case [text] if type(text) == str: line = line.strip()
logging.debug(f"{text} is a string.") if results := re.findall(search_pattern, line, re.IGNORECASE):
parse_text(text) logging.debug(f"Found matches: {results}")
case [*line]: if len(results) != 1:
logging.debug("This is a list of lines.") logging.debug("More than 1 match found.")
for line in input_text: else:
line = line.strip() logging.debug("Only 1 match found.")
parse_text(line) parentheses_items: list = []
case _: # FIXME: add links to other mentioned sections, for now just link the first one
logging.debug("This is nothing I recognize.") section_id = format_section_id(results[0])
for match in results:
issue_number = match.split("#").pop()
@cli.command("parse-text") if "jsc" in match:
@click.argument("text") parentheses_items.append(make_jira_url(issue_number))
def parse_text_command(text): if "bsc" in match:
parse_text(text) parentheses_items.append(make_bugzilla_url(issue_number))
parentheses_text = ", ".join(parentheses_items)
click.echo(make_entry(section_id, parentheses_text))
def parse_text(line): else:
if results := re.findall(search_pattern, line, re.IGNORECASE): logging.debug(f"Nothing found in line '{line}'. Ignoring.")
logging.debug(f"Found matches: {results}")
parentheses_items: list = []
# FIXME: add links to other mentioned sections, for now just link the first one
section_id = format_section_id(results[0])
for match in results:
issue_number = match.split("#").pop()
if "jsc" in match:
parentheses_items.append(make_jira_url(issue_number))
if "bsc" in match:
parentheses_items.append(make_bugzilla_url(issue_number))
parentheses_text = ", ".join(parentheses_items)
click.echo(make_entry(section_id, parentheses_text))
else:
logging.debug(f"Nothing found in line '{line}'. Ignoring.")
@cli.command() @cli.command()
@click.argument("filename", type=click.File()) @click.argument("filename", type=click.File())
def parse_file(filename: IO): def parse(filename: IO):
parse(filename.readlines()) parse_text(filename.readlines())
if __name__ == "__main__": if __name__ == "__main__":