Skip to content

Commit

Permalink
Merge pull request #4 from rnitame/feature-get_daily-events
Browse files Browse the repository at this point in the history
コマンドを実行した日のイベントを取得できるようにする
  • Loading branch information
Ryo Nitami authored May 3, 2017
2 parents 596601a + 8fadeb0 commit 9723cd2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# github-daily-report
# github-daily-report


## Set personal token

```
$ cp token.txt.example token.txt
// rewrite token
$ vi token.txt
```
8 changes: 6 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ import:
- package: golang.org/x/oauth2
subpackages:
- '...'
- package: github.com/tidwall/gjson
- package: github.com/tidwall/match
22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (

"bufio"

"time"

"strings"

"github.com/google/go-github/github"
"github.com/tidwall/gjson"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -41,11 +46,22 @@ func main() {
tc := oauth2.NewClient(oauth2.NoContext, ts)

client := github.NewClient(tc)
repos, _, err := client.Repositories.List(oauth2.NoContext, "", nil)
options := github.ListOptions{Page: 1, PerPage: 50}
events, _, err := client.Activity.ListEventsPerformedByUser(oauth2.NoContext, "rnitame", false, &options)
if err != nil {
log.Fatal(err)
}

// 自分のリポジトリ一覧表示
fmt.Print(repos)
// コマンド叩いた日のイベントを表示する
jst, _ := time.LoadLocation("Asia/Tokyo")
today := time.Now()
const layout = "2006-01-02"
for _, value := range events {
// API から取ってきた CreatedAt の文字列に、コマンド叩いた日付が含まれていれば表示
if strings.Contains(value.CreatedAt.In(jst).String(), string(today.Format(layout))) {
json, _ := value.RawPayload.MarshalJSON()
payload := gjson.Get(string(json), "action")
fmt.Println(*value.Repo.Name, *value.Type, payload)
}
}
}
1 change: 1 addition & 0 deletions token.txt.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aljdflajdfalkjfalksdfjaslkfjaldkfj

0 comments on commit 9723cd2

Please sign in to comment.