package crs
A tool for managing code review comments embedded in source code
Install
Dune Dependency
Authors
Maintainers
Sources
crs-0.0.20250705.tbz
sha256=e9f9f5ec5aea9658ed640aaa06f887985bb6870adcf7555ebf6d48bb741e4793
sha512=901ac1caae6c4103a320b4a3a177ca3aa0583ad533c54e7740aba6652ccdbd6311d07ab4b73e3ba750beed24f85479b5e1b0e94504ecfd0c59bd49cdabebc369
doc/src/crs.crs-cli/summary_table.ml.html
Source file summary_table.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
(********************************************************************************) (* crs - A tool for managing code review comments embedded in source code *) (* Copyright (C) 2024-2025 Mathieu Barbin <mathieu.barbin@gmail.com> *) (* *) (* This file is part of crs. *) (* *) (* crs is free software; you can redistribute it and/or modify it under the *) (* terms of the GNU Lesser General Public License as published by the Free *) (* Software Foundation either version 3 of the License, or any later version, *) (* with the LGPL-3.0 Linking Exception. *) (* *) (* crs is distributed in the hope that it will be useful, but WITHOUT ANY *) (* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *) (* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License and *) (* the file `NOTICE.md` at the root of this repository for more details. *) (* *) (* You should have received a copy of the GNU Lesser General Public License *) (* and the LGPL-3.0 Linking Exception along with this library. If not, see *) (* <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively. *) (********************************************************************************) module By_type = struct module Type = struct type t = | Invalid | CR | XCR | Soon | Someday [@@deriving compare, sexp_of] let to_string t = match sexp_of_t t with | Atom a -> a | List _ -> assert false ;; let of_cr (cr : Cr_comment.t) = match Cr_comment.header cr with | Error _ -> Invalid | Ok h -> (match Cr_comment.Header.status h with | XCR -> XCR | CR -> (match Cr_comment.Header.qualifier h with | None -> CR | Soon -> Soon | Someday -> Someday)) ;; end module Row = struct type t = { type_ : Type.t ; count : int } end type t = { rows : Row.t list } let make (crs : Cr_comment.t list) = let rows = List.map crs ~f:Type.of_cr |> List.sort_and_group ~compare:Type.compare |> List.map ~f:(function | [] -> assert false | type_ :: _ as list -> { Row.type_; count = List.length list }) in { rows } ;; let columns = Text_table.O. [ Column.make ~header:"CR Type" (fun (row : Row.t) -> Cell.text (Type.to_string row.type_)) ; Column.make ~header:"Count" ~align:Right (fun (row : Row.t) -> Cell.text ~style: (match row.type_ with | Invalid -> Style.fg_red | CR | XCR | Soon | Someday -> Style.default) (Int.to_string_hum row.count)) ] ;; let to_text_table t = if List.is_empty t.rows then None else Some (Text_table.make ~columns ~rows:t.rows) ;; end module Type = struct type t = | CR | XCR | Soon | Someday let of_header h = match Cr_comment.Header.status h with | XCR -> XCR | CR -> (match Cr_comment.Header.qualifier h with | None -> CR | Soon -> Soon | Someday -> Someday) ;; end module Key = struct type t = { reporter : Vcs.User_handle.t ; recipient : Vcs.User_handle.t option } [@@deriving compare] let of_header (h : Cr_comment.Header.t) = { reporter = Cr_comment.Header.reporter h; recipient = Cr_comment.Header.recipient h } ;; end module Row = struct type t = { reporter : Vcs.User_handle.t ; recipient : Vcs.User_handle.t option ; cr_count : int ; xcr_count : int ; soon_count : int ; someday_count : int ; total_count : int } end type t = { rows : Row.t list } let make (crs : Cr_comment.t list) = let rows = List.filter_map crs ~f:(fun cr -> match Cr_comment.header cr with | Error _ -> None | Ok h -> let key = Key.of_header h in let type_ = Type.of_header h in Some (key, type_)) |> List.sort_and_group ~compare:(fun (k1, _) (k2, _) -> Key.compare k1 k2) |> List.map ~f:(function | [] -> assert false | ({ Key.reporter; recipient }, _) :: _ as list -> let cr_count = ref 0 in let xcr_count = ref 0 in let soon_count = ref 0 in let someday_count = ref 0 in let total_count = ref 0 in List.iter list ~f:(fun (_, type_) -> Int.incr total_count; match (type_ : Type.t) with | CR -> Int.incr cr_count | XCR -> Int.incr xcr_count | Soon -> Int.incr soon_count | Someday -> Int.incr someday_count); { Row.reporter ; recipient ; cr_count = !cr_count ; xcr_count = !xcr_count ; soon_count = !soon_count ; someday_count = !someday_count ; total_count = !total_count }) in { rows } ;; let columns = let count ~header count = Text_table.O.( Column.make ~header ~align:Right (fun (row : Row.t) -> let count = count row in if count = 0 then Cell.empty else Cell.text (Int.to_string_hum count))) in Text_table.O. [ Column.make ~header:"Reporter" (fun (row : Row.t) -> Cell.text (Vcs.User_handle.to_string row.reporter)) ; Column.make ~header:"For" (fun (row : Row.t) -> match row.recipient with | None -> Cell.empty | Some user -> Cell.text (Vcs.User_handle.to_string user)) ; count ~header:"CRs" (fun row -> row.cr_count) ; count ~header:"XCRs" (fun row -> row.xcr_count) ; count ~header:"Soon" (fun row -> row.soon_count) ; count ~header:"Someday" (fun row -> row.someday_count) ; count ~header:"Total" (fun row -> row.total_count) ] ;; let to_text_table t = if List.is_empty t.rows then None else Some (Text_table.make ~columns ~rows:t.rows) ;;
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>