<commit_before>package runner

import (
	"fmt"
	"os"
	"strconv"

	"github.com/odlp/inflight/project"
)

type Config struct {
	OutputPath       string
	GitAuthorEmail   string
	TrackerAPIToken  string
	TrackerProjectID int
}

type Runner struct {
	Project project.Project
	Writer  Writer
	Config  Config
}

func NewRunner(outputPath string) Runner {
	c := configWithOutputPath(outputPath)
	p := project.NewProject(c.TrackerAPIToken, c.TrackerProjectID)
	return Runner{
		Project: p,
		Writer:  Writer{},
		Config:  c,
	}
}

func (r Runner) Exec() {
	u, err := r.Project.FindUserByEmail(r.Config.GitAuthorEmail)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	s, err := r.Project.FindCurrentStory(u)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	outputText := fmt.Sprintf("[%d]\n", s.ID)
	r.Writer.WriteToFile(r.Config.OutputPath, outputText)
}

const EnvGitAuthorEmail = "GIT_AUTHOR_EMAIL"
const EnvTrackerAPIToken = "TRACKER_API_TOKEN"
const EnvTrackerProjectID = "TRACKER_PROJECT_ID"

func configWithOutputPath(outputPath string) Config {
	projectID, _ := strconv.Atoi(os.Getenv(EnvTrackerProjectID))
	return Config{
		OutputPath:       outputPath,
		GitAuthorEmail:   os.Getenv(EnvGitAuthorEmail),
		TrackerAPIToken:  os.Getenv(EnvTrackerAPIToken),
		TrackerProjectID: projectID,
	}
}<commit_msg>Correct story ID output into commit message<commit_after>package runner

import (
	"fmt"
	"os"
	"strconv"

	"github.com/odlp/inflight/project"
)

type Config struct {
	OutputPath       string
	GitAuthorEmail   string
	TrackerAPIToken  string
	TrackerProjectID int
}

type Runner struct {
	Project project.Project
	Writer  Writer
	Config  Config
}

func NewRunner(outputPath string) Runner {
	c := configWithOutputPath(outputPath)
	p := project.NewProject(c.TrackerAPIToken, c.TrackerProjectID)
	return Runner{
		Project: p,
		Writer:  Writer{},
		Config:  c,
	}
}

func (r Runner) Exec() {
	u, err := r.Project.FindUserByEmail(r.Config.GitAuthorEmail)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	s, err := r.Project.FindCurrentStory(u)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	outputText := fmt.Sprintf("[#%d]\n", s.ID)
	r.Writer.WriteToFile(r.Config.OutputPath, outputText)
}

const EnvGitAuthorEmail = "GIT_AUTHOR_EMAIL"
const EnvTrackerAPIToken = "TRACKER_API_TOKEN"
const EnvTrackerProjectID = "TRACKER_PROJECT_ID"

func configWithOutputPath(outputPath string) Config {
	projectID, _ := strconv.Atoi(os.Getenv(EnvTrackerProjectID))
	return Config{
		OutputPath:       outputPath,
		GitAuthorEmail:   os.Getenv(EnvGitAuthorEmail),
		TrackerAPIToken:  os.Getenv(EnvTrackerAPIToken),
		TrackerProjectID: projectID,
	}
}
{'fraction_non_alphanumeric': 0.11186440677966102, 'fraction_numerical': 0.0015065913370998117, 'mean_word_length': 4.639065817409766, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7510354', 'n_tokens_mistral': 1017, 'n_tokens_neox': 976, 'n_words': 194}