-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.go
75 lines (58 loc) · 1.71 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
69
70
71
72
73
74
75
package main
import (
"context"
"os"
"flag"
"fmt"
"github.com/google/go-github/github"
logging "github.com/op/go-logging"
"golang.org/x/oauth2"
)
var PRMirrorer = PRMirror{}
var CreateLabels = false
var DumpDB = false
func init() {
flag.BoolVar(&CreateLabels, "CreateLabels", false, "Create all of the labels")
flag.BoolVar(&DumpDB, "DumpDB", false, "Dump the database to stdout")
flag.Parse()
}
func main() {
backend := logging.NewLogBackend(os.Stderr, "", 0)
backendFormatter := logging.NewBackendFormatter(backend, format)
logging.SetBackend(backendFormatter)
Configuration := Config{}.Init()
if _, err := os.Stat(fmt.Sprintf("%s%s", Configuration.RepoPath, Configuration.ToolPath)); os.IsNotExist(err) {
log.Errorf("Could not find the shell script located at %s%s\n", Configuration.RepoPath, Configuration.ToolPath)
return
}
Database := NewDatabase()
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: Configuration.GitHubToken},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
client.UserAgent = "HippieStation/PRMirror"
PRMirrorer = PRMirror{
GitHubClient: client,
Context: &ctx,
Configuration: &Configuration,
Database: Database,
GitLock: &SpinLock{},
}
if CreateLabels {
PRMirrorer.CreateLabel("Upstream PR Open", "28a745")
PRMirrorer.CreateLabel("Upstream PR Closed", "cb2431")
PRMirrorer.CreateLabel("Upstream PR Merged", "6f42c1")
} else if DumpDB {
PRMirrorer.Database.DumpDB()
}
if Configuration.UseWebhook {
log.Info("Using the webhook listener\n")
PRMirrorer.RunWebhookListener()
} else {
log.Info("Using the event scraper\n")
PRMirrorer.RunEventScraper()
}
defer Database.Close()
}