From d4dbd42c435f8c1484bdd612640cc8a2b0cb9d68 Mon Sep 17 00:00:00 2001 From: k-waragai Date: Fri, 30 Jun 2017 17:01:08 +0900 Subject: [PATCH 1/2] hogehoge --- ReviewComment.go | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ReviewComment.go diff --git a/ReviewComment.go b/ReviewComment.go new file mode 100644 index 0000000..1f3e388 --- /dev/null +++ b/ReviewComment.go @@ -0,0 +1,90 @@ +package main + +import ( + "bufio" + "encoding/json" + "fmt" + "net/http" + "os" + "strings" + "time" +) + +type Actor struct { + ID int + Login string + GravatarID string + URL string + AvatarURL string +} + +type Repo struct { + ID int + Name string + URL string `json:"url"` +} + +type Payload struct { + PushID int + Size int + DistinctSize int + Ref string + Head string + Before string + Commits []Commits +} + +type Commits struct { + SHA string + Message string + Distinct string + URL string +} + +type Data struct { + ID string `json:"id"` + Type string `json:"type"` + Actor Actor `json:"actor"` + Repo Repo `json:"repo"` + PayLoad Payload `json:"payload"` + Public string `json:"public"` + CreatedAt string `json:"created_at"` +} + +func main() { + fmt.Print("UserName >>> ") + ownerName := getWord() + "/events" + url := "https://api.github.com/users/" + ownerName + req, _ := http.NewRequest("GET", url, nil) + cl := new(http.Client) + resp, _ := cl.Do(req) + defer resp.Body.Close() + + dec := json.NewDecoder(resp.Body) + var d []Data + dec.Decode(&d) + var count = 0 + for _, json := range d { + // 日付の文字列をパースする + var ts = strings.Replace(json.CreatedAt, "T", " ", 1) + ts = strings.Replace(ts, "Z", " UTC", 1) + // UTCをJSTに置換する + t, _ := time.Parse("2006-01-02 15:04:05 MST", ts) + jst := time.FixedZone("Asia/Tokyo", 9*60*60) + tJst := t.In(jst) + // 今日の日付とパースした日付を比較する + nowJst := time.Now() + if tJst.Format("2006-01-02") == nowJst.Format("2006-01-02") && + json.Type == "PushEvent" { + count += len(json.PayLoad.Commits) + } + } + fmt.Println(count) +} + +func getWord() (stringReturned string) { + sc := bufio.NewScanner(os.Stdin) + sc.Scan() + stringReturned = sc.Text() + return +} From b416dc40f6d7e8ae7647d9d312336131a536f70b Mon Sep 17 00:00:00 2001 From: k-waragai Date: Tue, 4 Jul 2017 17:11:38 +0900 Subject: [PATCH 2/2] deleted --- OnedayCommits.go | 18 -------------- ReviewComment.go | 63 +++++++++++++++++------------------------------- versus.go | 20 +++++++-------- 3 files changed, 32 insertions(+), 69 deletions(-) diff --git a/OnedayCommits.go b/OnedayCommits.go index 1f3e388..91d747d 100644 --- a/OnedayCommits.go +++ b/OnedayCommits.go @@ -10,20 +10,6 @@ import ( "time" ) -type Actor struct { - ID int - Login string - GravatarID string - URL string - AvatarURL string -} - -type Repo struct { - ID int - Name string - URL string `json:"url"` -} - type Payload struct { PushID int Size int @@ -42,12 +28,8 @@ type Commits struct { } type Data struct { - ID string `json:"id"` Type string `json:"type"` - Actor Actor `json:"actor"` - Repo Repo `json:"repo"` PayLoad Payload `json:"payload"` - Public string `json:"public"` CreatedAt string `json:"created_at"` } diff --git a/ReviewComment.go b/ReviewComment.go index 1f3e388..d7d476a 100644 --- a/ReviewComment.go +++ b/ReviewComment.go @@ -10,79 +10,60 @@ import ( "time" ) -type Actor struct { - ID int - Login string - GravatarID string - URL string - AvatarURL string -} - -type Repo struct { - ID int - Name string - URL string `json:"url"` -} - type Payload struct { - PushID int - Size int - DistinctSize int - Ref string - Head string - Before string - Commits []Commits + Action string + Comment []Comment + Number int } -type Commits struct { - SHA string - Message string - Distinct string - URL string +type Comment struct { + body string + CreatedAT string } type Data struct { - ID string `json:"id"` Type string `json:"type"` - Actor Actor `json:"actor"` - Repo Repo `json:"repo"` PayLoad Payload `json:"payload"` - Public string `json:"public"` CreatedAt string `json:"created_at"` } func main() { - fmt.Print("UserName >>> ") - ownerName := getWord() + "/events" + fmt.Println("ユーザー名を入力してください") + fmt.Print("YourName: ") + comments := PullRequestComments() + fmt.Println(comments) +} + +func PullRequestComments() (pullreqtotal int) { + ownerName := getUserName() + "/events" url := "https://api.github.com/users/" + ownerName req, _ := http.NewRequest("GET", url, nil) - cl := new(http.Client) - resp, _ := cl.Do(req) + client := new(http.Client) + resp, _ := client.Do(req) defer resp.Body.Close() - dec := json.NewDecoder(resp.Body) var d []Data dec.Decode(&d) var count = 0 for _, json := range d { - // 日付の文字列をパースする + // 日付文字列パース var ts = strings.Replace(json.CreatedAt, "T", " ", 1) ts = strings.Replace(ts, "Z", " UTC", 1) - // UTCをJSTに置換する + // JST置換 t, _ := time.Parse("2006-01-02 15:04:05 MST", ts) jst := time.FixedZone("Asia/Tokyo", 9*60*60) tJst := t.In(jst) - // 今日の日付とパースした日付を比較する + // 日付比較 nowJst := time.Now() if tJst.Format("2006-01-02") == nowJst.Format("2006-01-02") && json.Type == "PushEvent" { - count += len(json.PayLoad.Commits) + count += len(json.PayLoad.Comment) } } - fmt.Println(count) + return count } -func getWord() (stringReturned string) { +func getUserName() (stringReturned string) { sc := bufio.NewScanner(os.Stdin) sc.Scan() stringReturned = sc.Text() diff --git a/versus.go b/versus.go index b02ba59..994a8f7 100644 --- a/versus.go +++ b/versus.go @@ -10,6 +10,16 @@ import ( "time" ) +type Data struct { + ID string `json:"id"` + Type string `json:"type"` + Actor Actor `json:"actor"` + Repo Repo `json:"repo"` + PayLoad Payload `json:"payload"` + Public string `json:"public"` + CreatedAt string `json:"created_at"` +} + type Actor struct { ID int Login string @@ -41,15 +51,6 @@ type Commits struct { URL string } -type Data struct { - ID string `json:"id"` - Type string `json:"type"` - Actor Actor `json:"actor"` - Repo Repo `json:"repo"` - PayLoad Payload `json:"payload"` - Public string `json:"public"` - CreatedAt string `json:"created_at"` -} func main() { fmt.Println("ユーザー名を入力してください") @@ -69,7 +70,6 @@ func main() { fmt.Println("DROW") fmt.Printf("MyCommits: %d\nPlayer Commits: %d", player1, player2) } - } // commitCount is counts the number of commits .