all repos — min @ 94421c582287baafa59d63404e1c5b3d989b52d6

A small but practical concatenative programming language.

Implemented github asset management.
h3rald h3rald@h3rald.com
Sun, 06 Dec 2020 23:01:40 +0100
commit

94421c582287baafa59d63404e1c5b3d989b52d6

parent

a78d9cb90091d81450cbf3e85f42bd8e5ed7ae63

2 files changed, 41 insertions(+), 15 deletions(-)

jump to
M lib/min_http.nimlib/min_http.nim

@@ -50,7 +50,10 @@ var res = newDict(i.scope)

res = i.dset(res, "version", resp.version.newVal) res = i.dset(res, "status", resp.status[0..2].parseInt.newVal) res = i.dset(res, "headers", i.newVal(resp.headers)) - res = i.dset(res, "body", resp.body.newVal) + var b = "" + if resp.status != $Http204: + b = resp.body + res = i.dset(res, "body", b.newVal) i.push res def.symbol("get-content") do (i: In):
M tasks/github.mintasks/github.min

@@ -18,9 +18,9 @@ :headers

( response to-json "response.json" fwrite - response /body from-json :body response /status :status (status 300 >) ( + response /body from-json :body body /message :message status string @status "Error $#: $#" (status message) =% error status int exit

@@ -30,7 +30,8 @@ (

:data data /endpoint :endpoint "api" :subdomain - "https://api.github.com/repos/h3rald/min$#" (endpoint) =% :url + (data ?subdomain) (data /subdomain @subdomain) when + "https://$#.github.com/repos/h3rald/min$#" (subdomain endpoint) =% :url {} url %url data /method %method

@@ -39,13 +40,35 @@ (data /headers %headers)

(headers %headers) if (data ?body) (data /body %body) when - request :response + request :response response /status :status response /body :body - handle-errors - body from-json + handle-errors + (body length 0 >) (body from-json) ({}) if ) :gh-req +( + :data + data /id :id + {} + "/releases/$#/assets" (id) =% %endpoint + "GET" %method + gh-req +) :get-assets + +( + config get-assets =assets + config /id :id + assets (/id) map =assets-ids + assets-ids ( + :asset + {} + "/releases/assets/$#" (asset) =% %endpoint + "DELETE" %method + gh-req + ) foreach +) :delete-assets + ; Module symbols ( {}

@@ -67,27 +90,27 @@ gh-req /id string :id

"Draft release v$# ($#) updated successfully" (min-version id) =% notice ) %update ( - config /id :id - {} - "/releases/$#/assets" (id) =% %endpoint - "GET" %method - gh-req =assets + config get-assets =assets assets size :total - "There are $# assets in release $#" (total min-version) =% notice - assets ("- $#" swap cons % notice) foreach + "are" :verb + (total 1 ==) ("is" @verb) when + "There $# $# assets in release v$#" (verb total min-version) =% notice + assets (/name () cons "- $#" swap % notice) foreach assets ) %assets ( config /id :id - . ls ("\.zip$" match) filter + config delete-assets + . ls ("\.zip$" match) filter ( filename :file "Uploading: $#" (file) =% notice file fread :body headers "application/zip" %Content-Type :asset-headers {} - "/releases/$#/assets" (id) =% %endpoint + "/releases/$#/assets?name=$#" (id file) =% %endpoint asset-headers %headers + "uploads" %subdomain "POST" %method body %body gh-req