Commit cf1abd6
Changed files (4)
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)
+ }
}
}
test/data/issues.json
go.mod
@@ -2,4 +2,6 @@ module gitlab.com/mokhax/stanuki
go 1.22
-require github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1 // indirect
+require github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1
+
+require github.com/google/jsonapi v1.0.0 // indirect
go.sum
@@ -1,2 +1,12 @@
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/google/jsonapi v1.0.0 h1:qIGgO5Smu3yJmSs+QlvhQnrscdZfFhiV6S8ryJAglqU=
+github.com/google/jsonapi v1.0.0/go.mod h1:YYHiRPJT8ARXGER8In9VuLv4qvLfDmA9ULQqptbLE4s=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
+github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1 h1:MIqcDqEAcr16QUq/kFJC3xbYoaAjjsxYEJLGtol2U58=
github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1/go.mod h1:Hf/0a9FveTBuVKvZ+Emmw6BlJyLGlhgjQwa4dFXp48s=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=