Skip to content

Instantly share code, notes, and snippets.

@toomasv
Created June 29, 2017 08:58
Show Gist options
  • Save toomasv/d95f7c964bd25a9c85a5c9e6bded0379 to your computer and use it in GitHub Desktop.
Save toomasv/d95f7c964bd25a9c85a5c9e6bded0379 to your computer and use it in GitHub Desktop.
Find feats through github-api.v3
Red [
Title: {Find feats through github-api.v3}
Author: {Toomas Vooglaid}
Started: {2017-06-27}
Needs: {
* rebolek's http-tools (https://github.com/rebolek/red-tools/blob/master/http-tools.red)
* my regex~ (https://github.com/toomasv/regex/blob/master/regex~.red)
* my to-columns (https://gist.github.com/toomasv/464bd3bc775b75ce734bebf6d7aca190)
* github access token
}
]
do %../regex/regex~.red
do %http-tools.red
do %../utils/to-columns.red
github: context [
commit-page: https://github.com/red/red/commit/
github-api: https://api.github.com
commits-api: append copy github-api "/search/commits"
items: none
;get-endpoints: does [endpoints: json/decode read https://api.github.com]
;get-user: does [user: json/decode read to-url rejoin [endpoints/current_user_url "?access_token=" read %github.token]]
;get-gists: does [gists: json/decode read to-url rejoin [user/gists_url ~ "s|\{/gist_id}||" "?access_token=" read %github.token]]
;get-gist: func [gist-id][json/decode read to-url rejoin [user/gists_url ~ rejoin ["s|\{/gist_id}|" gist-id "|"] "?access_token=" read %github.token]]
comment {
set [resp-code headers response] write/info rejoin [
https://api.github.com/search/repositories?access_token= read %github.token
"&q=repo:red/red"] [
GET [Accept: "application/vnd.github.mercy-prview+json"]
]
]
probe json/decode response
}
set 'feats func [since /local resp][
set [resp-code headers response] write/info rejoin [
commits-api
"?access_token=" read %github.token
"&q=repo:red/red+FEAT+committer-date:>=" since "&sort=committer-date&order=desc"
][
GET [Accept: "application/vnd.github.cloak-preview+json"]
]
resp: json/decode response
items: select resp 'items
;count: select resp 'total_count
;incomplete?: select resp 'incomplete_results
n: 0
foreach commit items [
to-columns reduce [
commit/commit/committer/date ~ "s/T.+$//"
commit/committer/login
replace/all find/tail commit/commit/message "FEAT: " #"^/" "^/^-"
][a b c][
pad/left to-string n: n + 1 3 " " pad (a) 13 pad (b) 12 (c)
]
]
]
set 'see func [n][browse append copy commit-page select pick items n 'sha]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment