How we track our todo comments using GitHub Actions | ZenML Blog

Last updated: October 17, 2022.

If you’re a software developer, you’re probably familiar with the following scenario: You’re working on a new feature or trying to fix a bug, and while reading through some code existing code you notice that there’s a nicer way to write it, or maybe a potential edge case isn’t handled. But where to go from here? Write a todo comment and let your future self handle it of course!

Problems for future me

While this might not be the optimal solution, I still regularly use todo comments if the fix is too complicated to implement right away as I find it can get quite distracting to repeatedly switch to my browser and create an issue with a meaningful description.

How to keep todo comments in sync with Jira issues

This however brings a problem with it: these todos are separated from our Jira board so we did not take them into account when planning our sprints. Keeping the comments in code in sync with our Jira issues manually would require a considerable amount of effort. We would have to periodically go over the entire codebase and create issues for new todos as well as delete issues and todos if their counterpart was removed. Instead, we looked at multiple GitHub integrations in the Jira marketplace but couldn’t find an existing solution with similar features, so we decided to implement a GitHub Action that helps us track todos automatically.

TODO

GitHub Actions to the rescue

Each time something is pushed to the main branch, a GitHub workflow is triggered which simply calls a python script to do the heavy lifting. The script itself uses the following regular expression to find todo comments in our python files:

pattern = r"(^[ \t]*#) TODO ?\[(LOWEST|LOW|MEDIUM|HIGH|HIGHEST|[A-Z]*?-[0-9]*?)\]:(.*$\n(\1 {2}.*$\n)*)"

Don’t worry I won’t bore you with the details of how this expression works, but it essentially means that our todo comments have to conform to a certain syntax (a comment starting with a capital TODO followed by a priority in square brackets and a colon) in order for the script to detect them. Once all syntactically correct todos are found, they are processed as follows:

If you’re interested in more details or having something similar in your projects, check out the script and the accompanying GitHub workflow.

Michael Schuster is a Machine Learning Engineer at ZenML.


More from us: