Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the issue comments to the contributions #21

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (#21, @gpetiot)

### Changed

Expand Down
51 changes: 42 additions & 9 deletions lib/contributions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ let query user =
}
}
}
issueComments(last: 40) {
nodes {
url
publishedAt
repository { nameWithOwner }
issue { title }
body
}
}
}
}|}
User.query user
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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. *)
Expand All @@ -188,6 +207,8 @@ 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
| `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
Expand Down Expand Up @@ -275,6 +296,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";
};
];
}

Expand All @@ -300,4 +330,7 @@ let%expect_test "Contributions.pp" =
xxx

Title5 [#165](https://github.com/tarides/okra/issues/165).
xxx

Commented on "Title6" [#114](https://github.com/tarides/okra/issues/114#issuecomment-1994130584).
xxx |}]
2 changes: 1 addition & 1 deletion lib/contributions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 40 additions & 2 deletions test/lib/test_contributions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -134,6 +139,15 @@ let request ~user =
}
}
}
issueComments(last: 40) {
nodes {
url
publishedAt
repository { nameWithOwner }
issue { title }
body
}
}
}
}|}
User.query user
Expand Down Expand Up @@ -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"
}
]
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
Loading