mirror of
https://github.com/ditkrg/todo-to-issue-action.git
synced 2026-01-25 07:16:42 +00:00
Support new branches with multiple commits (#25)
Add support for newly created branches with multiple commits
This commit is contained in:
@@ -12,6 +12,14 @@ inputs:
|
|||||||
description: "The path to the repository where the action will be used, e.g. 'alstr/my-repo' (automatically set)"
|
description: "The path to the repository where the action will be used, e.g. 'alstr/my-repo' (automatically set)"
|
||||||
required: true
|
required: true
|
||||||
default: "${{ github.repository }}"
|
default: "${{ github.repository }}"
|
||||||
|
BEFORE:
|
||||||
|
description: "The SHA of the last pushed commit (automatically set)"
|
||||||
|
required: true
|
||||||
|
default: "${{ github.event.before }}"
|
||||||
|
COMMITS:
|
||||||
|
description: "An array of commit objects describing the pushed commits"
|
||||||
|
required: true
|
||||||
|
default: "${{ toJSON(github.event.commits) }}"
|
||||||
SHA:
|
SHA:
|
||||||
description: "The SHA of the latest commit (automatically set)"
|
description: "The SHA of the latest commit (automatically set)"
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
21
main.py
21
main.py
@@ -48,7 +48,9 @@ class GitHubClient(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.repo = os.getenv('INPUT_REPO')
|
self.repo = os.getenv('INPUT_REPO')
|
||||||
|
self.before = os.getenv('INPUT_BEFORE')
|
||||||
self.sha = os.getenv('INPUT_SHA')
|
self.sha = os.getenv('INPUT_SHA')
|
||||||
|
self.commits = json.loads(os.getenv('INPUT_COMMITS'))
|
||||||
self.token = os.getenv('INPUT_TOKEN')
|
self.token = os.getenv('INPUT_TOKEN')
|
||||||
self.issues_url = f'{self.repos_url}{self.repo}/issues'
|
self.issues_url = f'{self.repos_url}{self.repo}/issues'
|
||||||
self.issue_headers = {
|
self.issue_headers = {
|
||||||
@@ -60,9 +62,22 @@ class GitHubClient(object):
|
|||||||
# Retrieve the existing repo issues now so we can easily check them later.
|
# Retrieve the existing repo issues now so we can easily check them later.
|
||||||
self._get_existing_issues()
|
self._get_existing_issues()
|
||||||
|
|
||||||
|
def get_timestamp(self, commit):
|
||||||
|
return commit.get('timestamp')
|
||||||
|
|
||||||
def get_last_diff(self):
|
def get_last_diff(self):
|
||||||
"""Get the last commit diff."""
|
"""Get the last diff."""
|
||||||
diff_url = f'{self.repos_url}{self.repo}/commits/{self.sha}'
|
if self.before != '0000000000000000000000000000000000000000':
|
||||||
|
# There is a valid before SHA to compare with
|
||||||
|
diff_url = f'{self.repos_url}{self.repo}/compare/{self.before}...{self.sha}'
|
||||||
|
elif len(self.commits) == 1:
|
||||||
|
# There is only one commit
|
||||||
|
diff_url = f'{self.repos_url}{self.repo}/commits/{self.sha}'
|
||||||
|
else:
|
||||||
|
# There are several commits: compare with the oldest one
|
||||||
|
oldest = sorted(self.commits, key=self.get_timestamp)[0]['id']
|
||||||
|
diff_url = f'{self.repos_url}{self.repo}/compare/{oldest}...{self.sha}'
|
||||||
|
|
||||||
diff_headers = {
|
diff_headers = {
|
||||||
'Accept': 'application/vnd.github.v3.diff',
|
'Accept': 'application/vnd.github.v3.diff',
|
||||||
'Authorization': f'token {self.token}'
|
'Authorization': f'token {self.token}'
|
||||||
@@ -260,7 +275,6 @@ class GitHubClient(object):
|
|||||||
else:
|
else:
|
||||||
print('Issue card could not be added to project')
|
print('Issue card could not be added to project')
|
||||||
|
|
||||||
|
|
||||||
class TodoParser(object):
|
class TodoParser(object):
|
||||||
"""Parser for extracting information from a given diff file."""
|
"""Parser for extracting information from a given diff file."""
|
||||||
FILE_HUNK_PATTERN = r'(?<=diff)(.*?)(?=diff\s--git\s)'
|
FILE_HUNK_PATTERN = r'(?<=diff)(.*?)(?=diff\s--git\s)'
|
||||||
@@ -589,7 +603,6 @@ class TodoParser(object):
|
|||||||
projects = list(filter(None, projects.split(',')))
|
projects = list(filter(None, projects.split(',')))
|
||||||
return projects
|
return projects
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 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()
|
||||||
|
|||||||
Reference in New Issue
Block a user