Skip to content

Commit

Permalink
Cleanup the types corresponding to the JSON response
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot committed Mar 19, 2024
1 parent 5eb0b61 commit 3aed1ec
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 83 deletions.
10 changes: 5 additions & 5 deletions lib/contributions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type item = {
type t = { username : string; activity : item list Repo_map.t }

let read_issues =
List.map (fun (c : Json.issueContribution) ->
List.map (fun (c : Json.Issue.contribution) ->
let date = c.occurredAt in
let url = c.issue.url in
let title = c.issue.title in
Expand All @@ -94,7 +94,7 @@ let read_issues =
{ kind = `Issue; date; url; title; body; repo })

let read_issue_comments =
List.map (fun (c : Json.issueComment) ->
List.map (fun (c : Json.Issue.comment) ->
let date = c.publishedAt in
let url = c.url in
let title = c.issue.title in
Expand All @@ -103,7 +103,7 @@ let read_issue_comments =
{ kind = `Issue_comment; date; url; title; body; repo })

let read_prs =
List.map (fun (c : Json.pullRequestContribution) ->
List.map (fun (c : Json.PullRequest.contribution) ->
let date = c.occurredAt in
let url = c.pullRequest.url in
let title = c.pullRequest.title in
Expand All @@ -112,7 +112,7 @@ let read_prs =
{ kind = `PR; date; url; title; body; repo })

let read_reviews =
List.map (fun (c : Json.pullRequestReviewContribution) ->
List.map (fun (c : Json.PullRequest.Review.contribution) ->
let date = c.occurredAt in
let state = c.pullRequestReview.state in
let url = c.pullRequestReview.url in
Expand All @@ -122,7 +122,7 @@ let read_reviews =
{ kind = `Review state; date; url; title; body; repo })

let read_repos =
List.map (fun (c : Json.repositoryContribution) ->
List.map (fun (c : Json.Repository.contribution) ->
let date = c.occurredAt in
let url = c.repository.url in
let repo = c.repository.nameWithOwner in
Expand Down
151 changes: 73 additions & 78 deletions lib/contributions_json_response.ml
Original file line number Diff line number Diff line change
@@ -1,91 +1,85 @@
open Ppx_yojson_conv_lib.Yojson_conv.Primitives

type repository_name = { nameWithOwner : string } [@@deriving yojson]
type repository = { url : string; nameWithOwner : string } [@@deriving yojson]

type issue = {
url : string;
title : string;
body : string;
repository : repository_name;
}
[@@deriving yojson]

type issueContribution = { occurredAt : string; issue : issue }
[@@deriving yojson]

type issueContributions = { nodes : issueContribution list } [@@deriving yojson]

type pullRequest = {
url : string;
title : string;
body : string;
repository : repository_name;
}
[@@deriving yojson]

type pullRequestContribution = {
occurredAt : string;
pullRequest : pullRequest;
}
[@@deriving yojson]

type pullRequestContributions = { nodes : pullRequestContribution list }
[@@deriving yojson]

type pullRequest_title = { title : string } [@@deriving yojson]

type pullRequestReview = {
url : string;
pullRequest : pullRequest_title;
body : string;
state : string;
repository : repository_name;
}
[@@deriving yojson]

type pullRequestReviewContribution = {
occurredAt : string;
pullRequestReview : pullRequestReview;
}
[@@deriving yojson]

type pullRequestReviewContributions = {
nodes : pullRequestReviewContribution list;
}
[@@deriving yojson]

type repositoryContribution = { occurredAt : string; repository : repository }
[@@deriving yojson]

type repositoryContributions = { nodes : repositoryContribution list }
[@@deriving yojson]
module Repository = struct
type t = { url : string; nameWithOwner : string } [@@deriving yojson]
type name = { nameWithOwner : string } [@@deriving yojson]

type contribution = { occurredAt : string; repository : t }
[@@deriving yojson]

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

module Issue = struct
type t = {
url : string;
title : string;
body : string;
repository : Repository.name;
}
[@@deriving yojson]

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
type t = {
url : string;
title : string;
body : string;
repository : Repository.name;
}
[@@deriving yojson]

type title = { title : string } [@@deriving yojson]

type contribution = { occurredAt : string; pullRequest : t }
[@@deriving yojson]

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

module Review = struct
type t = {
url : string;
pullRequest : title;
body : string;
state : string;
repository : Repository.name;
}
[@@deriving yojson]

type contribution = { occurredAt : string; pullRequestReview : t }
[@@deriving yojson]

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

type contributionsCollection = {
issueContributions : issueContributions;
pullRequestContributions : pullRequestContributions;
pullRequestReviewContributions : pullRequestReviewContributions;
repositoryContributions : repositoryContributions;
}
[@@deriving yojson]

type issue_title = { title : string } [@@deriving yojson]

type issueComment = {
url : string;
publishedAt : string;
issue : issue_title;
repository : repository_name;
body : string;
issueContributions : Issue.contributions;
pullRequestContributions : PullRequest.contributions;
pullRequestReviewContributions : PullRequest.Review.contributions;
repositoryContributions : Repository.contributions;
}
[@@deriving yojson]

type issueComments = { nodes : issueComment list } [@@deriving yojson]

type user_data = {
login : string;
contributionsCollection : contributionsCollection;
issueComments : issueComments;
issueComments : Issue.comments;
}
[@@deriving yojson]

Expand All @@ -94,5 +88,6 @@ type data = {
viewer : user_data option; [@yojson.option]
}
[@@deriving yojson]
(** The key is either [viewer] or [user] depending on the request but the value associated is the same. *)

type t = { data : data } [@@deriving yojson]

0 comments on commit 3aed1ec

Please sign in to comment.