mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-25 07:16:42 +00:00
parent
a7d3343580
commit
c7ca1ac039
@ -69,3 +69,6 @@ inputs:
|
|||||||
ISSUE_TEMPLATE:
|
ISSUE_TEMPLATE:
|
||||||
description: 'The template used to format new issues'
|
description: 'The template used to format new issues'
|
||||||
required: false
|
required: false
|
||||||
|
IDENTIFIERS:
|
||||||
|
description: 'Dictionary of custom identifiers'
|
||||||
|
required: false
|
||||||
47
main.py
47
main.py
@ -24,7 +24,7 @@ class Issue(object):
|
|||||||
"""Basic Issue model for collecting the necessary info to send to GitHub."""
|
"""Basic Issue model for collecting the necessary info to send to GitHub."""
|
||||||
|
|
||||||
def __init__(self, title, labels, assignees, milestone, user_projects, org_projects, body, hunk, file_name,
|
def __init__(self, title, labels, assignees, milestone, user_projects, org_projects, body, hunk, file_name,
|
||||||
start_line, markdown_language, status):
|
start_line, markdown_language, status, identifier):
|
||||||
self.title = title
|
self.title = title
|
||||||
self.labels = labels
|
self.labels = labels
|
||||||
self.assignees = assignees
|
self.assignees = assignees
|
||||||
@ -37,6 +37,7 @@ class Issue(object):
|
|||||||
self.start_line = start_line
|
self.start_line = start_line
|
||||||
self.markdown_language = markdown_language
|
self.markdown_language = markdown_language
|
||||||
self.status = status
|
self.status = status
|
||||||
|
self.identifier = identifier
|
||||||
|
|
||||||
|
|
||||||
class GitHubClient(object):
|
class GitHubClient(object):
|
||||||
@ -293,8 +294,20 @@ class TodoParser(object):
|
|||||||
ORG_PROJECTS_PATTERN = re.compile(r'(?<=org projects:\s).+')
|
ORG_PROJECTS_PATTERN = re.compile(r'(?<=org projects:\s).+')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# We could support more identifiers later quite easily.
|
# Load any custom identifiers, otherwise use the default.
|
||||||
self.identifier = 'TODO'
|
custom_identifiers = os.getenv('INPUT_IDENTIFIERS')
|
||||||
|
if custom_identifiers:
|
||||||
|
try:
|
||||||
|
self.identifiers_dict = json.loads(custom_identifiers)
|
||||||
|
for identifier_dict in self.identifiers_dict:
|
||||||
|
if type(identifier_dict['name']) != str or type(identifier_dict['labels']) != list:
|
||||||
|
raise TypeError
|
||||||
|
self.identifiers = [identifier['name'] for identifier in self.identifiers_dict]
|
||||||
|
except (json.JSONDecodeError, KeyError, TypeError):
|
||||||
|
print('Invalid identifiers dict, ignoring.')
|
||||||
|
self.identifiers_dict = None
|
||||||
|
self.identifiers = ['TODO']
|
||||||
|
|
||||||
self.languages_dict = None
|
self.languages_dict = None
|
||||||
|
|
||||||
# Load the languages data for ascertaining file types.
|
# Load the languages data for ascertaining file types.
|
||||||
@ -400,7 +413,7 @@ class TodoParser(object):
|
|||||||
extracted_comments = []
|
extracted_comments = []
|
||||||
prev_comment = None
|
prev_comment = None
|
||||||
for i, comment in enumerate(comments):
|
for i, comment in enumerate(comments):
|
||||||
if i == 0 or self.identifier in comment.group(0):
|
if i == 0 or re.search('|'.join(self.identifiers), comment.group(0)):
|
||||||
extracted_comments.append([comment])
|
extracted_comments.append([comment])
|
||||||
else:
|
else:
|
||||||
if comment.start() == prev_comment.end() + 1:
|
if comment.start() == prev_comment.end() + 1:
|
||||||
@ -416,7 +429,7 @@ class TodoParser(object):
|
|||||||
comments = re.finditer(comment_pattern, block['hunk'], re.DOTALL)
|
comments = re.finditer(comment_pattern, block['hunk'], re.DOTALL)
|
||||||
extracted_comments = []
|
extracted_comments = []
|
||||||
for i, comment in enumerate(comments):
|
for i, comment in enumerate(comments):
|
||||||
if self.identifier in comment.group(0):
|
if re.search('|'.join(self.identifiers), comment.group(0)):
|
||||||
extracted_comments.append([comment])
|
extracted_comments.append([comment])
|
||||||
|
|
||||||
for comment in extracted_comments:
|
for comment in extracted_comments:
|
||||||
@ -464,7 +477,7 @@ class TodoParser(object):
|
|||||||
for line in lines:
|
for line in lines:
|
||||||
line_status, committed_line = self._get_line_status(line)
|
line_status, committed_line = self._get_line_status(line)
|
||||||
cleaned_line = self._clean_line(committed_line, marker)
|
cleaned_line = self._clean_line(committed_line, marker)
|
||||||
line_title, ref = self._get_title(cleaned_line)
|
line_title, ref, identifier = self._get_title(cleaned_line)
|
||||||
if line_title:
|
if line_title:
|
||||||
if ref:
|
if ref:
|
||||||
issue_title = f'[{ref}] {line_title}'
|
issue_title = f'[{ref}] {line_title}'
|
||||||
@ -482,7 +495,8 @@ class TodoParser(object):
|
|||||||
file_name=code_block['file'],
|
file_name=code_block['file'],
|
||||||
start_line=code_block['start_line'],
|
start_line=code_block['start_line'],
|
||||||
markdown_language=code_block['markdown_language'],
|
markdown_language=code_block['markdown_language'],
|
||||||
status=line_status
|
status=line_status,
|
||||||
|
identifier=identifier
|
||||||
)
|
)
|
||||||
|
|
||||||
# Calculate the file line number that this issue references.
|
# Calculate the file line number that this issue references.
|
||||||
@ -514,6 +528,14 @@ class TodoParser(object):
|
|||||||
issue.org_projects.extend(org_projects)
|
issue.org_projects.extend(org_projects)
|
||||||
elif len(cleaned_line):
|
elif len(cleaned_line):
|
||||||
issue.body.append(cleaned_line)
|
issue.body.append(cleaned_line)
|
||||||
|
|
||||||
|
if issue is not None and issue.identifier is not None and self.identifiers_dict is not None:
|
||||||
|
for identifier_dict in self.identifiers_dict:
|
||||||
|
if identifier_dict['name'] == issue.identifier:
|
||||||
|
for label in identifier_dict['labels']:
|
||||||
|
if label not in issue.labels:
|
||||||
|
issue.labels.append(label)
|
||||||
|
|
||||||
return issue
|
return issue
|
||||||
|
|
||||||
def _get_line_status(self, comment):
|
def _get_line_status(self, comment):
|
||||||
@ -548,12 +570,16 @@ class TodoParser(object):
|
|||||||
"""Check the passed comment for a new issue title (and reference, if specified)."""
|
"""Check the passed comment for a new issue title (and reference, if specified)."""
|
||||||
title = None
|
title = None
|
||||||
ref = None
|
ref = None
|
||||||
title_pattern = re.compile(r'(?<=' + self.identifier + r'[\s:]).+')
|
title_identifier = None
|
||||||
|
for identifier in self.identifiers:
|
||||||
|
title_identifier = identifier
|
||||||
|
title_pattern = re.compile(r'(?<=' + identifier + r'[\s:]).+')
|
||||||
title_search = title_pattern.search(comment, re.IGNORECASE)
|
title_search = title_pattern.search(comment, re.IGNORECASE)
|
||||||
if title_search:
|
if title_search:
|
||||||
title = title_search.group(0).strip()
|
title = title_search.group(0).strip()
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
title_ref_pattern = re.compile(r'(?<=' + self.identifier + r'\().+')
|
title_ref_pattern = re.compile(r'(?<=' + identifier + r'\().+')
|
||||||
title_ref_search = title_ref_pattern.search(comment, re.IGNORECASE)
|
title_ref_search = title_ref_pattern.search(comment, re.IGNORECASE)
|
||||||
if title_ref_search:
|
if title_ref_search:
|
||||||
title = title_ref_search.group(0).strip()
|
title = title_ref_search.group(0).strip()
|
||||||
@ -561,7 +587,8 @@ class TodoParser(object):
|
|||||||
if ref_search:
|
if ref_search:
|
||||||
ref = ref_search.group(0)
|
ref = ref_search.group(0)
|
||||||
title = title.replace(ref, '', 1).lstrip(':) ')
|
title = title.replace(ref, '', 1).lstrip(':) ')
|
||||||
return title, ref
|
break
|
||||||
|
return title, ref, title_identifier
|
||||||
|
|
||||||
def _get_labels(self, comment):
|
def _get_labels(self, comment):
|
||||||
"""Check the passed comment for issue labels."""
|
"""Check the passed comment for issue labels."""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user