From 3dadfbdf338af0e72eefada7bbcb997b62a3798e Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 13 Aug 2018 01:22:04 +0800 Subject: cleanup root dir --- ci/upload.sc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ci/upload.sc (limited to 'ci/upload.sc') diff --git a/ci/upload.sc b/ci/upload.sc new file mode 100644 index 0000000..6c47295 --- /dev/null +++ b/ci/upload.sc @@ -0,0 +1,52 @@ +#!/usr/bin/env amm +import ammonite.ops._ +import scalaj.http._ + +@main +def shorten(longUrl: String) = { + println("shorten longUrl " + longUrl) + val shortUrl = Http("https://git.io") + .postForm(Seq("url" -> longUrl)) + .asString + .headers("Location") + .head + println("shorten shortUrl " + shortUrl) + shortUrl +} +@main +def apply(uploadedFile: Path, + tagName: String, + uploadName: String, + authKey: String): String = { + val body = Http("https://api.github.com/repos/lihaoyi/cask/releases/tags/" + tagName) + .header("Authorization", "token " + authKey) + .asString.body + + val parsed = ujson.read(body) + + println(body) + + val snapshotReleaseId = parsed("id").num.toInt + + + val uploadUrl = + s"https://uploads.github.com/repos/lihaoyi/cask/releases/" + + s"$snapshotReleaseId/assets?name=$uploadName" + + val res = Http(uploadUrl) + .header("Content-Type", "application/octet-stream") + .header("Authorization", "token " + authKey) + .timeout(connTimeoutMs = 5000, readTimeoutMs = 60000) + .postData(read.bytes! uploadedFile) + .asString + + println(res.body) + val longUrl = ujson.read(res.body)("browser_download_url").str.toString + + println("Long Url " + longUrl) + + val shortUrl = shorten(longUrl) + + println("Short Url " + shortUrl) + shortUrl +} -- cgit v1.2.3