Using Slack to remind open GitLab MR’s

Lucas Yuri
3 min readSep 24, 2021

At the end of this Article you’ll know how to use Slack to send periodic messages with all opened GitLab MR’s of your team. You’ll receive a message like that:

Slack message with all opened MR’s at GitLab

This is very useful when you have a team with more than 5/6 developers and has lots of MR’s. You could schedule this integration to send messages at your team slack channel at the beginning and at the end of workday. So, they will be remind to review incoming code changes, making your team more agile.

Clone the repository

You will use the repository bellow:

Follow the instructions present at README to clone it, and at this article I’ll show how to setup to your environment.

To make this integration, we’ll use GitLab API, Slack Webhook and node-cron.

Now that you have cloned the repository above, you only need to configure the .env file to access the services above.

GitLab

We need to set 3 variables at .env to configure GitLab (GITLAB_URL, GITLAB_PROJECT_ACCESS_TOKEN, GITLAB_PROJECT_ID)

To get your GITLAB_PROJECT_ID, you should go to your project/group page and get its ID. You can see the number 13492402 at screenshot.

If you don’t use a GitLab instance, your GITLAB_URL will be https://gitlab.com/api/v4/.
If you use a GitLab instace, your GITLAB_URL will be https://gitlab.example.com/api/v4/ (only check your GitLab URL and add /api/v4/ )

At least, to set GITLAB_PROJECT_ACCESS_TOKEN, you should generate a GitLab access token.

To do that, go to user setting and access tokens at your GitLab Account.

Set a name to your token and select read_api check-box.
Then click at Create personal access token button.

Your token will be created.

Now you have all necessary configuration to access GitLab API, it’s time to see how to allow slack integration.

Slack

We need to setup 2 .env variables (SLACK_WEBHOOK, SLACK_CHANNEL)

SLACK_CHANNEL is the channel name of your Slack workspace

To get your SLACK_WEBHOOK, you should configure Incoming Webhooks App at your Slack workspace

You should find this App at your slack workspace and click Add to Slack and configure it.

Then you will receive an Webhook URL, just copy that to SLACK_WEBHOOK variable and now you will be able to integrate with Slack.

Now we are able to get GitLab info and send it to Slack. Finally, let’s configure the frequency of these messages.

Node-Cron

To configure the frequency of those messages, we need to setup 2 .env variables (CRON_TASK_INTERVAL, TASK_INTERVAL_TIMEZONE).

CRON_TASK_INTERVAL will be when you want to receive the reminder, the sintax is based on GNU Crontab.
TASK_INTERVAL_TIMEZONE will be the timezone of the task, you can check the option available at moment-timezone.

As example, if you set:
CRON_TASK_INTERVAL=0 9 * * 1–5
TASK_INTERVAL_TIMEZONE=America/Sao_Paulo
Every 9AM at workdays, slack will notify with opened MR’s

That’s all folks

Now you have all needed configuration, just deploy that reminder application wherever you prefer and comment here if it helped to improve your team.

--

--