Skip to content

Commit

Permalink
Filter out null elements that are sometimes in the nodes list (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot authored Apr 4, 2024
1 parent c3865ad commit 7cd1725
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
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 (#39, @gpetiot)

## 2.0.0

### Fixed
Expand Down
20 changes: 14 additions & 6 deletions lib/contributions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 =
Expand Down
13 changes: 7 additions & 6 deletions lib/contributions_json_response.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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 = {
Expand All @@ -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

Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion test/lib/test_contributions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ let activity_example ~user =
]
}
}
}
},
null
]
},
"pullRequestReviewContributions": {
Expand Down

0 comments on commit 7cd1725

Please sign in to comment.