-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (51 loc) · 1.45 KB
/
main.go
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
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/andresterba/waybar-issues/config"
provider "github.com/andresterba/waybar-issues/provider"
)
type waybarResponse struct {
Text string `json:"text"`
Class string `json:"class"`
}
func checkError(err error) {
if err != nil {
log.Fatal(err)
os.Exit(1)
}
}
func main() {
configuration := config.Configuration{}
err := config.LoadConfigFile(config.GetConfigPath(), &configuration)
checkError(err)
var providers []provider.Provider
for _, configEntry := range configuration.Entries {
switch configEntry.Typ {
case "gitlab":
gitLabStatus := provider.NewGitLabStats(configEntry.Username, configEntry.Token, configEntry.URL, configEntry.DisplayName)
err := gitLabStatus.Process()
checkError(err)
providers = append(providers, gitLabStatus)
case "github":
gitHubStatus := provider.NewGitHubStats(configEntry.Username, configEntry.Token, configEntry.DisplayName)
err := gitHubStatus.Process()
checkError(err)
providers = append(providers, gitHubStatus)
default:
log.Fatal(fmt.Errorf("%s is not supported", configEntry.Typ))
}
}
var responseText string
for _, provider := range providers {
responseText += provider.GetFormatedOutput()
}
waybarResponse := waybarResponse{Text: responseText, Class: "issues"}
waybarResponseJSON, err := json.Marshal(waybarResponse)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(waybarResponseJSON))
}