<commit_before>package latest

import (
	"fmt"
	"strings"

	"github.com/google/go-github/github"
	"github.com/hashicorp/go-version"
)

// FixVersionStrFunc is function to fix version string
// so that it can be interpreted as SemVer by hashicorp/go-version
type FixVersionStrFunc func(string) string

var defaultFixVersionStrFunc FixVersionStrFunc

func init() {
	defaultFixVersionStrFunc = FixNothing()
}

// GithubTag is implemented Source interface. It uses GitHub API
// and fetch tags from repository.
type GithubTag struct {
	// Owner and Repository are GitHub owner name and its repository name
	// e.g., If you want to check https://github.com/tcnksm/ghr version
	// Repository is `ghr`, and Owner is `tcnksm`
	Owner      string
	Repository string

	// FixVersionStrFunc is function to fix version string (in this case tag
	// name string) on GitHub so that it can be interpreted as SemVer
	// by hashicorp/go-version. By default, it does nothing (calles FixNothing()).
	FixVersionStrFunc FixVersionStrFunc

	// URL & Token is used for GitHub Enterprise
	URL   string
	Token string
}

func (g *GithubTag) fixVersionStrFunc() FixVersionStrFunc {
	if g.FixVersionStrFunc == nil {
		return defaultFixVersionStrFunc
	}

	return g.FixVersionStrFunc
}

func FixNothing() FixVersionStrFunc {
	return func(s string) string {
		return s
	}
}

// DeleteFrontV delete first `v` charactor on version string
// e.g., `v0.1.1` becomes `0.1.1`
func DeleteFrontV() FixVersionStrFunc {
	return func(s string) string {
		return strings.Replace(s, "v", "", 1)
	}
}

func (g *GithubTag) newClient() *github.Client {
	return github.NewClient(nil)
}

func (g *GithubTag) Validate() error {

	if len(g.Repository) == 0 {
		return fmt.Errorf("GitHub repository name must be set")
	}

	if len(g.Owner) == 0 {
		return fmt.Errorf("GitHub owner name must be set")
	}

	return nil
}

// Fetch fetches github tags and interpret them as version.Version and return.
// To fetch tags, use google/go-github package.
func (g *GithubTag) Fetch() (*FetchResponse, error) {

	fr := NewFetchResponse()
<commit_msg>Refactoring<commit_after>package latest

import (
	"fmt"
	"strings"

	"github.com/google/go-github/github"
	"github.com/hashicorp/go-version"
)

// FixVersionStrFunc is function to fix version string
// so that it can be interpreted as SemVer by http://godoc.org/github.com/hashicorp/go-version
type FixVersionStrFunc func(string) string

var defaultFixVersionStrFunc FixVersionStrFunc

func init() {
	defaultFixVersionStrFunc = FixNothing()
}

// GithubTag is implemented Source interface. It uses GitHub API
// and fetch tags from repository.
type GithubTag struct {
	// Owner and Repository are GitHub owner name and its repository name
	// e.g., If you want to check https://github.com/tcnksm/ghr version
	// Repository is `ghr`, and Owner is `tcnksm`
	Owner      string
	Repository string

	// FixVersionStrFunc is function to fix version string (in this case tag
	// name string) on GitHub so that it can be interpreted as SemVer
	// by hashicorp/go-version. By default, it does nothing (calles FixNothing()).
	FixVersionStrFunc FixVersionStrFunc

	// URL & Token is used for GitHub Enterprise
	URL   string
	Token string
}

func (g *GithubTag) fixVersionStrFunc() FixVersionStrFunc {
	if g.FixVersionStrFunc == nil {
		return defaultFixVersionStrFunc
	}

	return g.FixVersionStrFunc
}

// FixNothing does nothing. This is a default function of FixVersionStrFunc.
func FixNothing() FixVersionStrFunc {
	return func(s string) string {
		return s
	}
}

// DeleteFrontV delete first `v` charactor on version string
// e.g., `v0.1.1` becomes `0.1.1`.
func DeleteFrontV() FixVersionStrFunc {
	return func(s string) string {
		return strings.Replace(s, "v", "", 1)
	}
}

func (g *GithubTag) newClient() *github.Client {
	return github.NewClient(nil)
}

func (g *GithubTag) Validate() error {

	if len(g.Repository) == 0 {
		return fmt.Errorf("GitHub repository name must be set")
	}

	if len(g.Owner) == 0 {
		return fmt.Errorf("GitHub owner name must be set")
	}

	return nil
}

// Fetch fetches github tags on Github.
// To fetch tags, it uses http://godoc.org/github.com/google/go-github/github.
func (g *GithubTag) Fetch() (*FetchResponse, error) {

	fr := NewFetchResponse()

{'fraction_non_alphanumeric': 0.10201688555347092, 'fraction_numerical': 0.004221388367729831, 'mean_word_length': 3.9363425925925926, 'pattern_counts': {'":': 0, '<': 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': '2512751', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1348, 'n_words': 465}