Remove gh

This commit is contained in:
Elliot Glaysher 2018-12-10 15:52:16 -08:00
parent b00f78be28
commit 52fa131081
10 changed files with 0 additions and 760 deletions

View File

@ -1,329 +0,0 @@
:: This is a connector for the Github API v3.
::
:: You can interact with this in a few different ways:
::
:: - .^({type} %gx /=gh={/endpoint}) to read data or
:: .^(arch %gy /=gh={/endpoint}) to explore the possible
:: endpoints.
::
:: - subscribe to /listen/{owner}/{repo}/{events...} for
:: webhook-powered event notifications. For event list, see
:: https://developer.github.com/webhooks/.
::
:: This is written with the standard structure for api
:: connectors, as described in lib/connector.hoon.
::
/? 314
/- gh, plan-acct
/+ gh-parse, connector
::
::
=, html
=, eyre
=> |%
++ move (pair bone card)
++ card
$% {$diff sub-result}
{$them wire (unit hiss)}
{$hiss wire {~ ~} $httr {$hiss hiss}}
==
::
:: Types of results we produce to subscribers.
::
++ sub-result
$% {$arch arch}
{$gh-issue issue:gh}
{$gh-list-issues (list issue:gh)}
{$gh-issues issues:gh}
{$gh-issue-comment issue-comment:gh}
{$json json}
{$null ~}
==
::
:: Types of webhooks we expect.
::
++ hook-response
$% {$gh-issues issues:gh}
{$gh-issue-comment issue-comment:gh}
==
--
=+ connector=(connector move sub-result) :: Set up connector library
::
=, gall
|_ $: hid/bowl
hook/(map @t {id/@t listeners/(set bone)}) :: map events to listeners
==
:: ++ prep _`. :: Clear state when code changes
::
:: List of endpoints
::
++ places
|= wir/wire
^- (list place:connector)
=+ (helpers:connector ost.hid wir "https://api.github.com")
=> |% :: gh-specific helpers
++ read-sentinel
|=(pax/path [ost %diff %arch `0vsen.tinel ~])
::
++ sigh-list-issues-x
|= jon/json
%+ bind ((ar:jo issue:gh-parse) jon)
|= issues/(list issue:gh)
gh-list-issues+issues
::
++ sigh-list-issues-y
|= jon/json
%+ bind ((ar:jo issue:gh-parse) jon)
|= issues/(list issue:gh)
:- `(shax (jam issues))
%- malt ^- (list {@ta ~})
:- [%gh-list-issues ~]
(turn issues |=(issue:gh [(rsh 3 2 (scot %ui number)) ~]))
--
:~ ^- place :: /
:* guard=~
read-x=read-null
read-y=(read-static %issues ~)
sigh-x=sigh-strange
sigh-y=sigh-strange
==
^- place :: /issues
:* guard={$issues ~}
read-x=read-null
read-y=(read-static %mine %by-repo ~)
sigh-x=sigh-strange
sigh-y=sigh-strange
==
^- place :: /issues/mine
:* guard={$issues $mine ~}
read-x=(read-get /issues)
read-y=(read-static %gh-list-issues ~)
sigh-x=sigh-list-issues-x
sigh-y=sigh-list-issues-y
==
^- place :: /issues/mine/<mark>
:* guard={$issues $mine @t ~}
read-x=read-null
read-y=read-sentinel
sigh-x=sigh-list-issues-x
sigh-y=sigh-list-issues-y
==
^- place :: /issues/by-repo
:* guard={$issues $by-repo ~}
read-x=read-null
^= read-y
|= pax/path
=+ /(scot %p our.hid)/home/(scot %da now.hid)/web/plan
=+ .^({* acc/(map knot plan-acct)} %cx -)
::
((read-static usr:(~(got by acc) %github) ~) pax)
sigh-x=sigh-strange
sigh-y=sigh-strange
==
^- place :: /issues/by-repo/<user>
:* guard={$issues $by-repo @t ~}
read-x=read-null
read-y=|=(pax/path (get /users/[-.+>.pax]/repos))
sigh-x=sigh-strange
^= sigh-y
|= jon/json
%+ bind ((ar:jo repository:gh-parse) jon)
|= repos/(list repository:gh)
[~ (malt (turn repos |=(repository:gh [name ~])))]
==
^- place :: /issues/by-repo/<user>/<repo>
:* guard={$issues $by-repo @t @t ~}
read-x=|=(pax/path (get /repos/[-.+>.pax]/[-.+>+.pax]/issues))
read-y=|=(pax/path (get /repos/[-.+>.pax]/[-.+>+.pax]/issues))
sigh-x=sigh-list-issues-x
sigh-y=sigh-list-issues-y
==
^- place :: /issues/by-repo/<user>/<repo>/<number>
:* guard={$issues $by-repo @t @t @t ~}
^= read-x
|=(pax/path (get /repos/[-.+>.pax]/[-.+>+.pax]/issues/[-.+>+>.pax]))
::
^= read-y
|= pax/path
%. pax
?: ((sane %tas) -.+>+>.pax)
read-sentinel
(read-static %gh-issue ~)
::
^= sigh-x
|= jon/json
%+ bind (issue:gh-parse jon)
|= issue/issue:gh
gh-issue+issue
::
sigh-y=sigh-strange
==
^- place :: /issues/by-repo/<u>/<r>/<n>/<mark>
:* guard={$issues $by-repo @t @t @t @t ~}
read-x=read-null
read-y=read-sentinel
sigh-x=sigh-strange
sigh-y=sigh-strange
==
==
::
:: When a peek on a path blocks, ford turns it into a peer on
:: /scry/{care}/{path}. You can also just peer to this
:: directly.
::
:: We hand control to ++scry.
::
++ peer-scry
|= pax/path
^- {(list move) _+>.$}
?> ?=({care:clay *} pax)
:_ +>.$ :_ ~
(read:connector ost.hid (places %read pax) i.pax t.pax)
::
:: HTTP response. We make sure the response is good, then
:: produce the result (as JSON) to whoever sent the request.
::
++ sigh-httr
|= {way/wire res/httr}
^- {(list move) _+>.$}
?. ?=({$read care:clay @ *} way)
~& res=res
[~ +>.$]
=* style i.way
=* ren i.t.way
=* pax t.t.way
:_ +>.$ :_ ~
:+ ost.hid %diff
(sigh:connector (places ren style pax) ren pax res)
::
:: HTTP error. We just print it out, though maybe we should
:: also produce a result so that the request doesn't hang?
::
++ sigh-tang
|= {way/wire tan/tang}
^- {(list move) _+>.$}
%- (slog >%gh-sigh-tang< tan)
[[ost.hid %diff null+~]~ +>.$]
::
:: We can't actually give the response to pretty much anything
:: without blocking, so we just block unconditionally.
::
++ peek
|= {ren/@tas tyl/path}
^- (unit (unit (pair mark *)))
~ ::``noun/[ren tyl]
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Webhook-powered event streams (/listen) ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: To listen to a webhook-powered stream of events, subscribe
:: to /listen/<user>/<repo>/<events...>
::
:: We hand control to ++listen.
::
++ peer-listen
|= pax/path
^- {(list move) _+>.$}
?. ?=({@ @ *} pax)
~& [%bad-listen-path pax]
[~ +>.$]
(listen pax)
::
:: This core handles event subscription requests by starting or
:: updating the webhook flow for each event.
::
++ listen
|= pax/path
=| mow/(list move)
=< abet:listen
|%
++ abet :: Resolve core.
^- {(list move) _+>.$}
[(flop mow) +>.$]
::
++ send-hiss :: Send a hiss
|= hiz/hiss
^+ +>
=+ wir=`wire`[%x %listen pax]
+>.$(mow [[ost.hid %hiss wir `~ %httr [%hiss hiz]] mow])
::
:: Create or update a webhook to listen for a set of events.
::
++ listen
^+ .
=+ pax=pax :: TMI-proofing
?> ?=({@ @ *} pax)
=+ events=t.t.pax
|- ^+ +>+.$
?~ events
+>+.$
?: (~(has by hook) i.events)
$(+>+ (update-hook i.events), events t.events)
$(+>+ (create-hook i.events), events t.events)
::
:: Set up a webhook.
::
++ create-hook
|= event/@t
^+ +>
?> ?=({@ @ *} pax)
=+ clean-event=`tape`(turn (trip event) |=(a/@tD ?:(=('_' a) '-' a)))
=. hook
%+ ~(put by hook) (crip clean-event)
=+ %+ fall
(~(get by hook) (crip clean-event))
*{id/@t listeners/(set bone)}
[id (~(put in listeners) ost.hid)]
%- send-hiss
:* %+ scan
=+ [(trip i.pax) (trip i.t.pax)]
"https://api.github.com/repos/{-<}/{->}/hooks"
auri:de-purl
%post ~ ~
%- as-octt:mimes %- en-json %- pairs:enjs:format :~
name+s+%web
active+b+&
events+a+~[s+event] ::(turn `(list ,@t)`t.t.pax |=(a=@t s/a))
:- %config
%- pairs:enjs:format :~
=+ =+ clean-event
"http://107.170.195.5:8443/~/to/gh/gh-{-}.json?anon&wire=/"
[%url s+(crip -)]
[%'content_type' s+%json]
==
==
==
::
:: Add current bone to the list of subscribers for this event.
::
++ update-hook
|= event/@t
^+ +>
=+ hok=(~(got by hook) event)
%_ +>.$
hook
%+ ~(put by hook) event
hok(listeners (~(put in listeners.hok) ost.hid))
==
--
::
:: Pokes that aren't caught in more specific arms are handled
:: here. These should be only from webhooks firing, so if we
:: get any mark that we shouldn't get from a webhook, we reject
:: it. Otherwise, we spam out the event to everyone who's
:: listening for that event.
::
++ poke
|= response/hook-response
^- {(list move) _+>.$}
=+ hook-data=(~(get by hook) (rsh 3 3 -.response))
?~ hook-data
~& [%strange-hook hook response]
[~ +>.$]
:: ~& response=response
:_ +>.$
%+ turn ~(tap in listeners.u.hook-data)
|= ost/bone
[ost %diff response]
--

View File

@ -178,10 +178,6 @@
:- /gen/cosmetic "incomplete"
:- /gen/lust "incomplete"
:- /gen/scantastic "incomplete"
::
:- /app/gh "crashes with new type system"
:- /mar/gh/issue-comment "wants old 'speech:hall'"
:- /mar/gh/issues "wants old 'speech:hall'"
::
:- /lib/down-jet "depends on lib/down-jet/parse"
:- /mar/down "depends on lib/down-jet/parse"

View File

@ -1,10 +0,0 @@
/- gh
/+ gh-parse, httr-to-json
|_ commit/commit:gh
++ grab
|%
++ noun commit:gh
++ httr (cork httr-to-json json)
++ json commit:gh-parse
--
--

View File

@ -1,42 +0,0 @@
:: Converts the result of an 'issues' event into a issues:gh.
/- gh
/+ gh-parse, hall
|_ issue-comment/issue-comment:gh
++ grow
|%
++ hall-speeches
^- (list speech:hall)
:_ ~
=+ ^= txt
;: (cury cat 3)
'on issue #'
`@t`(rsh 3 2 (scot %ui number.issue.issue-comment))
': '
body.comment.issue-comment
==
:* %api %github
login.sender.issue-comment
(rash html-url.sender.issue-comment aurf:urlp)
txt
txt
(rash html-url.comment.issue-comment aurf:urlp)
%- jobe :~
repository+s+name.repository.issue-comment
number+(numb:enjs:format number.issue.issue-comment)
title+s+title.issue.issue-comment
==
==
--
++ grab
|%
++ json
=; jop |=(jon/^json `issue-comment:gh`(need (jop jon)))
%- ot:dejs-soft:format
:~ repository+repository:gh-parse
sender+user:gh-parse
action+so:dejs-soft:format
issue+issue:gh-parse
comment+comment:gh-parse
==
--
--

View File

@ -1,17 +0,0 @@
/- gh
/+ gh-parse, httr-to-json
=, mimes:html
|_ issue/issue:gh
++ grab
|%
++ noun issue:gh
++ httr (cork httr-to-json json)
++ json issue:gh-parse
--
++ grow
|%
++ json raw.issue
++ mime [/txt/plain (as-octs (crip <issue>))]
++ txt (print-issue:gh-parse issue)
--
--

View File

@ -1,139 +0,0 @@
:: Converts the result of an 'issues' event into a issues:gh.
/- gh
/+ gh-parse, hall
|_ issues/issues:gh
++ grow
|%
++ hall-speeches
^- (list speech:hall)
:_ ~
=+ ^= txt
?- -.action.issues
$assigned
;: (cury cat 3)
'assigned issue #'
(rsh 3 2 (scot %ui number.issue.issues))
' to '
login.assignee.action.issues
' ('
title.issue.issues
')'
==
::
$unassigned
;: (cury cat 3)
'unassigned issue #'
(rsh 3 2 (scot %ui number.issue.issues))
' from '
login.assignee.action.issues
' ('
title.issue.issues
')'
==
::
$labeled
;: (cury cat 3)
'labeled issue #'
(rsh 3 2 (scot %ui number.issue.issues))
' as '
name.label.action.issues
' ('
title.issue.issues
')'
==
::
$unlabeled
;: (cury cat 3)
'unlabeled issue #'
(rsh 3 2 (scot %ui number.issue.issues))
' as '
name.label.action.issues
' ('
title.issue.issues
')'
==
::
$opened
;: (cury cat 3)
'opened issue #'
(rsh 3 2 (scot %ui number.issue.issues))
': '
title.issue.issues
==
::
$closed
;: (cury cat 3)
'closed issue #'
(rsh 3 2 (scot %ui number.issue.issues))
': '
title.issue.issues
==
::
$reopened
;: (cury cat 3)
'reopened issue #'
(rsh 3 2 (scot %ui number.issue.issues))
': '
title.issue.issues
==
==
^- speech:hall
:* %api %github
login.sender.issues
(rash html-url.sender.issues aurf:urlp)
txt txt
(rash html-url.issue.issues aurf:urlp)
%- jobe
%+ welp
:~ repository+s+name.repository.issues
number+(jone number.issue.issues)
title+s+title.issue.issues
action+s+-.action.issues
==
?- -.action.issues
$assigned
:~ assignee+s+login.assignee.action.issues
assignee-url+s+url.assignee.action.issues
==
::
$unassigned
:~ assignee+s+login.assignee.action.issues
assignee-url+s+url.assignee.action.issues
==
::
$labeled
:~ label+s+name.label.action.issues
==
::
$unlabeled
:~ label+s+name.label.action.issues
==
::
$opened ~
$closed ~
$reopened ~
==
==
--
++ grab
|%
++ json
|= jon/^json
^- issues:gh
=+ top=(need ((om:dejs-soft:format some) jon))
:* (need (repository:gh-parse (~(got by top) %repository)))
(need (user:gh-parse (~(got by top) %sender)))
=+ action=(need (so:dejs-soft:format (~(got by top) %action)))
?+ action ~|([%bad-action action] !!)
$assigned [action (need (user:gh-parse (~(got by top) %assignee)))]
$unassigned [action (need (user:gh-parse (~(got by top) %assignee)))]
$labeled [action (need (label:gh-parse (~(got by top) %label)))]
$unlabeled [action (need (label:gh-parse (~(got by top) %label)))]
$opened [action ~]
$closed [action ~]
$reopened [action ~]
==
(need (issue:gh-parse (~(got by top) %issue)))
==
--
--

View File

@ -1,18 +0,0 @@
/- gh
/+ gh-parse
=, mimes:html
|_ issues/(list issue:gh)
++ grab
|%
++ noun (list issue:gh)
--
++ grow
|%
++ json [%a (turn issues |=(issue:gh raw))]
++ mime [/txt/plain (as-octs (crip <issues>))]
++ txt =- ?~ - - ->
%+ roll (turn issues print-issue:gh-parse)
|= {a/wain b/wain}
:(welp b ~['----------------------------------------'] a)
--
--

View File

@ -1,6 +0,0 @@
|_ {method/meth:eyre endpoint/(list @t) jon/json}
++ grab
|%
++ noun {method/meth:eyre endpoint/(list @t) jon/json}
--
--

View File

@ -1,10 +0,0 @@
/- gh
/+ gh-parse, httr-to-json
|_ repo/repository:gh
++ grab
|%
++ noun repository:gh
++ httr (cork httr-to-json json)
++ json repository:gh-parse
--
--

View File

@ -1,185 +0,0 @@
:: https://developer.github.com/v3/
::
:: These types correspond to the types that Github's API
:: produces, so please check Github's documentation for
:: details.
::
:: For parsing JSON into these types, check out the gh-parse
:: library.
::
|%
++ repository
$: id/id
name/@t
full-name/@t
owner/user
private/?
html-url/@t
description/@t
fork/?
url/@t
forks-url/@t
keys-url/@t
collaborators-url/@t
teams-url/@t
hooks-url/@t
issue-events-url/@t
events-url/@t
assignees-url/@t
branches-url/@t
tags-url/@t
blobs-url/@t
git-tags-url/@t
git-refs-url/@t
trees-url/@t
statuses-url/@t
languages-url/@t
stargazers-url/@t
contributors-url/@t
subscribers-url/@t
subscription-url/@t
commits-url/@t
git-commits-url/@t
comments-url/@t
issue-comment-url/@t
contents-url/@t
compare-url/@t
merges-url/@t
archive-url/@t
downloads-url/@t
issues-urls/@t
pulls-url/@t
milestones-url/@t
notifications-url/@t
labels-url/@t
releases-url/@t
created-at/time
updated-at/time
pushed-at/time
git-url/@t
ssh-url/@t
clone-url/@t
svn-url/@t
homepage/json
size/@ud
stargazers-count/@ud
watchers-count/@ud
language/json
has-issues/?
has-downloads/?
has-wiki/?
has-pages/?
forks-count/@ud
mirror-url/json
open-issues-count/@ud
forks/@ud
open-issues/@ud
watchers/@ud
default-branch/@t
==
++ commit
$: sha/@t
url/@t
author/author
committer/author
message/@t
tree/point
parents/(list point)
verification/verification
==
++ user
$: login/@t
id/id
avatar-url/@t
gravatar-id/@t
url/@t
html-url/@t
followers-url/@t
following-url/@t
gists-url/@t
starred-url/@t
subscriptions-url/@t
organizations-url/@t
repos-url/@t
events-url/@t
received-events/@t
type/@t
site-admin/?
==
++ issue
$: raw/json
url/@t
labels-url/@t
comments-url/@t
events-url/@t
html-url/@t
id/id
number/@ud
title/@t
user/user
labels/(list label)
state/@t
locked/?
assignee/(unit user)
milestone/json
comments/@ud
created-at/time
updated-at/time
closed-at/(unit time)
body/@t
==
++ author
$: date/@t
name/@t
email/@t
==
++ point
$: url/@t
sha/@t
==
++ verification
$: verified/?
reason/@t
signature/(unit @t)
payload/(unit @t)
==
++ label
$: url/@t
name/@t
color/@t
==
++ comment
$: url/@t
html-url/@t
issue-url/@t
id/id
user/user
created-at/time
updated-at/time
body/@t
==
++ id @t
++ time @t
++ issues
$: repository/repository
sender/user
$= action
$% {$assigned assignee/user}
{$unassigned assignee/user}
{$labeled label/label}
{$unlabeled label/label}
{$opened ~}
{$closed ~}
{$reopened ~}
==
issue/issue
==
++ issue-comment
$: repository/repository
sender/user
action/@t
issue/issue
comment/comment
==
++ ping {repo/json sender/json hok/(list @t) hook-id/@t zen/json}
--