JIRA - Comment triggered incorrectly
Overview
A project has the JIRA issue tracker service enabled, configured with a user who can comment on JIRA issues. A commit is pushed to the project that contains text that looks like a reference to a GitLab issue (such as "Add data for device #12345 (closed)")
Expected
The JIRA service does nothing as there is nothing in the commit text that looks like a reference to a JIRA issue (such as PROJECT-123)
Actual
GitLab tries to comment on https://jira.example.com/rest/api/2/issue/12345/comment (https://jira.example.com/rest/api/2/issue/12345/comment) . (ie. Using the GitLab-like issue ID)
This fails in most cases since Jira issues normally have an ID like PROJECT-123, but it turns out that in addition to the PROJECT-123 ID Jira also has some numerical, unique internal issue ID that looks like "12345". The API also accepts this as an issue ID in addition to the usual PROJECT-123 string. So the 12345 string sometimes matches an actual Jira issue, and a comment is added to that issue… Though it is completely unrelated to the commit!
This is particularly difficult to undo as by default Jira does not allow deleting comments on Closed issues. This behaviour is causing a lot of wasted time in manual operation to fix the unwanted comments.
We believe that the JIRA integration service should not try to add comments to an issue that doesn't match the external issue reference pattern (https://gitlab.com/gitlab-org/gitlab-ee/blob/master/app/models/external_issue.rb#L34), i.e. only comment If the issue reference looks like PROJECT-123.
Reproduce:
- In order to repro this issue, you may find the actual internal issue ID of a JIRA issue from the API with e.g.
- curl https://jira.example.com/rest/api/2/issue/PROJECT-123 (https://jira.example.com/rest/api/2/issue/PROJECT-123) | jq .id
- And specify it in a commit's message with format #undefined