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 new file mode 100644 index 0000000..d7d476a --- /dev/null +++ b/ReviewComment.go @@ -0,0 +1,71 @@ +package main + +import ( + "bufio" + "encoding/json" + "fmt" + "net/http" + "os" + "strings" + "time" +) + +type Payload struct { + Action string + Comment []Comment + Number int +} + +type Comment struct { + body string + CreatedAT string +} + +type Data struct { + Type string `json:"type"` + PayLoad Payload `json:"payload"` + CreatedAt string `json:"created_at"` +} + +func main() { + 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) + 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) + // 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.Comment) + } + } + return count +} + +func getUserName() (stringReturned string) { + sc := bufio.NewScanner(os.Stdin) + sc.Scan() + stringReturned = sc.Text() + return +} 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 .