diff --git a/src/webhooks.go b/src/webhooks.go index f0cc1f3..b4e1266 100644 --- a/src/webhooks.go +++ b/src/webhooks.go @@ -8,8 +8,6 @@ import ( "strings" ) -const INDENT = " " - func ListenForWebHook(config Config, msgChan chan string) { http.HandleFunc("/", CreateHandler(msgChan)) @@ -19,8 +17,13 @@ func ListenForWebHook(config Config, msgChan chan string) { fmt.Println(err) } } + +func shortHash(hash string) string { + return hash[0:7] +} + func CreateHandler(msgChan chan string) http.HandlerFunc { - return func (writer http.ResponseWriter, request * http.Request) { + return func(writer http.ResponseWriter, request *http.Request) { defer request.Body.Close() data, err := ioutil.ReadAll(request.Body) if err != nil { @@ -67,13 +70,31 @@ func handlePush(data []byte, msgChan chan string) { outIrcMessage := strings.Builder{} outIrcMessage.WriteString(fmt.Sprintf( - "[%s] %s pushed %d commit(s)", + "[%s] %s pushed %d commit(s) to ref %s: %s..%s", pushData.Repository.FullName, pushData.Pusher.Login, len(pushData.Commits), - )) + pushData.Ref, + shortHash(pushData.Before), + shortHash(pushData.After), + )) msgChan <- outIrcMessage.String() + count := 0 + for _, commit := range pushData.Commits { + if count > 4 { + break + } + commitDesc := strings.SplitN(commit.Message, "\n", 1)[0] + msgChan <- fmt.Sprintf( + "[%s] commit %s created by %s: %s", + pushData.Repository.FullName, + shortHash(commit.Hash), + commit.Author.Username, + commitDesc, + ) + count++ + } }