-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.pony
65 lines (59 loc) · 1.89 KB
/
main.pony
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use "../../github_rest_api"
use "../../github_rest_api/request"
use "cli"
use "net"
actor Main
new create(env: Env) =>
try
// ----- CLI setup
let cs =
CommandSpec.leaf("get-issue-comments",
"Get all comments for an issue",
[
OptionSpec.string("owner", "Owner of the repository the issue is in")
OptionSpec.string("repo", "Name of the repository the issue is in")
OptionSpec.i64("issue", "Issue number to get comments for")
OptionSpec.string("token",
"GitHub personal access token"
where default' = "")
]
)? .> add_help()?
let cmd = match CommandParser(cs).parse(env.args, env.vars)
| let c: Command =>
c
| let ch: CommandHelp =>
ch.print_help(env.out)
return
| let se: SyntaxError =>
env.err.print(se.string())
env.exitcode(1)
return
end
let owner = cmd.option("owner").string()
let repo = cmd.option("repo").string()
let issue = cmd.option("issue").i64()
let token = cmd.option("token").string()
// ----- Get issue comments
let auth = TCPConnectAuth(env.root)
let creds = Credentials(auth, token)
let p = GetIssueComments(owner, repo, issue, creds)
p.next[None](PrintIssueComments~apply(env.out))
else
env.out.print("Something went wrong")
end
primitive PrintIssueComments
fun apply(out: OutStream, r: IssueCommentsOrError) =>
match r
| let comments: Array[IssueComment] val =>
for c in comments.values() do
out.print("Comment ==>")
out.print(c.body)
out.print(c.html_url)
out.print(c.issue_url)
end
| let e: RequestError =>
out.print("Unable to retrieve issue comments")
out.print(e.status.string())
out.print(e.response_body)
out.print(e.message)
end