gitlab_mr_check 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gitlab_mr_check-1.3.0/LICENSE +201 -0
- gitlab_mr_check-1.3.0/PKG-INFO +84 -0
- gitlab_mr_check-1.3.0/README.md +69 -0
- gitlab_mr_check-1.3.0/pyproject.toml +299 -0
- gitlab_mr_check-1.3.0/src/gitlab_mr_check/__init__.py +70 -0
- gitlab_mr_check-1.3.0/src/gitlab_mr_check/cli.py +101 -0
- gitlab_mr_check-1.3.0/src/gitlab_mr_check/gitlab_mr_check.py +199 -0
- gitlab_mr_check-1.3.0/src/gitlab_mr_check/helpers/__init__.py +1 -0
- gitlab_mr_check-1.3.0/src/gitlab_mr_check/helpers/config.py +122 -0
- gitlab_mr_check-1.3.0/src/gitlab_mr_check/py.typed +0 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Yorick Hoorneman
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitlab_mr_check
|
|
3
|
+
Version: 1.3.0
|
|
4
|
+
Summary: GitLab Merge Request 4-Eyes Approval Audit Tool
|
|
5
|
+
Author: Yorick Hoorneman
|
|
6
|
+
Author-email: Yorick Hoorneman <yhoorneman@schubergphilis.com>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
10
|
+
Requires-Dist: python-gitlab>=8.2.0
|
|
11
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
12
|
+
Requires-Dist: tabulate>=0.10.0
|
|
13
|
+
Requires-Python: >=3.13
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# gitlab-mr-check
|
|
17
|
+
|
|
18
|
+
[](https://pypi.org/project/gitlab_mr_check/)
|
|
19
|
+
[](https://www.python.org)
|
|
20
|
+
[](https://opensource.org/license/apache-2.0)
|
|
21
|
+
[](https://github.com/astral-sh/uv)
|
|
22
|
+
[](https://github.com/astral-sh/ruff)
|
|
23
|
+
[](https://github.com/astral-sh/ty)
|
|
24
|
+
[](https://github.com/pylint-dev/pylint)
|
|
25
|
+
[](https://github.com/rohaquinlop/complexipy)
|
|
26
|
+
[](https://pyscn.ludo-tech.org)
|
|
27
|
+
[](https://pytest.org)
|
|
28
|
+
[](https://tox.wiki)
|
|
29
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
30
|
+
[](https://conventionalcommits.org)
|
|
31
|
+
[](https://keepachangelog.com/en/1.1.0/)
|
|
32
|
+
[]()
|
|
33
|
+
[](https://coverage.readthedocs.io/)
|
|
34
|
+
[](https://pyscn.ludo-tech.org)
|
|
35
|
+
|
|
36
|
+
GitLab Merge Request 4-Eyes Approval Audit Tool
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
Legacy: `pip install gitlab_mr_check`
|
|
41
|
+
|
|
42
|
+
Preferred: `uv add gitlab_mr_check`
|
|
43
|
+
|
|
44
|
+
## Developing further
|
|
45
|
+
|
|
46
|
+
> Development flow as [Paleofuturistic Python](https://github.com/schubergphilis/paleofuturistic_python)
|
|
47
|
+
|
|
48
|
+
Prerequisite: [uv](https://docs.astral.sh/uv/)
|
|
49
|
+
|
|
50
|
+
### Setup
|
|
51
|
+
|
|
52
|
+
- Fork and clone this repository.
|
|
53
|
+
- Download dependencies: `uv sync --all-extras --dev`
|
|
54
|
+
- On first run of any workflow command, the bootstrap step will prompt to install pre-commit hooks.
|
|
55
|
+
|
|
56
|
+
### Workflow
|
|
57
|
+
|
|
58
|
+
All commands are invoked via `./workflow.cmd <namespace>.<task>`:
|
|
59
|
+
|
|
60
|
+
| Command | Description |
|
|
61
|
+
|---------|-------------|
|
|
62
|
+
| `./workflow.cmd format` | Format code and sort imports |
|
|
63
|
+
| `./workflow.cmd lint` | Run all linters (ruff, pylint, ty, complexipy, commitizen) |
|
|
64
|
+
| `./workflow.cmd test` | Run all tests (pytest) |
|
|
65
|
+
| `./workflow.cmd build` | Run security checks and build the package |
|
|
66
|
+
| `./workflow.cmd release -i <type>` | Bump version, tag, push, build, publish, and upload SBOM |
|
|
67
|
+
| `./workflow.cmd quality` | Run code quality analysis (pyscn) |
|
|
68
|
+
| `./workflow.cmd secure` | Run security audit and generate SBOM |
|
|
69
|
+
| `./workflow.cmd document` | Build and view documentation (mkdocs) |
|
|
70
|
+
| `./workflow.cmd container.build` | Build the dependency cache container image |
|
|
71
|
+
| `./workflow.cmd container.act` | Run the CI workflow locally using act |
|
|
72
|
+
| `./workflow.cmd develop.pre-commit` | Run all pre-commit hooks on the codebase |
|
|
73
|
+
| `./workflow.cmd bootstrap --force` | Re-run the development environment setup |
|
|
74
|
+
|
|
75
|
+
### Development cycle
|
|
76
|
+
|
|
77
|
+
- Add dependencies: `uv add some_lib_you_need`
|
|
78
|
+
- Develop (optional, tinker: `uvx --with-editable . ptpython`)
|
|
79
|
+
- Format: `./workflow.cmd format`
|
|
80
|
+
- Lint: `./workflow.cmd lint`
|
|
81
|
+
- Test: `./workflow.cmd test`
|
|
82
|
+
- Build: `./workflow.cmd build`
|
|
83
|
+
- Review docs: `./workflow.cmd document`
|
|
84
|
+
- Make a pull request.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# gitlab-mr-check
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/gitlab_mr_check/)
|
|
4
|
+
[](https://www.python.org)
|
|
5
|
+
[](https://opensource.org/license/apache-2.0)
|
|
6
|
+
[](https://github.com/astral-sh/uv)
|
|
7
|
+
[](https://github.com/astral-sh/ruff)
|
|
8
|
+
[](https://github.com/astral-sh/ty)
|
|
9
|
+
[](https://github.com/pylint-dev/pylint)
|
|
10
|
+
[](https://github.com/rohaquinlop/complexipy)
|
|
11
|
+
[](https://pyscn.ludo-tech.org)
|
|
12
|
+
[](https://pytest.org)
|
|
13
|
+
[](https://tox.wiki)
|
|
14
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
15
|
+
[](https://conventionalcommits.org)
|
|
16
|
+
[](https://keepachangelog.com/en/1.1.0/)
|
|
17
|
+
[]()
|
|
18
|
+
[](https://coverage.readthedocs.io/)
|
|
19
|
+
[](https://pyscn.ludo-tech.org)
|
|
20
|
+
|
|
21
|
+
GitLab Merge Request 4-Eyes Approval Audit Tool
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Legacy: `pip install gitlab_mr_check`
|
|
26
|
+
|
|
27
|
+
Preferred: `uv add gitlab_mr_check`
|
|
28
|
+
|
|
29
|
+
## Developing further
|
|
30
|
+
|
|
31
|
+
> Development flow as [Paleofuturistic Python](https://github.com/schubergphilis/paleofuturistic_python)
|
|
32
|
+
|
|
33
|
+
Prerequisite: [uv](https://docs.astral.sh/uv/)
|
|
34
|
+
|
|
35
|
+
### Setup
|
|
36
|
+
|
|
37
|
+
- Fork and clone this repository.
|
|
38
|
+
- Download dependencies: `uv sync --all-extras --dev`
|
|
39
|
+
- On first run of any workflow command, the bootstrap step will prompt to install pre-commit hooks.
|
|
40
|
+
|
|
41
|
+
### Workflow
|
|
42
|
+
|
|
43
|
+
All commands are invoked via `./workflow.cmd <namespace>.<task>`:
|
|
44
|
+
|
|
45
|
+
| Command | Description |
|
|
46
|
+
|---------|-------------|
|
|
47
|
+
| `./workflow.cmd format` | Format code and sort imports |
|
|
48
|
+
| `./workflow.cmd lint` | Run all linters (ruff, pylint, ty, complexipy, commitizen) |
|
|
49
|
+
| `./workflow.cmd test` | Run all tests (pytest) |
|
|
50
|
+
| `./workflow.cmd build` | Run security checks and build the package |
|
|
51
|
+
| `./workflow.cmd release -i <type>` | Bump version, tag, push, build, publish, and upload SBOM |
|
|
52
|
+
| `./workflow.cmd quality` | Run code quality analysis (pyscn) |
|
|
53
|
+
| `./workflow.cmd secure` | Run security audit and generate SBOM |
|
|
54
|
+
| `./workflow.cmd document` | Build and view documentation (mkdocs) |
|
|
55
|
+
| `./workflow.cmd container.build` | Build the dependency cache container image |
|
|
56
|
+
| `./workflow.cmd container.act` | Run the CI workflow locally using act |
|
|
57
|
+
| `./workflow.cmd develop.pre-commit` | Run all pre-commit hooks on the codebase |
|
|
58
|
+
| `./workflow.cmd bootstrap --force` | Re-run the development environment setup |
|
|
59
|
+
|
|
60
|
+
### Development cycle
|
|
61
|
+
|
|
62
|
+
- Add dependencies: `uv add some_lib_you_need`
|
|
63
|
+
- Develop (optional, tinker: `uvx --with-editable . ptpython`)
|
|
64
|
+
- Format: `./workflow.cmd format`
|
|
65
|
+
- Lint: `./workflow.cmd lint`
|
|
66
|
+
- Test: `./workflow.cmd test`
|
|
67
|
+
- Build: `./workflow.cmd build`
|
|
68
|
+
- Review docs: `./workflow.cmd document`
|
|
69
|
+
- Make a pull request.
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "gitlab_mr_check"
|
|
3
|
+
version = "1.3.0"
|
|
4
|
+
description = "GitLab Merge Request 4-Eyes Approval Audit Tool"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{name = "Yorick Hoorneman", email = "yhoorneman@schubergphilis.com"},
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.13"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"python-gitlab>=8.2.0",
|
|
12
|
+
"pyyaml>=6.0.3",
|
|
13
|
+
"tabulate>=0.10.0",
|
|
14
|
+
]
|
|
15
|
+
license = "Apache-2.0"
|
|
16
|
+
license-files = ["LICENSE"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
# Python versions supported by the package
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
# click is a transient dependency of mkdocs, but broken beyond version 8.2.1
|
|
23
|
+
# so this pin is needed until the following issue is fixed:
|
|
24
|
+
# https://github.com/mkdocs/mkdocs/issues/4032
|
|
25
|
+
[dependency-groups]
|
|
26
|
+
dev = [
|
|
27
|
+
"click<=8.2.1",
|
|
28
|
+
{include-group = "develop"},
|
|
29
|
+
{include-group = "document"},
|
|
30
|
+
{include-group = "lint"},
|
|
31
|
+
{include-group = "quality"},
|
|
32
|
+
{include-group = "security"},
|
|
33
|
+
{include-group = "test"},
|
|
34
|
+
]
|
|
35
|
+
develop = [
|
|
36
|
+
"pre-commit",
|
|
37
|
+
]
|
|
38
|
+
document = [
|
|
39
|
+
"mkdocs==1.6.1",
|
|
40
|
+
"mkdocs-include-markdown-plugin",
|
|
41
|
+
"mkdocstrings[python]==0.30.1",
|
|
42
|
+
]
|
|
43
|
+
lint = [
|
|
44
|
+
"commitizen",
|
|
45
|
+
"complexipy",
|
|
46
|
+
"pylint",
|
|
47
|
+
"ruff==0.13.1",
|
|
48
|
+
"ty",
|
|
49
|
+
]
|
|
50
|
+
quality = [
|
|
51
|
+
"pyscn",
|
|
52
|
+
]
|
|
53
|
+
security = [
|
|
54
|
+
"cyclonedx-bom",
|
|
55
|
+
"pip-audit",
|
|
56
|
+
]
|
|
57
|
+
test = [
|
|
58
|
+
"pytest",
|
|
59
|
+
"pytest-cov",
|
|
60
|
+
"pytest-env",
|
|
61
|
+
"pytest-html",
|
|
62
|
+
"pytest-xdist",
|
|
63
|
+
# Pin uv to match [tool.uv] required-version — tox-uv depends on the uv
|
|
64
|
+
# Python package, which installs a uv binary into .venv/bin that would
|
|
65
|
+
# otherwise shadow the image's /usr/local/bin/uv and break the check.
|
|
66
|
+
"uv==0.11.7",
|
|
67
|
+
"tox>=4.21",
|
|
68
|
+
"tox-uv>=1.16",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[build-system]
|
|
72
|
+
requires = ["uv_build>=0.8.15,<=0.11.7"]
|
|
73
|
+
build-backend = "uv_build"
|
|
74
|
+
|
|
75
|
+
[tool.pyscn.complexity]
|
|
76
|
+
paths = ["src", "tests", "_CI/tasks"]
|
|
77
|
+
low_threshold = 5
|
|
78
|
+
medium_threshold = 10
|
|
79
|
+
max_complexity = 15
|
|
80
|
+
|
|
81
|
+
[tool.pyscn.dead_code]
|
|
82
|
+
min_severity = "warning"
|
|
83
|
+
|
|
84
|
+
[tool.pyscn.output]
|
|
85
|
+
directory = "reports"
|
|
86
|
+
|
|
87
|
+
[tool.commitizen]
|
|
88
|
+
name = "cz_conventional_commits"
|
|
89
|
+
version_provider = "uv"
|
|
90
|
+
version_scheme = "pep440"
|
|
91
|
+
tag_format = "v$version"
|
|
92
|
+
changelog_file = "docs/changelog.md"
|
|
93
|
+
|
|
94
|
+
[tool.commitizen.change_type_map]
|
|
95
|
+
feat = "Features"
|
|
96
|
+
fix = "Bug Fixes"
|
|
97
|
+
perf = "Performance"
|
|
98
|
+
refactor = "Refactoring"
|
|
99
|
+
docs = "Documentation"
|
|
100
|
+
build = "Build"
|
|
101
|
+
ci = "CI"
|
|
102
|
+
chore = "Chores"
|
|
103
|
+
revert = "Reverts"
|
|
104
|
+
|
|
105
|
+
[tool.ruff]
|
|
106
|
+
target-version = "py313"
|
|
107
|
+
# Exclude a variety of commonly ignored directories.
|
|
108
|
+
exclude = [
|
|
109
|
+
".bzr",
|
|
110
|
+
".direnv",
|
|
111
|
+
".eggs",
|
|
112
|
+
".git",
|
|
113
|
+
".git-rewrite",
|
|
114
|
+
".hg",
|
|
115
|
+
".ipynb_checkpoints",
|
|
116
|
+
".mypy_cache",
|
|
117
|
+
".nox",
|
|
118
|
+
".pants.d",
|
|
119
|
+
".pyenv",
|
|
120
|
+
".pytest_cache",
|
|
121
|
+
".pytype",
|
|
122
|
+
".ruff_cache",
|
|
123
|
+
".svn",
|
|
124
|
+
".tox",
|
|
125
|
+
".venv",
|
|
126
|
+
".vscode",
|
|
127
|
+
"__pypackages__",
|
|
128
|
+
"_build",
|
|
129
|
+
"buck-out",
|
|
130
|
+
"build",
|
|
131
|
+
"dist",
|
|
132
|
+
"node_modules",
|
|
133
|
+
"site-packages",
|
|
134
|
+
"venv",
|
|
135
|
+
"scratch",
|
|
136
|
+
"_CI/lib",
|
|
137
|
+
]
|
|
138
|
+
# Same as Black.
|
|
139
|
+
line-length = 120
|
|
140
|
+
indent-width = 4
|
|
141
|
+
|
|
142
|
+
[tool.ruff.lint]
|
|
143
|
+
select = ["ALL"]
|
|
144
|
+
ignore = [
|
|
145
|
+
# Docstring style conflicts (pick one from each pair)
|
|
146
|
+
"D203", # one-blank-line-before-class (conflicts with D211)
|
|
147
|
+
"D213", # multi-line-summary-second-line (conflicts with D212)
|
|
148
|
+
# "D105", # undocumented-magic-method
|
|
149
|
+
# "D107", # undocumented-public-init
|
|
150
|
+
# "TRY003", # raise-vanilla-args
|
|
151
|
+
# "EM101", # raw-string-in-exception
|
|
152
|
+
# "EM102", # f-string-in-exception
|
|
153
|
+
# "BLE001", # blind-exception (legitimate in network code)
|
|
154
|
+
# "FBT001", # boolean-type-hint-positional-argument
|
|
155
|
+
# "FBT002", # boolean-default-value-positional-argument
|
|
156
|
+
# "PLR0912", # too-many-branches
|
|
157
|
+
# "PLR0913", # too-many-arguments
|
|
158
|
+
# "PLR0915", # too-many-statements
|
|
159
|
+
# "C901", # complex-structure
|
|
160
|
+
# "PLC0415", # import-outside-toplevel (used intentionally)
|
|
161
|
+
# "ANN002", # missing-type-args
|
|
162
|
+
# "ANN003", # missing-type-kwargs
|
|
163
|
+
# "ANN401", # dynamically-typed-expression (Any in **kwargs is legitimate)
|
|
164
|
+
# "TD", # todo comments
|
|
165
|
+
# "FIX", # fixme comments
|
|
166
|
+
# "ERA", # commented-out code
|
|
167
|
+
# Formatter conflicts
|
|
168
|
+
"COM812", # missing-trailing-comma (conflicts with formatter)
|
|
169
|
+
"Q000", # bad-quotes-inline-string (conflicts with format.quote-style)
|
|
170
|
+
"Q003",
|
|
171
|
+
]
|
|
172
|
+
|
|
173
|
+
# Allow fix for all enabled rules (when `--fix`) is provided.
|
|
174
|
+
fixable = ["ALL"]
|
|
175
|
+
unfixable = []
|
|
176
|
+
|
|
177
|
+
# Allow unused variables when underscore-prefixed.
|
|
178
|
+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
|
179
|
+
|
|
180
|
+
[tool.ruff.lint.pydocstyle]
|
|
181
|
+
convention = "google"
|
|
182
|
+
|
|
183
|
+
[tool.ruff.lint.per-file-ignores]
|
|
184
|
+
"tests/*.py" = ["S101", "S311", "RUF012", "PLR2004"]
|
|
185
|
+
"src/*.py" = ["UP038"]
|
|
186
|
+
|
|
187
|
+
[tool.ruff.format]
|
|
188
|
+
# Like Black, use double quotes for strings.
|
|
189
|
+
quote-style = "single"
|
|
190
|
+
|
|
191
|
+
# Like Black, indent with spaces, rather than tabs.
|
|
192
|
+
indent-style = "space"
|
|
193
|
+
|
|
194
|
+
# Like Black, respect magic trailing commas.
|
|
195
|
+
skip-magic-trailing-comma = false
|
|
196
|
+
|
|
197
|
+
# Like Black, automatically detect the appropriate line ending.
|
|
198
|
+
line-ending = "auto"
|
|
199
|
+
|
|
200
|
+
docstring-code-format = true
|
|
201
|
+
docstring-code-line-length = "dynamic"
|
|
202
|
+
|
|
203
|
+
[tool.ruff.lint.flake8-quotes]
|
|
204
|
+
docstring-quotes = "double"
|
|
205
|
+
|
|
206
|
+
[tool.ty.environment]
|
|
207
|
+
extra-paths = ["_CI/lib/vendor"]
|
|
208
|
+
|
|
209
|
+
[tool.pylint.MASTER]
|
|
210
|
+
init-hook = "import sys; sys.path.append('src/'); sys.path.append('_CI/lib/vendor/')"
|
|
211
|
+
|
|
212
|
+
[tool.pylint."MESSAGES CONTROL"]
|
|
213
|
+
max-line-length = 120
|
|
214
|
+
disable = [
|
|
215
|
+
"too-few-public-methods",
|
|
216
|
+
"duplicate-code",
|
|
217
|
+
"logging-fstring-interpolation",
|
|
218
|
+
"too-many-ancestors",
|
|
219
|
+
"import-outside-toplevel",
|
|
220
|
+
# Complexity thresholds — already enforced by ruff (PLR0912/PLR0913/PLR0915)
|
|
221
|
+
"too-many-arguments",
|
|
222
|
+
"too-many-positional-arguments",
|
|
223
|
+
"too-many-branches",
|
|
224
|
+
"too-many-statements",
|
|
225
|
+
"too-many-locals",
|
|
226
|
+
"too-many-instance-attributes",
|
|
227
|
+
# Design choices
|
|
228
|
+
"unused-argument", # handled by ruff ARG rules
|
|
229
|
+
"wrong-import-position", # handled by ruff isort
|
|
230
|
+
# "broad-exception-caught", # legitimate in network/auth code
|
|
231
|
+
# "protected-access", # companion-object pattern
|
|
232
|
+
]
|
|
233
|
+
|
|
234
|
+
[tool.pytest.ini_options]
|
|
235
|
+
addopts = [
|
|
236
|
+
"-n", "auto",
|
|
237
|
+
"--strict-markers",
|
|
238
|
+
"--cov", "--cov-report=term-missing",
|
|
239
|
+
"--cov-report=html:reports/coverage",
|
|
240
|
+
"--cov-report=json:reports/coverage.json",
|
|
241
|
+
"--html=reports/tests.html", "--self-contained-html",
|
|
242
|
+
]
|
|
243
|
+
markers = []
|
|
244
|
+
filterwarnings = []
|
|
245
|
+
pythonpath = ["src"]
|
|
246
|
+
testpaths = ["tests"]
|
|
247
|
+
env = []
|
|
248
|
+
env_files = [".env"]
|
|
249
|
+
|
|
250
|
+
[tool.coverage.run]
|
|
251
|
+
source = ["src"]
|
|
252
|
+
branch = true
|
|
253
|
+
|
|
254
|
+
[tool.coverage.report]
|
|
255
|
+
show_missing = true
|
|
256
|
+
skip_covered = true
|
|
257
|
+
fail_under = 33
|
|
258
|
+
exclude_lines = [
|
|
259
|
+
"pragma: no cover",
|
|
260
|
+
"if __name__ == .__main__.",
|
|
261
|
+
"raise NotImplementedError",
|
|
262
|
+
"if TYPE_CHECKING:",
|
|
263
|
+
"@overload",
|
|
264
|
+
]
|
|
265
|
+
|
|
266
|
+
[tool.coverage.paths]
|
|
267
|
+
source = [
|
|
268
|
+
"src/",
|
|
269
|
+
"*/site-packages/",
|
|
270
|
+
]
|
|
271
|
+
|
|
272
|
+
[tool.coverage.html]
|
|
273
|
+
directory = "reports/coverage"
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
[tool.uv]
|
|
277
|
+
required-version = "==0.11.7"
|
|
278
|
+
exclude-newer = "1 week"
|
|
279
|
+
|
|
280
|
+
[tool.tox]
|
|
281
|
+
requires = ["tox>=4.21", "tox-uv>=1.16"]
|
|
282
|
+
env_list = [
|
|
283
|
+
"py313",
|
|
284
|
+
]
|
|
285
|
+
|
|
286
|
+
[tool.tox.env_run_base]
|
|
287
|
+
runner = "uv-venv-lock-runner"
|
|
288
|
+
dependency_groups = ["test"]
|
|
289
|
+
commands = [["pytest", { replace = "posargs", default = [], extend = true }]]
|
|
290
|
+
|
|
291
|
+
[tool.docker-versions]
|
|
292
|
+
# Container image references consumed by Dockerfiles and CI. The uv version lives in
|
|
293
|
+
# [tool.uv] required-version above — `info.uv-version` parses it from there. The image
|
|
294
|
+
# strings below are kept consistent with that version by hand (uv is mentioned in each).
|
|
295
|
+
# `alpine-image` is mirrored literally in .gitlab-ci.yml's variables: block — GitLab
|
|
296
|
+
# cannot evaluate `image:` from pyproject at pipeline-creation time.
|
|
297
|
+
base-image = "ghcr.io/astral-sh/uv:0.11.7-python3.13-trixie-slim"
|
|
298
|
+
uv-image = "ghcr.io/astral-sh/uv:0.11.7"
|
|
299
|
+
alpine-image = "ghcr.io/astral-sh/uv:0.11.7-alpine3.22"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 gitlab-mr-check
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
"""gitlab-mr-check."""
|
|
17
|
+
|
|
18
|
+
__author__ = 'gitlab-mr-check <yhoorneman@schubergphilis.com>'
|
|
19
|
+
__docformat__ = 'google'
|
|
20
|
+
__date__ = '23-04-2026'
|
|
21
|
+
__copyright__ = 'Copyright 2026, gitlab-mr-check'
|
|
22
|
+
__credits__ = ['gitlab-mr-check']
|
|
23
|
+
__license__ = 'Apache-2.0'
|
|
24
|
+
__maintainer__ = 'gitlab-mr-check'
|
|
25
|
+
__email__ = '<yhoorneman@schubergphilis.com>'
|
|
26
|
+
__status__ = 'Development'
|
|
27
|
+
|
|
28
|
+
from .gitlab_mr_check import (
|
|
29
|
+
MRApprovalResult,
|
|
30
|
+
ProjectMRAuditResult,
|
|
31
|
+
audit,
|
|
32
|
+
evaluate_mrs_4eyes_per_project,
|
|
33
|
+
filter_empty_results_by_field,
|
|
34
|
+
get_groups_recursive,
|
|
35
|
+
get_mrs_by_project,
|
|
36
|
+
get_mrs_by_projects,
|
|
37
|
+
has_4eyes_approval,
|
|
38
|
+
mr_is_merged,
|
|
39
|
+
mr_updated_in_years,
|
|
40
|
+
sort_results_by_field,
|
|
41
|
+
)
|
|
42
|
+
from .helpers.config import (
|
|
43
|
+
Config,
|
|
44
|
+
GitlabAuditConfig,
|
|
45
|
+
GitlabConfig,
|
|
46
|
+
GitlabGroupConfig,
|
|
47
|
+
LoggingConfig,
|
|
48
|
+
parse_config_file,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
'Config',
|
|
53
|
+
'GitlabAuditConfig',
|
|
54
|
+
'GitlabConfig',
|
|
55
|
+
'GitlabGroupConfig',
|
|
56
|
+
'LoggingConfig',
|
|
57
|
+
'MRApprovalResult',
|
|
58
|
+
'ProjectMRAuditResult',
|
|
59
|
+
'audit',
|
|
60
|
+
'evaluate_mrs_4eyes_per_project',
|
|
61
|
+
'filter_empty_results_by_field',
|
|
62
|
+
'get_groups_recursive',
|
|
63
|
+
'get_mrs_by_project',
|
|
64
|
+
'get_mrs_by_projects',
|
|
65
|
+
'has_4eyes_approval',
|
|
66
|
+
'mr_is_merged',
|
|
67
|
+
'mr_updated_in_years',
|
|
68
|
+
'parse_config_file',
|
|
69
|
+
'sort_results_by_field',
|
|
70
|
+
]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Command-line interface for gitlab-mr-check."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import csv
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
from functools import partial
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from tabulate import tabulate
|
|
13
|
+
|
|
14
|
+
from gitlab_mr_check.gitlab_mr_check import audit
|
|
15
|
+
from gitlab_mr_check.helpers.config import parse_config_file
|
|
16
|
+
|
|
17
|
+
LOGGER = logging.getLogger('gitlab-mr-check')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def parse_args() -> argparse.Namespace:
|
|
21
|
+
"""Parse and validate command-line arguments."""
|
|
22
|
+
parser = argparse.ArgumentParser(description='Validate that all MRs have 4-eyes approval')
|
|
23
|
+
parser.add_argument('--url', default=os.environ.get('URL', ''), help='GitLab host URL')
|
|
24
|
+
parser.add_argument('--token', default=os.environ.get('TOKEN', ''), help='GitLab access token')
|
|
25
|
+
parser.add_argument('--config', default='config.yaml', help='Path to config file')
|
|
26
|
+
parser.add_argument('--log-level', default='INFO', help='Logging level')
|
|
27
|
+
parser.add_argument('--output', choices=['table', 'csv'], default='table', help='Output format')
|
|
28
|
+
parser.add_argument('--output-file', help='Output file for CSV (default: stdout)')
|
|
29
|
+
parser.add_argument('--fields', help='Comma-separated list of fields to include')
|
|
30
|
+
args = parser.parse_args()
|
|
31
|
+
if not args.url or not args.token:
|
|
32
|
+
parser.error('--url and --token are required (or set URL and TOKEN env vars)')
|
|
33
|
+
if args.output == 'csv' and not args.output_file:
|
|
34
|
+
parser.error('--output-file is required when --output is csv')
|
|
35
|
+
args.url = args.url.rstrip('/')
|
|
36
|
+
args.fields = [f.strip() for f in args.fields.split(',') if f.strip()] if args.fields else None
|
|
37
|
+
return args
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def output_table(results: list[dict[str, Any]], fields: list[str] | None = None) -> None:
|
|
41
|
+
"""Print results as a formatted table to stdout."""
|
|
42
|
+
if fields:
|
|
43
|
+
results = [{k: row.get(k, '') for k in fields} for row in results]
|
|
44
|
+
print(tabulate(results, headers='keys')) # noqa: T201
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def output_csv(
|
|
48
|
+
results: list[dict[str, Any]],
|
|
49
|
+
output_file: str | None = None,
|
|
50
|
+
fields: list[str] | None = None,
|
|
51
|
+
) -> None:
|
|
52
|
+
"""Write results as CSV to a file or stdout."""
|
|
53
|
+
if fields:
|
|
54
|
+
results = [{k: row.get(k, '') for k in fields} for row in results]
|
|
55
|
+
fieldnames = list(results[0].keys()) if results else []
|
|
56
|
+
if output_file:
|
|
57
|
+
with Path(output_file).open('w', newline='', encoding='utf-8') as f:
|
|
58
|
+
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
|
59
|
+
writer.writeheader()
|
|
60
|
+
writer.writerows(results)
|
|
61
|
+
else:
|
|
62
|
+
writer = csv.DictWriter(sys.stdout, fieldnames=fieldnames)
|
|
63
|
+
writer.writeheader()
|
|
64
|
+
writer.writerows(results)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def show_results(
|
|
68
|
+
results: list[dict[str, Any]],
|
|
69
|
+
output_format: str,
|
|
70
|
+
output_file: str | None = None,
|
|
71
|
+
fields: list[str] | None = None,
|
|
72
|
+
) -> None:
|
|
73
|
+
"""Dispatch results to the appropriate output function."""
|
|
74
|
+
output_funcs: dict[str, Any] = {
|
|
75
|
+
'table': partial(output_table, fields=fields),
|
|
76
|
+
'csv': partial(output_csv, output_file=output_file, fields=fields),
|
|
77
|
+
}
|
|
78
|
+
try:
|
|
79
|
+
output_funcs[output_format](results)
|
|
80
|
+
except KeyError as exc:
|
|
81
|
+
msg = f'Unknown output format: {output_format}'
|
|
82
|
+
raise ValueError(msg) from exc
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def main() -> None:
|
|
86
|
+
"""Entry point for the gitlab-mr-check CLI."""
|
|
87
|
+
args = parse_args()
|
|
88
|
+
logging.basicConfig(level=args.log_level.upper())
|
|
89
|
+
try:
|
|
90
|
+
config = parse_config_file(args.config)
|
|
91
|
+
except FileNotFoundError:
|
|
92
|
+
sys.exit(f'Config file not found: {args.config}')
|
|
93
|
+
except ValueError as exc:
|
|
94
|
+
sys.exit(f'Invalid config: {exc}')
|
|
95
|
+
results = audit(url=args.url, token=args.token, config=config)
|
|
96
|
+
rows = [
|
|
97
|
+
{'project': r.name, 'iid': mr.iid, 'passed': mr.passed, 'reasoning': mr.reasoning}
|
|
98
|
+
for r in results
|
|
99
|
+
for mr in r.mr_results
|
|
100
|
+
]
|
|
101
|
+
show_results(rows, args.output, output_file=args.output_file, fields=args.fields)
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 gitlab-mr-check
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
"""gitlab-mr-check."""
|
|
17
|
+
|
|
18
|
+
import logging
|
|
19
|
+
from dataclasses import asdict, dataclass, field
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from functools import partial
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
import gitlab
|
|
25
|
+
import gitlab.v4.objects
|
|
26
|
+
|
|
27
|
+
from gitlab_mr_check.helpers.config import Config
|
|
28
|
+
|
|
29
|
+
__author__ = 'gitlab-mr-check <yhoorneman@schubergphilis.com>'
|
|
30
|
+
__docformat__ = 'google'
|
|
31
|
+
__date__ = '23-04-2026'
|
|
32
|
+
__copyright__ = 'Copyright 2026, gitlab-mr-check'
|
|
33
|
+
__credits__ = ['gitlab-mr-check']
|
|
34
|
+
__license__ = 'Apache-2.0'
|
|
35
|
+
__maintainer__ = 'gitlab-mr-check'
|
|
36
|
+
__email__ = '<yhoorneman@schubergphilis.com>'
|
|
37
|
+
__status__ = 'Development'
|
|
38
|
+
|
|
39
|
+
LOGGER_BASENAME = 'gitlab-mr-check'
|
|
40
|
+
LOGGER = logging.getLogger(LOGGER_BASENAME)
|
|
41
|
+
LOGGER.addHandler(logging.NullHandler())
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class MRApprovalResult:
|
|
46
|
+
"""Result of a 4-eyes approval check for a single merge request."""
|
|
47
|
+
|
|
48
|
+
iid: int
|
|
49
|
+
passed: bool
|
|
50
|
+
reasoning: str
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass
|
|
54
|
+
class ProjectMRAuditResult:
|
|
55
|
+
"""Aggregated audit result for all merge requests in a project."""
|
|
56
|
+
|
|
57
|
+
name: str
|
|
58
|
+
mr_results: list[MRApprovalResult] = field(default_factory=list)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def passed(self) -> bool:
|
|
62
|
+
"""Return True if all MRs in this project passed the 4-eyes check."""
|
|
63
|
+
return all(mr.passed for mr in self.mr_results) if self.mr_results else True
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def mrs_passed(self) -> list[MRApprovalResult]:
|
|
67
|
+
"""Return the list of MRs that passed."""
|
|
68
|
+
return [mr for mr in self.mr_results if mr.passed]
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def mrs_failed(self) -> list[MRApprovalResult]:
|
|
72
|
+
"""Return the list of MRs that failed."""
|
|
73
|
+
return [mr for mr in self.mr_results if not mr.passed]
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def percentage(self) -> float:
|
|
77
|
+
"""Return the pass percentage across all MRs."""
|
|
78
|
+
total = len(self.mr_results)
|
|
79
|
+
return (len(self.mrs_passed) / total * 100) if total else 0
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def summary(self) -> str:
|
|
83
|
+
"""Return a human-readable summary line."""
|
|
84
|
+
return f'Passed: {len(self.mrs_passed)}, Failed: {len(self.mrs_failed)}, Percentage: {self.percentage:.2f}%'
|
|
85
|
+
|
|
86
|
+
def to_dict(self) -> dict:
|
|
87
|
+
"""Serialise this result including all computed properties."""
|
|
88
|
+
result = asdict(self)
|
|
89
|
+
for attr in dir(self):
|
|
90
|
+
if not attr.startswith('_') and attr not in result:
|
|
91
|
+
value = getattr(self, attr)
|
|
92
|
+
if not callable(value):
|
|
93
|
+
result[attr] = value
|
|
94
|
+
return result
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def get_groups_recursive(gl: gitlab.Gitlab, group_id_or_name: str | int) -> list[Any]:
|
|
98
|
+
"""Recursively collect a group and all of its subgroups."""
|
|
99
|
+
group = gl.groups.get(group_id_or_name)
|
|
100
|
+
result = [group]
|
|
101
|
+
for subgroup in group.subgroups.list(all=True):
|
|
102
|
+
result.extend(get_groups_recursive(gl, subgroup.id))
|
|
103
|
+
return result
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def has_4eyes_approval(mr: gitlab.v4.objects.ProjectMergeRequest) -> MRApprovalResult:
|
|
107
|
+
"""Check whether a merge request satisfies the 4-eyes approval requirement."""
|
|
108
|
+
approvals = mr.approvals.get()
|
|
109
|
+
approved_by = approvals.approved_by
|
|
110
|
+
author = mr.author['username']
|
|
111
|
+
approvers = {user['user']['username'] for user in approved_by}
|
|
112
|
+
passed = bool(approvers - {author})
|
|
113
|
+
reasoning = f'MR !{mr.iid} by {author} approved by {", ".join(approvers)} - 4-eyes approval: {passed}'
|
|
114
|
+
return MRApprovalResult(iid=mr.iid, passed=passed, reasoning=reasoning)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def mr_is_merged(mr: gitlab.v4.objects.ProjectMergeRequest) -> bool:
|
|
118
|
+
"""Return True if the MR state is merged."""
|
|
119
|
+
return mr.state == 'merged'
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def mr_updated_in_years(mr: gitlab.v4.objects.ProjectMergeRequest, years: list[int]) -> bool:
|
|
123
|
+
"""Return True if the MR was last updated in one of the given calendar years."""
|
|
124
|
+
return datetime.fromisoformat(mr.updated_at).year in years
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def get_mrs_by_project(project: gitlab.v4.objects.Project, filters: list[Any]) -> list[Any]:
|
|
128
|
+
"""Return all MRs from a project that pass every filter predicate."""
|
|
129
|
+
return [mr for mr in project.mergerequests.list(all=True) if all(f(mr) for f in filters)]
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def get_mrs_by_projects(projects: list[Any], filters: list[Any]) -> dict[str, list[Any]]:
|
|
133
|
+
"""Return a mapping of project name to filtered MR list for each project."""
|
|
134
|
+
return {project.name: get_mrs_by_project(project, filters) for project in projects}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def evaluate_mrs_4eyes_per_project(project_mrs: dict[str, list[Any]]) -> list[ProjectMRAuditResult]:
|
|
138
|
+
"""Evaluate 4-eyes approval for every MR in every project."""
|
|
139
|
+
return [
|
|
140
|
+
ProjectMRAuditResult(name=name, mr_results=[has_4eyes_approval(mr) for mr in mrs])
|
|
141
|
+
for name, mrs in project_mrs.items()
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def filter_empty_results_by_field(items: list[Any], field_name: str) -> list[Any]:
|
|
146
|
+
"""Return only items where the given field is truthy."""
|
|
147
|
+
return [r for r in items if getattr(r, field_name)]
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def sort_results_by_field(items: list[Any], field_name: str) -> list[Any]:
|
|
151
|
+
"""Return items sorted ascending by the given field."""
|
|
152
|
+
return sorted(items, key=lambda r: getattr(r, field_name))
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def audit(url: str, token: str, config: Config) -> list[ProjectMRAuditResult]:
|
|
156
|
+
"""Run the full GitLab MR 4-eyes audit and return the results.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
url: GitLab instance URL.
|
|
160
|
+
token: GitLab personal access token.
|
|
161
|
+
config: Parsed configuration object.
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
List of per-project audit results, sorted by pass status, with empty projects excluded.
|
|
165
|
+
"""
|
|
166
|
+
LOGGER.info('Starting audit validation for GitLab Merge Requests 4-eyes approval')
|
|
167
|
+
gl = gitlab.Gitlab(url, token)
|
|
168
|
+
|
|
169
|
+
LOGGER.info('Getting the groups recursively')
|
|
170
|
+
gl_groups = []
|
|
171
|
+
for group_cfg in config.gitlab.groups:
|
|
172
|
+
gl_groups.extend(get_groups_recursive(gl, group_cfg.name))
|
|
173
|
+
for group in gl_groups:
|
|
174
|
+
LOGGER.info(' Group: %s (path: %s)', group.name, group.full_path)
|
|
175
|
+
|
|
176
|
+
LOGGER.info('Getting the projects under the groups')
|
|
177
|
+
gl_projects = []
|
|
178
|
+
for group in gl_groups:
|
|
179
|
+
group_projects = group.projects.list(all=True)
|
|
180
|
+
LOGGER.info(' Group %s: %d project(s)', group.full_path, len(group_projects))
|
|
181
|
+
for project in group_projects:
|
|
182
|
+
LOGGER.info(' Project: %s (archived: %s)', project.path_with_namespace, project.archived)
|
|
183
|
+
gl_projects.append(gl.projects.get(project.id))
|
|
184
|
+
LOGGER.info(
|
|
185
|
+
'Found %d project(s) (%d after excluding archived)',
|
|
186
|
+
len(gl_projects),
|
|
187
|
+
sum(1 for p in gl_projects if not p.archived),
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
LOGGER.info('Getting the merge requests under the projects')
|
|
191
|
+
gl_project_mrs = get_mrs_by_projects(
|
|
192
|
+
projects=[p for p in gl_projects if not p.archived],
|
|
193
|
+
filters=[mr_is_merged, partial(mr_updated_in_years, years=config.gitlab.audit.years)],
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
LOGGER.info('Evaluating merge requests for 4-eyes approval')
|
|
197
|
+
results = evaluate_mrs_4eyes_per_project(gl_project_mrs)
|
|
198
|
+
results = filter_empty_results_by_field(results, 'mr_results')
|
|
199
|
+
return sort_results_by_field(results, 'passed')
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Helper modules for gitlab-mr-check."""
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Configuration loading and parsing for gitlab-mr-check."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import yaml
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class GitlabGroupConfig:
|
|
12
|
+
"""Configuration for a single GitLab group."""
|
|
13
|
+
|
|
14
|
+
name: str = ''
|
|
15
|
+
|
|
16
|
+
def __bool__(self) -> bool:
|
|
17
|
+
"""Return True if the group name is set."""
|
|
18
|
+
return bool(self.name)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class GitlabAuditConfig:
|
|
23
|
+
"""Configuration for the audit scope (which years to include)."""
|
|
24
|
+
|
|
25
|
+
years: list[int] = field(default_factory=list)
|
|
26
|
+
|
|
27
|
+
def __bool__(self) -> bool:
|
|
28
|
+
"""Return True if at least one audit year is configured."""
|
|
29
|
+
return bool(self.years)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class GitlabConfig:
|
|
33
|
+
"""Configuration for the GitLab connection and audit scope."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, groups: list[dict], audit: dict) -> None:
|
|
36
|
+
"""Initialise GitLab config from raw dicts."""
|
|
37
|
+
self.groups = [GitlabGroupConfig(**group) for group in groups]
|
|
38
|
+
self.audit = GitlabAuditConfig(**audit)
|
|
39
|
+
|
|
40
|
+
def __bool__(self) -> bool:
|
|
41
|
+
"""Return True if both groups and audit scope are configured."""
|
|
42
|
+
return all([self.groups, self.audit])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class LoggingConfig:
|
|
47
|
+
"""Configuration for the optional MDR log handler."""
|
|
48
|
+
|
|
49
|
+
host: str = ''
|
|
50
|
+
token: str = ''
|
|
51
|
+
ssl_verify: bool = True
|
|
52
|
+
|
|
53
|
+
def __post_init__(self) -> None:
|
|
54
|
+
"""Override host and token from environment variables when not set explicitly."""
|
|
55
|
+
self.host = self.host or os.getenv('LOGGING_HOST', '')
|
|
56
|
+
self.token = self.token or os.getenv('LOGGING_TOKEN', '')
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass
|
|
60
|
+
class Config:
|
|
61
|
+
"""Root configuration object."""
|
|
62
|
+
|
|
63
|
+
gitlab: GitlabConfig
|
|
64
|
+
logging: LoggingConfig
|
|
65
|
+
|
|
66
|
+
def __bool__(self) -> bool:
|
|
67
|
+
"""Return True if the GitLab config is populated."""
|
|
68
|
+
return bool(self.gitlab)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _read_config_file(config_path: str) -> str:
|
|
72
|
+
"""Read a config file and return its raw contents."""
|
|
73
|
+
try:
|
|
74
|
+
with Path(config_path).open(encoding='utf-8') as file:
|
|
75
|
+
content = file.read()
|
|
76
|
+
except FileNotFoundError as exc:
|
|
77
|
+
msg = f'Configuration file not found: {config_path}'
|
|
78
|
+
raise FileNotFoundError(msg) from exc
|
|
79
|
+
if not content.strip():
|
|
80
|
+
msg = f"Configuration file '{config_path}' is empty."
|
|
81
|
+
raise ValueError(msg)
|
|
82
|
+
return content
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _parse_config_data(content: str) -> dict:
|
|
86
|
+
"""Parse a YAML string and return the result as a dict."""
|
|
87
|
+
try:
|
|
88
|
+
config_data = yaml.safe_load(content)
|
|
89
|
+
except yaml.YAMLError as exc:
|
|
90
|
+
msg = f'Error parsing configuration file as YAML: {exc}'
|
|
91
|
+
raise ValueError(msg) from exc
|
|
92
|
+
|
|
93
|
+
if not isinstance(config_data, dict):
|
|
94
|
+
msg = 'Parsed YAML is not a dict'
|
|
95
|
+
raise TypeError(msg)
|
|
96
|
+
|
|
97
|
+
return config_data
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def build_config(config_data: dict) -> Config:
|
|
101
|
+
"""Build a Config object from a raw config dict."""
|
|
102
|
+
try:
|
|
103
|
+
gitlab_config = GitlabConfig(**config_data.get('gitlab', {}))
|
|
104
|
+
logging_config = LoggingConfig(**config_data.get('logging', {}))
|
|
105
|
+
except (KeyError, TypeError) as exc:
|
|
106
|
+
msg = f'Missing required configuration key: {exc}'
|
|
107
|
+
raise ValueError(msg) from exc
|
|
108
|
+
|
|
109
|
+
config = Config(gitlab=gitlab_config, logging=logging_config)
|
|
110
|
+
|
|
111
|
+
if not config:
|
|
112
|
+
msg = 'Incomplete configuration data.'
|
|
113
|
+
raise ValueError(msg)
|
|
114
|
+
|
|
115
|
+
return config
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def parse_config_file(config_path: str) -> Config:
|
|
119
|
+
"""Read, parse, and validate a YAML config file into a Config object."""
|
|
120
|
+
content = _read_config_file(config_path)
|
|
121
|
+
config_data = _parse_config_data(content)
|
|
122
|
+
return build_config(config_data)
|
|
File without changes
|