<commit_before>package gerrittest

import (
	"errors"
	"net/url"
	"os"
	"os/exec"
	"strings"
)

// Helpers provides structs and functions for setting up and
// interacting with Gerrit.

var (
	// ErrGerritDown is returned by Ping() if Gerrit appears to be down.
	ErrGerritDown = errors.New(
		"Gerrrit is not running or failed to start.")
)

// GerritHelpers is a struct which provides helper methods for interacting
// with a running instance of Gerrit.
type GerritHelpers struct {
	PortHTTP int
	PortSSH  int
	Address  string
}

// AddressOnly returns the address part of the given value. For example:
//           127.0.0.1:5000 -> 127.0.0.1
//    tcp://127.0.0.1:5000/ -> 127.0.0.1
func AddressOnly(value string) string {
	value = strings.TrimSpace(value)
	if parsed, err := url.Parse(value); err == nil {
		if parsed.Host == "" {
			return value
		}
		value = parsed.Host
	}
	if strings.Contains(value, ":") {
		value = strings.Split(value, ":")[0]
	}

	return value
}

// GetAddress attempts to returns the address where we should expect to
// connect to. This will try $DOCKER_HOST first and failing that attempt
// to use docker-machine before finally giving up and returning 127.0.0.1
func GetAddress() string {
	address := "127.0.0.1"

	dockerhost := os.Getenv("DOCKER_HOST")
	if dockerhost != "" {
		address = AddressOnly(dockerhost)
	} else {
		command := exec.Command("docker-machine", "ip")
		if data, err := command.Output(); err == nil {
			address = AddressOnly(string(data))
		}
	}

	return address
}

// NewGerritHelpers produces a new *GerritHelpers struct.
func NewGerritHelpers(container *Container) (*GerritHelpers, error) {

	helpers := &GerritHelpers{
		PortHTTP: int(container.HTTP),
		PortSSH:  int(container.SSH),
	}
	return helpers, helpers.Ping()<commit_msg>use LookupEnv instead<commit_after>package gerrittest

import (
	"errors"
	"net/url"
	"os"
	"os/exec"
	"strings"
)

// Helpers provides structs and functions for setting up and
// interacting with Gerrit.

var (
	// ErrGerritDown is returned by Ping() if Gerrit appears to be down.
	ErrGerritDown = errors.New(
		"Gerrrit is not running or failed to start.")
)

// GerritHelpers is a struct which provides helper methods for interacting
// with a running instance of Gerrit.
type GerritHelpers struct {
	PortHTTP int
	PortSSH  int
	Address  string
}

// AddressOnly returns the address part of the given value. For example:
//           127.0.0.1:5000 -> 127.0.0.1
//    tcp://127.0.0.1:5000/ -> 127.0.0.1
func AddressOnly(value string) string {
	value = strings.TrimSpace(value)
	if parsed, err := url.Parse(value); err == nil {
		if parsed.Host == "" {
			return value
		}
		value = parsed.Host
	}
	if strings.Contains(value, ":") {
		value = strings.Split(value, ":")[0]
	}

	return value
}

// GetAddress attempts to returns the address where we should expect to
// connect to. This will try $DOCKER_HOST first and failing that attempt
// to use docker-machine before finally giving up and returning 127.0.0.1.
func GetAddress() string {
	address := "127.0.0.1"

	if dockerhost, set := os.LookupEnv("DOCKER_HOST"); set {
		address = AddressOnly(dockerhost)
	} else {
		command := exec.Command("docker-machine", "ip")
		if data, err := command.Output(); err == nil {
			address = AddressOnly(string(data))
		}
	}

	return address
}

// NewGerritHelpers produces a new *GerritHelpers struct.
func NewGerritHelpers(container *Container) (*GerritHelpers, error) {

	helpers := &GerritHelpers{
		PortHTTP: int(container.HTTP),
		PortSSH:  int(container.SSH),
	}
	return helpers, helpers.Ping()
{'fraction_non_alphanumeric': 0.12206703910614525, 'fraction_numerical': 0.025139664804469275, 'mean_word_length': 3.5676020408163267, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, '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': '1482955', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1180, 'n_words': 370}