Skip to content

Latest commit

 

History

History
114 lines (87 loc) · 5.8 KB

gitlab.md

File metadata and controls

114 lines (87 loc) · 5.8 KB

gitlab.md (scripts/forge/providers)

Revision: 1 Last modified: 2026-12-04T18:15:21Z

Overview

This is a library. It is sourced by scripts/forge/forge.sh, never executed. No shebang, mode rw-rw-r--.

GitLab adapter — GitLab REST v4 over curl. It implements the same provider contract as scripts/forge/providers/gitea.sh; read that guide for the contract. This guide records what is specific to GitLab, and GitLab is the most behaviourally different of the five.

Two properties matter:

  1. GitLab has no pre-release flag. FG_PRE_SUPPORTED=0, so forge.sh prints NOTE: prerelease_unsupported and never claims a prerelease there. Asking for --prerelease does not fail; it is honestly downgraded and reported.
  2. GitLab is the one forge whose release target is DERIVED from the tag. FG_TARGET_DERIVED=1: the release object's commit.id is the commit the forge resolves from the tag, not a field the tool sent. That is the only case in this tool where a read-back target can contribute to proving the commit, which makes GitLab the one provider where release-ensure can reach RESULT: OK on a release that already existed without a separate tag check.

Also: a project is addressed by its URL-encoded full path — group/sub/project becomes group%2Fsub%2Fproject — and forge.sh deliberately allows GitLab paths deeper than OWNER/REPO (up to 20 segments) for exactly this reason. A release is addressed by its tag, not by a numeric id.

Prerequisites

As for every provider: sourced by forge.sh after lib/common.sh / lib/credentials.sh / lib/http.sh, with FG_OWNER, FG_REPO, FG_REPO_FULL, FG_API_BASE, FG_API_ORIGIN and an initialised FG_TMP. Needs jq.

Usage examples

Through forge.sh (this file is not invoked directly):

bash scripts/forge/forge.sh detect --remote origin
bash scripts/forge/forge.sh probe --remote origin
bash scripts/forge/forge.sh tag-get --remote origin --tag v1.2.3

# a nested group path is legal on GitLab only
bash scripts/forge/forge.sh repo-exists --url git@gitlab.com:group/sub/project.git

Contract check in isolation:

bash -c '. scripts/forge/lib/common.sh; . scripts/forge/providers/gitlab.sh; \
  FG_OWNER=g FG_REPO=p FG_REPO_FULL=group/sub/project; prov_init; \
  printf "%s|%s|%s|%s\n" "$FG_AUTH_FMT" "$FG_RPATH" "$FG_PRE_SUPPORTED" "$FG_TARGET_DERIVED"'

Exit codes

Library: functions return 0 when a state was determined and 1 only when no HTTP answer arrived (FG_NET set). Every HTTP status is a result encoded in the state variables. User-visible exit codes belong to forge.sh — see docs/scripts/forge.md.

Edge cases

  • --prerelease requested — accepted but not applied; forge.sh prints NOTE: prerelease_unsupported. No false claim, no hard failure.
  • A draft release — GitLab has no draft concept here, so FG_REL_DRAFT is pinned to false rather than left unknown; a caller can therefore read it without a "did the forge report this" caveat.
  • A release id — FG_REL_ID is set to the tag name, because GitLab addresses a release by tag. The id-safety check in forge.sh (fg_ok_rel_id) therefore accepts a tag-shaped id for GitLab and a numeric/UUID id for the other four.
  • A nested project path — encoded, never resolved by hand. forge.sh refuses path segments that are unsafe, and refuses paths deeper than 20 segments.
  • An annotated tag — repository/tags/{tag} reports commit.id, which is already the commit the tag resolves to; no peel is needed.
  • Write paths (POST /releases, PUT /releases/{tag}) are LIVE-UNPROVEN. Note the update verb is PUT here, not PATCH.
  • scripts/release/tag_and_release.sh keeps its own glab leg — a separate path by design decision, not a duplicate of this adapter.

Internal behaviour

  1. prov_init — PRIVATE-TOKEN: %s, Accept: application/json, FG_RPATH="/projects/${FG_REPO_FULL//\//%2F}", FG_PRE_SUPPORTED=0, FG_TARGET_DERIVED=1.
  2. prov_repo GETs the project and sets FG_HAS_RELEASES=unknown (GitLab does not expose a unit flag this adapter reads).
  3. prov_release_get GETs /releases/{tag}; 200 → present with tag_name, FG_REL_ID="$FG_REL_TAG" and commit.id as the target; 404 → absent. There is no releases_disabled gap here.
  4. prov_release_create builds {tag_name,name,description} (description from the notes file via --rawfile) and POSTs; 201 → created, 409 → exists. The PRE argument is ignored on purpose.
  5. prov_release_update PUTs {name,description} to /releases/{tag}; 200 → updated.
  6. prov_tag_get GETs /repository/tags/{tag}; 200 → present with .commit.id, 404 → absent.
  7. prov_probe issues three read-only GETs: project, /releases?per_page=1, /repository/tags?per_page=1.

Related scripts

  • scripts/forge/providers/gitea.sh — the canonical provider-contract statement this file implements.
  • scripts/forge/forge.sh — the driver; note the GitLab special case in fg_ok_rel_id and the FG_TARGET_DERIVED=1 path in fg_end_ensure.
  • scripts/forge/lib/http.sh — the HTTP client.
  • scripts/release/tag_and_release.sh — the glab-based sibling leg.
  • config/forge/hosts.tsv — maps gitlab.com to gitlab with token variable GITLAB_TOKEN, and records that GitLab has no pre-release flag.

Last verified

2026-12-04 — bash -n scripts/forge/providers/gitlab.sh → exit 0. Contract check a reader can repeat:

bash -c '. scripts/forge/lib/common.sh; . scripts/forge/providers/gitlab.sh; \
  FG_OWNER=g FG_REPO=p FG_REPO_FULL=group/sub/project; prov_init; \
  printf "%s|%s|%s|%s\n" "$FG_AUTH_FMT" "$FG_RPATH" "$FG_PRE_SUPPORTED" "$FG_TARGET_DERIVED"'

Expected: PRIVATE-TOKEN: %s|/projects/group%2Fsub%2Fproject|0|1.