all repos — min @ fd8841c40490084474af44b9be6283bf2fcf9719

A small but practical concatenative programming language.

The http module is no longer imported.
h3rald h3rald@h3rald.com
Sun, 29 Sep 2024 11:14:50 +0200
commit

fd8841c40490084474af44b9be6283bf2fcf9719

parent

e5baefa7107c10b1e70bf83d49539e19560dfffc

4 files changed, 9 insertions(+), 9 deletions(-)

jump to
M next-release.mdnext-release.md

@@ -56,6 +56,7 @@ - The **crypto** module is no longer imported.

- The **math** module is no longer imported. - **math** module: renamed **r2g** to **math.r2d** - The **net** module is no longer imported. +- The **http** module is no longer imported.
M prelude.minprelude.min

@@ -1,5 +1,4 @@

; Imports -'http import 'xml import ; Unseal prompt symbol 'prompt unseal-symbol
M tasks/github.mintasks/github.min

@@ -1,1 +1,1 @@

-#!/usr/bin/env min "_helpers" require :helpers 'helpers import "next-release.md" fs.read escape :release-body "tasks/data/draft-release.json" fs.read :draft-release-template config "version" dict.get :min-version env "github-token" dict.get :token draft-release-template ("version" min-version "body" release-body) =% :draft-release-body {} "application/vnd.github.v3+json" "Accept" dict.set "token $#" (token) =% "Authorization" dict.set :headers ( symbol handle-errors (dict :response ==>) ( response to-json "response.json" fs.write response "status" dict.get :status (status 300 >) ( response "body" dict.get from-json :body body "message" dict.get :message status string @status "Error $#: $#" (status message) =% io.error status int exit ) when ) ) :: ;; Handles HTTP errors. ( symbol gh-req (dict :data ==> dict|quot :result) ( data "endpoint" dict.get :endpoint "api" :subdomain (data 'subdomain dict.has?) (data "subdomain" dict.get @subdomain) when "https://$#.github.com/repos/h3rald/min$#" (subdomain endpoint) =% :url {} url "url" dict.set data "method" dict.get "method" dict.set (data 'headers dict.has?) (data "headers" dict.get "headers" dict.set) (headers "headers" dict.set) if (data 'body dict.has?) (data "body" dict.get "body" dict.set) when request :response response "status" dict.get :status response "body" dict.get :body response handle-errors (body length 0 >) (body from-json) ({}) if @result ) ) :: ;; Execute a request using the Github API. ( symbol get-assets (dict :data ==> quot :result) ( data "id" dict.get :id {} "/releases/$#/assets" (id) =% "endpoint" dict.set "GET" "method" dict.set gh-req @result ) ) :: ;; Retrieve the assets from an existing Github release. ( symbol delete-assets (dict :config ==>) ( config get-assets :assets config "id" dict.get :id assets ("id" dict.get) map :assets-ids assets-ids ( :asset {} "/releases/assets/$#" (asset) =% "endpoint" dict.set "DELETE" "method" dict.set gh-req stack.pop ) foreach ) ) :: ;; Delete all assets from an existing Github release. #|| Tasks ||# ( symbol draft (==>) ( {} "/releases" "endpoint" dict.set "POST" "method" dict.set draft-release-body "body" dict.set gh-req "id" dict.get string :id ;; Save Release ID to min.yml config id "id" dict.set to-yaml "min.yml" fs.write "Draft release v$# ($#) created successfully" (min-version id) =% io.notice! ) ) :: ;; Creates a new draft release on Github. ( symbol update (==>) ( config "id" dict.get :id {} "/releases/$#" (id) =% "endpoint" dict.set "PATCH" "method" dict.set draft-release-body "body" dict.set gh-req "id" dict.get string :id "Draft release v$# ($#) updated successfully" (min-version id) =% io.notice! ) ) :: ;; Updates the text of the current draft Github release. ( symbol assets (==>) ( config get-assets =assets assets size :total "are" :verb (total 1 ==) ("is" @verb) when "There $# $# assets in release v$#" (verb total min-version) =% io.notice! assets ("name" dict.get () stack.cons "- $#" stack.swap % io.notice!) foreach ) ) :: ;; Retrieve a list of all the assets of the current draft Github release. ( symbol upload (==>) ( config "id" dict.get :id config delete-assets sys.pwd sys.ls ("\\.zip$" match?) filter ( fs.filename :file "Uploading: $#" (file) =% io.notice! file fs.read :body headers "application/zip" "Content-Type" dict.set :asset-headers {} "/releases/$#/assets?name=$#" (id file) =% "endpoint" dict.set asset-headers "headers" dict.set "uploads" "subdomain" dict.set "POST" "method" dict.set body "body" dict.set gh-req stack.pop ) foreach ) ) :: ;; Uploads all assets to the current draft Github release, deleting any existing asset. +#!/usr/bin/env min "_helpers" require :helpers 'helpers import "next-release.md" fs.read escape :release-body "tasks/data/draft-release.json" fs.read :draft-release-template config "version" dict.get :min-version env "github-token" dict.get :token draft-release-template ("version" min-version "body" release-body) =% :draft-release-body {} "application/vnd.github.v3+json" "Accept" dict.set "token $#" (token) =% "Authorization" dict.set :headers ( symbol handle-errors (dict :response ==>) ( response to-json "response.json" fs.write response "status" dict.get :status (status 300 >) ( response "body" dict.get from-json :body body "message" dict.get :message status string @status "Error $#: $#" (status message) =% io.error status int exit ) when ) ) :: ;; Handles HTTP errors. ( symbol gh-req (dict :data ==> dict|quot :result) ( data "endpoint" dict.get :endpoint "api" :subdomain (data 'subdomain dict.has?) (data "subdomain" dict.get @subdomain) when "https://$#.github.com/repos/h3rald/min$#" (subdomain endpoint) =% :url {} url "url" dict.set data "method" dict.get "method" dict.set (data 'headers dict.has?) (data "headers" dict.get "headers" dict.set) (headers "headers" dict.set) if (data 'body dict.has?) (data "body" dict.get "body" dict.set) when http.request :response response "status" dict.get :status response "body" dict.get :body response handle-errors (body length 0 >) (body from-json) ({}) if @result ) ) :: ;; Execute a request using the Github API. ( symbol get-assets (dict :data ==> quot :result) ( data "id" dict.get :id {} "/releases/$#/assets" (id) =% "endpoint" dict.set "GET" "method" dict.set gh-req @result ) ) :: ;; Retrieve the assets from an existing Github release. ( symbol delete-assets (dict :config ==>) ( config get-assets :assets config "id" dict.get :id assets ("id" dict.get) map :assets-ids assets-ids ( :asset {} "/releases/assets/$#" (asset) =% "endpoint" dict.set "DELETE" "method" dict.set gh-req stack.pop ) foreach ) ) :: ;; Delete all assets from an existing Github release. #|| Tasks ||# ( symbol draft (==>) ( {} "/releases" "endpoint" dict.set "POST" "method" dict.set draft-release-body "body" dict.set gh-req "id" dict.get string :id ;; Save Release ID to min.yml config id "id" dict.set to-yaml "min.yml" fs.write "Draft release v$# ($#) created successfully" (min-version id) =% io.notice! ) ) :: ;; Creates a new draft release on Github. ( symbol update (==>) ( config "id" dict.get :id {} "/releases/$#" (id) =% "endpoint" dict.set "PATCH" "method" dict.set draft-release-body "body" dict.set gh-req "id" dict.get string :id "Draft release v$# ($#) updated successfully" (min-version id) =% io.notice! ) ) :: ;; Updates the text of the current draft Github release. ( symbol assets (==>) ( config get-assets =assets assets size :total "are" :verb (total 1 ==) ("is" @verb) when "There $# $# assets in release v$#" (verb total min-version) =% io.notice! assets ("name" dict.get () stack.cons "- $#" stack.swap % io.notice!) foreach ) ) :: ;; Retrieve a list of all the assets of the current draft Github release. ( symbol upload (==>) ( config "id" dict.get :id config delete-assets sys.pwd sys.ls ("\\.zip$" match?) filter ( fs.filename :file "Uploading: $#" (file) =% io.notice! file fs.read :body headers "application/zip" "Content-Type" dict.set :asset-headers {} "/releases/$#/assets?name=$#" (id file) =% "endpoint" dict.set asset-headers "headers" dict.set "uploads" "subdomain" dict.set "POST" "method" dict.set body "body" dict.set gh-req stack.pop ) foreach ) ) :: ;; Uploads all assets to the current draft Github release, deleting any existing asset.
M tests/http.mintests/http.min

@@ -6,9 +6,9 @@

"postman-echo.com" :host "https://$1" (host) => % :url - ("$1/get" (url) => % get-content from-json "headers" dict.get "user-agent" dict.get "min http-module/$1" (version) => % ==) test.assert + ("$1/get" (url) => % http.get-content from-json "headers" dict.get "user-agent" dict.get "min http-module/$1" (version) => % ==) test.assert - ("$1/get?test=Hello!" (url) => % "tests/test1.json" :file file download file fs.read from-json "args" dict.get "test" dict.get "Hello!" ==) test.assert + ("$1/get?test=Hello!" (url) => % "tests/test1.json" :file file http.download file fs.read from-json "args" dict.get "test" dict.get "Hello!" ==) test.assert "tests/test1.json" sys.rm (

@@ -16,7 +16,7 @@ {} (

("$1/get" (url) => % "url" dict.set) ("GET" "method" dict.set) ({"it-it" :Accept-Language} "headers" dict.set) - (request) + (http.request) ) tap "body" dict.get from-json "headers" dict.get "accept-language" dict.get "it-it" == ) test.assert

@@ -25,7 +25,7 @@ {} (

("$1/put" (url) => % "url" dict.set) ("PUT" "method" dict.set) ({} to-json "body" dict.set) - (request) + (http.request) ) tap "body" dict.get from-json "data" dict.get {} == ) test.assert

@@ -34,7 +34,7 @@ {} (

("$1/post" (url) => % "url" dict.set) ("POST" "method" dict.set) ({"post" :test} to-json "body" dict.set) - (request) + (http.request) ) tap "headers" dict.get "content-type" dict.get "^application/json" match? ) test.assert

@@ -43,7 +43,7 @@ {} (

("$1/patch" (url) => % "url" dict.set) ("PATCH" "method" dict.set) ({} to-json "body" dict.set) - (request) + (http.request) ) tap "body" dict.get from-json "data" dict.get {} == ) test.assert

@@ -52,7 +52,7 @@ (

{} ( ("$1/delete" (url) => % "url" dict.set) ("DELETE" "method" dict.set) - (request) + (http.request) ) tap "body" dict.get from-json "url" dict.get "https?:\\/\\/$1/delete" (host) => % match? ) test.assert