<commit_before>package commands

import (
	"fmt"
	"log"
	"net/url"

	"github.com/concourse/atc"
	"github.com/concourse/fly/atcclient"
	"github.com/concourse/fly/rc"
)

type ChecklistCommand struct {
	Pipeline string `short:"p" long:"pipeline" required:"true" description:"The pipeline from which to generate the Checkfile"`
}

func (command *ChecklistCommand) Execute([]string) error {
	connection, err := rc.TargetConnection(Fly.Target)
	if err != nil {
		log.Fatalln(err)
	}

	pipelineName := command.Pipeline

	client := atcclient.NewClient(connection)
	config, _, _, err := client.PipelineConfig(pipelineName)
	if err != nil {
		log.Fatalln(err)
	}

	printCheckfile(pipelineName, config, newTarget(connection.URL()))

	return nil
}

func printCheckfile(pipelineName string, config atc.Config, au target) {
	for _, group := range config.Groups {
		printGroup(pipelineName, group, au)
	}

	miscJobs := orphanedJobs(config)
	if len(miscJobs) > 0 {
		printGroup(pipelineName, atc.GroupConfig{Name: "misc", Jobs: miscJobs}, au)
	}
}

func printGroup(pipelineName string, group atc.GroupConfig, au target) {
	fmt.Printf("#- %s\n", group.Name)
	for _, job := range group.Jobs {
		fmt.Printf("%s: concourse.check %s %s %s %s %s\n", job, au.url, au.username, au.password, pipelineName, job)
	}
	fmt.Println("")
}

func orphanedJobs(config atc.Config) []string {
	allJobNames := map[string]struct{}{}
	for _, jobConfig := range config.Jobs {
		allJobNames[jobConfig.Name] = struct{}{}
	}

	for _, group := range config.Groups {
		for _, job := range group.Jobs {
			delete(allJobNames, job)
		}
	}

	result := make([]string, 0, len(config.Jobs))
	for job := range allJobNames {
		result = append(result, job)
	}

	return result
}

type target struct {
	url      string
	username string
	password string
}

func newTarget(rawTarget string) target {
	u, err := url.Parse(rawTarget)
	if err != nil {
		log.Fatalln("invalid target '%s': %s\n", rawTarget, err.Error())
	}

	var username, password string
	if user := u.User; user != nil {
		username = u.User.Username()
		password, _ = u.User.Password()
	}
	u.User = nil
	url := u.String()

	return target{
		url:      url,
		username: username,
		password: password,
	}
}<commit_msg>generated Checkfiles do not include credentials<commit_after>package commands

import (
	"fmt"
	"log"

	"github.com/concourse/atc"
	"github.com/concourse/fly/atcclient"
	"github.com/concourse/fly/rc"
)

type ChecklistCommand struct {
	Pipeline string `short:"p" long:"pipeline" required:"true" description:"The pipeline from which to generate the Checkfile"`
}

func (command *ChecklistCommand) Execute([]string) error {
	connection, err := rc.TargetConnection(Fly.Target)
	if err != nil {
		log.Fatalln(err)
	}

	pipelineName := command.Pipeline

	client := atcclient.NewClient(connection)
	config, _, _, err := client.PipelineConfig(pipelineName)
	if err != nil {
		log.Fatalln(err)
	}

	printCheckfile(pipelineName, config, connection.URL())

	return nil
}

func printCheckfile(pipelineName string, config atc.Config, url string) {
	for _, group := range config.Groups {
		printGroup(pipelineName, group, url)
	}

	miscJobs := orphanedJobs(config)
	if len(miscJobs) > 0 {
		printGroup(pipelineName, atc.GroupConfig{Name: "misc", Jobs: miscJobs}, url)
	}
}

func printGroup(pipelineName string, group atc.GroupConfig, url string) {
	fmt.Printf("#- %s\n", group.Name)
	for _, job := range group.Jobs {
		fmt.Printf("%s: concourse.check %s %s %s\n", job, url, pipelineName, job)
	}
	fmt.Println("")
}

func orphanedJobs(config atc.Config) []string {
	allJobNames := map[string]struct{}{}
	for _, jobConfig := range config.Jobs {
		allJobNames[jobConfig.Name] = struct{}{}
	}

	for _, group := range config.Groups {
		for _, job := range group.Jobs {
			delete(allJobNames, job)
		}
	}

	result := make([]string, 0, len(config.Jobs))
	for job := range allJobNames {
		result = append(result, job)
	}

	return result
}
{'fraction_non_alphanumeric': 0.1424581005586592, 'fraction_numerical': 0.001015744032503809, 'mean_word_length': 4.395890410958904, 'pattern_counts': {'":': 0, '<': 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': '5356222', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1379, 'n_words': 332}