Created
May 25, 2020 10:52
-
-
Save Oldes/44d3a145c638e6bc61d06559ae8c9bbb to your computer and use it in GitHub Desktop.
Simple Github API context
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
Rebol [ | |
title: "Github API" | |
author: "Oldes" | |
license: MIT | |
] | |
My-GitHub-authorization: "token ..." ;<--- replace ... with your API token! | |
github: context [ | |
api.github: https://api.github.com/ | |
owner: repository: none | |
authorization: :My-GitHub-authorization | |
data: #() | |
response: none | |
use-repo: func[o r][ owner: o repository: r] | |
get: object [ | |
issues: func[][ | |
*do 'GET [%repos/ owner %/ repository %/issues] none | |
] | |
issue: func[number [integer!]][ | |
*do 'GET [%repos/ owner %/ repository %/issues/ number] none | |
] | |
issue-comments: func[ | |
{Gets all comments of an issue by its number} | |
number [integer!] | |
][ | |
*do 'GET [%repos/ owner %/ repository %/issues/ number %/comments] none | |
] | |
issue-labels: func[ | |
{Gets all labels of an issue by its number} | |
number [integer!] | |
][ | |
*do 'GET [%repos/ owner %/ repository %/issues/ number %/labels] none | |
] | |
current-user: does [*do 'GET %user none] | |
] | |
post: object [ | |
issue: func[ | |
data [map!] {title, body, labels etc..} | |
][ | |
unless block? data/labels [ data/labels: reduce [labels] ] | |
*do 'POST [%repos/ owner %/ repository %/issues] data | |
] | |
issue-comment: func[ | |
{Adds a comment to an issue by its number} | |
number [integer!] | |
body [string!] | |
][ | |
clear data | |
data/body: body | |
*do 'POST [%repos/ owner %/ repository %/issues/ number %/comments] data | |
] | |
issue-label: func[ | |
{Adds a label to an issue by its number} | |
number [integer!] | |
body [string! block!] | |
][ | |
clear data | |
append data/labels: clear [] body | |
*do 'POST [%repos/ owner %/ repository %/issues/ number %/labels] data | |
] | |
] | |
edit: object [ | |
issue: func[number [integer!] data [map!]][ | |
*do 'PATCH [%repos/ owner %/ repository %/issues/ number] data | |
] | |
] | |
*do: func[method [word!] path data [map! none!] /local url][ | |
url: join api.github path | |
;?? url | |
header: clear #() | |
header/Authorization: authorization | |
header/X-OAuth-Scopes: "repo" | |
header/Accept: "Accept: application/vnd.github.v3+json" | |
if map? data [header/Content-Type: "application/json"] | |
response: write url reduce [method to-block header to-json data] | |
try [response: load-json to string! response] | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment