-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (64 loc) · 1.76 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 (
"errors"
"flag"
"fmt"
"log"
"os"
"time"
"github.com/adamliesko/go-thanks/discover"
"github.com/adamliesko/go-thanks/thank"
"github.com/adamliesko/go-thanks/thank/github"
"github.com/adamliesko/go-thanks/thank/gitlab"
)
var (
githubToken = flag.String("github-token", os.Getenv("GITHUB_TOKEN"), "Github API token. Defaults to env variable GITHUB_TOKEN.")
gitlabToken = flag.String("gitlab-token", os.Getenv("GITLAB_TOKEN"), "Gitlab API token. Defaults to env variable GITLAB_TOKEN.")
projectPath = flag.String("project-path", ".", "Path to Go project.")
)
func thankGiants(thankers []thank.Thanker, path string) error {
startedAt := time.Now()
log.Println("==== Discovering ====")
repos, err := discover.Repositories(path)
if err != nil {
return fmt.Errorf("error getting thankable repositories: %v", err)
}
log.Printf("Discovered %d repositories\n", len(repos))
if len(repos) == 0 {
return nil
}
log.Println("====== Thanking =====")
ts, err := thank.AuthThankers(thankers)
if err != nil {
return fmt.Errorf("error authenticating available thankers: %v", err)
}
if len(ts) == 0 {
return errors.New("none authenticated thankers found")
}
thanked, err := thank.Thank(ts, repos)
if err != nil {
return fmt.Errorf("error thanking: %v", err)
}
log.Println("======== Done =======")
took := time.Since(startedAt)
log.Printf("Thanked to %d repositories 🙏! (took %v)\n", thanked, took)
return nil
}
func run() error {
var ts []thank.Thanker
if *githubToken != "" {
gt := github.New(*githubToken)
ts = append(ts, gt)
}
if *gitlabToken != "" {
gt := gitlab.New(*gitlabToken)
ts = append(ts, gt)
}
return thankGiants(ts, *projectPath)
}
func main() {
flag.Parse()
if err := run(); err != nil {
log.Fatal(err)
}
}