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

Distinguish between issue comments and PR comments #38

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
### Changed

- API: `Contributions.of_json` parameter `~from` is replaced by `~period` (#31, @gpetiot)
- Distinguish between issue comments and PR comments (#<PR_NUMBER>, @gpetiot)
gpetiot marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down
20 changes: 15 additions & 5 deletions lib/contributions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/contributions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions lib/contributions_json_response.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -84,7 +84,7 @@ type contributionsCollection = {
type user_data = {
login : string;
contributionsCollection : contributionsCollection;
issueComments : Issue.comments;
issueComments : comments;
}
[@@deriving yojson]

Expand Down
16 changes: 14 additions & 2 deletions test/expect/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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).
Expand Down
30 changes: 26 additions & 4 deletions test/lib/test_contributions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ 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"

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
Expand Down Expand Up @@ -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"
}
]
}
Expand Down Expand Up @@ -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";
Expand Down
Loading