Commit 47c21780 authored by Zac Wood's avatar Zac Wood

Handles commits better

parent 0e6a91f4
......@@ -48,7 +48,7 @@ func main() {
contribs := parseContriubtors(events)
fmt.Println("Thanks to our contributors this week!")
fmt.Println(contribs.reportString())
fmt.Println(contribs.String())
}
func parseContriubtors(events []*gitlab.Event) contributors {
......@@ -60,11 +60,14 @@ func parseContriubtors(events []*gitlab.Event) contributors {
cType := event.ActionName + event.TargetType
authorActivity := contribs[event.AuthorUsername]
switch cType {
case "pushed to":
authorActivity[pushedTo]++
fallthrough
case "pushed new":
authorActivity[pushedNew]++
if event.PushData != nil {
authorActivity[pushedTo] += event.PushData.CommitCount
}
case "openedMergeRequest":
authorActivity[openedMergeRequest]++
case "acceptedMergeRequest":
......@@ -78,15 +81,12 @@ func parseContriubtors(events []*gitlab.Event) contributors {
return contribs
}
func (c contributors) reportString() string {
func (c contributors) String() string {
result := ""
for name, activity := range c {
result += name + ":\n"
if activity[pushedTo] > 0 {
result += fmt.Sprintf("\tPushed %d times\n", activity[pushedTo])
}
if activity[pushedNew] > 0 {
result += fmt.Sprintf("\tPushed %d new branches\n", activity[pushedNew])
result += fmt.Sprintf("\tPushed %d commits\n", activity[pushedTo])
}
if activity[openedMergeRequest] > 0 {
result += fmt.Sprintf("\tOpened %d merge requests\n", activity[openedMergeRequest])
......
package gitlab
type Event struct {
ActionName string `json:"action_name"`
TargetType string `json:"target_type"`
AuthorID int `json:"author_id"`
AuthorUsername string `json:"author_username"`
ActionName string `json:"action_name"`
TargetType string `json:"target_type"`
AuthorID int `json:"author_id"`
AuthorUsername string `json:"author_username"`
PushData *pushData `json:"push_data"`
}
type pushData struct {
CommitCount int `json:"commit_count"`
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment