-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
92 lines (77 loc) · 2.28 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"flag"
"os"
"strings"
"github.com/bitrise-io/go-utils/log"
"github.com/lszucs/github-to-discourse/internal/github"
"github.com/lszucs/github-to-discourse/internal/steplib"
"github.com/lszucs/github-to-discourse/internal/runmode"
)
const (
defaultMode = "dry"
defaultRepoSrc = "cherry"
defaultOrgs = "bitrise-steplib,bitrise-io,bitrise-community"
)
var (
mode string
repoSrc string
orgs string
)
func init() {
flag.StringVar(&mode, "mode", defaultMode, "--mode=dry|live (dry: only prints what would happen, but modifies nothing)")
flag.StringVar(&repoSrc, "repo-src", defaultRepoSrc, "--repo-src=cherry|steplib (repo loader to use to process arguments)")
flag.StringVar(&orgs, "orgs", defaultOrgs, "--orgs=bitrise-steplib,bitrise-io (filters step repos to those owned by given orgs)")
}
func getRepoURLs(repoSrc string, srcStr string) ([]string, error) {
var repoURLs []string
var err error
switch repoSrc {
case "steplib":
fromOrgs := strings.Split(orgs, ",")
repoURLs, err = steplib.LoadRepos(srcStr, fromOrgs)
if err != nil {
return nil, fmt.Errorf("load repos from steplib: %s")
}
return repoURLs, nil
case "cherry":
return strings.Split(srcStr, ","), nil
default:
return nil, fmt.Errorf("error: not recognized repo source %s", repoSrc)
}
}
func main() {
flag.Parse()
if len(flag.Args()) == 0 {
log.Errorf("error: no repo source url specified")
os.Exit(1)
}
log.Infof("get repos")
repoURLs, err := getRepoURLs(repoSrc, flag.Args()[0])
if err != nil {
log.Errorf("error getting repos using mode %s and arg %s: %s", repoSrc, flag.Args()[0], err)
os.Exit(1)
}
log.Printf("loaded %d repos: %s", len(repoURLs), repoURLs)
log.Infof("get open issues")
issues := github.GetOpenIssues(repoURLs)
log.Printf("found %d open issues: %s", len(issues), github.GetHTMLURLs(issues))
var stats runmode.Stats
switch mode {
case "dry":
stats, err = runmode.DryRun(issues)
case "live":
stats, err = runmode.LiveRun(issues)
default:
log.Errorf("error: unkown run mode %s", mode)
os.Exit(1)
}
if err != nil {
log.Errorf("error: %s", err)
os.Exit(1)
}
log.Successf("success!")
log.Printf("run stats:")
log.Printf("open/pr/stale/migrated: %d/%d/%d/%d ", stats.Processed, stats.PullRequest, stats.Stale, stats.Active)
}