<commit_before>package hooks

import (
	"fmt"
	"log"
	"net/http"

	"github.com/parkr/auto-reply/ctx"
)

// GlobalHandler is a handy handler which can take in every event,
// choose which handlers to fire, and fires them.
type GlobalHandler struct {
	Context       *ctx.Context
	EventHandlers map[EventType][]EventHandler
}

// HandlePayload handles the actual unpacking of the payload and firing of the proper handlers.
// It will never respond with anything but a 200.
func (h *GlobalHandler) HandlePayload(w http.ResponseWriter, r *http.Request, payload []byte) {
	eventType := r.Header.Get("X-GitHub-Event")

	if eventType == "ping" {
		event := structFromPayload(eventType, payload)
		ping, ok := event.(*pingEventPayload)
		if !ok {
			log.Println(string(payload))
			http.Error(w, "you sure that was a ping message?", 200)
			return
		}
		http.Error(w, ping.Zen, 200)
		return
	}

	if handlers, ok := h.EventHandlers[EventType(eventType)]; ok {
		numHandlers := h.FireHandlers(handlers, eventType, payload)

		issueCommentHandlers, ok := h.EventHandlers[EventType(eventType)]<commit_msg>Just plop the payload in there.<commit_after>package hooks

import (
	"fmt"
	"log"
	"net/http"

	"github.com/parkr/auto-reply/ctx"
)

// GlobalHandler is a handy handler which can take in every event,
// choose which handlers to fire, and fires them.
type GlobalHandler struct {
	Context       *ctx.Context
	EventHandlers map[EventType][]EventHandler
}

// HandlePayload handles the actual unpacking of the payload and firing of the proper handlers.
// It will never respond with anything but a 200.
func (h *GlobalHandler) HandlePayload(w http.ResponseWriter, r *http.Request, payload []byte) {
	eventType := r.Header.Get("X-GitHub-Event")

	if eventType == "ping" {
		event := structFromPayload(eventType, payload)
		ping, ok := event.(*pingEventPayload)
		if !ok {
			log.Println(string(payload))
			http.Error(w, "you sure that was a ping message?", 200)
			return
		}
		http.Error(w, ping.Zen, 200)
		return
	}

	log.Println("payload:", string(payload))

	if handlers, ok := h.EventHandlers[EventType(eventType)]; ok {
		numHandlers := h.FireHandlers(handlers, eventType, payload)

		issueCommentHandlers, ok := h.EventHandlers[EventType(eventType)]
{'fraction_non_alphanumeric': 0.11838006230529595, 'fraction_numerical': 0.00801068090787717, 'mean_word_length': 4.327014218009479, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6779036', 'n_tokens_mistral': 781, 'n_tokens_neox': 709, 'n_words': 216}