forked from com-lihaoyi/Ammonite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.sc
executable file
·39 lines (30 loc) · 986 Bytes
/
upload.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env amm
import ammonite.ops._
import scalaj.http._
def apply(tagName: String, uploadName: String, authKey: String): String = {
val parsed = upickle.json.read(
Http("https://api.github.com/repos/lihaoyi/Ammonite/releases").asString.body
)
val snapshotReleaseId =
parsed.arr
.find(_("tag_name").str == tagName)
.get("id")
.num.toInt
val uploadUrl =
s"https://uploads.github.com/repos/lihaoyi/Ammonite/releases/" +
s"$snapshotReleaseId/assets?name=$uploadName"
val res = Http(uploadUrl)
.header("Content-Type", "application/octet-stream")
.header("Authorization", "token " + authKey)
.postData(read! cwd/"favicon.png")
.asString
val longUrl = upickle.json.read(res.body)("browser_download_url").str
println("Long Url " + longUrl)
val shortUrl = Http("https://git.io")
.postForm(Seq("url" -> longUrl))
.asString
.headers("Location")
.head
println("Short Url " + shortUrl)
shortUrl
}