Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Check for maintainer emails in the opam file
Browse files Browse the repository at this point in the history
This commit adds a simple regex search for emails in the maintainer
field. Closes #20
  • Loading branch information
punchagan committed Aug 29, 2024
1 parent 9d80340 commit 25a288d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(library
(name opam_ci_check)
(public_name opam-ci-check)
(libraries opam-client sexplib mula))
(libraries opam-client sexplib mula str))
9 changes: 9 additions & 0 deletions lib/lint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ module Checks = struct
if is_build then [ (pkg, DuneIsBuild) ] else errors
| None -> []

let check_maintainer_email ~pkg opam =
let maintainers = OpamFile.OPAM.maintainer opam in
List.filter_map
(fun m ->
if Str.string_match (Str.regexp ".*<?.*@.*>?") m 0 then None
else Some (pkg, MaintainerEmailMissing m))
maintainers

let opam_lint ~pkg opam =
OpamFileTools.lint ~check_upstream:true opam
|> List.map (fun x -> (pkg, OpamLint x))
Expand Down Expand Up @@ -343,6 +351,7 @@ module Checks = struct
check_checksums;
check_package_dir ~repo_dir;
opam_lint;
check_maintainer_email;
check_no_pin_depends;
check_no_extra_files;
Prefix.check_prefix_conflict_class_mismatch;
Expand Down
6 changes: 6 additions & 0 deletions lib/lint_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type error =
| UnexpectedFile of string
| ForbiddenPerm of string
| OpamLint of (int * [ `Warning | `Error ] * string)
| MaintainerEmailMissing of string
| FailedToDownload of string
| NameCollision of string
| WeakChecksum of string
Expand Down Expand Up @@ -137,5 +138,10 @@ let msg_of_error (package, (err : error)) =
| OpamLint warn ->
let warn = OpamFileTools.warns_to_string [ warn ] in
Printf.sprintf "Error in %s: %s" pkg warn
| MaintainerEmailMissing maintainer ->
Printf.sprintf
"Error in %s: Maintainer email missing. Please add a maintainer email \
to the opam file. Maintainer: %s"
pkg maintainer
| ParseError ->
Printf.sprintf "Error in %s: Failed to parse the opam file" pkg
2 changes: 2 additions & 0 deletions test/lint.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Setup repo for incorrect b package tests
Test the following:
- [b.0.0.1] is missing the [author] field
- [b.0.0.1] is missing the maintainer's email in the [maintainer] field
- [b.0.0.2] has an extra unknown field
- [b.0.0.3] has a pin-depends present, and a conflict class without the required prefix; use of extra-files and a weak checksum algorithm
- [system-b.0.0.1] is using a restricted prefix in its name
Expand All @@ -54,6 +55,7 @@ Test the following:
$ opam-ci-check lint -r . -c b.0.0.1
Linting opam-repository at $TESTCASE_ROOT/. ...
Error in b.0.0.1: warning 25: Missing field 'authors'
Error in b.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Jane
[1]
$ opam-ci-check lint -r . -c b.0.0.2
Linting opam-repository at $TESTCASE_ROOT/. ...
Expand Down
4 changes: 2 additions & 2 deletions test/patches/a-1.patch
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ index 0000000..58229e8
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -37,7 +37,7 @@ index 0000000..58229e8
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand Down
2 changes: 1 addition & 1 deletion test/patches/a_1-name-collision.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ index 0000000..58229e8
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand Down
6 changes: 3 additions & 3 deletions test/patches/b-correct.patch
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ index 0000000..69040f4
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -41,7 +41,7 @@ index 0000000..1581508
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -61,7 +61,7 @@ index 0000000..5ec1dc4
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand Down
14 changes: 7 additions & 7 deletions test/patches/b-incorrect-opam.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 0000000..3697498
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Jane"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
+bug-reports: "https://github.com/ocurrent/opam-repo-ci/issues"
Expand All @@ -26,7 +26,7 @@ index 0000000..a47aabf
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand Down Expand Up @@ -54,7 +54,7 @@ index 0000000..5bab63e
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand Down Expand Up @@ -84,7 +84,7 @@ index 0000000..0808e56
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -104,7 +104,7 @@ index 0000000..5bab63e
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -129,7 +129,7 @@ index 0000000..5bab63e
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -153,7 +153,7 @@ index 0000000..5bab63e
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand Down
8 changes: 4 additions & 4 deletions test/patches/levenshtein-2.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 0000000..5246a83
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -25,7 +25,7 @@ index 0000000..5246a83
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -43,7 +43,7 @@ index 0000000..5246a83
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand All @@ -61,7 +61,7 @@ index 0000000..5246a83
+opam-version: "2.0"
+synopsis: "Synopsis"
+description: "Description"
+maintainer: "Maintainer"
+maintainer: "Maintainer <[email protected]>"
+author: "Author"
+license: "Apache-2.0"
+homepage: "https://github.com/ocurrent/opam-repo-ci"
Expand Down

0 comments on commit 25a288d

Please sign in to comment.