diff options
| author | mo khan <mo@mokhan.ca> | 2024-06-05 17:16:17 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2024-06-05 17:16:17 -0600 |
| commit | 5779ea0f400b7e8df223fe320ab07727227a2f3c (patch) | |
| tree | c29c4ba835a6149f1709a00492062e10483852c5 | |
| parent | 8f77a3bbcd298e3839e8276276ee4bcd2a826c3b (diff) | |
Save issues to yaml file
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | go.mod | 3 | ||||
| -rw-r--r-- | go.sum | 6 | ||||
| -rw-r--r-- | pkg/db/client.go | 24 | ||||
| -rw-r--r-- | pkg/gitlab/issue.go | 5 |
5 files changed, 33 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2de89b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/db @@ -5,12 +5,13 @@ go 1.22 require ( github.com/magefile/mage v1.15.0 github.com/stretchr/testify v1.8.0 - github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1 + github.com/xlgmokha/x v0.0.0-20240605230110-5cbcac4d8ff8 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/jsonapi v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) @@ -12,10 +12,12 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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= +github.com/xlgmokha/x v0.0.0-20240605230110-5cbcac4d8ff8 h1:Hmyf8pgNUs3l8TW0YdUarBVAU+hWX87efBukspg4nWc= +github.com/xlgmokha/x v0.0.0-20240605230110-5cbcac4d8ff8/go.mod h1:C9MUZ3A7PTPbrLNTvu2lKhpM0dFpPHt5yH8YGuYzmKQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 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/pkg/db/client.go b/pkg/db/client.go index a656505..4f43403 100644 --- a/pkg/db/client.go +++ b/pkg/db/client.go @@ -1,17 +1,26 @@ package db import ( + "bytes" + "fmt" + "io/ioutil" "os" "path/filepath" + "github.com/xlgmokha/x/pkg/env" + "github.com/xlgmokha/x/pkg/serde" "github.com/xlgmokha/x/pkg/x" ) -type Storage[T any] struct { +type Paramable interface { + ToParam() string +} + +type Storage[T Paramable] struct { dir string } -func New[T any](dir string) *Storage[T] { +func New[T Paramable](dir string) *Storage[T] { fullPath := x.Must(filepath.Abs(dir)) x.Check(os.MkdirAll(fullPath, 0700)) @@ -21,5 +30,14 @@ func New[T any](dir string) *Storage[T] { } func (db *Storage[T]) Save(item T) error { - return nil + w := new(bytes.Buffer) + x.Check(serde.To(w, item, serde.YAML)) + if env.Fetch("DUMP", "") != "" { + fmt.Println(w.String()) + } + return ioutil.WriteFile( + fmt.Sprintf("%v/%v.yaml", db.dir, item.ToParam()), + w.Bytes(), + 0700, + ) } diff --git a/pkg/gitlab/issue.go b/pkg/gitlab/issue.go index 30e95ab..8251915 100644 --- a/pkg/gitlab/issue.go +++ b/pkg/gitlab/issue.go @@ -1,6 +1,7 @@ package gitlab import ( + "fmt" "io" "time" @@ -27,6 +28,10 @@ type Issue struct { Labels []string `json:"labels"` } +func (issue *Issue) ToParam() string { + return fmt.Sprintf("%v", issue.ID) +} + func FromIssues(r io.Reader) ([]Issue, error) { return serde.From[[]Issue](r, serde.JSON) } |
