How can we push a message reply as comment back to GitLab issues

We are very happy with the GitLab Mattermost integration and we get all events to issues in GitLab as new messages in Mattermost. This is done by enabling the Slack service in the GitLab project and configuring the inbound hook for the right channel in Mattermost. Nice and easy.

Now, it is tempting in Mattermost to reply to content of such messages in Mattermost. The whole team can see those replies and even a discussion could follow out of this. However, we would rather prefer to have issue related discussions as comments in GitLab - and that’s why we are looking for a solution like this:

If there is a message in Mattermost that was sent by GitLab and is issue related, each reply in Mattermost should be pushed back as a new comment to that issue into GitLab. Is that possible? Maybe this is something for a Hubot integration but I was wondering if someone has already done this and wanted to share their implementation details.

Digging around and looking into the GitLab API for this, I think that this could be done with the Hubot approach (or any other Bot), but there are two more issues that I can see so far:

  1. Authentication: If the bot were to push the comment to an issue, it looks like a comment by the Bot in GitLab and not the real user who posted the comment in Mattermost. Not sure how to resolve that.
  2. Also, such a new comment would trigger another push to Mattermost from GitLab service which then makes this a duplicate of the comment which is already there. That would certainly feel like spam and we would have to find a solution for that as well.

Any other thoughts? Or even proposals on how to solve these?

Hi @jurgenhaas,

I can understand the desire to be able to comment straight from Mattermost to GitLab, that would be pretty cool. There are a few issues that you’d need to take a look at if you want to get a rich integration between Mattermost and GitLab set up:

  1. This is the hardest issue to solve, and to do properly we’d need to build the GitLab integration directly into the Mattermost codebase and it would then have access to post as a GitLab user through OAuth2. The best solution besides doing that is to just post as a bot and have the bot start the message with who made the post in Mattermost.
  2. You might be able to get around this using a bot that acts as an intermediate between Mattermost and GitLab. It could add and remove keywords from the message (or possibly some other field) to identify which messages need to be posted or which would be duplicates.
  3. Another issue is having the bot determine which GitLab issue to post to based on the post from Mattermost. I’m not sure how you’d handle this with the webhooks as they are right now without having your users manually add some information to the post in Mattermost, which isn’t a particularly good solution.