A command line tool for bulk GitLab operations

Posted on February 1, 2020

This post presents a new GitLab tool called gitlab-tools.

It is a command line tool supports bulk operations:

  1. Add a list of users to a group with Reporter role.
  2. Add a group as a member to all projects that have a given name.
  3. Print details of projects that have a given name.
  4. Submit specific files to MOSS for plagiarism detection (for teaching/assessing programming).

It is open source: https://gitlab.com/robstewart57/gitlab-tools

Please see the README file in that GitLab project for installation instructions.

Creating a GitLab Access Token

Before using this tool, you first create an access token using the GitLab web interface.

Go to your profile on the GitLab server you are using, e.g. https://gitlab.example.com/profile, replacing the domain name with your GitLab instance URL.

Click Access Tokens on the left. Then click Create personal access token.

Keep a record of the token, because gitlab-tools will ask you for it.

Add users to a group

First create a CSV file, e.g. users.csv, with comma separated GitLab user IDs that you want to add to a GitLab group.

Let's say we want to add them to a group called WebDevelopers, this command will add all users to that group with the role of Reporter:

gitlab-tools \
  --host https://gitlab.example.com \
  --userFilename users.csv \
  --add-reporters-to-group \
  --group WebDevelopers

Adding a group to multiple projects

Let's say we want to add a group as a Reporter, e.g. CodeReviewers, to all projects that have a given name, e.g. BackendDatabase:

gitlab-tools \
  --host https://gitlab.example.com \
  --share-projects-with-group \
  --project BackendDatabase \
  --group CodeReviewers

Printing details for projects

Let's say we want to list details about all projects with the name Tetris:

gitlab-tools \
  --host https://gitlab.example.com \
  --projectDetails \
  --project Tetris

It'll report:

For example:

finding details for project: Tetris
user1/Tetris : passing, 1 members, visibility private, 35 commits.
user2/Tetris : failing, 1 members, visibility private, 1 commits.
user3/Tetris : failing, 1 members, visibility private, 8 commits.
...

Summary

The gitlab-tools command line tool allows to perform bulk GitLab operations. It is useful to automate changes on GitLab instances with hundreds/thousands of users. It also integrates the MOSS plagiarism detection service, which is useful when detecting code plagiarism in the context of assessed programming in an educational setting. See this for more details.

This gitlab-tools software has been implemented using the gitlab-haskell library (details), which uses the GitLab REST API.

If you have questions, discover any bugs, or wish to request a feature, please do so here: https://gitlab.com/robstewart57/gitlab-tools/issues