Skip to content

cifvts/mattermost-integration-gitlab

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitLab Integration Service for Mattermost

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.

Project Goal

The goal of this project is to provide a fully-functional template on which the Mattermost community can create their own integration services. Community members are invited to fork this repo to add improvements and to create new integrations.

To have your work included on the Mattermost integrations page, please mail info@mattermost.com or tweet to @MattermostHQ.

Requirements

To run this integration you need:

  1. A web server running Ubuntu 14.04 and Python 2.7 or compatible versions.
  2. A GitLab account with a repository to which you have administrator access
  3. A Mattermost account where incoming webhooks are enabled

Many web server options will work, below we provide instructions for Heroku and a general Linux/Ubuntu server.

Heroku-based Install

To install this project using Heroku, you will need:

  1. A Heroku account, available for free at Heroku.com
  2. A GitHub account, available for free at GitHub.com

Here's how to start:

  1. Create a copy of this project to manipulate

  2. Log in to your GitHub account. Go to the Github repository of this project and click Fork in the top-right corner to create a copy of this project that you control and manipulate.

  3. Deploy your project copy to Heroku

  4. Go to your Heroku Dashboard and click + in the top-right corner then Create New App. Give your app a unqiue name (like mattermost-gitlab-[YOUR_GITHUB_USERNAME]), select your region and click Create App.

  5. Heroku directs you to the Deploy tab of the dashboard for your new app, select GitHub as your connection option, then click Connect to GitHub at the bottom of the screen to authorize Herkou to access your GitHub account.

  6. In the pop up window, click Authorize Application to allow Heroku to access your accounts repositories. On your Heroku dashboard, select your account in the first drop-down then search for the repo we created earlier by forking this project. Type mattermost-integration-gitlab in the repo-name field, then click Search and then the Connect button once Heroku finds your repository.

  7. Scroll to the bottom of the new page. Under the Manual Deploy section, make sure the master branch is selected then click Deploy Branch. After a few seconds you'll see a confirmation that the app has been deployed.

  8. At the top of your app dashboard, go to the Settings tab and scroll down to the Domains section. 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)

  9. Leave your Heroku interface open as we'll come back to it to finish the setup.

  10. Connect your project to your GitLab account for outgoing webhooks

  11. Log in to GitLab account and open 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. In the URL field enter http://<your-heroku-domain>/ from the previous step, plus the word new_event to create an entry that reads http://<your-heroku-domain>/new_event so events from your GitLab project are sent to your Heroku server. Make sure your URL has a leading http:// or https://.

  12. On the same page, under Trigger select Push events, Comment events, Issue events, Merge Request events

  13. (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.

  14. Click Add Web Hook and check that your new webhook entry is added to the Web hooks section below the button.

  15. Leave this page open as we'll come back to it to test that everything is working.

  16. Set up your Mattermost instance to receive incoming webhooks

  17. Log in to your Mattermost account. Click the three dot menu at the top of the left-hand side and go to Account Settings > Integrations > Incoming Webhooks.

  18. Under Add a new incoming webhook select the channel in which you want GitLab notifications to appear, then click Add to create a new entry.

  19. Copy the contents next to URL of the new webhook you just created (we'll refer to this as https://<your-mattermost-webhook-URL> and add it to your Heroku server).

  20. Go back to your Heroku app dashboard under the Settings tab. Under the Config Variables section, click Reveal Config Vars

    1. Type MATTERMOST_WEBHOOK_URL in the KEY field and paste https://<your-mattermost-webhook-URL> into the VALUE field, then click Add.
    2. In the second KEY field, type PUSH_TRIGGER and in the corresponding VALUE field, type True.
  21. Test your webhook integration

  22. If your GitLab project is in active development, return to the Settings > Web Hooks 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. You should see a notification on the Gitlab page that the hook was successfully executed. In Mattermost, go to the channel which you specified when creating the URL for your incoming webhook and make sure that the message delivered successfully.

  23. If your GitLab project is new, try creating a test issue and then verify that the issue is posted to Mattermost.

  24. Back on the settings tab of your Heroku app dashboard, under the Config Variables, click Reveal Config Vars and then click the X next to the PUSH_TRIGGER field you added. This config variable was used for testing only, and is better left turned off for production

  25. If you have any issues, please go to http://forum.mattermost.org and let us know which steps in these instructions were unclear or didn't work.

Linux/Ubuntu 14.04 Web Server Install

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:

  1. Set up your Mattermost instance to receive incoming webhooks

  2. Log in to your Mattermost account. Click the three dot menu at the top of the left-hand side and go to Account Settings > Integrations > Incoming Webhooks.

  3. Under Add a new incoming webhook select the channel in which you want GitLab notifications to appear, then click Add to create a new entry.

  4. Copy the contents next to URL of the new webhook you just created (we'll refer to this as https://<your-mattermost-webhook-URL>).

  5. Set up this project to run on your web server

  6. Set up a Linux Ubuntu 14.04 server either on your own machine or on a hosted service, like AWS.

  7. SSH into the machine, or just open your terminal if you're installing locally.

  8. Confirm Python 2.7 or a compatible version is installed by running:

    • python --version If it's not installed you can find it here
  9. Install pip and other essentials:

    • sudo apt-get install python-pip python-dev build-essential
  10. Clone this GitHub repo:

    • git clone https://github.com/mattermost/mattermost-integration-gitlab.git
    • cd mattermost-integration-gitlab
  11. Install integration requirements:

    • sudo pip install -r requirements.txt
  12. Edit config.json:

    • Set "webhook_url": "<your-mattermost-webhook-URL>" This is the URL you copied in the last section
    • Set "channel": "<channel_name>" if you want to use another channel instead of the one configured in the Incoming Webhook creation
    • Set `"port": " if you want to run multiple integrations or multiple instances of the server on the same machine
  13. Run the server:

    • python server.py
  14. Connect your project to your GitLab account for outgoing webhooks

  15. Log in to GitLab account and open 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. In the URL field enter http://<your-web-server-domain>/ from the previous step, plus the word new_event to create an entry that reads http://<your-web-server-domain>/new_event so events from your GitLab project are sent to your Heroku server. Make sure your URL has a leading http:// or https://.

  16. On the same page, under Trigger select Push events, Comment events, Issue events, Merge Request events

  17. (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.

  18. Click Add Web Hook and check that your new webhook entry is added to the Web hooks section below the button.

  19. Leave this page open as we'll come back to it to test that everything is working.

  20. Test your webhook integration

  21. If your GitLab project is in active development, return to the Settings > Web Hooks 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. You should see a notification on the Gitlab page that the hook was successfully executed. In Mattermost, go to the channel which you specified when creating the URL for your incoming webhook and make sure that the message delivered successfully.

  22. If your GitLab project is new, try creating a test issue and then verify that the issue is posted to Mattermost.

  23. If you have any issues, please go to http://forum.mattermost.org and let us know which steps in these instructions were unclear or didn't work.

config.json explained

{
    "webhook_url": ""
    "port": 5000,
    "username": "gitlab",
    "icon_url": "https://gitlab.com/uploads/project/avatar/13083/gitlab-logo-square.png",
    "channel_name": "",
    "routing": {
    }
}
  • webhook_url: the Incoming Webhooks, mandatory
  • port: the IP port where the server bind to listen to incoming Webhooks (server listen to 0.0.0.0 by default), mandatory
  • username: the username used by the server, if is Enable Overriding of Usernames from Webhooks, optional
  • icon_url: image used by the server, if is Enable Overriding of Icon from Webhooks, optional
  • channel_name: target channel for the incoming Webhooks. Can be blank, target will be the channel set up on Incoming Webhooks setup, optional
  • routing: it contains a the routing to allow Incoming Webhooks from specific projects to be sent in specific channels:
"routing": {
    "project1": "channel1",
    "project2": "channel2"
}

If project do not have any specific routing rule, it will use default channel_name

About

GitLab Integration Service for Mattermost

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%