Check commits array is not empty

This commit is contained in:
alstr 2021-08-26 19:09:28 +01:00
parent 4b6c80501f
commit 1169721b22

View File

@ -67,7 +67,7 @@ class GitHubClient(object):
def get_last_diff(self):
"""Get the last diff."""
if self.before != '0000000000000000000000000000000000000000' or len(self.commits) == 0:
if self.before != '0000000000000000000000000000000000000000':
# There is a valid before SHA to compare with, or this is a release being created
diff_url = f'{self.repos_url}{self.repo}/compare/{self.before}...{self.sha}'
elif len(self.commits) == 1:
@ -275,6 +275,7 @@ class GitHubClient(object):
else:
print('Issue card could not be added to project')
class TodoParser(object):
"""Parser for extracting information from a given diff file."""
FILE_HUNK_PATTERN = r'(?<=diff)(.*?)(?=diff\s--git\s)'
@ -603,9 +604,11 @@ class TodoParser(object):
projects = list(filter(None, projects.split(',')))
return projects
if __name__ == "__main__":
# Create a basic client for communicating with GitHub, automatically initialised with environment variables.
client = GitHubClient()
if len(client.commits) != 0:
# Get the diff from the last pushed commit.
last_diff = StringIO(client.get_last_diff())
# Parse the diff for TODOs and create an Issue object for each.