← All Modules

assay.gitlab

GitLab REST API v4 client. Projects, repositories, commits, merge requests, pipelines, jobs, issues, releases, groups, container registry, webhooks, environments, and deploy tokens.

Supports both private access token (PRIVATE-TOKEN header) and OAuth2 bearer authentication.

local gitlab = require("assay.gitlab")
local c = gitlab.client("https://gitlab.example.com", { token = "glpat-xxxx" })

c.projects

c.files

c.repository

c.commits

c.branches

c.tags

c.merge_requests

c.pipelines

c.jobs

c.releases

c.issues

c.groups

c.registry

c.hooks

c.users

c.environments

c.deploy_tokens

Example: Atomic Multi-File Commit

local gitlab = require("assay.gitlab")
local c = gitlab.client("https://gitlab.example.com", { token = env.get("GITLAB_TOKEN") })

local result = c.commits:create(42, {
    branch = "main",
    commit_message = "Update config for v2.0",
    actions = {
        { action = "update", file_path = "config/app.yaml", content = "version: 2.0\n" },
        { action = "update", file_path = "config/db.yaml",  content = "pool_size: 20\n" },
    },
})
log.info("Committed: " .. result.short_id)

Example: Create and Merge an MR

local gitlab = require("assay.gitlab")
local c = gitlab.client("https://gitlab.example.com", { token = env.get("GITLAB_TOKEN") })

-- Create branch
c.branches:create(42, { branch = "feat/update", ref = "main" })

-- Commit changes
c.commits:create(42, {
    branch = "feat/update",
    commit_message = "Update dependencies",
    actions = {
        { action = "update", file_path = "package.json", content = '{"version": "2.0.0"}' },
    },
})

-- Open MR
local mr = c.merge_requests:create(42, {
    source_branch = "feat/update",
    target_branch = "main",
    title = "Update dependencies to v2.0",
})

-- Approve and merge
c.merge_requests:approve(42, mr.iid)
c.merge_requests:merge(42, mr.iid, { squash = true, should_remove_source_branch = true })