<commit_before>package main

import (
	"bufio"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"strings"

	"github.com/jhunt/play.spruce.cf/github"
)

type Result struct {
	Arguments []string `json:"args"`
	About     string   `json:"about"`
	Stdout    string   `json:"stdout"`
	Stderr    string   `json:"stderr"`
	Success   bool     `json:"success"`
}

func GetSpruces() ([]string, error) {
	r, err := github.Releases("geofffranks", "spruce")
	if err != nil {
		return nil, fmt.Errorf("github api: %s", err)
	}
	l := github.LatestFrom("1.0.2", r)
	for _, v := range l {
		f, err := os.Create(fmt.Sprintf("/tmp/spruce-%s", v))
		log.Printf("downloading spruce v%s", v)
		if err != nil {
			return nil, fmt.Errorf("failed to download spruce v%s: %s", v, err)
		}
		github.Download("geofffranks", "spruce", v, f)
		f.Chmod(0755)
		f.Close()
	}
	return l, nil
}

func Spruce(where string, flavor string, args ...string) (*Result, error) {
	r := &Result{Arguments: args}

	spruce := fmt.Sprintf("/tmp/spruce-%s", flavor)
	cmd := exec.Command(spruce, args...)
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		log.Printf("failed to get stdout pipe from command: %s", err)
		return nil, err
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		log.Printf("failed to get stderr pipe from command: %s", err)
		return nil, err
	}

	if where != "" {
		err = os.Chdir(where)
		if err != nil {
			log.Printf("failed to chdir to %s: %s", where, err)
			return nil, err
		}
	}
	where, _ = os.Getwd()
	log.Printf("running `spruce %v' in %s", args, where)
	err = cmd.Start()<commit_msg>Prevent environment variable leakage (#6)<commit_after>package main

import (
	"bufio"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"strings"

	"github.com/jhunt/play.spruce.cf/github"
)

type Result struct {
	Arguments []string `json:"args"`
	About     string   `json:"about"`
	Stdout    string   `json:"stdout"`
	Stderr    string   `json:"stderr"`
	Success   bool     `json:"success"`
}

func GetSpruces() ([]string, error) {
	r, err := github.Releases("geofffranks", "spruce")
	if err != nil {
		return nil, fmt.Errorf("github api: %s", err)
	}
	l := github.LatestFrom("1.0.2", r)
	for _, v := range l {
		f, err := os.Create(fmt.Sprintf("/tmp/spruce-%s", v))
		log.Printf("downloading spruce v%s", v)
		if err != nil {
			return nil, fmt.Errorf("failed to download spruce v%s: %s", v, err)
		}
		github.Download("geofffranks", "spruce", v, f)
		f.Chmod(0755)
		f.Close()
	}
	return l, nil
}

func Spruce(where string, flavor string, args ...string) (*Result, error) {
	r := &Result{Arguments: args}

	spruce := fmt.Sprintf("/tmp/spruce-%s", flavor)
	cmd := exec.Command(spruce, args...)
	cmd.Env = []string{
		"REDACT=Redact Vault Creds",
	}
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		log.Printf("failed to get stdout pipe from command: %s", err)
		return nil, err
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		log.Printf("failed to get stderr pipe from command: %s", err)
		return nil, err
	}

	if where != "" {
		err = os.Chdir(where)
		if err != nil {
			log.Printf("failed to chdir to %s: %s", where, err)
			return nil, err
		}
	}
	where, _ = os.Getwd()
	log.Printf("running `spruce %v' in %s", args, where)
	err = cmd.Start()
{'fraction_non_alphanumeric': 0.18021638330757342, 'fraction_numerical': 0.00463678516228748, 'mean_word_length': 3.463448275862069, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3765444', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1271, 'n_words': 342}