<commit_before>package bazooka

import (
	"fmt"
	"time"
)

type Project struct {
	ScmType string `bson:"scm_type" json:"scm_type"`
	ScmURI  string `bson:"scm_uri" json:"scm_uri"`
	Name    string `bson:"name" json:"name"`
	ID      string `bson:"id" json:"id"`
}

type Variant struct {
	Status     JobStatus `bson:"status" json:"status"`
	Started    time.Time `bson:"started" json:"started"`
	Completed  time.Time `bson:"completed" json:"completed"`
	BuildImage string    `bson:"image" json:"image"`
	JobID      string    `bson:"job_id" json:"job_id"`
	Number     int       `bson:"number" json:"number"`
	ID         string    `bson:"id" json:"id"`
}

type StartJob struct {
	ScmReference string `json:"reference"`
}

type JobStatus string

const (
	JOB_SUCCESS JobStatus = "SUCCESS"
	JOB_FAILED            = "FAILED"
	JOB_ERRORED           = "ERRORED"
	JOB_RUNNING           = "RUNNING"
)

type Job struct {
	ID              string      `bson:"id" json:"id"`
	ProjectID       string      `bson:"project_id" json:"project_id"`
	OrchestrationID string      `bson:"orchestration_id" json:"orchestration_id"`
	Started         time.Time   `bson:"started" json:"started"`
	Completed       time.Time   `bson:"completed" json:"completed"`
	Status          JobStatus   `bson:"status" json:"status"`
	SCMMetadata     SCMMetadata `bson:"scm_metadata" json:"scm_metadata"`
}

type LogEntry struct {
	ID        string    `bson:"id" json:"id"`
	Message   string    `bson:"msg" json:"msg"`
	Time      time.Time `bson:"time" json:"time"`
	ProjectID string    `bson:"project_id" json:"project_id"`
	JobID     string    `bson:"job_id" json:"job_id"`
	VariantID string    `bson:"variant_id" json:"variant_id"`
	Image     string    `bson:"image" json:"image"`
}

type SCMMetadata struct {
	Origin    string   `bson:"origin" json:"origin" yaml:"origin"`
	Reference string   `bson:"reference" json:"reference" yaml:"reference"`
	CommitID  string   `bson:"commit_id" json:"commit_id" yaml:"commit_id"`
	Author    Person   `bson:"author" json:"author" yaml:"author"`
	Committer Person   `bson:"committer" json:"committer" yaml:"committer"`
	Date      YamlTime `bson:"time" json:"date" yaml:"date"`
	Message   string   `bson:"message" json:"message" yaml:"message"`
}

type Person struct {
	Name  string `bson:"name" json:"name" yaml:"name"`
	Email string `bson:"email" json:"email" yaml:"email"`
}

type Image struct {
	Name        string `bson:"name" json:"name"`
	Description string `bson:"description" json:"description"`
	Image       string `bson:"image" json:"image"`
	ID          string `bson:"id" json:"id"`
}

type Config struct {
	Language      string       `yaml:"language"`
	Setup         []string     `yaml:"setup,omitempty"`
	BeforeInstall []string     `yaml:"before_install,omitempty"`
	Install       []string     `yaml:"install,omitempty"`
	BeforeScript  []string     `yaml:"before_script,omitempty"`
	Script        []string     `yaml:"script,omitempty"`
	AfterScript   []string     `yaml:"after_script,omitempty"`
	AfterSuccess  []string     `yaml:"after_success,omitempty"`
	AfterFailure  []string     `yaml:"after_failure,omitempty"`
	Services      []string     `yaml:"services,omitempty"`
	Env           []string     `yaml:"env,omitempty"`
	FromImage     string       `yaml:"from"`
	Matrix        ConfigMatrix `yaml:"matrix,omitempty"`
}

type ConfigMatrix struct {
	Exclude []map[string]interface{} `yaml:"exclude,omitempty"`
}

type YamlTime struct {
	time.Time
}

func (t *YamlTime) UnmarshalYAML(unmarshal func(interface{}) error) error {
	timeAsString := ""
	if err := unmarshal(&timeAsString); err != nil {
		return err
	}
	if len(timeAsString) == 0 {
		return nil
	}

	timeFormats := []string{
		time.ANSIC,
		time.ANSIC,
		time.UnixDate,
		time.RubyDate,
		time.RFC822,
		time.RFC822Z,
		time.RFC850,
		time.RFC1123,<commit_msg>Whenever we take commands in the config (install, script, ...), accept a single or a list of strings. Fixes #8<commit_after>package bazooka

import (
	"fmt"
	"time"
)

type Project struct {
	ScmType string `bson:"scm_type" json:"scm_type"`
	ScmURI  string `bson:"scm_uri" json:"scm_uri"`
	Name    string `bson:"name" json:"name"`
	ID      string `bson:"id" json:"id"`
}

type Variant struct {
	Status     JobStatus `bson:"status" json:"status"`
	Started    time.Time `bson:"started" json:"started"`
	Completed  time.Time `bson:"completed" json:"completed"`
	BuildImage string    `bson:"image" json:"image"`
	JobID      string    `bson:"job_id" json:"job_id"`
	Number     int       `bson:"number" json:"number"`
	ID         string    `bson:"id" json:"id"`
}

type StartJob struct {
	ScmReference string `json:"reference"`
}

type JobStatus string

const (
	JOB_SUCCESS JobStatus = "SUCCESS"
	JOB_FAILED            = "FAILED"
	JOB_ERRORED           = "ERRORED"
	JOB_RUNNING           = "RUNNING"
)

type Job struct {
	ID              string      `bson:"id" json:"id"`
	ProjectID       string      `bson:"project_id" json:"project_id"`
	OrchestrationID string      `bson:"orchestration_id" json:"orchestration_id"`
	Started         time.Time   `bson:"started" json:"started"`
	Completed       time.Time   `bson:"completed" json:"completed"`
	Status          JobStatus   `bson:"status" json:"status"`
	SCMMetadata     SCMMetadata `bson:"scm_metadata" json:"scm_metadata"`
}

type LogEntry struct {
	ID        string    `bson:"id" json:"id"`
	Message   string    `bson:"msg" json:"msg"`
	Time      time.Time `bson:"time" json:"time"`
	ProjectID string    `bson:"project_id" json:"project_id"`
	JobID     string    `bson:"job_id" json:"job_id"`
	VariantID string    `bson:"variant_id" json:"variant_id"`
	Image     string    `bson:"image" json:"image"`
}

type SCMMetadata struct {
	Origin    string   `bson:"origin" json:"origin" yaml:"origin"`
	Reference string   `bson:"reference" json:"reference" yaml:"reference"`
	CommitID  string   `bson:"commit_id" json:"commit_id" yaml:"commit_id"`
	Author    Person   `bson:"author" json:"author" yaml:"author"`
	Committer Person   `bson:"committer" json:"committer" yaml:"committer"`
	Date      YamlTime `bson:"time" json:"date" yaml:"date"`
	Message   string   `bson:"message" json:"message" yaml:"message"`
}

type Person struct {
	Name  string `bson:"name" json:"name" yaml:"name"`
	Email string `bson:"email" json:"email" yaml:"email"`
}

type Image struct {
	Name        string `bson:"name" json:"name"`
	Description string `bson:"description" json:"description"`
	Image       string `bson:"image" json:"image"`
	ID          string `bson:"id" json:"id"`
}

type Config struct {
	Language      string       `yaml:"language"`
	Setup         Commands     `yaml:"setup,omitempty"`
	BeforeInstall Commands     `yaml:"before_install,omitempty"`
	Install       Commands     `yaml:"install,omitempty"`
	BeforeScript  Commands     `yaml:"before_script,omitempty"`
	Script        Commands     `yaml:"script,omitempty"`
	AfterScript   Commands     `yaml:"after_script,omitempty"`
	AfterSuccess  Commands     `yaml:"after_success,omitempty"`
	AfterFailure  Commands     `yaml:"after_failure,omitempty"`
	Services      []string     `yaml:"services,omitempty"`
	Env           []string     `yaml:"env,omitempty"`
	FromImage     string       `yaml:"from"`
	Matrix        ConfigMatrix `yaml:"matrix,omitempty"`
}

type Commands []string

func (c *Commands) UnmarshalYAML(unmarshal func(interface{}) error) error {
	var raw interface{}
	if err := unmarshal(&raw); err != nil {
		return err
	}

	switch convCmd := raw.(type) {
	case string:
		*c = []string{convCmd}
		return nil
	case []interface{}:
		*c = make([]string, len(convCmd))
		for i, rawCmd := range convCmd {
			cmd, ok := rawCmd.(string)
			if !ok {
				return fmt.Errorf("Command list (install, script, ...) can only contain strings")
			}
			(*c)[i] = cmd
		}
		return nil
	default:
		return fmt.Errorf("Commands (install, script, ...) can be either a tring or a list of strings")
	}
}

type ConfigMatrix struct {
	Exclude []map[string]interface{} `yaml:"exclude,omitempty"`
}

type YamlTime struct {
	time.Time
}

func (t *YamlTime) UnmarshalYAML(unmarshal func(interface{}) error) error {
	timeAsString := ""
	if err := unmarshal(&timeAsString); err != nil {
		return err
	}
	if len(timeAsString) == 0 {
		return nil
	}

	timeFormats := []string{
		time.ANSIC,
		time.ANSIC,
		time.UnixDate,
		time.RubyDate,
		time.RFC822,
		time.RFC822Z,
		time.RFC850,
		time.RFC1123,
{'fraction_non_alphanumeric': 0.1411035633416756, 'fraction_numerical': 0.003456083899416041, 'mean_word_length': 3.803663423010876, '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': '6225729', 'n_tokens_mistral': 2892, 'n_tokens_neox': 2794, 'n_words': 665}