Skip to content

Commit cc0aec8

Browse files
authored
docs: set up GitLab CI with the Catalog component (#105)
1 parent b3bedc2 commit cc0aec8

2 files changed

Lines changed: 84 additions & 41 deletions

File tree

‎docs/guides/integrations.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ push and pull request, with no workflow file and no CI minutes.
7171

7272
One job in the pipeline runs `commit-check-ci`, which finds the merge or pull
7373
request and checks its branch, every commit it adds and, if asked, its title
74-
and description. [Set it up →](other-ci.md)
74+
and description. On GitLab a component from the CI/CD Catalog adds that job.
75+
[Set it up →](other-ci.md)
7576

7677
## MCP server
7778

‎docs/guides/other-ci.md‎

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,22 @@ does that job: `commit-check-ci`, which comes with the package from 2.23.0
66
on. It finds the merge or pull request from the variables the CI system sets
77
and checks the source branch and every commit the request adds, against the
88
same `cchk.toml` as the hook and the Action. The title, the description, each
9-
commit's author and the files it changes are one option away.
9+
commit's author and the files it changes are one option away. On GitLab the
10+
[Commit Check component](https://gitlab.com/explore/catalog/commit-check/commit-check)
11+
in the CI/CD Catalog adds the job for you.
1012

1113
On Azure Pipelines, and on any other CI, the job is
1214
[written by hand](#azure-pipelines).
1315

1416
## GitLab CI
1517

1618
```yaml title=".gitlab-ci.yml"
17-
commit-check:
18-
image: python:3.13
19-
variables:
20-
GIT_DEPTH: "0"
21-
rules:
22-
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
23-
script:
24-
- pip install commit-check
25-
- commit-check-ci
19+
include:
20+
- component: gitlab.com/commit-check/commit-check/commit-check@2
2621
```
2722
23+
The component adds one job, `commit-check`, to merge request pipelines. It
24+
installs the latest commit-check 2.x from PyPI and runs `commit-check-ci`.
2825
Every check is listed under a heading of its own, and one failure fails the
2926
job:
3027

@@ -44,45 +41,80 @@ Commit 20119d2e fix: trim the user name
4441
1 of 3 failed.
4542
```
4643

47-
- `GIT_DEPTH: "0"` turns shallow cloning off, for this job only. The command
44+
- The job clones the full history (`GIT_DEPTH: "0"`), for this job only. It
4845
needs every commit of the merge request and the commit they start from.
49-
With a clone that ends inside the merge request the job fails and names
50-
this setting, rather than pass with commits unchecked.
51-
- The command fetches the target branch itself, which
52-
`require_rebase_target` ([CC202](../rules.md#cc202)) compares with. For a
53-
merge request from a fork it fetches from the target project. A pipeline
54-
that runs in a fork of a private project cannot fetch it: with that rule
55-
set the branch check fails there, and without the rule the branch name is
56-
checked as usual.
46+
- The job fetches the target branch itself, which `require_rebase_target`
47+
([CC202](../rules.md#cc202)) compares with. For a merge request from a fork
48+
it fetches from the target project. A pipeline that runs in a fork of a
49+
private project cannot fetch it: with that rule set the branch check fails
50+
there, and without the rule the branch name is checked as usual.
5751
- In a merged results pipeline, `HEAD` is a merge commit GitLab made. The
5852
checks stop at the merge request's own last commit.
59-
- `rules` keeps the job to merge request pipelines. In any other pipeline the
60-
command checks the branch and the last commit only, and says so.
61-
- The `python` image ships with git. A `-slim` image does not, and needs it
62-
installed first.
53+
- `@2` follows the latest 2.x release of the component. To stay on one
54+
release, write it out: `@2.0.0`.
6355

64-
### Options
56+
### Inputs
6557

66-
Each check has an option, named after the
58+
Each check has an input, named after the
6759
[Action's input](github-actions.md#inputs) and on or off by default as it is
6860
there:
6961

70-
| Option | Default | What it checks |
62+
| Input | Default | What it checks |
7163
|---|---|---|
72-
| `--message` | on | The message of every commit the request adds. |
73-
| `--branch` | on | The name of the source branch, and `require_rebase_target` if it is set. |
74-
| `--author-name` | off | The author name of every commit. |
75-
| `--author-email` | off | The author email of every commit. |
76-
| `--files` | off | The files every commit changes, against the [`[files]` rules](../rules.md#push-rules). |
77-
| `--pr-title` | off | The title, with the message rules a one-line title can meet. |
78-
| `--pr-body-ai-attribution` | off | The description, against the AI attribution rules. |
64+
| `message` | `true` | The message of every commit the request adds. |
65+
| `branch` | `true` | The name of the source branch, and `require_rebase_target` if it is set. |
66+
| `author-name` | `false` | The author name of every commit. |
67+
| `author-email` | `false` | The author email of every commit. |
68+
| `files` | `false` | The files every commit changes, against the [`[files]` rules](../rules.md#push-rules). |
69+
| `pr-title` | `false` | The title, with the message rules a one-line title can meet. |
70+
| `pr-body-ai-attribution` | `false` | The description, against the AI attribution rules. |
71+
72+
```yaml
73+
include:
74+
- component: gitlab.com/commit-check/commit-check/commit-check@2
75+
inputs:
76+
author-email: true
77+
branch: false
78+
```
79+
80+
Four more inputs shape the job itself:
81+
82+
| Input | Default | What it does |
83+
|---|---|---|
84+
| `version` | `2.*` | The commit-check release to install: `2.*` for the latest 2.x, or an exact one such as `2.24.1`. |
85+
| `image` | `python:3.13` | The image the job runs in. It needs Python 3.11 or newer with pip, and git, which `-slim` and `-alpine` images do not have. |
86+
| `stage` | `test` | The stage the job runs in. |
87+
| `job-name` | `commit-check` | The name of the job. |
88+
89+
### Writing the job yourself
7990

91+
A self-managed GitLab cannot include a component from gitlab.com. There, or
92+
to call the command your own way, write the job out:
93+
94+
```yaml title=".gitlab-ci.yml"
95+
commit-check:
96+
image: python:3.13
97+
variables:
98+
GIT_DEPTH: "0"
99+
rules:
100+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
101+
script:
102+
- pip install commit-check
103+
- commit-check-ci
104+
```
105+
106+
Each check input above is an option of `commit-check-ci` with the same name.
80107
An option alone switches its check on, and `=false` switches one off:
81108

82109
```yaml
83110
- commit-check-ci --author-email --branch=false
84111
```
85112

113+
With a clone that ends inside the merge request the job fails and names
114+
`GIT_DEPTH`, rather than pass with commits unchecked. In a pipeline that is
115+
not for a merge request the command checks the branch and the last commit
116+
only, and says so.
117+
86118
### Making a failed check block the merge
87119

88120
Two things decide whether a failed check stops the merge request:
@@ -115,28 +147,37 @@ Two things decide whether a failed check stops the merge request:
115147

116148
### Merge request title and description
117149

118-
GitLab passes both to the job, so two options are all it takes:
150+
GitLab passes both to the job, so two inputs are all it takes:
119151

120152
```yaml
121-
- commit-check-ci --pr-title --pr-body-ai-attribution
153+
include:
154+
- component: gitlab.com/commit-check/commit-check/commit-check@2
155+
inputs:
156+
pr-title: true
157+
pr-body-ai-attribution: true
122158
```
123159

124-
- `--pr-title` checks the title with the message rules a one-line title can
125-
meet: everything `--message` runs except a body (CC011), a sign-off (CC012)
160+
In a job written by hand they are `--pr-title` and `--pr-body-ai-attribution`.
161+
162+
- `pr-title` checks the title with the message rules a one-line title can
163+
meet: everything `message` runs except a body (CC011), a sign-off (CC012)
126164
and an AI author (CC017). With squash merges the title is often the commit
127165
message that lands. A draft marker (`Draft:`, `[Draft]`, `(Draft)`) is not
128166
part of the title that is checked.
129-
- `--pr-body-ai-attribution` checks the description against your
167+
- `pr-body-ai-attribution` checks the description against your
130168
`ai_attribution` policy, and, when `[pull_request] ai_declaration_checkboxes`
131169
is set, that it ticks exactly one AI declaration box (CC501). GitLab task
132170
lists (`- [x]`, `* [x]`, `1. [x]`) are read like GitHub's.
133171
- GitLab passes a job only the first 2700 characters of a description, so
134172
only that part is checked, and the job says so when it happens. Put the AI
135173
declaration boxes near the top of the merge request template, so a long
136174
description does not cut them off. To fail a description that was cut
137-
rather than check part of it, add before the `commit-check-ci` line:
175+
rather than check part of it, give the job a `before_script`. A job of the
176+
same name in your `.gitlab-ci.yml` is merged with the component's:
138177

139178
```yaml
179+
commit-check:
180+
before_script:
140181
- test "$CI_MERGE_REQUEST_DESCRIPTION_IS_TRUNCATED" != "true" || { echo "The description is over 2700 characters; GitLab passed only part of it"; exit 1; }
141182
```
142183

@@ -167,7 +208,8 @@ pipelines:
167208
step runs. The checks stop at `BITBUCKET_COMMIT`, the pull request's own
168209
last commit, so commits that only came in with that merge are not checked.
169210
The rebase check judges that commit too, not the merge.
170-
- The output and the [options](#options) are the same as on GitLab.
211+
- The output is the same as on GitLab, and so are the options of a
212+
[job written by hand](#writing-the-job-yourself).
171213

172214
### Pull request title and description
173215

0 commit comments

Comments
 (0)