Docs menu

Set up Connect a GitLab project

Connect a GitLab project

A project can take its issues and merge requests from your own GitLab instead of GitHub. It connects with a GitLab access token and needs no GitHub App. This page gives what differs from GitHub. For every other step, follow Your first project.

Labels, the factorial branch, the readiness checks and the dashboard work as they do on GitHub.

Before you start

You need:

  • A GitLab project in which you have the Maintainer role.
  • A project or group access token with the Maintainer role and the api, read_repository and write_repository scopes. Factorial gives each agent run a Developer token for that project only, made from this token.
  • A runtime whose agents have glab. The published image has it on the host. A cloud sandbox needs a template build that has it. See Runtimes.

Create the project

Do steps 1 and 3 of Your first project: start Factorial and create a runtime. GitLab needs no GitHub App, so step 2 does not apply. Then:

  1. Open Projects and push Create project.
  2. Enter a Name. For Repository host, choose GitLab.
  3. Enter the GitLab URL with https://, for example https://gitlab.example.com.
  4. Paste the Access token.
  5. Enter the Bot username: the GitLab user that owns the token. For a project access token, this is the bot user that GitLab made for the token.
  6. Push List repositories, and choose the Repository. The list holds the projects where the token has the Maintainer role or higher. When GitLab cannot list them, or lists none, the page shows a Repository URL field in its place: enter, for example, https://gitlab.example.com/group/project. The field also takes the path, as group/project or group/sub/project.
  7. Push Create project. Factorial opens Initialize project.

Factorial uses the bot username to tell its own comments from a person's. The form lets you leave it empty, but fill it in.

The new project already has its ticket source and its token. Continue at step 5 of Your first project. Initialize project works on GitLab as it does on GitHub. The templates serve GitHub and GitLab. On a GitLab project, their agents open merge requests with glab.

At the end, Open an issue on GitLab opens a new issue without a label. Add the label factorial:new yourself.

Decide a gate

  • To accept the work, approve the merge request in GitLab.
  • To send the work back, start a review on the merge request, choose Request changes, and submit the review. A comment alone, on the merge request or on the issue, does not send work back.
  • The Request changes button on the ticket page works as it does on GitHub.

Turn on the webhook

The webhook is optional. Factorial reads GitLab every 30 seconds, and a webhook makes it react to a change at once. GitLab must be able to reach the address of Factorial.

  1. Make a secret: a long random string, for example the output of openssl rand -hex 32.
  2. Under Project settings, open Git source. Enter the secret in Webhook secret and push Save.
  3. In GitLab, open the Settings, Webhooks page of the project, and add a webhook.
  4. For the URL, enter https://<your Factorial address>/factorial/webhooks/gitlab. For the secret token, enter the same secret.
  5. Tick the triggers for push, issue, comment, merge request and pipeline events. Save the webhook.

More than one project can read the same GitLab project. A delivery wakes each project whose secret matches it. When no secret matches, Factorial answers 401.

A GitLab with a private certificate authority

Factorial trusts the usual public certificate authorities. When the certificate of your GitLab comes from your own authority, give Factorial that certificate on Create project or on the Git source page:

  • Paste the PEM text in CA bundle PEM.
  • Or, on an install with one organization, enter a PEM file on the host in CA bundle path.

Factorial adds these certificates to the system store. Each agent run gets the same file in SSL_CERT_FILE, CURL_CA_BUNDLE and GIT_SSL_CAINFO, so git, curl and Node trust your GitLab too.

Rules for the GitLab URL

Factorial refuses a GitLab URL that has one of these:

  • A user name, a password, port 0, a query or a fragment.
  • A host name that is not ASCII. Write an international name in punycode.
  • A host that is, or resolves to, a loopback, link-local, unspecified or multicast address.

On an install that lets anyone create an organization, the URL must also use https, and its host must not be a private, shared or reserved address.

Settings for the whole install

An operator can set one GitLab for every project in factorial.env. A project uses these values only when two things are true: its GitLab URL has the same origin as FACTORIAL_GITLAB__BASE_URL, and the install has one organization. Otherwise the project keeps its own token and secret.

SettingWhat it holds
FACTORIAL_GITLAB__BASE_URLThe GitLab URL. Factorial always permits its origin
FACTORIAL_GITLAB__TOKENAn access token with the Maintainer role
FACTORIAL_GITLAB__WEBHOOK_SECRETThe webhook secret
FACTORIAL_GITLAB__BOT_LOGINThe GitLab user that owns the token
FACTORIAL_GITLAB__CA_BUNDLEA PEM file of more certificate authorities