-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (47 loc) · 975 Bytes
/
main.go
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
57
58
59
60
61
62
63
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"net/http"
)
type Release struct {
Name string `json:"name"`
}
func main() {
org := flag.String("org", "", "github org")
repo := flag.String("repo", "", "github repo")
flag.Parse()
if len(*org) < 1 {
fmt.Println("missing required option: org")
return
}
if len(*repo) < 1 {
fmt.Println("missing required option: repo")
return
}
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases", *org, *repo)
response, err := http.Get(url)
if err != nil {
fmt.Println("error:", err)
return
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
fmt.Println("error:", err)
return
}
var releases []Release
err = json.Unmarshal(body, &releases)
if err != nil {
fmt.Println("error:", err)
return
}
count := len(releases)
for index := count - 1; index >= 0; index-- {
release := releases[index]
fmt.Println(release.Name[1:])
}
}