Skip to content

Commit 97b4dd8

Browse files
author
Guillaume Petiot
committed
Filter out null elements that are sometimes in the nodes list
1 parent c3865ad commit 97b4dd8

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

Diff for: CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## unreleased
2+
3+
### Fixed
4+
5+
- Filter out null elements that are sometimes in the nodes list (#<PR_NUMBER>, @gpetiot)
6+
17
## 2.0.0
28

39
### Fixed

Diff for: lib/contributions.ml

+14-6
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ type item = {
9898

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

101-
let read_issues =
101+
let filter_null_nodes l = List.filter_map (fun x -> x) l
102+
103+
let read_issues l =
102104
List.map (fun (c : Json.Issue.contribution) ->
103105
let date = c.occurredAt in
104106
let url = c.issue.url in
105107
let title = c.issue.title in
106108
let body = c.issue.body in
107109
let repo = c.issue.repository.nameWithOwner in
108110
{ kind = `Issue; date; url; title; body; repo })
111+
@@ filter_null_nodes l
109112

110-
let read_issue_comments =
113+
let read_issue_comments l =
111114
List.map (fun (c : Json.comment) ->
112115
let date = c.publishedAt in
113116
let url = c.url in
@@ -118,8 +121,9 @@ let read_issue_comments =
118121
let body = c.body in
119122
let repo = c.repository.nameWithOwner in
120123
{ kind = `Comment kind; date; url; title; body; repo })
124+
@@ filter_null_nodes l
121125

122-
let read_prs ~username =
126+
let read_prs ~username l =
123127
List.fold_left
124128
(fun acc (c : Json.PullRequest.contribution) ->
125129
let date = c.occurredAt in
@@ -137,12 +141,14 @@ let read_prs ~username =
137141
if String.equal login username then
138142
{ kind = `Merge; date; url; title; body = ""; repo } :: acc
139143
else acc)
140-
acc timeline_items
144+
acc
145+
@@ filter_null_nodes timeline_items
141146
in
142147
acc)
143148
[]
149+
@@ filter_null_nodes l
144150

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

155-
let read_repos =
162+
let read_repos l =
156163
List.map (fun (c : Json.Repository.contribution) ->
157164
let date = c.occurredAt in
158165
let url = c.repository.url in
159166
let repo = c.repository.nameWithOwner in
160167
let title = "Created new repository" in
161168
{ kind = `New_repo; date; url; title; body = ""; repo })
169+
@@ filter_null_nodes l
162170

163171
let of_json ~period:(from, to_) ~user json =
164172
let* json =

Diff for: lib/contributions_json_response.ml

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Repository = struct
77
type contribution = { occurredAt : string; repository : t }
88
[@@deriving yojson]
99

10-
type contributions = { nodes : contribution list } [@@deriving yojson]
10+
type contributions = { nodes : contribution option list } [@@deriving yojson]
1111
end
1212

1313
module Issue = struct
@@ -21,13 +21,13 @@ module Issue = struct
2121

2222
type title = { title : string } [@@deriving yojson]
2323
type contribution = { occurredAt : string; issue : t } [@@deriving yojson]
24-
type contributions = { nodes : contribution list } [@@deriving yojson]
24+
type contributions = { nodes : contribution option list } [@@deriving yojson]
2525
end
2626

2727
module PullRequest = struct
2828
type actor = { login : string } [@@deriving yojson]
2929
type timelineItem = { createdAt : string; actor : actor } [@@deriving yojson]
30-
type timelineItems = { nodes : timelineItem list } [@@deriving yojson]
30+
type timelineItems = { nodes : timelineItem option list } [@@deriving yojson]
3131

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

46-
type contributions = { nodes : contribution list } [@@deriving yojson]
46+
type contributions = { nodes : contribution option list } [@@deriving yojson]
4747

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

61-
type contributions = { nodes : contribution list } [@@deriving yojson]
61+
type contributions = { nodes : contribution option list }
62+
[@@deriving yojson]
6263
end
6364
end
6465

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

74-
type comments = { nodes : comment list } [@@deriving yojson]
75+
type comments = { nodes : comment option list } [@@deriving yojson]
7576

7677
type contributionsCollection = {
7778
issueContributions : Issue.contributions;

Diff for: test/lib/test_contributions.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ let activity_example ~user =
287287
]
288288
}
289289
}
290-
}
290+
},
291+
null
291292
]
292293
},
293294
"pullRequestReviewContributions": {

0 commit comments

Comments
 (0)