mirror of
https://git.ferricyanide.solutions/A_D/irc-webhooks.git
synced 2024-12-22 18:47:04 +00:00
made push messages clearer
This commit is contained in:
parent
ec93fcaff9
commit
e736688891
@ -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++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user