-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.art
83 lines (68 loc) · 2.26 KB
/
main.art
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;========================================
; GitHub API
; Package for Arturo
;
; (c) 2023 Dr.Kameleon
; aka Yanis Zafirópulos
;========================================
; MIT License
;========================================
define :githubApi [apiKey][
;---------------------------
; Initialization
;---------------------------
init: [
this\apiHeaders: (null? this\apiKey)?
-> #[]
-> #[
"Accept": "application/vnd.github+json"
"Authorization": ~{Bearer |this\apiKey|}
"X-GitHub-Api-Version": "2022-11-28"
]
this\UseGhTool?: false
]
;---------------------------
; Private methods
;---------------------------
processRequest: function [req][
(this\UseGhTool?)?[
got: execute ~{!sh
gh api -H "Accept: |this\accepting|" -H "X-GitHub-Api-Version: |this\apiVersion|" /|req|
}
return read.json got
][
got: request.get.headers: this\apiHeaders ~{https://api.github.com/|req|} ø
return read.json got\body
]
]
;---------------------------
; Public methods
;---------------------------
getRepo: function [owner, repo][
;; description: « initiate a new graph environment with given name and body
;; returns: :block
return this\processRequest ~{repos/|owner|/|repo|}
]
getRepoContributors: function [owner, repo][
return this\processRequest ~{repos/|owner|/|repo|/contributors}
]
getRepoLanguages: function [owner, repo][
return this\processRequest ~{repos/|owner|/|repo|/languages}
]
getRepoTags: function [owner, repo][
return this\processRequest ~{repos/|owner|/|repo|/tags}
]
getRepoTopics: function [owner, repo][
return this\processRequest ~{repos/|owner|/|repo|/topics}
]
getUserRepos: function [username][
return this\processRequest ~{users/|username|/repos}
]
]
zzz: #[
getRepo: function [owner :string :literal, repo :string :literal][
;; description: « initiate a new graph environment with given name and body
;; returns: :block
return this\processRequest ~{repos/|owner|/|repo|}
]
]