This integrations service posts issue, comment and merge request events from a GitLab repository into specific Mattermost channels by formatting output from GitLab's outgoing webhooks to Mattermost's incoming webhooks.
Mattermost community members are invited to fork this repo to create new integrations. To have your integration referenced on http://www.mattermost.org/webhooks/, please mail [email protected] or tweet to @MattermostHQ.
To run this integration you need:
- A web server supporting Python 2.7 or a compatible version to run this software (optionally, you could use a service provider like Heroku - see instructions below)
- A GitLab account with a repository to which you have administrator access
- A Mattermost account where incoming webhooks are enabled
Regarding 1. there are many options for web servers you can use, below we provide instructions for both Heroku and a general Linux/Ubuntu server to get something running:
To install this project using Heroku, you will need:
- A Heroku account, available for free from Heroku.com
- A GitHub account, available for free from GitHub.com
Here's how to start:
-
Create a copy of this project to manipulate
-
From the Github repository of this project click Fork in the top-right corner to create a copy of this project that you control and can update as you like.
-
Deploy your project copy to Heroku
-
Go to your Heroku Dashboard and click + in the top-right corner then New App. Give your app a unqiue name (like
mattermost-[YOUR_GITHUB_USERNAME]
), select your region and click Create App. -
On the Deploy screen, select GitHub at the top, then click Connect to GitHub to authorize Herkou to access your GitHub account.
-
Select your account and search for your repo name, for example
mattermost-[YOUR_GITHUB_USERNAME]
, in the repo-name field, then click Search then the Connect button next to your repository. -
Scroll to the bottom of the new page and under the Manual Deploy section click Deploy Branch, making sure the
master
branch is selected. -
Go to Settings > Domains > Settings and copy the URL below Heroku Domain (we'll refer to this as
http://<your-heroku-domain>/
and we'll need it in the next step) -
Leave your Heroku interface open as we'll come back to it to finish the setup.
-
Connect your project to your GitLab account for outgoing webhooks
-
Log in to GitLab account and to the project from which you want to receive updates and to which you have administrator access. From the left side of the project screen, click on Settings > Web Hooks and in the URL field enter
http://<your-heroku-domain>/
from the previous step, plus the word**new_event**
to create an entry that readshttp://<your-heroku-domain>/new_event
so events from your GitLab project are sent to your Heroku server. -
From the same page, under Trigger select Push events, Comment events, Issue events, Merge Request events
-
(Recommended but optional): Encrypt your connection from GitLab to your project by selecting Enable SSL verification. If this option is not available and you're not familiar with how to set it up, contact your GitLab System Administrator for help.
-
Click Add Web Hook to check that a new entry about your webhook is added to the Web hooks section below the button.
-
Leave this page open as we'll come back to it to test that everything is working.
-
Connect your project to your Mattermost account for incoming webhooks
-
Log in to your Mattermost account, and from three dot icon at the top of the left-hand menu go to Account Settings > Integrations > Incoming Webhooks > Edit.
-
Under Add a new incoming webhook select the channel in which you want GitLab notifications to appear, then click Add, which should create a new entry below.
-
From the new entry below, copy the contents next to URL (we'll refer to this as
https://<your-mattermost-webhook-URL>
and add it to your Heroku server). -
Go to your Heroku app page and to Settings > Config Variables > Reveal Config Vars
- Add MATTERMOST_WEBHOOK_URL in the KEY field and paste
https://<your-mattermost-webhook-URL>
into VALUE and click Add - In the second KEY field add PUSH_TRIGGER and in the corresponding VALUE field add True.
- Add MATTERMOST_WEBHOOK_URL in the KEY field and paste
-
Test that everything is working
-
If your GitLab project is in active development, return to the webhooks page of your GitLab project and click Test Hook to send a test message about one of your recent updates from your GitLab project to Mattermost
-
If your GitLab project is not active, if it's brand new for example, try creating an issue as a test, and check that the new issues is posted to Mattermost
-
Back on the settings page of your Heroku app, under the Config Variables, click Reveal Config Vars and then click the
X
next to the PUSH_TRIGGER field you added. This was used for testing only, and is better left turned off for production -
If you have any issues, it's probably our fault for not well documenting the setup. So please go to http://forum.mattermost.org and let us know that our instructions didn't work, and let us know which steps were the most unclear.
The following procedure shows how to install this project on a Linux web server running Ubuntu 14.04. The following instructions work behind a firewall so long as the web server has access to your GitLab and Mattermost instances.
To install this project using a Linux-based web server, you will need:
- A Linux/Ubuntu 14.04 web server supporting Python 2.7 or a compatible version. Other compatible operating systems and Python versions should also work.
Here's how to start:
-
Set up your Mattermost instance to receive incoming webhooks
-
Log in to your Mattermost account, and from three dot icon at the top of the left-hand menu go to Account Settings > Integrations > Incoming Webhooks > Edit.
-
Under Add a new incoming webhook select the channel in which you want GitLab notifications to appear, then click Add, which should create a new entry below.
-
From the new entry below, copy the contents next to URL (we'll refer to this as
https://<your-mattermost-webhook-URL>
and add it to your Heroku server). -
Set up this project to run on your web server
-
Set up a Linux Ubuntu 14.04 server either on your own machine or on a hosted service, like AWS.
-
SSH into the machine, or just open your terminal if you're installing locally.
-
Confirm Python 2.7 or a compatible version is installed by running:
python --version
- If it's not installed you can find it here
-
Install pip and other essentials
sudo apt-get install python-pip python-dev build-essential
-
Clone this GitHub repo with
git clone https://github.com/mattermost/mattermost-integration-gitlab.git
cd mattermost-integration-gitlab
-
Install integration requirements
sudo pip -r requirements.txt
-
Add the following lines to your
~/.bash_profile
export MATTERMOST_WEBHOOK_URL=https://<your-mattermost-webhook-URL>
This is the URL you copied in the last sectionexport PUSH_TRIGGER=True
This is the URL you copied in the last sectionexport PORT=<your-port-number>
The port number you want the integration to listen on (defaults to 5000)
-
Source your bash profile
source ~/.bash_profile
-
Run the server
python server.py
-
Connect your project to your GitLab account for outgoing webhooks
-
Log in to GitLab account and to the project from which you want to receive updates and to which you have administrator access. From the left side of the project screen, click on Settings > Web Hooks and in the URL field enter
http://<your-web-server-domain>/
from the previous step, plus the word**new_event**
to create an entry that readshttp://<your-web-server-domain>/new_event
so events from your GitLab project are sent to your web server. -
From the same page, under Trigger select Push events, Comment events, Issue events, Merge Request events
-
(Recommended but optional): Encrypt your connection from GitLab to your project by selecting Enable SSL verification. If this option is not available and you're not familiar with how to set it up, contact your GitLab System Administrator for help.
-
Click Add Web Hook to check that a new entry about your webhook is added to the Web hooks section below the button.
-
Test that everything is working
-
If your GitLab project is in active development, return to the webhooks page of your GitLab project and click Test Hook to send a test message about one of your recent updates from your GitLab project to Mattermost
-
If your GitLab project is not active, if it's brand new for example, try creating an issue as a test, and check that the new issues is posted to Mattermost
-
Remove the
export PUSH_TRIGGER=True
line from your~/.bash_profile
and source it againsource ~/.bash_profile
. This was used for testing only, and is better left turned off for production -
If you have any issues, it's probably our fault for not well documenting the setup. So please go to http://forum.mattermost.org and let us know that our instructions didn't work, and let us know which steps were the most unclear.