diff options
| author | mo khan <mo@mokhan.ca> | 2024-05-18 12:01:38 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2024-05-18 12:01:38 -0600 |
| commit | cf1abd6a058af31659fe8692ae771d0f5d63626b (patch) | |
| tree | fa59efc0db39f41eb5c8578b246f760c299239c4 /cmd/stanuki | |
| parent | a2f462e1289ba8ae63ea207483f254a43c82649c (diff) | |
feat: parse issues from JSON response
Diffstat (limited to 'cmd/stanuki')
| -rw-r--r-- | cmd/stanuki/main.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/cmd/stanuki/main.go b/cmd/stanuki/main.go index ea7c5d2..332c1ad 100644 --- a/cmd/stanuki/main.go +++ b/cmd/stanuki/main.go @@ -7,20 +7,31 @@ import ( "net/http" "github.com/xlgmokha/x/pkg/env" + "github.com/xlgmokha/x/pkg/serde" "github.com/xlgmokha/x/pkg/x" ) +type Issue struct { + ID int `json:"id"` + IID int `json:"iid"` + ProjectID int `json:"project_id"` + Title string `json:"title"` + Description string `json:"description"` +} + func main() { token := env.Fetch("GITLAB_TOKEN", "") - url := "https://gitlab.com/api/v4/groups/4/issues" + url := "https://gitlab.com/api/v4/groups/9970/issues" client := http.Client{} request := x.Must(http.NewRequestWithContext(context.TODO(), "GET", url, nil)) request.Header.Add("Authorization", fmt.Sprintf("Bearer %v", token)) response := x.Must(client.Do(request)) - - if response.StatusCode == http.StatusOK { - } else { - fmt.Println(response.Status) + if env.Fetch("DUMP", "") != "" { fmt.Println(string(x.Must(io.ReadAll(response.Body)))) + } else { + issues := x.Must(serde.From[[]Issue](response.Body, serde.JSON)) + for _, issue := range issues { + fmt.Printf("%v: %v\n", issue.ID, issue.Title) + } } } |
