From cf1abd6a058af31659fe8692ae771d0f5d63626b Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 18 May 2024 12:01:38 -0600 Subject: feat: parse issues from JSON response --- cmd/stanuki/main.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'cmd') 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) + } } } -- cgit v1.2.3