GitLab
The bundled gitlab plugin shows the merge requests of the branch a thread works on in the panel
beside the thread ("Merge requests"), with their state, pipeline, mergeability, approvals and open
discussions. It works with gitlab.com and with self-hosted GitLab, and only reads: it never
creates, comments on or merges anything.
Setting it up
Section titled “Setting it up”Everything is in the GitLab plugin's card on the Plugins tab of the app's "Settings" screen (unfold
it), under GitLab instances: a row per GitLab server, with its base URL and the secret that
holds its token. The default is one row, https://gitlab.com, with the token GITLAB_TOKEN.
- The server. Give its base URL; for GitLab served under a path, the path too
(
https://example.com/gitlab). Add adds a row for another server. - The token. In GitLab, make a personal (or project, or group) access token with the
read_apiscope: User settings → Access tokens. Under the row's token the card says whether it is set; Set asks for the value and stores it as a global secret, at once and never to be shown again (the pencil replaces it, the bin deletes it). Leave the token's name empty forGITLAB_TOKEN; a server with a token of its own needs another name, which must start withGITLAB_(the plugin's permission allows only those, see below). - Save the settings (the token itself is already stored).
The plugin looks a token up the way qcc secret exec does in that thread: the thread's project's
secret first, then the global one. So a project can have a token of its own under the same name;
the card names the projects that do. Those are set on the Secrets tab of the project's settings or
with
qcc secret set GITLAB_TOKEN --project Shop.
From a terminal, the same setting takes the rows the short way — separated by commas, each a URL
optionally followed by a space and the token's name — and the daemon keeps them as a list of rows
(qcc plugin settings gitlab shows it):
qcc plugin set gitlab instances "https://gitlab.com, https://gitlab.example.com GITLAB_WORK_TOKEN"qcc secret set GITLAB_TOKEN --global # asks for the value without echoqcc secret set GITLAB_WORK_TOKEN --globalThat is all: open a thread whose folder is a checkout of a GitLab project (a worktree of
env-git-worktree or the repository itself), then the "Merge requests" tab of its panel.
What it shows
Section titled “What it shows”For the thread's folder the plugin asks git for the branch (git symbolic-ref --short HEAD) and
the origin remote (git remote get-url origin). The remote's host is matched with an instance's
host; SSH (git@host:group/sub/project.git, ssh://git@host:2222/…) and HTTPS remotes
(https://host:8443/…, credentials in the URL are ignored) all work, ports aside. The project is
the remote's path, subgroups included.
Then it asks the API for every merge request whose source is that branch, in any state, and shows the open ones first, then the latest merged or closed, five at most. Each one shows:
!iidand the title, a link that opens the merge request in the browser, and the target branch;- the state: opened, draft, merged, closed;
- for an open one: the status of its head pipeline, its mergeability (
detailed_merge_statusin words: ready to merge, pipeline must pass, conflicts, needs rebase, …), approvals (1/2where GitLab has approval rules, otherwise who approved) and the number of unresolved discussion threads (100+past one page of discussions).
Instead of merge requests the panel explains, when it can't show them, why. A problem fixed in the settings (a server or a token) comes with an Open GitLab settings button that opens the plugin's card, unfolded, on the Plugins tab of the settings, and the command that fixes it from a terminal:
- the folder is not a git repository, or the thread is not on a branch;
- there is no
originremote, or it is on a host that is not among the instances (with the command that adds it to those there are); - the instances setting cannot be read;
- there is no token:
No token for gitlab.example.com …and the command to store it,qcc secret set GITLAB_TOKEN --global; - GitLab refused: a wrong or expired token (401), a token without
read_apior without access to the project (403, 404), too many requests (429); - the branch has no merge requests: "No merge requests for branch X."
When it asks GitLab
Section titled “When it asks GitLab”Every answer is kept, per thread, and the panel says how old it is. The plugin asks again:
- when the panel is drawn and the last answer is more than a minute old;
- every minute while the panel was looked at in the last three minutes;
- after an agent's turn in that thread (it may have pushed or opened a merge request), at most once every five seconds;
- when you press Refresh.
One look is one request for the list and three for each open merge request (itself, for its head
pipeline; its approvals; its discussions), for at most three open ones. A server that answers
429 Too Many Requests is left alone for as long as its Retry-After says (a minute when it does
not say), for every thread. Requests time out after 20 seconds. Changing the instances setting
drops what is known and looks again.
Permissions
Section titled “Permissions”gitlab is an ordinary plugin with no privileges; its manifest asks for:
| permission | why |
|---|---|
threads |
threads.get: the folder a thread works in. It never starts or drives a thread. |
process = ["git"] |
the branch and the remote of that folder |
secrets = ["GITLAB_*"] |
the tokens: GITLAB_TOKEN and the other names starting with GITLAB_ |
http = ["https://*", "http://*"] |
the API of whatever server the user names; plain http only for one named with http:// |
timers, turn-events |
looking again while the panel is open and after a turn |
A token never leaves the plugin but in the PRIVATE-TOKEN header of a request to the instance it
belongs to; the plugin does not log or show it, and the daemon logs only which secret a plugin read.
How plugins get secrets and send requests is in Writing a plugin.
Limits
Section titled “Limits”- Only
originis looked at. A fork whose merge requests live in the upstream project shows none. - Remotes are matched by host alone. A GitLab whose SSH host differs from its web host (say
ssh.gitlab.example.com) needs anoriginwith the web host, or is not found. - Only
PRIVATE-TOKENis sent: personal, project and group access tokens work; OAuth tokens do not. - The panel shows what GitLab said at the last look, up to a minute old, and nothing while no panel of the thread is open; the thread's row in the sidebar has no merge request mark.