blob: 783f76802c3cc02fc62c0d978d864055530cfde3 (
plain) (
blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/usr/bin/env amm
import ammonite.ops._
@main
def shorten(longUrl: String) = {
println("shorten longUrl " + longUrl)
val shortUrl = requests.post(
"https://git.io",
data = Seq("url" -> longUrl),
).headers("location").head
println("shorten shortUrl " + shortUrl)
shortUrl
}
@main
def apply(uploadedFile: Path,
tagName: String,
uploadName: String,
authKey: String): String = {
val body = requests.get(
s"https://api.github.com/repos/lihaoyi/cask/releases/tags/$tagName",
headers = Seq("Authorization" -> s"token $authKey")
).text
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 = requests.post(
uploadUrl,
data = read.bytes! uploadedFile,
headers = Seq(
"Content-Type" -> "application/octet-stream",
"Authorization" -> s"token $authKey"
),
connectTimeout = 5000, readTimeout = 60000
)
println(res.text)
val longUrl = ujson.read(res.text)("browser_download_url").str.toString
println("Long Url " + longUrl)
val shortUrl = shorten(longUrl)
println("Short Url " + shortUrl)
shortUrl
}
|