alstr / todo-to-issue-action

Action that converts TODO comments to GitHub issues on push.
MIT License
630 stars 121 forks source link

Add ability to ignore TODOs in some files #78

Closed timmorey closed 3 years ago

timmorey commented 3 years ago

We have some code in one of our repositories that we don't really own, and we'd like to avoid creating TODO issues when it is updated.

The use case is that we have some code committed in our vendor directory that is developed by another team. We need it at build time (and can't just npm install it), and we periodically update it to make sure we've got the latest version. When we update it, this action creates issues for TODO comments in the code, even though we aren't in a position to address those TODOs.

Do you think it would be possible to add an optional patterns, indicating which files should be ignored (or which ones should be parsed)? For example, we'd like to be able to configure something like

- name: "TODO to Issue"
  uses: "alstr/todo-to-issue-action@v4.0.2"
  id: "todo"
  with:
    TOKEN: ${{ secrets.GITHUB_TOKEN }}
    CLOSE_ISSUES: true
    IGNORE: "vendor/**/*"

If this sounds feasible and desirable, I would be interested in taking a stab at implementation (some guidance would be helpful).

alstr commented 3 years ago

Thanks for the suggestion, I think it's a good idea.

I think something along the lines of what you suggested would work well. Around here we could check the filename against the provided patterns and continue if there is a match:

https://github.com/alstr/todo-to-issue-action/blob/1169721b229b543f62442d3e8a9ab5007f6e5d19/main.py#L350

Here's some pseudocode, assuming the patterns are provided as a comma-separated list of regex patterns (not ideal, but not sure if a list can be provided to the action?):

- name: "TODO to Issue"
  uses: "alstr/todo-to-issue-action@v4.0.2"
  id: "todo"
  with:
    TOKEN: ${{ secrets.GITHUB_TOKEN }}
    CLOSE_ISSUES: true
    IGNORE: "foo/bar/file.txt, images/.*"
ignore_patterns = os.getenv('INPUT_IGNORE', None)
if ignore_patterns:
    skip_file = False
    patterns_list = ignore_patterns.replace(', ', ',')
    patterns_list = list(filter(None, patterns_list.split(',')))
    for pattern in patterns_list:
        pattern_search = re.search(pattern, curr_file)
        if pattern_search.group(0):
            skip_file = True
            break
    if skip_file:
        continue

I haven't tested any of that.