Skip to content

Commit 4c4b56a

Browse files
committed
Adjust maintainer contact lint
Closes ocaml/infrastructure#152 by addressing the subsequenst requests for tweaked behavior.
1 parent 2653281 commit 4c4b56a

File tree

4 files changed

+77
-15
lines changed

4 files changed

+77
-15
lines changed

opam-ci-check/lib/lint.ml

+14-5
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,22 @@ module Checks = struct
265265
if is_build then (pkg, DuneIsBuild) :: errors else errors
266266
| None -> []
267267

268+
268269
let check_maintainer_email ~pkg opam =
270+
let is_present bug_reports =
271+
not @@ List.is_empty bug_reports
272+
in
273+
let includes_an_email maintainers =
274+
List.exists
275+
(fun m -> Str.string_match (Str.regexp ".*<?.*@.*>?") m 0)
276+
maintainers
277+
in
278+
let bug_reports = OpamFile.OPAM.bug_reports opam in
269279
let maintainers = OpamFile.OPAM.maintainer opam in
270-
List.filter_map
271-
(fun m ->
272-
if Str.string_match (Str.regexp ".*<?.*@.*>?") m 0 then None
273-
else Some (pkg, MaintainerEmailMissing m))
274-
maintainers
280+
if is_present bug_reports || includes_an_email maintainers then
281+
[]
282+
else
283+
[ (pkg, MaintainerWithoutContact maintainers) ]
275284

276285
let check_tags ~pkg opam =
277286
(* Check if any of the default tags are present *)

opam-ci-check/lib/lint_error.ml

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type error =
2626
| UnexpectedFile of string
2727
| ForbiddenPerm of string
2828
| OpamLint of (int * [ `Warning | `Error ] * string)
29-
| MaintainerEmailMissing of string
29+
| MaintainerWithoutContact of string list
3030
| FailedToDownload of string
3131
| NameCollision of string
3232
| WeakChecksum of string
@@ -149,11 +149,12 @@ let msg_of_error (package, (err : error)) =
149149
| OpamLint warn ->
150150
let warn = OpamFileTools.warns_to_string [ warn ] in
151151
Printf.sprintf "Error in %s: %s" pkg warn
152-
| MaintainerEmailMissing maintainer ->
152+
| MaintainerWithoutContact maintainer ->
153153
Printf.sprintf
154-
"Error in %s: Maintainer email missing. Please add a maintainer email \
155-
to the opam file. Maintainer: %s"
156-
pkg maintainer
154+
"Error in %s: There is no way to contact the maintainer(s) '%s'. A package \
155+
must either specify a url for 'bug-reports' or provide an email \
156+
address in the 'maintainer' field."
157+
pkg (String.concat ", " maintainer)
157158
| ParseError ->
158159
Printf.sprintf "Error in %s: Failed to parse the opam file" pkg
159160
| DefaultTagsPresent tags ->

opam-ci-check/test/lint.t

+57-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ Test the following:
6060
$ opam-ci-check lint -r . -c b.0.0.1
6161
Linting opam-repository at $TESTCASE_ROOT/. ...
6262
Error in b.0.0.1: warning 25: Missing field 'authors'
63-
Error in b.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Jane
6463
Warning in b.0.0.1: The package has not replaced the following default, example tags: topics, project
6564
[1]
6665
$ opam-ci-check lint -r . -c b.0.0.2
@@ -187,3 +186,60 @@ Test presence of unexpected files in a-1.0.0.2 package
187186
Linting opam-repository at $TESTCASE_ROOT/. ...
188187
Error in a-1.0.0.2: Forbidden permission for file packages/a-1/a-1.0.0.2/opam. All files should have permissions 644.
189188
[1]
189+
190+
# Maintainer contact lint
191+
192+
The maintainer contact lint requires that a package EITHER provide a URL for the
193+
`bug-tracker` OR that at least one email is provided in the `maintainer` field.
194+
If neither of there requirements are met, the check should fail, otherwise it
195+
should passes.
196+
197+
Add multiple maintainers with no email and remove the bug-reports field from a
198+
valid package:
199+
200+
$ git reset -q --hard initial-state
201+
$ sed -i \
202+
> -e 's/maintainer.*/maintainer: ["Maintainer1" "Maintaner2"]/' \
203+
> -e '/bug-reports.*/d' \
204+
> packages/a-1/a-1.0.0.1/opam
205+
$ git diff packages/a-1/a-1.0.0.1/opam | grep '^[+-][^+-]'
206+
-maintainer: "Maintainer <me@example.com>"
207+
+maintainer: ["Maintainer1" "Maintaner2"]
208+
-bug-reports: "https://github.com/ocurrent/opam-repo-ci/issues"
209+
210+
Test that we report the expected linting error:
211+
212+
$ opam-ci-check lint -r . -c a-1.0.0.1
213+
Linting opam-repository at $TESTCASE_ROOT/. ...
214+
Error in a-1.0.0.1: warning 36: Missing field 'bug-reports'
215+
Error in a-1.0.0.1: There is no way to contact the maintainer(s) 'Maintainer1, Maintaner2'. A package must either specify a url for 'bug-reports' or provide an email address in the 'maintainer' field.
216+
[1]
217+
218+
Add one email to the maintainers, and ensure it now passes the maintainer
219+
contact lint:
220+
221+
$ sed -i \
222+
> -e 's/"Maintaner2"/"Maintaner2 <me@example.com>"/' \
223+
> packages/a-1/a-1.0.0.1/opam
224+
$ git diff packages/a-1/a-1.0.0.1/opam | grep '^[+-][^+-]'
225+
-maintainer: "Maintainer <me@example.com>"
226+
+maintainer: ["Maintainer1" "Maintaner2 <me@example.com>"]
227+
-bug-reports: "https://github.com/ocurrent/opam-repo-ci/issues"
228+
$ opam-ci-check lint -r . -c a-1.0.0.1
229+
Linting opam-repository at $TESTCASE_ROOT/. ...
230+
Error in a-1.0.0.1: warning 36: Missing field 'bug-reports'
231+
[1]
232+
233+
Just remove the email address, leaving the bug-reports and ensure that it now
234+
passes linting:
235+
236+
$ git reset -q --hard initial-state
237+
$ sed -i \
238+
> -e 's/maintainer.*/maintainer: ["Maintainer1" "Maintaner2"]/' \
239+
> packages/a-1/a-1.0.0.1/opam
240+
$ git diff packages/a-1/a-1.0.0.1/opam | grep '^[+-][^+-]'
241+
-maintainer: "Maintainer <me@example.com>"
242+
+maintainer: ["Maintainer1" "Maintaner2"]
243+
$ opam-ci-check lint -r . -c a-1.0.0.1
244+
Linting opam-repository at $TESTCASE_ROOT/. ...
245+
No errors

test/lint.t

-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ Tests the following:
3131
$ opam-repo-ci-local --repo="." --branch=new-branch-1 --lint-only --no-web-server
3232
Error "Warning in system-b.0.0.1: package name has restricted prefix 'system-'
3333
Error in system-b.0.0.1: package with prefix 'system-' requires conflict class 'ocaml-system'
34-
Error in system-b.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer
3534
Error in b.0.0.3: package with conflict class 'ocaml-host-arch' requires name prefix 'host-arch-'
3635
Error in b.0.0.3: pin-depends present. This is not allowed in the opam-repository.
37-
Error in b.0.0.3: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer
38-
Error in b.0.0.2: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer
3936
Error in b.0.0.2: error 3: File format error in 'unknown-field' at line 11, column 0: Invalid field unknown-field
40-
Error in b.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer
4137
Error in b.0.0.1: warning 25: Missing field 'authors'"

0 commit comments

Comments
 (0)