forked from com-lihaoyi/Ammonite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.sc
41 lines (32 loc) · 1.03 KB
/
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
40
41
#!/usr/bin/env amm
import ammonite.ops._
import scalaj.http._
@main
def apply(uploadedFile: Path,
tagName: String,
uploadName: String,
authKey: String): String = {
println("upload.apply")
println(uploadedFile)
println(tagName)
println(uploadName)
println(authKey)
val body = Http("https://api.github.com/repos/lihaoyi/Ammonite/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/Ammonite/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").toString
longUrl
}