-
Notifications
You must be signed in to change notification settings - Fork 0
/
thank.go
50 lines (43 loc) · 1.16 KB
/
thank.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
// Package thank thanks (usually by starring) repositories providing Go packages.
package thank
import (
"log"
"github.com/adamliesko/go-thanks/discover"
)
// Thanker abstracts away a mean of thanking for a Go OSS contribution, usually by starring a repository.
type Thanker interface {
Auth() error
CanThank(discover.Repository) bool
Thank(discover.Repository) error
}
// AuthThankers produces a list of verified and authenticated thankers.
func AuthThankers(ts []Thanker) ([]Thanker, error) {
authed := []Thanker{}
for _, t := range ts {
if err := t.Auth(); err != nil {
return nil, err
}
authed = append(authed, t)
}
return authed, nil
}
// Thank thanks to all the repositories and their owners using one of the passed in thankers, usually by starring the
// repositories.
func Thank(ts []Thanker, repos []discover.Repository) (int, error) {
var thankedCount int
for _, r := range repos {
for _, s := range ts {
if !s.CanThank(r) {
continue
}
err := s.Thank(r)
if err != nil {
return thankedCount, err
}
log.Printf("Thanked to repository %s by %s\n", r.URL, r.Owner)
thankedCount++
break
}
}
return thankedCount, nil
}