As suggested by @embray, make issue linking for robust by first searching for groups of issues that are enclosed in square brackets and have the form [#...], then cycle over the issues inside each group.