mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-25 07:16:42 +00:00
Remove empty BEFORE sha check
This commit is contained in:
77
main.py
77
main.py
@@ -596,42 +596,41 @@ class TodoParser(object):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if os.getenv('INPUT_BEFORE') != '0000000000000000000000000000000000000000':
|
# Create a basic client for communicating with GitHub, automatically initialised with environment variables.
|
||||||
# Create a basic client for communicating with GitHub, automatically initialised with environment variables.
|
client = GitHubClient()
|
||||||
client = GitHubClient()
|
# Get the diff from the last pushed commit.
|
||||||
# Get the diff from the last pushed commit.
|
last_diff = StringIO(client.get_last_diff())
|
||||||
last_diff = StringIO(client.get_last_diff())
|
# Parse the diff for TODOs and create an Issue object for each.
|
||||||
# Parse the diff for TODOs and create an Issue object for each.
|
raw_issues = TodoParser().parse(last_diff)
|
||||||
raw_issues = TodoParser().parse(last_diff)
|
# This is a simple, non-perfect check to filter out any TODOs that have just been moved.
|
||||||
# This is a simple, non-perfect check to filter out any TODOs that have just been moved.
|
# It looks for items that appear in the diff as both an addition and deletion.
|
||||||
# It looks for items that appear in the diff as both an addition and deletion.
|
# It is based on the assumption that TODOs will not have identical titles in identical files.
|
||||||
# It is based on the assumption that TODOs will not have identical titles in identical files.
|
issues_to_process = []
|
||||||
issues_to_process = []
|
for values, similar_issues in itertools.groupby(raw_issues, key=operator.attrgetter('title', 'file_name',
|
||||||
for values, similar_issues in itertools.groupby(raw_issues, key=operator.attrgetter('title', 'file_name',
|
'markdown_language')):
|
||||||
'markdown_language')):
|
similar_issues = list(similar_issues)
|
||||||
similar_issues = list(similar_issues)
|
if (len(similar_issues) == 2 and ((similar_issues[0].status == LineStatus.ADDED and
|
||||||
if (len(similar_issues) == 2 and ((similar_issues[0].status == LineStatus.ADDED and
|
similar_issues[1].status == LineStatus.DELETED) or
|
||||||
similar_issues[1].status == LineStatus.DELETED) or
|
(similar_issues[1].status == LineStatus.ADDED and
|
||||||
(similar_issues[1].status == LineStatus.ADDED and
|
similar_issues[0].status == LineStatus.DELETED))):
|
||||||
similar_issues[0].status == LineStatus.DELETED))):
|
print(f'Issue "{values[0]}" appears as both addition and deletion. '
|
||||||
print(f'Issue "{values[0]}" appears as both addition and deletion. '
|
f'Assuming this issue has been moved so skipping.')
|
||||||
f'Assuming this issue has been moved so skipping.')
|
continue
|
||||||
continue
|
issues_to_process.extend(similar_issues)
|
||||||
issues_to_process.extend(similar_issues)
|
# Cycle through the Issue objects and create or close a corresponding GitHub issue for each.
|
||||||
# Cycle through the Issue objects and create or close a corresponding GitHub issue for each.
|
for j, raw_issue in enumerate(issues_to_process):
|
||||||
for j, raw_issue in enumerate(issues_to_process):
|
print(f'Processing issue {j + 1} of {len(issues_to_process)}')
|
||||||
print(f'Processing issue {j + 1} of {len(issues_to_process)}')
|
if raw_issue.status == LineStatus.ADDED:
|
||||||
if raw_issue.status == LineStatus.ADDED:
|
status_code = client.create_issue(raw_issue)
|
||||||
status_code = client.create_issue(raw_issue)
|
if status_code == 201:
|
||||||
if status_code == 201:
|
print('Issue created')
|
||||||
print('Issue created')
|
else:
|
||||||
else:
|
print('Issue could not be created')
|
||||||
print('Issue could not be created')
|
elif raw_issue.status == LineStatus.DELETED and os.getenv('INPUT_CLOSE_ISSUES', 'true') == 'true':
|
||||||
elif raw_issue.status == LineStatus.DELETED and os.getenv('INPUT_CLOSE_ISSUES', 'true') == 'true':
|
status_code = client.close_issue(raw_issue)
|
||||||
status_code = client.close_issue(raw_issue)
|
if status_code == 201:
|
||||||
if status_code == 201:
|
print('Issue closed')
|
||||||
print('Issue closed')
|
else:
|
||||||
else:
|
print('Issue could not be closed')
|
||||||
print('Issue could not be closed')
|
# Stagger the requests to be on the safe side.
|
||||||
# Stagger the requests to be on the safe side.
|
sleep(1)
|
||||||
sleep(1)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user