<commit_before>package pkgcloud

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"path/filepath"
	"strconv"
	"strings"
)

var serviceURL = "https://packagecloud.io"

type Client struct {
	token string
}

func NewClient(token string) *Client {
	if token == "" {
		token = os.Getenv("PACKAGECLOUD_TOKEN")
	}
	return &Client{token}
}

func (c Client) PushPackage(target, name string) error {
	s := strings.Split(target, "/")
	user, repo, distro, version := s[0], s[1], s[2], s[3]

	id, err := distroID(filepath.Ext(name), distro+"/"+version)
	if err != nil {
		return err
	}

	endpoint := fmt.Sprintf("%s/api/v1/repos/%s/%s/packages.json",
		serviceURL, user, repo)
	extraParams := map[string]string{
		"package[distro_version_id]": strconv.Itoa(id),
	}
	request, err := NewFileUploadRequest(endpoint, extraParams,
		"package[package_file]", name)
	if err != nil {
		return err
	}<commit_msg>Check that target has the right length<commit_after>package pkgcloud

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"path/filepath"
	"strconv"
	"strings"
)

var serviceURL = "https://packagecloud.io"

type Client struct {
	token string
}

func NewClient(token string) *Client {
	if token == "" {
		token = os.Getenv("PACKAGECLOUD_TOKEN")
	}
	return &Client{token}
}

func (c Client) PushPackage(target, name string) error {
	s := strings.Split(target, "/")
	if len(s) != 4 {
		return errors.New("invalid target: " + target)
	}
	user, repo, distro, version := s[0], s[1], s[2], s[3]

	id, err := distroID(filepath.Ext(name), distro+"/"+version)
	if err != nil {
		return err
	}

	endpoint := fmt.Sprintf("%s/api/v1/repos/%s/%s/packages.json",
		serviceURL, user, repo)
	extraParams := map[string]string{
		"package[distro_version_id]": strconv.Itoa(id),
	}
	request, err := NewFileUploadRequest(endpoint, extraParams,
		"package[package_file]", name)
	if err != nil {
		return err
	}
{'fraction_non_alphanumeric': 0.16851558372952985, 'fraction_numerical': 0.005810882197569995, 'mean_word_length': 4.411428571428571, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '167055', 'n_tokens_mistral': 750, 'n_tokens_neox': 728, 'n_words': 163}