summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/stanuki/main.go21
-rw-r--r--go.mod4
-rw-r--r--go.sum10
-rw-r--r--test/data/issues.json0
4 files changed, 29 insertions, 6 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)
+ }
}
}
diff --git a/go.mod b/go.mod
index 324b8b6..44e95a7 100644
--- a/go.mod
+++ b/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
diff --git a/go.sum b/go.sum
index 73c19f3..fedec6e 100644
--- a/go.sum
+++ b/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=
diff --git a/test/data/issues.json b/test/data/issues.json
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/data/issues.json