Add support for auto assigning issues

Closes #84
This commit is contained in:
alstr 2021-11-05 09:19:50 +00:00
parent 315813a568
commit 7712fef2fd
3 changed files with 14 additions and 1 deletions

View File

@ -37,7 +37,7 @@ Create a `workflow.yml` file in your `.github/workflows` directory like:
steps:
- uses: "actions/checkout@master"
- name: "TODO to Issue"
uses: "alstr/todo-to-issue-action@v4.3.1"
uses: "alstr/todo-to-issue-action@v4.4"
id: "todo"
```
@ -51,6 +51,7 @@ The workflow file takes the following optional inputs:
| `CLOSE_ISSUES` | No | Optional boolean input that specifies whether to attempt to close an issue when a TODO is removed. Default: `true`. |
| `AUTO_P` | No | Optional boolean input that specifies whether to format each line in multiline TODOs as a new paragraph. Default: `true`. |
| `IGNORE` | No | Optional string input that provides comma-delimited regular expressions that match files in the repo that we should not scan for TODOs. By default, we will scan all files. |
| `AUTO_ASSIGN` | No | Optional boolean input that specifies whether to assign the newly created issue to the user who triggered the action. If users are manually assigned to an issue, this setting is ignored. Default: `false`. |
These can be specified in `with` in the workflow file.

View File

@ -58,3 +58,11 @@ inputs:
IGNORE:
description: "A collection of comma-delimited regular expression that matches files that should be ignored when searching for TODOs"
required: false
AUTO_ASSIGN:
description: "Automatically assign new issues to the user who triggered the action"
required: true
default: false
ACTOR:
description: "The username of the person who triggered the action"
required: true
default: "${{ github.actor }}"

View File

@ -62,6 +62,8 @@ class GitHubClient(object):
self.line_break = '\n\n' if auto_p else '\n'
# Retrieve the existing repo issues now so we can easily check them later.
self._get_existing_issues()
self.auto_assign = os.getenv('INPUT_AUTO_ASSIGN', 'false') == 'true'
self.actor = os.getenv('INPUT_ACTOR')
def get_timestamp(self, commit):
return commit.get('timestamp')
@ -146,6 +148,8 @@ class GitHubClient(object):
# We need to check if any assignees/milestone specified exist, otherwise issue creation will fail.
valid_assignees = []
if len(issue.assignees) == 0 and self.auto_assign:
valid_assignees.append(self.actor)
for assignee in issue.assignees:
assignee_url = f'{self.repos_url}{self.repo}/assignees/{assignee}'
assignee_request = requests.get(url=assignee_url, headers=self.issue_headers)