Skip to content

Commit 4d73151

Browse files
Alec CunninghamAlec Cunningham
Alec Cunningham
authored and
Alec Cunningham
committed
fix: address all errors
1 parent f33b126 commit 4d73151

File tree

9 files changed

+198
-27
lines changed

9 files changed

+198
-27
lines changed

cmd/server/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/moosh3/github-actions-aggregator/pkg/db"
1111
"github.com/moosh3/github-actions-aggregator/pkg/github"
1212
"github.com/moosh3/github-actions-aggregator/pkg/logger"
13+
"github.com/moosh3/github-actions-aggregator/pkg/worker"
1314
)
1415

1516
func main() {
@@ -34,8 +35,10 @@ func main() {
3435
// Initialize GitHub client
3536
githubClient := github.NewClient(cfg.GitHub.AccessToken)
3637

38+
workerPool := worker.NewWorkerPool(database, cfg.WorkerPoolSize)
39+
3740
// Start the API server
38-
api.StartServer(cfg, database, githubClient)
41+
api.StartServer(cfg, database, githubClient, workerPool)
3942
}
4043

4144
func runMigrations() error {

go.mod

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ module github.com/moosh3/github-actions-aggregator
22

33
go 1.23.2
44

5+
require (
6+
github.com/gin-gonic/gin v1.10.0
7+
github.com/google/go-github/v50 v50.2.0
8+
github.com/sirupsen/logrus v1.9.3
9+
github.com/spf13/viper v1.19.0
10+
github.com/stretchr/testify v1.9.0
11+
golang.org/x/oauth2 v0.23.0
12+
gorm.io/driver/postgres v1.5.9
13+
gorm.io/gorm v1.25.12
14+
)
15+
516
require (
617
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
718
github.com/bytedance/sonic v1.11.6 // indirect
@@ -13,14 +24,16 @@ require (
1324
github.com/fsnotify/fsnotify v1.7.0 // indirect
1425
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
1526
github.com/gin-contrib/sse v0.1.0 // indirect
16-
github.com/gin-gonic/gin v1.10.0 // indirect
1727
github.com/go-playground/locales v0.14.1 // indirect
1828
github.com/go-playground/universal-translator v0.18.1 // indirect
1929
github.com/go-playground/validator/v10 v10.20.0 // indirect
2030
github.com/goccy/go-json v0.10.2 // indirect
21-
github.com/google/go-github/v50 v50.2.0 // indirect
2231
github.com/google/go-querystring v1.1.0 // indirect
2332
github.com/hashicorp/hcl v1.0.0 // indirect
33+
github.com/jackc/pgpassfile v1.0.0 // indirect
34+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
35+
github.com/jackc/pgx/v5 v5.5.5 // indirect
36+
github.com/jackc/puddle/v2 v2.2.1 // indirect
2437
github.com/jinzhu/inflection v1.0.0 // indirect
2538
github.com/jinzhu/now v1.1.5 // indirect
2639
github.com/json-iterator/go v1.1.12 // indirect
@@ -35,14 +48,11 @@ require (
3548
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3649
github.com/sagikazarmark/locafero v0.4.0 // indirect
3750
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
38-
github.com/sirupsen/logrus v1.9.3 // indirect
3951
github.com/sourcegraph/conc v0.3.0 // indirect
4052
github.com/spf13/afero v1.11.0 // indirect
4153
github.com/spf13/cast v1.6.0 // indirect
4254
github.com/spf13/pflag v1.0.5 // indirect
43-
github.com/spf13/viper v1.19.0 // indirect
4455
github.com/stretchr/objx v0.5.2 // indirect
45-
github.com/stretchr/testify v1.9.0 // indirect
4656
github.com/subosito/gotenv v1.6.0 // indirect
4757
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
4858
github.com/ugorji/go/codec v1.2.12 // indirect
@@ -52,11 +62,10 @@ require (
5262
golang.org/x/crypto v0.23.0 // indirect
5363
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
5464
golang.org/x/net v0.25.0 // indirect
55-
golang.org/x/oauth2 v0.23.0 // indirect
65+
golang.org/x/sync v0.8.0 // indirect
5666
golang.org/x/sys v0.20.0 // indirect
5767
golang.org/x/text v0.19.0 // indirect
5868
google.golang.org/protobuf v1.34.1 // indirect
5969
gopkg.in/ini.v1 v1.67.0 // indirect
6070
gopkg.in/yaml.v3 v3.0.1 // indirect
61-
gorm.io/gorm v1.25.12 // indirect
6271
)

go.sum

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
1515
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1616
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
1717
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
18+
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
19+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
1820
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1921
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
2022
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
@@ -23,6 +25,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
2325
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
2426
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
2527
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
28+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
29+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
2630
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
2731
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
2832
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
@@ -32,13 +36,23 @@ github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaC
3236
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
3337
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
3438
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
39+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
40+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3541
github.com/google/go-github/v50 v50.2.0 h1:j2FyongEHlO9nxXLc+LP3wuBSVU9mVxfpdYUexMpIfk=
3642
github.com/google/go-github/v50 v50.2.0/go.mod h1:VBY8FB6yPIjrtKhozXv4FQupxKLS6H4m6xFZlT43q8Q=
3743
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
3844
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
3945
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
4046
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
4147
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
48+
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
49+
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
50+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
51+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
52+
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
53+
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
54+
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
55+
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
4256
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
4357
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
4458
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -49,6 +63,10 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
4963
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
5064
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
5165
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
66+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
67+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
68+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
69+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
5270
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
5371
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
5472
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
@@ -67,6 +85,8 @@ github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h
6785
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6886
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
6987
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
88+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
89+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
7090
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
7191
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
7292
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
@@ -119,6 +139,8 @@ golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
119139
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
120140
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
121141
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
142+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
143+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
122144
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
123145
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
124146
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -129,20 +151,22 @@ golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
129151
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
130152
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
131153
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
132-
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
133-
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
134154
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
135155
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
136156
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
137157
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
138158
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
139159
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
140160
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
161+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
162+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
141163
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
142164
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
143165
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
144166
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
145167
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
168+
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
169+
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
146170
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
147171
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
148172
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=

pkg/config/config.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ type DatabaseConfig struct {
2121
}
2222

2323
type Config struct {
24-
ServerPort string
25-
LogLevel string
26-
GitHub GitHubConfig
27-
Database DatabaseConfig
24+
ServerPort string
25+
LogLevel string
26+
GitHub GitHubConfig
27+
Database DatabaseConfig
28+
WorkerPoolSize int
2829
}
2930

3031
func LoadConfig() *Config {
@@ -38,8 +39,9 @@ func LoadConfig() *Config {
3839
}
3940

4041
return &Config{
41-
ServerPort: viper.GetString("server.port"),
42-
LogLevel: viper.GetString("log.level"),
42+
ServerPort: viper.GetString("server.port"),
43+
LogLevel: viper.GetString("log.level"),
44+
WorkerPoolSize: viper.GetInt("worker.pool_size"),
4345
GitHub: GitHubConfig{
4446
ClientID: viper.GetString("github.client_id"),
4547
ClientSecret: viper.GetString("github.client_secret"),

pkg/db/db.go

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package db
22

33
import (
4+
"fmt"
5+
46
"github.com/google/go-github/v50/github"
57
"github.com/moosh3/github-actions-aggregator/pkg/config"
68
"github.com/moosh3/github-actions-aggregator/pkg/db/models"
9+
"gorm.io/driver/postgres"
710
"gorm.io/gorm"
811
"gorm.io/gorm/clause"
912
)
@@ -12,19 +15,62 @@ type Database struct {
1215
Conn *gorm.DB
1316
}
1417

15-
func InitDB(cfg *config.Config) (*gorm.DB, error) {
16-
// Database initialization logic
18+
func InitDB(cfg *config.Config) (*Database, error) {
19+
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=github_actions_aggregator sslmode=disable",
20+
cfg.Database.Host, cfg.Database.Port, cfg.Database.User, cfg.Database.Password)
21+
22+
conn, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
23+
if err != nil {
24+
return nil, fmt.Errorf("failed to connect to database: %w", err)
25+
}
26+
27+
// Auto-migrate the schema
28+
err = conn.AutoMigrate(&models.Repository{}, &models.WorkflowRun{}, &models.Statistics{})
29+
if err != nil {
30+
return nil, fmt.Errorf("failed to auto-migrate schema: %w", err)
31+
}
32+
33+
return &Database{Conn: conn}, nil
34+
}
35+
36+
func (db *Database) GetRepository() (models.Repository, error) {
37+
var repo models.Repository
38+
err := db.Conn.Find(&repo).Error
39+
return repo, err
1740
}
1841

19-
func (db *Database) GetMonitoredRepositories() ([]models.Repository, error) {
42+
func (db *Database) GetRepositories() ([]models.Repository, error) {
2043
var repos []models.Repository
2144
err := db.Conn.Where("monitor = ?", true).Find(&repos).Error
2245
return repos, err
2346
}
2447

48+
func (db *Database) SaveRepository(repo *models.Repository) error {
49+
repository := models.Repository{
50+
Name: repo.Name,
51+
Owner: repo.Owner,
52+
}
53+
return db.Conn.Create(repository).Error
54+
}
55+
56+
func (db *Database) DeleteRepository(id int) error {
57+
return db.Conn.Delete(&models.Repository{}, id).Error
58+
}
59+
60+
func (db *Database) GetWorkflowRun(id int) (*models.WorkflowRun, error) {
61+
var run models.WorkflowRun
62+
err := db.Conn.First(&run, id).Error
63+
return &run, err
64+
}
65+
66+
func (db *Database) GetWorkflowRuns(repoID int) ([]models.WorkflowRun, error) {
67+
var runs []models.WorkflowRun
68+
err := db.Conn.Where("repository_id = ?", repoID).Find(&runs).Error
69+
return runs, err
70+
}
71+
2572
func (db *Database) SaveWorkflowRun(run *github.WorkflowRun) error {
2673
workflowRun := models.WorkflowRun{
27-
ID: run.GetID(),
2874
WorkflowID: run.GetWorkflowID(),
2975
RepositoryID: run.GetRepository().GetID(),
3076
Status: run.GetStatus(),
@@ -33,7 +79,6 @@ func (db *Database) SaveWorkflowRun(run *github.WorkflowRun) error {
3379
Event: run.GetEvent(),
3480
CreatedAt: run.GetCreatedAt().Time,
3581
UpdatedAt: run.GetUpdatedAt().Time,
36-
// Add other fields as needed
3782
}
3883

3984
// Upsert operation
@@ -43,7 +88,46 @@ func (db *Database) SaveWorkflowRun(run *github.WorkflowRun) error {
4388
}).Create(&workflowRun).Error
4489
}
4590

91+
func (db *Database) DeleteWorkflowRun(id int) error {
92+
return db.Conn.Delete(&models.WorkflowRun{}, id).Error
93+
}
94+
95+
func (db *Database) GetWorkflow(id int) (*models.Workflow, error) {
96+
var workflow models.Workflow
97+
err := db.Conn.First(&workflow, id).Error
98+
return &workflow, err
99+
}
100+
101+
func (db *Database) GetWorkflows() ([]models.Workflow, error) {
102+
var workflows []models.Workflow
103+
err := db.Conn.Find(&workflows).Error
104+
return workflows, err
105+
}
106+
107+
func (db *Database) SaveWorkflow(workflow *models.Workflow) error {
108+
workflowModel := models.Workflow{
109+
Name: workflow.Name,
110+
}
111+
return db.Conn.Create(workflowModel).Error
112+
}
113+
114+
func (db *Database) DeleteWorkflow(id int) error {
115+
return db.Conn.Delete(&models.Workflow{}, id).Error
116+
}
117+
118+
func (db *Database) GetStatistics() ([]models.Statistics, error) {
119+
var stats []models.Statistics
120+
err := db.Conn.Find(&stats).Error
121+
return stats, err
122+
}
123+
46124
func (db *Database) SaveStatistics(stats *models.Statistics) error {
47-
// Upsert operation
48-
return db.Conn.Save(stats).Error
125+
workflowStatistics := models.Statistics{
126+
ID: stats.ID,
127+
}
128+
return db.Conn.Save(workflowStatistics).Error
129+
}
130+
131+
func (db *Database) DeleteStatistics(id int) error {
132+
return db.Conn.Delete(&models.Statistics{}, id).Error
49133
}

pkg/db/models/workflow_run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type WorkflowRun struct {
1616
Status string
1717
Conclusion string
1818
EventType string
19+
Event string
1920
URL string
2021
HTMLURL string
2122
JobsURL string

0 commit comments

Comments
 (0)