diff --git a/CHANGES.md b/CHANGES.md index f684e62..53806f4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,11 +7,14 @@ ### Changed - API: `Contributions.of_json` parameter `~from` is replaced by `~period` (#31, @gpetiot) +- Distinguish between issue comments and PR comments (#38, @gpetiot) + API: new constructor `Comment` replacing `Issue_comment` ### Added - Display curl requests and responses in debug mode (`-vv` or `--verbosity debug`) (#36, @gpetiot) - Add the PR merge events to the contributions (#37, @emillon, @gpetiot) + API: new constructor `Merge` ## 1.0.1 diff --git a/lib/contributions.ml b/lib/contributions.ml index 21b60e9..ee2e27d 100644 --- a/lib/contributions.ml +++ b/lib/contributions.ml @@ -84,7 +84,12 @@ module Repo_map = Map.Make (String) type item = { repo : string; kind : - [ `Issue | `Issue_comment | `PR | `Review of string | `Merge | `New_repo ]; + [ `Issue + | `PR + | `Comment of [ `Issue | `PR ] + | `Review of string + | `Merge + | `New_repo ]; date : Datetime.t; url : string; title : string; @@ -103,13 +108,16 @@ let read_issues = { kind = `Issue; date; url; title; body; repo }) let read_issue_comments = - List.map (fun (c : Json.Issue.comment) -> + List.map (fun (c : Json.comment) -> let date = c.publishedAt in let url = c.url in let title = c.issue.title in + let kind = + if Astring.String.is_infix ~affix:"/issues/" url then `Issue else `PR + in let body = c.body in let repo = c.repository.nameWithOwner in - { kind = `Issue_comment; date; url; title; body; repo }) + { kind = `Comment kind; date; url; title; body; repo }) let read_prs ~username = List.fold_left @@ -209,9 +217,11 @@ 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 on %S [#%s](%s)" t.title (id t.url) t.url | `PR -> Fmt.pf f "%s [#%s](%s)" t.title (id t.url) t.url + | `Comment `Issue -> + Fmt.pf f "Commented on issue %S [#%s](%s)" t.title (id t.url) t.url + | `Comment `PR -> + Fmt.pf f "Commented on PR %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 | `Merge -> Fmt.pf f "Merged %S [#%s](%s)" t.title (id t.url) t.url | `New_repo -> Fmt.pf f "Created repository [%s](%s)" t.repo t.url diff --git a/lib/contributions.mli b/lib/contributions.mli index 0d4eb33..bfe878c 100644 --- a/lib/contributions.mli +++ b/lib/contributions.mli @@ -5,7 +5,12 @@ end type item = { repo : string; kind : - [ `Issue | `Issue_comment | `PR | `Review of string | `Merge | `New_repo ]; + [ `Issue + | `PR + | `Comment of [ `Issue | `PR ] + | `Review of string + | `Merge + | `New_repo ]; date : Datetime.t; url : string; title : string; diff --git a/lib/contributions_json_response.ml b/lib/contributions_json_response.ml index bdeac1b..28c095a 100644 --- a/lib/contributions_json_response.ml +++ b/lib/contributions_json_response.ml @@ -22,17 +22,6 @@ module Issue = struct type title = { title : string } [@@deriving yojson] type contribution = { occurredAt : string; issue : t } [@@deriving yojson] type contributions = { nodes : contribution list } [@@deriving yojson] - - type comment = { - url : string; - publishedAt : string; - issue : title; - repository : Repository.name; - body : string; - } - [@@deriving yojson] - - type comments = { nodes : comment list } [@@deriving yojson] end module PullRequest = struct @@ -73,6 +62,17 @@ module PullRequest = struct end end +type comment = { + url : string; + publishedAt : string; + issue : Issue.title; + repository : Repository.name; + body : string; +} +[@@deriving yojson] + +type comments = { nodes : comment list } [@@deriving yojson] + type contributionsCollection = { issueContributions : Issue.contributions; pullRequestContributions : PullRequest.contributions; @@ -84,7 +84,7 @@ type contributionsCollection = { type user_data = { login : string; contributionsCollection : contributionsCollection; - issueComments : Issue.comments; + issueComments : comments; } [@@deriving yojson] diff --git a/test/expect/main.ml b/test/expect/main.ml index 79b14dc..877d562 100644 --- a/test/expect/main.ml +++ b/test/expect/main.ml @@ -93,7 +93,16 @@ let contributions_example ~user = }; { repo = "tarides/okra"; - kind = `Issue_comment; + kind = `Comment `PR; + date = "2024-03-13T11:09:56Z"; + url = + "https://github.com/tarides/okra/pull/114#issuecomment-1994130584"; + title = "Gitlab: exception when parsing Gitlab's JSON"; + body = "xxx"; + }; + { + repo = "tarides/okra"; + kind = `Comment `Issue; date = "2024-03-13T11:09:56Z"; url = "https://github.com/tarides/okra/issues/114#issuecomment-1994130584"; @@ -157,7 +166,10 @@ let%expect_test "Contributions.pp" = APPROVED Make README.md more precise [#166](https://github.com/tarides/okra/pull/166#pullrequestreview-1905972361). xxx - Commented on "Gitlab: exception when parsing Gitlab's JSON" [#114](https://github.com/tarides/okra/issues/114#issuecomment-1994130584). + Commented on PR "Gitlab: exception when parsing Gitlab's JSON" [#114](https://github.com/tarides/okra/pull/114#issuecomment-1994130584). + xxx + + Commented on issue "Gitlab: exception when parsing Gitlab's JSON" [#114](https://github.com/tarides/okra/issues/114#issuecomment-1994130584). xxx Make the `get-activity` package known to ocaml-ci [#165](https://github.com/tarides/okra/issues/165). diff --git a/test/lib/test_contributions.ml b/test/lib/test_contributions.ml index 5a03986..b81d165 100644 --- a/test/lib/test_contributions.ml +++ b/test/lib/test_contributions.ml @@ -10,16 +10,17 @@ module Testable = struct module Kind = struct type t = [ `Issue - | `Issue_comment | `PR + | `Comment of [ `Issue | `PR ] | `Review of string | `Merge | `New_repo ] let pp fs = function | `Issue -> Format.fprintf fs "`Issue" - | `Issue_comment -> Format.fprintf fs "`Issue_comment" | `PR -> Format.fprintf fs "`PR" + | `Comment `Issue -> Format.fprintf fs "`Comment `Issue" + | `Comment `PR -> Format.fprintf fs "`Comment `PR" | `Review x -> Format.fprintf fs "`Review %S" x | `Merge -> Format.fprintf fs "`Merge" | `New_repo -> Format.fprintf fs "`New_repo" @@ -27,8 +28,9 @@ module Testable = struct let eq (x : t) (y : t) = match (x, y) with | `Issue, `Issue - | `Issue_comment, `Issue_comment | `PR, `PR + | `Comment `Issue, `Comment `Issue + | `Comment `PR, `Comment `PR | `Merge, `Merge | `New_repo, `New_repo -> true @@ -351,6 +353,17 @@ let activity_example ~user = "nameWithOwner": "tarides/okra" }, "body": "xxx" + }, + { + "url": "https://github.com/tarides/okra/pull/114#issuecomment-1994130584", + "publishedAt": "2024-03-13T11:09:56Z", + "issue": { + "title": "Gitlab: exception when parsing Gitlab's JSON" + }, + "repository": { + "nameWithOwner": "tarides/okra" + }, + "body": "xxx" } ] } @@ -515,7 +528,16 @@ let contributions_example2 ~user = }; { repo = "tarides/okra"; - kind = `Issue_comment; + kind = `Comment `PR; + date = "2024-03-13T11:09:56Z"; + url = + "https://github.com/tarides/okra/pull/114#issuecomment-1994130584"; + title = "Gitlab: exception when parsing Gitlab's JSON"; + body = "xxx"; + }; + { + repo = "tarides/okra"; + kind = `Comment `Issue; date = "2024-03-13T11:09:56Z"; url = "https://github.com/tarides/okra/issues/114#issuecomment-1994130584";