GithubHelp home page GithubHelp logo

mrbe4r / gitlab-mattermost-sync Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 14 KB

Python project to sync gitlab groups and project membership to mattermost

License: MIT License

Python 100.00%
gitlab mattermost synchronization python python3 automation

gitlab-mattermost-sync's Introduction

gitlab-mattermost-sync

Python project to sync GitLab groups and project membership to mattermost

The script will create the missing GitLab groups and projects into mattermost and sync membership of all GitLab groups and projects.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

This project has been tested on CentOS 7.6 with GitLab 11.x.x and Mattermost 5.x.x .

Python           : 3.4.9
pip3             : 8.1.2
python-gitlab    : 1.6.0
mattermostdriver : 6.1.1

Installing

You could either install requirements system wide or use virtual environment / conda, choose your poison.

To get this up and running you just need to do the following :

  • Clone the repo
git clone https://github.com/MrBE4R/gitlab-mattermost-sync.git
  • Install requirements
pip3 install -r ./gitlab-mattermost-sync/requirements.txt
  • Edit config.json with you values
EDITOR ./gitlab-mattermost-sync/config.json
  • Start the script and enjoy your sync users and groups being synced
cd ./gitlab-mattermost-sync && ./gitlab-mattermost-sync.py

You should get something like this :

Initializing gitlab-ldap-sync.
Done.
Connecting to GitLab
Done.
Connecting to Mattermost
Done.
Getting all groups from GitLab.
Done.
Getting all projects from GitLab.
Done.
Getting all groups from Mattermost.
Done.
Importing groups from GitLab
|- Workgin on < Group Name >.
|  |- < Group Name > already not exist in Mattermost, skipping creation.
|  |  |- User < login > present in GitLab and Mattermost, skipping
|  |  |- User < login > present in GitLab but not in Mattermost, updating Mattermost
|  |  |  |- User < login > does not have a mattermost account, skipping.
|  |- Done
|- Done
Done.
Importing project from GitLab
|- Workgin on < Project Name >.
|  |- < Project Name > already not exist in Mattermost, skipping creation.
|  |  |- User < login > present in GitLab and Mattermost, skipping
|  |  |- User < login > present in GitLab and Mattermost, skipping
|  |  |- User < login > present in GitLab and Mattermost, skipping
|- Done
Done.
Cleaning Mattermost membership
|- Workgin on < Channel Name >.
|  |  |- User gitlab present in GitLab and Mattermost, skipping
|- Done.
|- Workgin on < Channel Name >.
|  |  |- User < login > present in GitLab and Mattermost, skipping
|  |  |- User < login > present in GitLab and Mattermost, skipping
|  |  |- User < login > present in GitLab and Mattermost, skipping
|- Done.
Done.

You could add the script in a cron to run it periodically.

Deployment

How to configure config.json

{
  "syncInterval": "10m",                     // Actually not using it for now
  "log": "/tmp/gitlab-mattermost-sync.log",  // Actually not using it for now
  "gitlab": {
    "api": "https://gitlab.example.com",     // Url of your GitLab 
    "private_token": "xxxxxxxxxxxxxxxxxxxx", // Token generated in GitLab for an user with admin access
    "oauth_token": "",
  },
  "mattermost": {
    "api": "https://mattermost.example.com", // Url of your Mattermost 
    "private_token": "xxxxxxxxxxxxxxxxxxxx", // Token generated in GitLab for an user with admin access
    "username": "",                          // Login of mattermost admin user
    "password": ""                           // Password of mattermost admin user
  },
  "cleanup_mattermost": true
}

You should use private_token or oauth_token but not both. Check the gitlab documentation for how to generate the personal access token.

You should use private_token or username and password but not both. Check the mattermost documentation for how to generate the personal access token.

The accounts used should have admin right in GitLab and Mattermost.

cleanup_mattermost If set to true, the script will add and remove users in mattermost channels depending of their groups in GitLab.

TODO

  • Maybe implement sync interval directly in the script to avoid using cron or systemd
  • Use a true logging solution (no more silly print statements)
  • Find a way to create users in Mattermost from GitLab
  • your suggestions

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

  • Jean-François GUILLAUME (Jeff MrBear) - Initial work - MrBE4R

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

  • Hat tip to anyone whose code was used

gitlab-mattermost-sync's People

Contributors

mrbe4r avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.