-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
(terminal_size (>= "0.2.0")) | ||
(tty (>= "0.0.2")) | ||
(uutf (>= "1.0.3")) | ||
yojson | ||
) | ||
(tags | ||
(tui cli git github))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
(library | ||
(name gh) | ||
(libraries ezcurl)) | ||
(libraries ezcurl yojson)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
module Client = Client | ||
module Issues = Issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
(** This module contains functions to query GitHub API *) | ||
|
||
(** Queries related to issues. *) | ||
module Issues = Issues | ||
|
||
(** Generic client to submit GraphQL queries to GitHub API. *) | ||
module Client = Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module Json = Yojson.Basic.Util | ||
|
||
type t = { | ||
number : int; | ||
title : string; | ||
author : string; | ||
} | ||
|
||
let mk_issues_query ~owner ~repo = | ||
Printf.sprintf | ||
{| | ||
query { | ||
repository(owner: "%s", name: "%s") { | ||
issues(first: 2, states: [OPEN], orderBy: {field: CREATED_AT, direction: DESC}) { | ||
nodes { | ||
number | ||
title | ||
author { | ||
login | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|} | ||
owner repo | ||
|
||
(* Parse single issue from JSON: | ||
{ | ||
"number": 18, | ||
"title": "GitHub TUI: Release Tracker for v1.0", | ||
"author": { | ||
"login": "chshersh" | ||
} | ||
} | ||
*) | ||
let parse_issue json = | ||
let number = Json.(member "number" json |> to_int) in | ||
let title = Json.(member "title" json |> to_string) in | ||
let author = Json.(member "author" json |> member "login" |> to_string) in | ||
{ number; title; author } | ||
|
||
(* Parse a list of 't' from the following JSON: | ||
{ | ||
"data": { | ||
"repository": { | ||
"issues": { | ||
"nodes": [ | ||
{ | ||
"number": 18, | ||
"title": "GitHub TUI: Release Tracker for v1.0", | ||
"author": { | ||
"login": "chshersh" | ||
} | ||
}, | ||
{ | ||
"number": 17, | ||
"title": "Refactor fs.ml: Separate concerns in go_down and go_up functions", | ||
"author": { | ||
"login": "chshersh" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
*) | ||
let parse_issues json = | ||
json | ||
|> Yojson.Basic.from_string | ||
|> Json.path [ "data"; "repository"; "issues"; "nodes" ] | ||
|> Option.value ~default:(`List []) | ||
|> Json.convert_each parse_issue | ||
|
||
let issues ~owner ~repo = | ||
mk_issues_query ~owner ~repo |> Client.query |> parse_issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type t = { | ||
number : int; | ||
title : string; | ||
author : string; | ||
} | ||
|
||
(** Query all open issues *) | ||
val issues : owner:string -> repo:string -> t list |