GithubHelp home page GithubHelp logo

buzkall / gitlab-add-users-to-project Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 3 KB

Script to accelerate the process of adding users to your gitlab and convert them in members of a project

Python 100.00%

gitlab-add-users-to-project's Introduction

Gitlab helper: add users to a project

This script was created to make easier the process of creating new users in your gitlab and add them as members of a project.

It's done with python 3 and uses the python-gitlab library.

The idea is to use a CSV file with the emails, names and usernames of the users and specify the project to add them to.

gitlab_script_schema

Installation

If this case I have my local installation of python 3 with the alias python3, if you only have python 3 installed, you can use "python" and "pip" instead of the alias I use here.

virtualenv -p python3 venv
source venv/bin/activate
pip3 install -r requirements.txt

Modify the config file before moving it to the home folder

vi python-gitlab.example.cfg

This file allows you to specify the config for several gitlab installations, if you only have one, change the name "yourProjectName" and set it as default in line 2. In the case of having several, the gitlab id should be specified in the script when opening the config file (also when receiving the error: "gitlab.config.GitlabIDError: Impossible to get the gitlab id (not specified in config file)")

gl = gitlab.Gitlab.from_config('projectName', '/PATH_TO/.python-gitlab.cfg')

Specify your gitlab installation url in the config file and go to your Profile settings to get your access token. Gitlab help page to get your token.

[global]
default=yourProjectName
ssl_verify=false
true=60

[yourProjectName]
url=http:/YOUR_URL.COM
private_token=xxxxxx
api_version=4 

Now move the file to your home folder and add the dot before to convert it to a hidden file. The python-gitlab library expects this file to be there to login

mv python-gitlab.example.cfg ~/.python-gitlab.cfg

Usage

To use the script two parameters are needed:

  • The csv file
  • the id/path of the gitlab project

The script expects to find this three columns in the csv (with this order and with a header row like in the example file):

  • email
  • username
  • name
python3 add_users_to_project.py YOUR_FILE.csv USER/PROJECT-NAME

Output

Created user with email: [email protected] - id: 51
Added user user with email: [email protected] to the project
Created user with email: [email protected] - id: 52
Added user user with email: [email protected] to the project

If one of the user was already created or was already a member, it will skip the process.

User already exists with email: [email protected] - id: 51
User user with email: [email protected] already a member of the project
User already exists with email: [email protected] - id: 52
User user with email: [email protected] already a member of the project

iterm_capture

gitlab-add-users-to-project's People

Contributors

buzkall avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.