Skip to content

Commit b6c287e

Browse files
Alec CunninghamAlec Cunningham
authored andcommitted
chore: add additional logic
1 parent e09fd3b commit b6c287e

File tree

11 files changed

+194
-83
lines changed

11 files changed

+194
-83
lines changed

cmd/server/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/signal"
77
"syscall"
88

9+
"github.com/moosh3/github-actions-aggregator/pkg/github"
910
"github.com/mooshe3/github-actions-aggregator/pkg/api"
1011
"github.com/mooshe3/github-actions-aggregator/pkg/config"
1112
"github.com/mooshe3/github-actions-aggregator/pkg/db"
@@ -26,12 +27,21 @@ func main() {
2627
log.Fatalf("Failed to connect to database: %v", err)
2728
}
2829

30+
// Initialize GitHub client
31+
githubClient := github.NewClient(cfg.GitHub.AccessToken)
32+
33+
// Start the poller if enabled
34+
if cfg.EnablePolling {
35+
poller := github.NewPoller(database, githubClient, cfg.PollingInterval)
36+
go poller.Start()
37+
}
38+
2939
// Start the worker pool
3040
wp := worker.NewWorkerPool(database, 5) // Adjust the number of workers as needed
3141
wp.Start()
3242

3343
// Start the API server
34-
go api.StartServer(cfg, database)
44+
go api.StartServer(cfg, database, githubClient)
3545

3646
// Wait for interrupt signal to gracefully shut down the worker pool
3747
quit := make(chan os.Signal, 1)

configs/config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enable_polling: true
2+
polling_interval: 15m
3+
enable_webhooks: true
4+
5+
server:
6+
port: "8080"
7+
8+
log:
9+
level: "info"
10+
11+
github:
12+
client_id: "your_github_client_id"
13+
client_secret: "your_github_client_secret"
14+
access_token: "your_github_access_token"
15+
webhook_secret: "your_webhook_secret"

go.mod

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
module github.com/moosh3/github-actions-aggregator
1+
module github.com/mooshe3/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/moosh3/github-actions-aggregator v0.0.0-20241023163131-e09fd3b10193
9+
github.com/sirupsen/logrus v1.9.3
10+
github.com/spf13/viper v1.19.0
11+
github.com/stretchr/testify v1.9.0
12+
golang.org/x/oauth2 v0.23.0
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,11 @@ 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
71+
gorm.io/driver/postgres v1.5.9 // indirect
6272
)

go.sum

Lines changed: 28 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=
@@ -62,11 +80,15 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
6280
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
6381
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
6482
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
83+
github.com/moosh3/github-actions-aggregator v0.0.0-20241023163131-e09fd3b10193 h1:i13RmPt/rMcSoXtEvn4FVeE1PT99IM9E7o9BKnP36+Y=
84+
github.com/moosh3/github-actions-aggregator v0.0.0-20241023163131-e09fd3b10193/go.mod h1:Ktqf57eOHhEfrKpMTJ42kIbd7B1/KQ45C+XaFfoaZ6M=
6585
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
6686
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
6787
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6888
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
6989
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
90+
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
91+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
7092
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
7193
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
7294
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
@@ -119,6 +141,8 @@ golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
119141
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
120142
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
121143
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
144+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
145+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
122146
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
123147
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
124148
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -129,20 +153,22 @@ golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
129153
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
130154
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
131155
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=
134156
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
135157
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
136158
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
137159
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
138160
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
139161
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
140162
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
163+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
164+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
141165
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
142166
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
143167
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
144168
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
145169
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
170+
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
171+
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
146172
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
147173
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
148174
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=

pkg/api/router.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ import (
55
"github.com/moosh3/github-actions-aggregator/pkg/auth"
66
"github.com/moosh3/github-actions-aggregator/pkg/config"
77
"github.com/moosh3/github-actions-aggregator/pkg/github"
8+
"github.com/mooshe3/github-actions-aggregator/pkg/db"
89
)
910

10-
func StartServer(cfg *config.Config) {
11+
func StartServer(cfg *config.Config, db *db.Database, githubClient *github.Client) {
1112
r := gin.Default()
1213

1314
// Public routes
1415
r.GET("/login", auth.GitHubLogin)
1516
r.GET("/callback", auth.GitHubCallback)
1617

1718
// Webhook route (exclude middleware that could interfere)
18-
webhookHandler := github.NewWebhookHandler(db, cfg.GitHub.WebhookSecret)
19+
webhookHandler := github.NewWebhookHandler(db, githubClient, cfg.GitHub.WebhookSecret)
1920
r.POST("/webhook", webhookHandler.HandleWebhook)
2021

2122
// Protected routes

pkg/config/config.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,27 @@ import (
66
"github.com/spf13/viper"
77
)
88

9+
type GitHubConfig struct {
10+
ClientID string
11+
ClientSecret string
12+
AccessToken string
13+
WebhookSecret string
14+
}
15+
16+
type DatabaseConfig struct {
17+
Host string
18+
User string
19+
Password string
20+
DBName string
21+
Port string
22+
}
23+
924
type Config struct {
10-
ServerPort string
11-
LogLevel string
12-
// Add other configuration fields
25+
ServerPort string
26+
LogLevel string
27+
EnablePolling bool
28+
Database DatabaseConfig
29+
GitHub GitHubConfig
1330
}
1431

1532
func LoadConfig() *Config {
@@ -18,13 +35,25 @@ func LoadConfig() *Config {
1835
viper.AddConfigPath("configs/")
1936
viper.AutomaticEnv()
2037

38+
// Bind environment variables to specific keys
39+
viper.BindEnv("github.client_id", "GITHUB_CLIENT_ID")
40+
viper.BindEnv("github.client_secret", "GITHUB_CLIENT_SECRET")
41+
viper.BindEnv("github.access_token", "GITHUB_ACCESS_TOKEN")
42+
viper.BindEnv("github.webhook_secret", "GITHUB_WEBHOOK_SECRET")
43+
2144
if err := viper.ReadInConfig(); err != nil {
2245
log.Fatalf("Error reading config file: %v", err)
2346
}
2447

2548
return &Config{
2649
ServerPort: viper.GetString("server.port"),
2750
LogLevel: viper.GetString("log.level"),
28-
// Initialize other fields
51+
GitHub: GitHubConfig{
52+
ClientID: viper.GetString("github.client_id"),
53+
ClientSecret: viper.GetString("github.client_secret"),
54+
AccessToken: viper.GetString("github.access_token"),
55+
WebhookSecret: viper.GetString("github.webhook_secret"),
56+
},
57+
// Initialize other fields...
2958
}
3059
}

pkg/db/db.go

Lines changed: 18 additions & 0 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
)
@@ -14,6 +17,21 @@ type Database struct {
1417

1518
func InitDB(cfg *config.Config) (*gorm.DB, error) {
1619
// Database initialization logic
20+
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=UTC",
21+
cfg.Database.Host, cfg.Database.User, cfg.Database.Password, cfg.Database.DBName, cfg.Database.Port)
22+
23+
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
24+
if err != nil {
25+
return nil, fmt.Errorf("failed to connect to database: %w", err)
26+
}
27+
28+
// Auto-migrate the schema
29+
err = db.AutoMigrate(&models.Repository{}, &models.WorkflowRun{}, &models.Statistics{})
30+
if err != nil {
31+
return nil, fmt.Errorf("failed to auto-migrate database schema: %w", err)
32+
}
33+
34+
return db, nil
1735
}
1836

1937
func (db *Database) GetMonitoredRepositories() ([]models.Repository, error) {

pkg/github/client.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,51 @@
11
package github
22

3-
type GitHubClient interface {
4-
GetWorkflowRuns(repo string) ([]WorkflowRun, error)
3+
import (
4+
"context"
5+
6+
gh "github.com/google/go-github/v50/github"
7+
"golang.org/x/oauth2"
8+
)
9+
10+
type Client struct {
11+
ghClient *gh.Client
12+
ctx context.Context
13+
}
14+
15+
func NewClient(token string) *Client {
16+
ctx := context.Background()
17+
ts := oauth2.StaticTokenSource(
18+
&oauth2.Token{AccessToken: token},
19+
)
20+
tc := oauth2.NewClient(ctx, ts)
21+
client := gh.NewClient(tc)
22+
23+
return &Client{
24+
ghClient: client,
25+
ctx: ctx,
26+
}
27+
}
28+
29+
func (c *Client) ListWorkflows(owner, repo string) ([]*gh.Workflow, error) {
30+
workflows, _, err := c.ghClient.Actions.ListWorkflows(c.ctx, owner, repo, nil)
31+
if err != nil {
32+
return nil, err
33+
}
34+
return workflows.Workflows, nil
35+
}
36+
37+
func (c *Client) ListWorkflowRuns(owner, repo string, workflowID int64) ([]*gh.WorkflowRun, error) {
38+
runs, _, err := c.ghClient.Actions.ListWorkflowRunsByID(c.ctx, owner, repo, workflowID, nil)
39+
if err != nil {
40+
return nil, err
41+
}
42+
return runs.WorkflowRuns, nil
43+
}
44+
45+
func (c *Client) GetWorkflowRun(owner, repo string, runID int64) (*gh.WorkflowRun, error) {
46+
run, _, err := c.ghClient.Actions.GetWorkflowRunByID(c.ctx, owner, repo, runID)
47+
if err != nil {
48+
return nil, err
49+
}
50+
return run, nil
551
}

pkg/github/client_impl.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)