mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-25 07:16:42 +00:00
@@ -66,3 +66,6 @@ inputs:
|
|||||||
description: "The username of the person who triggered the action"
|
description: "The username of the person who triggered the action"
|
||||||
required: true
|
required: true
|
||||||
default: "${{ github.actor }}"
|
default: "${{ github.actor }}"
|
||||||
|
ISSUE_TEMPLATE:
|
||||||
|
description: "The template used to format new issues"
|
||||||
|
required: false
|
||||||
|
|||||||
43
main.py
43
main.py
@@ -8,7 +8,6 @@ import json
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
import hashlib
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import itertools
|
import itertools
|
||||||
import operator
|
import operator
|
||||||
@@ -114,37 +113,29 @@ class GitHubClient(object):
|
|||||||
if len(title) > 80:
|
if len(title) > 80:
|
||||||
# Title is too long.
|
# Title is too long.
|
||||||
title = title[:80] + '...'
|
title = title[:80] + '...'
|
||||||
url_to_line = f'https://github.com/{self.repo}/blob/{self.sha}/{issue.file_name}#L{issue.start_line}'
|
|
||||||
formatted_issue_body = self.line_break.join(issue.body)
|
formatted_issue_body = self.line_break.join(issue.body)
|
||||||
body = (formatted_issue_body + '\n\n'
|
url_to_line = f'https://github.com/{self.repo}/blob/{self.sha}/{issue.file_name}#L{issue.start_line}'
|
||||||
+ url_to_line + '\n\n'
|
snippet = '```' + issue.markdown_language + '\n' + issue.hunk + '\n' + '```'
|
||||||
+ '```' + issue.markdown_language + '\n'
|
|
||||||
+ issue.hunk + '\n'
|
|
||||||
+ '```')
|
|
||||||
|
|
||||||
|
issue_template = os.getenv('INPUT_ISSUE_TEMPLATE', None)
|
||||||
|
if issue_template:
|
||||||
|
issue_contents = (issue_template.replace('{{ title }}', issue.title)
|
||||||
|
.replace('{{ body }}', formatted_issue_body)
|
||||||
|
.replace('{{ url }}', url_to_line)
|
||||||
|
.replace('{{ snippet }}', snippet)
|
||||||
|
)
|
||||||
|
elif len(issue.body) != 0:
|
||||||
|
issue_contents = formatted_issue_body + '\n\n' + url_to_line + '\n\n' + snippet
|
||||||
|
else:
|
||||||
|
issue_contents = url_to_line + '\n\n' + snippet
|
||||||
# Check if the current issue already exists - if so, skip it.
|
# Check if the current issue already exists - if so, skip it.
|
||||||
# The below is a simple and imperfect check.
|
# The below is a simple and imperfect check based on the issue title.
|
||||||
issue_id = hashlib.sha1(body.encode('utf-8')).hexdigest()
|
|
||||||
body += '\n\n' + issue_id
|
|
||||||
for existing_issue in self.existing_issues:
|
for existing_issue in self.existing_issues:
|
||||||
if issue_id in existing_issue['body']:
|
if issue.title == existing_issue['title']:
|
||||||
# The issue_id matching means the issue issues are identical.
|
|
||||||
print(f'Skipping issue (already exists).')
|
print(f'Skipping issue (already exists).')
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
# There may be cases (rebasing) where a different SHA means the above comparison is False but the
|
|
||||||
# issue is otherwise identical.
|
|
||||||
# For now, if an issue already exists with the same title and file name, we will ignore it.
|
|
||||||
# This should cover most use cases. Long term we should improve how the action handles rebasing.
|
|
||||||
existing_issue_body = existing_issue['body']
|
|
||||||
issue_exists = (formatted_issue_body in existing_issue_body
|
|
||||||
and issue.file_name in existing_issue_body
|
|
||||||
and issue.markdown_language in existing_issue_body)
|
|
||||||
if issue_exists:
|
|
||||||
print(f'Skipping issue (already exists).')
|
|
||||||
return
|
|
||||||
|
|
||||||
new_issue_body = {'title': title, 'body': body, 'labels': issue.labels}
|
new_issue_body = {'title': title, 'body': issue_contents, 'labels': issue.labels}
|
||||||
|
|
||||||
# We need to check if any assignees/milestone specified exist, otherwise issue creation will fail.
|
# We need to check if any assignees/milestone specified exist, otherwise issue creation will fail.
|
||||||
valid_assignees = []
|
valid_assignees = []
|
||||||
@@ -486,7 +477,7 @@ class TodoParser(object):
|
|||||||
milestone=None,
|
milestone=None,
|
||||||
user_projects=[],
|
user_projects=[],
|
||||||
org_projects=[],
|
org_projects=[],
|
||||||
body=[line_title],
|
body=[],
|
||||||
hunk=code_block['hunk'],
|
hunk=code_block['hunk'],
|
||||||
file_name=code_block['file'],
|
file_name=code_block['file'],
|
||||||
start_line=code_block['start_line'],
|
start_line=code_block['start_line'],
|
||||||
|
|||||||
Reference in New Issue
Block a user