-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.go
55 lines (48 loc) · 1.34 KB
/
github.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
package moul
import (
"github.com/SlyMarbo/rss"
"github.com/google/go-github/github"
"github.com/patrickmn/go-cache"
)
var githubFeed *rss.Feed
func init() {
RegisterAction("github-activity", GetGithubActivityAction)
RegisterAction("github-repos", GetGithubReposAction)
}
func GetGithubActivityAction(args []string) (interface{}, error) {
if activity, found := moulCache.Get("github-activity"); found {
return activity, nil
}
activity, err := GetGithubActivity()
if err != nil {
return nil, err
}
moulCache.Set("github-activity", activity, cache.DefaultExpiration)
return activity, nil
}
func GetGithubReposAction(args []string) (interface{}, error) {
if repos, found := moulCache.Get("github-repos"); found {
return repos, nil
}
repos, err := GetGithubRepos()
if err != nil {
return nil, err
}
moulCache.Set("github-repos", repos, cache.DefaultExpiration)
return repos, nil
}
func GetGithubActivity() (*rss.Feed, error) {
var err error
if githubFeed == nil {
githubFeed, err = rss.Fetch("https://github.com/moul.atom")
} else {
err = githubFeed.Update()
}
return githubFeed, err
}
func GetGithubRepos() (interface{}, error) {
client := github.NewClient(nil)
opt := &github.RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"}
repos, _, err := client.Repositories.List("moul", opt)
return repos, err
}