-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
78 lines (59 loc) · 2.01 KB
/
main.go
File metadata and controls
78 lines (59 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"embed"
"flag"
"help-the-stars/internal"
"github.com/charmbracelet/log"
)
const defaultInterfalHours = 7
//go:embed migrations
var Migrations embed.FS
//go:embed templates
var templates embed.FS
//go:embed static/*
var staticFiles embed.FS
func main() {
flag.Usage = func() {
log.Info("Usage of Help the stars ⭐")
log.Info(" https://github.com/ad2ien/help-the-stars/")
log.Info("")
log.Info("Flags:")
flag.PrintDefaults()
}
debugFlag := flag.Bool("debug", false, "Display debug logs")
interval := flag.Int("interval", defaultInterfalHours, "Hours interval between github queries")
ghTokenFlag := flag.String("gh-token", "", "Github token")
labels := flag.String("labels",
"\"help-wanted\", \"help wanted\",\"junior friendly\",\"good first issue\"", "labels to look for")
dbFile := flag.String("db-file", "db/help-the-stars.db", "SQLite database file")
matrixServer := flag.String("matrix-server", "", "Matrix homeserver URL")
matrixUsername := flag.String("matrix-user", "", "Matrix user")
matrixPassword := flag.String("matrix-password", "", "Matrix password")
matrixRoomID := flag.String("matrix-room", "", "Matrix room ID")
flag.Parse()
serviceSetting := internal.NewSettingsService(
&internal.Settings{
GhToken: *ghTokenFlag,
Interval: *interval,
ConfiguredLabels: *labels,
DBFile: *dbFile,
MatrixServer: *matrixServer,
MatrixUsername: *matrixUsername,
MatrixPassword: *matrixPassword,
MatrixRoomID: *matrixRoomID,
})
serviceSetting.Print()
matrix := internal.CreateMatrixClient(context.Background(), serviceSetting)
db := internal.NewConnection(Migrations, serviceSetting)
defer db.Close()
controller := internal.CreateController(db.Connection, matrix, serviceSetting)
log.Info("Start worker...")
if *debugFlag {
log.SetLevel(log.DebugLevel)
}
log.Debug("Debugging on")
go controller.Worker()
server := internal.NewServer(controller, serviceSetting)
server.Start(&templates, &staticFiles)
}