diff --git a/lib/contributions.ml b/lib/contributions.ml index c9c631a..13d3dce 100644 --- a/lib/contributions.ml +++ b/lib/contributions.ml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lib/contributions_json_response.ml b/lib/contributions_json_response.ml index 9e6fb91..3da516a 100644 --- a/lib/contributions_json_response.ml +++ b/lib/contributions_json_response.ml @@ -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] @@ -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]