<commit_before>package helpers

import (
	"fmt"

	manifest "github.com/estafette/estafette-ci-manifest"
)

// InjectSteps injects git-clone and build-status steps if not present in manifest
func InjectSteps(mft manifest.EstafetteManifest, builderTrack, gitSource string) (injectedManifest manifest.EstafetteManifest, err error) {

	injectedManifest = mft

	initStepName := "initialize"
	if StepExists(injectedManifest.Stages, initStepName) {
		i := 0
		for StepExists(injectedManifest.Stages, initStepName) {
			initStepName = fmt.Sprintf("initialize-%v", i)
			i++
		}
	}

	initStep := &manifest.EstafetteStage{
		Name:           initStepName,
		ParallelStages: []*manifest.EstafetteStage{},
		AutoInjected:   true,
	}

	if !StepExists(injectedManifest.Stages, "git-clone") {
		initStep.ParallelStages = append(initStep.ParallelStages, &manifest.EstafetteStage{
			Name:           "git-clone",
			ContainerImage: fmt.Sprintf("extensions/git-clone:%v", builderTrack),
			AutoInjected:   true,
		})
	}

	if !StepExists(injectedManifest.Stages, "set-pending-build-status") {
		initStep.ParallelStages = append(initStep.ParallelStages, &manifest.EstafetteStage{
			Name:           "set-pending-build-status",
			ContainerImage: fmt.Sprintf("extensions/%v-status:%v", gitSource, builderTrack),
			CustomProperties: map[string]interface{}{
				"status": "pending",
			},
			AutoInjected: true,
			Retries:      3,
		})
	}
	if !StepExists(injectedManifest.Stages, "envvars") {
		initStep.ParallelStages = append(initStep.ParallelStages, &manifest.EstafetteStage{
			Name:           "envvars",
			ContainerImage: fmt.Sprintf("extensions/envvars:%v", builderTrack),
			AutoInjected:   true,
		})
	}

	if len(initStep.ParallelStages) > 0 {
		injectedManifest.Stages = append([]*manifest.EstafetteStage{initStep}, injectedManifest.Stages...)
	}

	if !StepExists(injectedManifest.Stages, "set-build-status") {
		// add set-build-status at the end if it doesn't exist yet
		setBuildStatusStep := &manifest.EstafetteStage{
			Name:           "set-build-status",
			ContainerImage: fmt.Sprintf("extensions/%v-status:%v", gitSource, builderTrack),
			When:           "status == 'succeeded' || status == 'failed'",
			AutoInjected:   true,
			Retries:        3,
		}
		injectedManifest.Stages = append(injectedManifest.Stages, setBuildStatusStep)<commit_msg>no retries for build status stages<commit_after>package helpers

import (
	"fmt"

	manifest "github.com/estafette/estafette-ci-manifest"
)

// InjectSteps injects git-clone and build-status steps if not present in manifest
func InjectSteps(mft manifest.EstafetteManifest, builderTrack, gitSource string) (injectedManifest manifest.EstafetteManifest, err error) {

	injectedManifest = mft

	initStepName := "initialize"
	if StepExists(injectedManifest.Stages, initStepName) {
		i := 0
		for StepExists(injectedManifest.Stages, initStepName) {
			initStepName = fmt.Sprintf("initialize-%v", i)
			i++
		}
	}

	initStep := &manifest.EstafetteStage{
		Name:           initStepName,
		ParallelStages: []*manifest.EstafetteStage{},
		AutoInjected:   true,
	}

	if !StepExists(injectedManifest.Stages, "git-clone") {
		initStep.ParallelStages = append(initStep.ParallelStages, &manifest.EstafetteStage{
			Name:           "git-clone",
			ContainerImage: fmt.Sprintf("extensions/git-clone:%v", builderTrack),
			AutoInjected:   true,
		})
	}

	if !StepExists(injectedManifest.Stages, "set-pending-build-status") {
		initStep.ParallelStages = append(initStep.ParallelStages, &manifest.EstafetteStage{
			Name:           "set-pending-build-status",
			ContainerImage: fmt.Sprintf("extensions/%v-status:%v", gitSource, builderTrack),
			CustomProperties: map[string]interface{}{
				"status": "pending",
			},
			AutoInjected: true,
		})
	}
	if !StepExists(injectedManifest.Stages, "envvars") {
		initStep.ParallelStages = append(initStep.ParallelStages, &manifest.EstafetteStage{
			Name:           "envvars",
			ContainerImage: fmt.Sprintf("extensions/envvars:%v", builderTrack),
			AutoInjected:   true,
		})
	}

	if len(initStep.ParallelStages) > 0 {
		injectedManifest.Stages = append([]*manifest.EstafetteStage{initStep}, injectedManifest.Stages...)
	}

	if !StepExists(injectedManifest.Stages, "set-build-status") {
		// add set-build-status at the end if it doesn't exist yet
		setBuildStatusStep := &manifest.EstafetteStage{
			Name:           "set-build-status",
			ContainerImage: fmt.Sprintf("extensions/%v-status:%v", gitSource, builderTrack),
			When:           "status == 'succeeded' || status == 'failed'",
			AutoInjected:   true,
		}
		injectedManifest.Stages = append(injectedManifest.Stages, setBuildStatusStep)
{'fraction_non_alphanumeric': 0.12701137095043982, 'fraction_numerical': 0.0012872774082814847, 'mean_word_length': 4.358620689655172, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '7457713', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1519, 'n_words': 272}