diff --git a/CHANGES.md b/CHANGES.md index c821d0d..1d9f8ec 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ - Add the `--version` command-line option (#13, @gpetiot) - Add a `--user` option to extract the activity of an engineer that is not the current user (#14, @gpetiot) +- Add the issue comments to the contributions (#, @gpetiot) ### Changed diff --git a/lib/contributions.ml b/lib/contributions.ml index 0ad226b..eb1c79a 100644 --- a/lib/contributions.ml +++ b/lib/contributions.ml @@ -54,6 +54,15 @@ let query user = } } } + issueComments(last: 40) { + nodes { + url + publishedAt + repository { nameWithOwner } + issue { title } + body + } + } } }|} User.query user @@ -75,7 +84,7 @@ module Repo_map = Map.Make (String) type item = { repo : string; - kind : [ `Issue | `PR | `Review of string | `New_repo ]; + kind : [ `Issue | `Issue_comment | `PR | `Review of string | `New_repo ]; date : Datetime.t; url : string; title : string; @@ -100,7 +109,7 @@ let read_issues json = Json.Util.to_list (json / "nodes") |> List.filter (( <> ) `Null) |> List.map (fun node -> - let* date = Datetime.parse (node / "occurredAt") in + let* date = node / "occurredAt" |> Datetime.parse in let x = node / "issue" in let* url = x / "url" |> to_string in let* title = x / "title" |> to_string in @@ -109,6 +118,18 @@ let read_issues json = Ok { kind = `Issue; date; url; title; body; repo }) |> combine +let read_issue_comments json = + Json.Util.to_list (json / "nodes") + |> List.filter (( <> ) `Null) + |> List.map (fun node -> + let* date = node / "publishedAt" |> Datetime.parse in + let* url = node / "url" |> to_string in + let* title = node / "issue" / "title" |> to_string in + let* body = node / "body" |> to_string in + let* repo = node / "repository" / "nameWithOwner" |> to_string in + Ok { kind = `Issue_comment; date; url; title; body; repo }) + |> combine + let read_prs json = Json.Util.to_list (json / "nodes") |> List.filter (( <> ) `Null) @@ -150,18 +171,16 @@ let read_repos json = |> combine let of_json ~from ~user json = - let* username = - json / "data" / User.response_field user / "login" |> to_string - in - let contribs = - json / "data" / User.response_field user / "contributionsCollection" - in + let root = json / "data" / User.response_field user in + let* username = root / "login" |> to_string in + let contribs = root / "contributionsCollection" in let* items = let* issues = read_issues (contribs / "issueContributions") in + let* issue_comments = read_issue_comments (root / "issueComments") in let* prs = read_prs (contribs / "pullRequestContributions") in let* reviews = read_reviews (contribs / "pullRequestReviewContributions") in let* repos = read_repos (contribs / "repositoryContributions") in - Ok (issues @ prs @ reviews @ repos) + Ok (issues @ issue_comments @ prs @ reviews @ repos) in let activity = (* GitHub seems to ignore the time part, so do the filtering here. *) @@ -188,6 +207,7 @@ let id url = let pp_title f t = match t.kind with | `Issue -> Fmt.pf f "%s [#%s](%s)" t.title (id t.url) t.url + | `Issue_comment -> Fmt.pf f "Commented %S [#%s](%s)" t.title (id t.url) t.url | `PR -> Fmt.pf f "%s [#%s](%s)" t.title (id t.url) t.url | `Review s -> Fmt.pf f "%s %s [#%s](%s)" s t.title (id t.url) t.url | `New_repo -> Fmt.pf f "Created repository [%s](%s)" t.repo t.url @@ -275,6 +295,15 @@ let contributions_example = title = "Title5"; body = "xxx"; }; + { + repo = "tarides/okra"; + kind = `Issue_comment; + date = "2024-03-13T11:09:56Z"; + url = + "https://github.com/tarides/okra/issues/114#issuecomment-1994130584"; + title = "Title6"; + body = "xxx"; + }; ]; } @@ -300,4 +329,7 @@ let%expect_test "Contributions.pp" = xxx Title5 [#165](https://github.com/tarides/okra/issues/165). + xxx + + Commented "Title6" [#114](https://github.com/tarides/okra/issues/114#issuecomment-1994130584). xxx |}] diff --git a/lib/contributions.mli b/lib/contributions.mli index b870910..c47b518 100644 --- a/lib/contributions.mli +++ b/lib/contributions.mli @@ -4,7 +4,7 @@ end type item = { repo : string; - kind : [ `Issue | `PR | `Review of string | `New_repo ]; + kind : [ `Issue | `Issue_comment | `PR | `Review of string | `New_repo ]; date : Datetime.t; url : string; title : string; diff --git a/test/lib/test_contributions.ml b/test/lib/test_contributions.ml index 1ae42c9..f88ff33 100644 --- a/test/lib/test_contributions.ml +++ b/test/lib/test_contributions.ml @@ -8,17 +8,22 @@ module Testable = struct module Item = struct module Kind = struct - type t = [ `Issue | `PR | `Review of string | `New_repo ] + type t = [ `Issue | `Issue_comment | `PR | `Review of string | `New_repo ] let pp fs = function | `Issue -> Format.fprintf fs "`Issue" + | `Issue_comment -> Format.fprintf fs "`Issue_comment" | `PR -> Format.fprintf fs "`PR" | `Review x -> Format.fprintf fs "`Review %S" x | `New_repo -> Format.fprintf fs "`New_repo" let eq (x : t) (y : t) = match (x, y) with - | `Issue, `Issue | `PR, `PR | `New_repo, `New_repo -> true + | `Issue, `Issue + | `Issue_comment, `Issue_comment + | `PR, `PR + | `New_repo, `New_repo -> + true | `Review x, `Review y -> String.equal x y | _ -> false end @@ -134,6 +139,15 @@ let request ~user = } } } + issueComments(last: 40) { + nodes { + url + publishedAt + repository { nameWithOwner } + issue { title } + body + } + } } }|} User.query user @@ -298,6 +312,21 @@ let activity_example ~user = } ] } + }, + "issueComments": { + "nodes": [ + { + "url": "https://github.com/tarides/okra/issues/114#issuecomment-1994130584", + "publishedAt": "2024-03-13T11:09:56Z", + "issue": { + "title": "Gitlab: exception when parsing Gitlab's JSON" + }, + "repository": { + "nameWithOwner": "tarides/okra" + }, + "body": "xxx" + } + ] } } } @@ -390,6 +419,15 @@ let contributions_example ~user = title = "Make README.md more precise"; body = "xxx"; }; + { + repo = "tarides/okra"; + kind = `Issue_comment; + date = "2024-03-13T11:09:56Z"; + url = + "https://github.com/tarides/okra/issues/114#issuecomment-1994130584"; + title = "Gitlab: exception when parsing Gitlab's JSON"; + body = "xxx"; + }; { repo = "tarides/okra"; kind = `Issue;