Is there any way to set up a Slack channel such that typing e.g. #361
links to issue 361 of a predefined repo or more generally use GitLab's special references?

- 25,759
- 22
- 127
- 221
3 Answers
If your needs are more specific than what the default GitLab integration provides, you can make your own Slack App/Bot.
There are a few ways to accomplish what you're looking for, the most typical solution would be a slash command as Thomas Kainrad mentioned.
If this isn't what you want and it's necessary that simply typing #395 in a channel links to #395 in your repository, your bot will need to use the message event from the Events API.
This event should be used cautiously - you will receive a request from Slack every single time a message is posted in any channel your application has access to. This may also include private messages depending on your application's scopes, so consider privacy and logging issues that this may raise.
However, using this you will be able to accomplish your goal. Simply check each message for the right text with some regex and then your bot can lookup and post the link to the repo in the Slack channel that the event came from.
If you have multiple repos and they're tied to specific channels you could add a slash command to associate the channel to a repo and then store that info in a database. Then when you receive a message event, read from the database using the id of the channel the message came from.

- 336
- 3
- 5
There is the GitLab Slack application:
https://docs.gitlab.com/ee/user/project/integrations/gitlab_slack_application.html
It is limited in its feautures, but you will be able to link to your issues.
Output from its help command:
Available commands
- /gitlab [project name or alias] issue show <id>
- /gitlab [project name or alias] issue new <title> *`⇧ Shift`*+*`↵ Enter`* <description>
- /gitlab [project name or alias] issue search <your query>
- /gitlab [project name or alias] issue move <issue_id> (to)? <project_path>
- /gitlab [project name or alias] deploy <environment> to <target-environment>
- /gitlab [project name or alias] run <command> <arguments>
Linking to issues works well, you will see Title, Assignee, Milestone, Labels and Weight directly within Slack.

- 2,542
- 21
- 26
-
1Hm, it's a step into the right direction, but unfortunately rather far from what I'd like to achieve... – Tobias Kienzler Feb 03 '19 at 20:10
-
I think the only additional option is manually configuring Slack slash commands: https://docs.gitlab.com/ee/user/project/integrations/slack_slash_commands.html However, these come with basically the same limitations. – Thomas Kainrad Feb 04 '19 at 09:41
It's a relatively simple, but kind of time consuming endeavor. All the resources are available to create a server to do what your wanting.
Use the gitlab api, along with your own server implementation. After that, just set up a slash commands and a slack bot to hook in with slack's webhooks (also see outgoing) and a slack bot to post to your server and to slack.

- 8,810
- 2
- 30
- 38