mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-22 22:06:43 +00:00
Fix malformed issue title
Improve code clarity Separate issue ref extraction Fixes #67
This commit is contained in:
parent
63126d7026
commit
3fd212fda1
@ -37,7 +37,7 @@ Create a `workflow.yml` file in your `.github/workflows` directory like:
|
|||||||
steps:
|
steps:
|
||||||
- uses: "actions/checkout@master"
|
- uses: "actions/checkout@master"
|
||||||
- name: "TODO to Issue"
|
- name: "TODO to Issue"
|
||||||
uses: "alstr/todo-to-issue-action@v4.0.8"
|
uses: "alstr/todo-to-issue-action@v4.0.9"
|
||||||
id: "todo"
|
id: "todo"
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -113,9 +113,9 @@ Milestone ID to assign to the issue. Only a single milestone can be specified an
|
|||||||
|
|
||||||
### Other Options
|
### Other Options
|
||||||
|
|
||||||
#### Identifier
|
#### Reference
|
||||||
|
|
||||||
As per the [Google Style Guide](https://google.github.io/styleguide/cppguide.html#TODO_Comments), you can provide an identifier after the TODO label. This will be included in the issue title for searchability.
|
As per the [Google Style Guide](https://google.github.io/styleguide/cppguide.html#TODO_Comments), you can provide a reference after the TODO label. This will be included in the issue title for searchability.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def hello_world():
|
def hello_world():
|
||||||
|
|||||||
29
main.py
29
main.py
@ -269,7 +269,7 @@ class TodoParser(object):
|
|||||||
LINE_NUMBERS_INNER_PATTERN = re.compile(r'@@[\d\s,\-+]*\s@@')
|
LINE_NUMBERS_INNER_PATTERN = re.compile(r'@@[\d\s,\-+]*\s@@')
|
||||||
ADDITION_PATTERN = re.compile(r'(?<=^\+).*')
|
ADDITION_PATTERN = re.compile(r'(?<=^\+).*')
|
||||||
DELETION_PATTERN = re.compile(r'(?<=^-).*')
|
DELETION_PATTERN = re.compile(r'(?<=^-).*')
|
||||||
IDENTIFIER_PATTERN = re.compile(r'.+?(?=\))')
|
REF_PATTERN = re.compile(r'.+?(?=\))')
|
||||||
LABELS_PATTERN = re.compile(r'(?<=labels:\s).+')
|
LABELS_PATTERN = re.compile(r'(?<=labels:\s).+')
|
||||||
ASSIGNEES_PATTERN = re.compile(r'(?<=assignees:\s).+')
|
ASSIGNEES_PATTERN = re.compile(r'(?<=assignees:\s).+')
|
||||||
MILESTONE_PATTERN = re.compile(r'(?<=milestone:\s).+')
|
MILESTONE_PATTERN = re.compile(r'(?<=milestone:\s).+')
|
||||||
@ -446,10 +446,10 @@ 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, identifier = self._get_title(cleaned_line)
|
line_title, ref = self._get_title(cleaned_line)
|
||||||
if line_title:
|
if line_title:
|
||||||
if identifier:
|
if ref:
|
||||||
issue_title = f'[{identifier}] {line_title}'
|
issue_title = f'[{ref}] {line_title}'
|
||||||
else:
|
else:
|
||||||
issue_title = line_title
|
issue_title = line_title
|
||||||
issue = Issue(
|
issue = Issue(
|
||||||
@ -527,18 +527,23 @@ class TodoParser(object):
|
|||||||
return comment.strip()
|
return comment.strip()
|
||||||
|
|
||||||
def _get_title(self, comment):
|
def _get_title(self, comment):
|
||||||
"""Check the passed comment for a new issue title (and identifier, if specified)."""
|
"""Check the passed comment for a new issue title (and reference, if specified)."""
|
||||||
title = None
|
title = None
|
||||||
identifier = None
|
ref = None
|
||||||
title_pattern = re.compile(r'(?<=' + self.identifier + r'[(\s:]).+')
|
title_pattern = re.compile(r'(?<=' + self.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()
|
||||||
identifier_search = self.IDENTIFIER_PATTERN.search(title)
|
else:
|
||||||
if identifier_search:
|
title_ref_pattern = re.compile(r'(?<=' + self.identifier + r'\().+')
|
||||||
identifier = identifier_search.group(0)
|
title_ref_search = title_ref_pattern.search(comment, re.IGNORECASE)
|
||||||
title = title.replace(identifier, '', 1).lstrip(':) ')
|
if title_ref_search:
|
||||||
return title, identifier
|
title = title_ref_search.group(0).strip()
|
||||||
|
ref_search = self.REF_PATTERN.search(title)
|
||||||
|
if ref_search:
|
||||||
|
ref = ref_search.group(0)
|
||||||
|
title = title.replace(ref, '', 1).lstrip(':) ')
|
||||||
|
return title, ref
|
||||||
|
|
||||||
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