Skip to content

GitLab integration

Nepenthes offers an integration with GitLab merge requests to link software development closely to planning and specification. You can create merge requests in GitLab and link them to work packages in Nepenthes.

Overview

Nepenthes work packages will directly display information from GitLab in a separate tab.

Gitlab tab in an Nepenthes work package

The tab shows all merge requests (MR) linked to a work package with the corresponding status (e.g. 'Ready' or 'Merged') as well as the state (e.g. 'success' or 'queued') of the GitLab actions configured to run for a MR. MRs and work packages are in an n:m relationship, so a work package can be linked to multiple merge requests and a merge request can be linked to multiple work packages.

Additionally, in your Nepenthes work package, the GitLab integration supports you in creating a branch specific to the work package and consequently the matching merge request.

Git snippets for GitLab integration in Nepenthes

Merge request activities will also show up in the Activity tab when the merge request is

  • first referenced (usually when opened)
  • merged
  • closed

GitLab comments on work package activity tab

Configuration

You will first have to configure both Nepenthes and GitLab for the integration to work.

Nepenthes

First you will need to create a user in Nepenthes that has the permission to make comments. This role only requires two permissions, View work packages and Add notes, which you will find in the Work packages and Gantt charts section under Roles and Permissions.

GitLab role with required permissions in Nepenthes

This user will then have to be added to each project with a role that allows them to see work packages and comment on them.

GitLab user added as member to project with respective role

Once the user is created you need to generate an Nepenthes API token for this user (you will need it on the GitLab side). For this you have to:

  1. Login as the newly created user
  2. Go to My Account (click on the Avatar in the top right corner and select My account)
  3. Go to Access Tokens
  4. Click on + API token

Make sure you copy the generated key and securely save it, as you will not be able to retrieve it later.

You can then configure the necessary webhook in GitLab.

Finally you will need to activate the GitLab module under Project settings so that all information pulling through from GitLab will be shown in the work packages.

Activate a GitLab module in Nepenthes

Seeing the GitLab tab requires Show GitLab content permission, so this permission needs to be granted to all roles in a project allowed to see the tab.

Grant permission to show GitLab content to user roles in Nepenthes

GitLab

In GitLab you have to set up a webhook in each repository to be integrated with Nepenthes. For that navigate to Settings -> Webhooks and click on Add new webhook.

Create the webhook in GitLab

You need to configure the URL . It must point to your Nepenthes server's GitLab webhook endpoint (/webhooks/gitlab).

You will need the API key you copied earlier in Nepenthes. Append it to the URL as a simple GET parameter named key. In the end the URL should look something like this:

https://myopenproject.com/webhooks/gitlab?key=4221687468163843

Note: For the events that should be triggered by the webhook, please select the following

  • Push events (all branches)
  • Comments
  • Issues events
  • Merge request events
  • Pipeline events

Note: If you are in a local network you might need to allow requests to the local network in your GitLab instance.
You can find this settings in the Outbound requests section when you navigate to Admin area -> Settings -> Network.

We recommend that you enable the SSL verification before you Add webhook.

Now the integration is set up on both sides and you can use it.

Using GitLab integration

Create merge requests

As merge requests are based on branches, a new branch needs to be created first. For that, open the GitLab tab in your Nepenthes work package detailed view. Click on Git snippets to extend the menu. First, copy the branch name by clicking the corresponding button.

Copy the branch name for GitLab in Nepenthes

Then, open your git client, e.g. Git desktop client or a console. There, you can create your branch by entering the branch name you copied from your Nepenthes work package. That way, all the branches will follow a common pattern and as the Nepenthes ID is included in the branch name, it will be easy to see the connection between a MR and a work package when taking a look at a list of MRs on GitLab.

Create a new branch in a Git desktop client

You can now publish your branch (you can also do this later, after making the changes and before opening a merge request).

Publish branch

With the branch opened, you can start the actual development work using your preferred tool to alter your codebase.

Gitlab changes in a merge request changes

Once you are satisfied with the changes you can create a commit. Within the 'Git snippets' menu, Nepenthes suggests a commit message for you based on the title and the URL of the work package.

Copy a Git commit message in Nepenthes

A URL pointing to a work package in the merge request description or a comment will link the two. The link needs to be in the MR and not in a commit, but GitLab will use the first commit message as the proposed branch description (as long as there is only one commit). Alternatively you can also use 'OP#' as a work package reference in an issue or a MR title, in this case "OP#388", where 388 is the ID of the work package.

Commit message in a Git client

Once the changes are made, you can create your merge request. Title and comment with the link to the respective Nepenthes work package will be prefilled, at least if there is only one commit to the branch. Because of this one commit limitation and if the policy is to create a branch as early as possible, there is a third option in the 'Git snippets' menu ('Create branch with empty commit') that will open a branch and add an empty commit to it in one command. Using this option, one can first create the branch quickly and have it linked to the work package right from the beginning. Commits can of course be added to the branch (and PR) after that.

Create a merge request

The branch description can be amended before a MR is created giving the opportunity to further describe the changes. To help with that, it is also possible to copy parts of the work package description since the description can be displayed in the markdown format. Links to additional work packages can also be included in the MR description.

If you use OP# as a reference in an Issue or MR title, all comments will be replicated in Nepenthes. However, sometimes you may only want to keep information about the status of an Issue/MR in Nepenthes without your comments being published. In this case, you can use "PP#" as a reference. For example "PR#388". This way the comments will not be published in Nepenthes. If you only want to publish one of the comments from a private Issue/MR, you can use "OP#" directly in that comment. This way only that specific comment will be published in Nepenthes, but the rest of the comments will remain private. Read more.

Open a GitLab merge request

Click on Create merge request and your merge request will be opened.

GitLab merge request opened

When you click on the link in the comment, it will take you to the Nepenthes work package, where you will see in the Activity tab of the work package that the merge request was created.

GitLab actions in activity tab

In the GitLab tab of that work package, the status of the merge request as well as status of all the configured GitLab Actions will also be displayed.

GitLab actions under GitLab tab in Nepenthes work package

If the status of a merge request changes, it will be reflected in the Nepenthes work package accordingly. Please see the example below.

GitLab merge request status change

Nepenthes GitLab integration allows linking GitLab issues directly with Nepenthes work packages.

Initially when no issues were linked yet you will see the following message under GitLab tab.

You can either create a new issue in GitLab, or edit an already existing one. Enter the code OP#388 into the issue title or description to create the link between the GitLab issue and the Nepenthes work package. In this case 388 is the work package ID.

Link a GitLab issue to Nepenthes work package

Once you save your changes or create a GitLab issue, it will become visible under the GitLab tab in Nepenthes.

New GitLab issues shown in Nepenthes work packages