<commit_before>package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
	"net/url"
	"os"
)

func pushbulletNotify() {
	accessToken := os.Getenv(pushbulletTokEnv)
	if accessToken == "" {
		log.Fatalf("Missing access token, %s must be set", pushbulletTokEnv)
	}

	payload := bytes.NewBuffer([]byte(fmt.Sprintf(
		`{"body":%q,"title":%q,"type":"note"}`, *message, *title,
	)))

	req, err := http.NewRequest("POST", "https://api.pushbullet.com/v2/pushes", payload)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Access-Token", accessToken)
	req.Header.Set("Content-Type", "application/json")

	if _, err = webClient.Do(req); err != nil {
		log.Fatal(err)
	}
}

func slackNotify() {
	accessToken := os.Getenv(slackTokEnv)
	if accessToken == "" {
		log.Fatalf("Missing access token, %s must be set", slackTokEnv)
	}

	dest := os.Getenv(slackDestEnv)
	if dest == "" {
		log.Fatalf("Missing destination, %s must be set", slackDestEnv)
	}

	vals := make(url.Values)
	vals.Set("token", accessToken)
	vals.Set("text", fmt.Sprintf("%s\n%s", *title, *message))
	vals.Set("username", "noti")
	vals.Set("channel", dest)

	resp, err := webClient.PostForm("https://slack.com/api/chat.postMessage", vals)
	if err != nil {
		log.Fatal(err)
	}

	r := make(map[string]interface{})
	if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
		resp.Body.Close()
		log.Fatal(err)
	}
	resp.Body.Close()

	if r["ok"] == false {
		log.Fatal("Slack API error: ", r["error"])
	}
}

func hipChatNotify() {
	accessToken := os.Getenv(hipChatTokEnv)
	if accessToken == "" {
		log.Fatalf("Missing access token, %s must be set", hipChatTokEnv)
	}

	dest := os.Getenv(hipChatDestEnv)
	if dest == "" {
		log.Fatalf("Missing destination, %s must be set", hipChatDestEnv)
	}

	payload := bytes.NewBuffer([]byte(fmt.Sprintf(
		`{"message":%q,"message_format":"text"}`,
		fmt.Sprintf("%s\n%s", *title, *message),
	)))

	ep := fmt.Sprintf("https://api.hipchat.com/v2/room/%s/notification", dest)
	req, err := http.NewRequest("POST", ep, payload)
	if err != nil {
		log.Fatal(err)
	}

	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
	req.Header.Set("Content-Type", "application/json")

	resp, err := webClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}

	r := make(map[string]interface{})
	if err := json.NewDecoder(resp.Body).Decode(&r); err == io.EOF {
		return
	} else if err != nil {
		resp.Body.Close()
		log.Fatal(err)
	}
	resp.Body.Close()

	if err, exists := r["error"]; exists {
		if m, is := err.(map[string]interface{}); is {
			log.Fatal("HipChat API error: ", m["message"])
		}
	}

}<commit_msg>Unmarshal to a struct instead of map<commit_after>package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
	"net/url"
	"os"
)

func pushbulletNotify() {
	accessToken := os.Getenv(pushbulletTokEnv)
	if accessToken == "" {
		log.Fatalf("Missing access token, %s must be set", pushbulletTokEnv)
	}

	payload := bytes.NewBuffer([]byte(fmt.Sprintf(
		`{"body":%q,"title":%q,"type":"note"}`, *message, *title,
	)))

	req, err := http.NewRequest("POST", "https://api.pushbullet.com/v2/pushes", payload)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Access-Token", accessToken)
	req.Header.Set("Content-Type", "application/json")

	if _, err = webClient.Do(req); err != nil {
		log.Fatal(err)
	}
}

func slackNotify() {
	accessToken := os.Getenv(slackTokEnv)
	if accessToken == "" {
		log.Fatalf("Missing access token, %s must be set", slackTokEnv)
	}

	dest := os.Getenv(slackDestEnv)
	if dest == "" {
		log.Fatalf("Missing destination, %s must be set", slackDestEnv)
	}

	vals := make(url.Values)
	vals.Set("token", accessToken)
	vals.Set("text", fmt.Sprintf("%s\n%s", *title, *message))
	vals.Set("username", "noti")
	vals.Set("channel", dest)

	resp, err := webClient.PostForm("https://slack.com/api/chat.postMessage", vals)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	var r struct {
		OK    bool
		Error string
	}

	if err := json.NewDecoder(resp.Body).Decode(&r); err == io.EOF {
		return
	} else if err != nil {
		resp.Body.Close()
		log.Fatal(err)
	}

	if !r.OK {
		resp.Body.Close()
		log.Fatal("Slack API error: ", r.Error)
	}
}

func hipChatNotify() {
	accessToken := os.Getenv(hipChatTokEnv)
	if accessToken == "" {
		log.Fatalf("Missing access token, %s must be set", hipChatTokEnv)
	}

	dest := os.Getenv(hipChatDestEnv)
	if dest == "" {
		log.Fatalf("Missing destination, %s must be set", hipChatDestEnv)
	}

	payload := bytes.NewBuffer([]byte(fmt.Sprintf(
		`{"message":%q,"message_format":"text"}`,
		fmt.Sprintf("%s\n%s", *title, *message),
	)))

	ep := fmt.Sprintf("https://api.hipchat.com/v2/room/%s/notification", dest)
	req, err := http.NewRequest("POST", ep, payload)
	if err != nil {
		log.Fatal(err)
	}

	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
	req.Header.Set("Content-Type", "application/json")

	resp, err := webClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	var r struct {
		Error struct {
			Code    int
			Message string
			Type    string
		}
	}

	if err := json.NewDecoder(resp.Body).Decode(&r); err == io.EOF {
		return
	} else if err != nil {
		resp.Body.Close()
		log.Fatal(err)
	}

	if m := r.Error.Message; m != "" {
		resp.Body.Close()
		log.Fatal("HipChat API error: ", m)
	}

}
{'fraction_non_alphanumeric': 0.19439252336448598, 'fraction_numerical': 0.0007476635514018691, 'mean_word_length': 4.019699812382739, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, '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': '5746179', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2029, 'n_words': 414}