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

Filter out null elements that are sometimes in the nodes list #39

Merged
merged 2 commits into from
Apr 4, 2024
Merged
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
Next Next commit
Filter out null elements that are sometimes in the nodes list
gpetiot committed Apr 4, 2024
commit 97b4dd8291ec0693632ffa14115c7546c03d24da
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## unreleased

### Fixed

- Filter out null elements that are sometimes in the nodes list (#<PR_NUMBER>, @gpetiot)
gpetiot marked this conversation as resolved.
Show resolved Hide resolved

## 2.0.0

### Fixed
20 changes: 14 additions & 6 deletions lib/contributions.ml
Original file line number Diff line number Diff line change
@@ -98,16 +98,19 @@ type item = {

type t = { username : string; activity : item list Repo_map.t }

let read_issues =
let filter_null_nodes l = List.filter_map (fun x -> x) l

let read_issues l =
List.map (fun (c : Json.Issue.contribution) ->
let date = c.occurredAt in
let url = c.issue.url in
let title = c.issue.title in
let body = c.issue.body in
let repo = c.issue.repository.nameWithOwner in
{ kind = `Issue; date; url; title; body; repo })
@@ filter_null_nodes l

let read_issue_comments =
let read_issue_comments l =
List.map (fun (c : Json.comment) ->
let date = c.publishedAt in
let url = c.url in
@@ -118,8 +121,9 @@ let read_issue_comments =
let body = c.body in
let repo = c.repository.nameWithOwner in
{ kind = `Comment kind; date; url; title; body; repo })
@@ filter_null_nodes l

let read_prs ~username =
let read_prs ~username l =
List.fold_left
(fun acc (c : Json.PullRequest.contribution) ->
let date = c.occurredAt in
@@ -137,12 +141,14 @@ let read_prs ~username =
if String.equal login username then
{ kind = `Merge; date; url; title; body = ""; repo } :: acc
else acc)
acc timeline_items
acc
@@ filter_null_nodes timeline_items
in
acc)
[]
@@ filter_null_nodes l

let read_reviews =
let read_reviews l =
List.map (fun (c : Json.PullRequest.Review.contribution) ->
let date = c.occurredAt in
let state = c.pullRequestReview.state in
@@ -151,14 +157,16 @@ let read_reviews =
let body = c.pullRequestReview.body in
let repo = c.pullRequestReview.repository.nameWithOwner in
{ kind = `Review state; date; url; title; body; repo })
@@ filter_null_nodes l

let read_repos =
let read_repos l =
List.map (fun (c : Json.Repository.contribution) ->
let date = c.occurredAt in
let url = c.repository.url in
let repo = c.repository.nameWithOwner in
let title = "Created new repository" in
{ kind = `New_repo; date; url; title; body = ""; repo })
@@ filter_null_nodes l

let of_json ~period:(from, to_) ~user json =
let* json =
13 changes: 7 additions & 6 deletions lib/contributions_json_response.ml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ module Repository = struct
type contribution = { occurredAt : string; repository : t }
[@@deriving yojson]

type contributions = { nodes : contribution list } [@@deriving yojson]
type contributions = { nodes : contribution option list } [@@deriving yojson]
end

module Issue = struct
@@ -21,13 +21,13 @@ 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 contributions = { nodes : contribution option list } [@@deriving yojson]
end

module PullRequest = struct
type actor = { login : string } [@@deriving yojson]
type timelineItem = { createdAt : string; actor : actor } [@@deriving yojson]
type timelineItems = { nodes : timelineItem list } [@@deriving yojson]
type timelineItems = { nodes : timelineItem option list } [@@deriving yojson]

type t = {
url : string;
@@ -43,7 +43,7 @@ module PullRequest = struct
type contribution = { occurredAt : string; pullRequest : t }
[@@deriving yojson]

type contributions = { nodes : contribution list } [@@deriving yojson]
type contributions = { nodes : contribution option list } [@@deriving yojson]

module Review = struct
type t = {
@@ -58,7 +58,8 @@ module PullRequest = struct
type contribution = { occurredAt : string; pullRequestReview : t }
[@@deriving yojson]

type contributions = { nodes : contribution list } [@@deriving yojson]
type contributions = { nodes : contribution option list }
[@@deriving yojson]
end
end

@@ -71,7 +72,7 @@ type comment = {
}
[@@deriving yojson]

type comments = { nodes : comment list } [@@deriving yojson]
type comments = { nodes : comment option list } [@@deriving yojson]

type contributionsCollection = {
issueContributions : Issue.contributions;
3 changes: 2 additions & 1 deletion test/lib/test_contributions.ml
Original file line number Diff line number Diff line change
@@ -287,7 +287,8 @@ let activity_example ~user =
]
}
}
}
},
null
]
},
"pullRequestReviewContributions": {