OCaml library and CLI for OCI and Docker image manipulation
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(lint): resolve E001, E005, E105, E320 across oci and homebrew

- E001: extract opt_true helper to reduce cyclomatic complexity in
Docker.config_jsont
- E005: extract bottle_steps, formula_update_steps, discover_bottles
to shorten long functions
- E105: simplify catch-all match in attestation.ml
- E320: shorten test identifiers with 5+ underscores in test_push.ml

+20 -24
+1 -5
src/attestation.ml
··· 28 28 | Some l -> ( 29 29 let blob = Cache.Blob.get_string cache (Descriptor.digest l) in 30 30 match Intoto.of_string blob with 31 - | Ok stmt -> 32 - let subject_digest = 33 - match Descriptor.platform d with _ -> digest 34 - in 35 - Some { subject_digest; statement = stmt } 31 + | Ok stmt -> Some { subject_digest = digest; statement = stmt } 36 32 | Error _ -> None)) 37 33 | _ -> None 38 34 | exception Failure _ -> None
+13 -13
src/spec/config.ml
··· 2 2 open Result.Syntax 3 3 4 4 let non_empty l = if l = [] then None else Some l 5 + let opt_true = function true -> Some true | false -> None 5 6 6 7 let labels_jsont = 7 8 map_jsont ··· 296 297 c.domain_name) 297 298 |> Jsont.Object.opt_mem "User" Jsont.string ~enc:(fun c -> c.user) 298 299 |> Jsont.Object.opt_mem "AttachStdin" Jsont.bool ~enc:(fun c -> 299 - if c.attach_stdin then Some true else None) 300 + opt_true c.attach_stdin) 300 301 |> Jsont.Object.opt_mem "AttachStdout" Jsont.bool ~enc:(fun c -> 301 - if c.attach_stdout then Some true else None) 302 + opt_true c.attach_stdout) 302 303 |> Jsont.Object.opt_mem "AttachStderr" Jsont.bool ~enc:(fun c -> 303 - if c.attach_stderr then Some true else None) 304 + opt_true c.attach_stderr) 304 305 |> Jsont.Object.opt_mem "ExposedPorts" set_jsont ~enc:(fun c -> 305 - if c.exposed_ports = [] then None else Some c.exposed_ports) 306 - |> Jsont.Object.opt_mem "Tty" Jsont.bool ~enc:(fun c -> 307 - if c.tty then Some true else None) 306 + non_empty c.exposed_ports) 307 + |> Jsont.Object.opt_mem "Tty" Jsont.bool ~enc:(fun c -> opt_true c.tty) 308 308 |> Jsont.Object.opt_mem "OpenStdin" Jsont.bool ~enc:(fun c -> 309 - if c.open_stdin then Some true else None) 309 + opt_true c.open_stdin) 310 310 |> Jsont.Object.opt_mem "StdinOnce" Jsont.bool ~enc:(fun c -> 311 - if c.stdin_once then Some true else None) 311 + opt_true c.stdin_once) 312 312 |> Jsont.Object.opt_mem "Env" (Jsont.list env_jsont) ~enc:(fun c -> c.env) 313 313 |> Jsont.Object.opt_mem "Cmd" (Jsont.list Jsont.string) ~enc:(fun c -> 314 314 c.cmd) 315 315 |> Jsont.Object.opt_mem "HealthCheck" set_jsont ~enc:(fun c -> 316 - if c.healthcheck = [] then None else Some c.healthcheck) 316 + non_empty c.healthcheck) 317 317 |> Jsont.Object.opt_mem "ArgsEscaped" Jsont.bool ~enc:(fun c -> 318 318 c.args_escaped) 319 319 |> Jsont.Object.opt_mem "Image" Jsont.string ~enc:(fun c -> c.image) 320 320 |> Jsont.Object.opt_mem "Volumes" set_jsont ~enc:(fun c -> 321 - if c.volumes = [] then None else Some c.volumes) 321 + non_empty c.volumes) 322 322 |> Jsont.Object.opt_mem "WorkingDir" Jsont.string ~enc:(fun c -> 323 323 if c.working_dir = "" then None else Some c.working_dir) 324 324 |> Jsont.Object.opt_mem "Entrypoint" (Jsont.list Jsont.string) 325 325 ~enc:(fun c -> c.entrypoint) 326 326 |> Jsont.Object.opt_mem "NetworkDisabled" Jsont.bool ~enc:(fun c -> 327 - if c.network_disabled then Some true else None) 327 + opt_true c.network_disabled) 328 328 |> Jsont.Object.opt_mem "MacAddress" Jsont.string ~enc:(fun c -> 329 329 c.mac_address) 330 330 |> Jsont.Object.opt_mem "OnBuild" (Jsont.list Jsont.string) ~enc:(fun c -> 331 331 c.on_build) 332 332 |> Jsont.Object.opt_mem "Labels" labels_jsont ~enc:(fun c -> 333 - if c.labels = [] then None else Some c.labels) 333 + non_empty c.labels) 334 334 |> Jsont.Object.opt_mem "StopSignal" Jsont.string ~enc:(fun c -> 335 335 c.stop_signal) 336 336 |> Jsont.Object.opt_mem "StopTimeout" Jsont.int ~enc:(fun c -> 337 337 c.stop_timeout) 338 338 |> Jsont.Object.opt_mem "Shell" (Jsont.list Jsont.string) ~enc:(fun c -> 339 - if c.shell = [] then None else Some c.shell) 339 + non_empty c.shell) 340 340 |> Jsont.Object.skip_unknown |> Jsont.Object.finish 341 341 342 342 type rootfs = { type_ : string; diff_ids : Digest.t list }
+6 -6
test/spec/test_push.ml
··· 161 161 (Digest.equal (Descriptor.digest l) (Descriptor.digest l')) 162 162 | Error (`Msg e) -> fail e 163 163 164 - let test_manifest_json_has_schema_version () = 164 + let test_manifest_has_schema_version () = 165 165 let m = build_manifest ~artifact_type:"application/vnd.test" [ "data" ] in 166 166 let json_str = Manifest.OCI.to_string m in 167 167 check bool "has schemaVersion" true 168 168 (Astring.String.is_infix ~affix:"\"schemaVersion\"" json_str) 169 169 170 - let test_manifest_json_has_media_type () = 170 + let test_manifest_has_media_type () = 171 171 let m = build_manifest ~artifact_type:"application/vnd.test" [ "data" ] in 172 172 let json_str = Manifest.OCI.to_string m in 173 173 check bool "has OCI manifest media type" true 174 174 (Astring.String.is_infix ~affix:"application/vnd.oci.image.manifest.v1+json" 175 175 json_str) 176 176 177 - let test_manifest_json_has_artifact_type () = 177 + let test_manifest_has_artifact_type () = 178 178 let artifact_type = "application/vnd.spaceos.init.v1" in 179 179 let m = build_manifest ~artifact_type [ "data" ] in 180 180 let json_str = Manifest.OCI.to_string m in ··· 370 370 test_case "manifest empty layers" `Quick test_manifest_empty_layers; 371 371 test_case "manifest roundtrip" `Quick test_manifest_roundtrip; 372 372 test_case "manifest JSON has schemaVersion" `Quick 373 - test_manifest_json_has_schema_version; 373 + test_manifest_has_schema_version; 374 374 test_case "manifest JSON has mediaType" `Quick 375 - test_manifest_json_has_media_type; 375 + test_manifest_has_media_type; 376 376 test_case "manifest JSON has artifactType" `Quick 377 - test_manifest_json_has_artifact_type; 377 + test_manifest_has_artifact_type; 378 378 test_case "manifest JSON has config" `Quick test_manifest_json_has_config; 379 379 test_case "manifest JSON has layers" `Quick test_manifest_json_has_layers; 380 380 test_case "manifest valid OCI" `Quick test_manifest_valid_oci;