<commit_before>package stacks

import (
	"fmt"
	"strings"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/cloudformation"
)

// StackExists - Returns true if stack exists in AWS Account
func (s *Stack) StackExists() bool {
	svc := cloudformation.New(s.Session, &aws.Config{Credentials: s.creds()})

	describeStacksInput := &cloudformation.DescribeStacksInput{
		StackName: aws.String(s.Stackname),
	}

	Log.Debug(fmt.Sprintln("Calling [DescribeStacks] with parameters:", describeStacksInput))
	_, err := svc.DescribeStacks(describeStacksInput)

	if err == nil {
		return true
	}

	return false
}

// State - returns complete/failed/pending state of stack
func (s *Stack) State() (string, error) {
	svc := cloudformation.New(s.Session, &aws.Config{Credentials: s.creds()})

	describeStacksInput := &cloudformation.DescribeStacksInput{
		StackName: aws.String(s.Stackname),
	}

	Log.Debug(fmt.Sprintln("Calling [DescribeStacks] with parameters: ", describeStacksInput))
	status, err := svc.DescribeStacks(describeStacksInput)
	if err != nil {
		if strings.Contains(err.Error(), "not exist") {
			return state.pending, nil
		}
		return "", err
	}

	if strings.Contains(strings.ToLower(status.GoString()), "complete") {
		return state.complete, nil
	} else if strings.Contains(strings.ToLower(status.GoString()), "fail") {
		return state.failed, nil
	}
	return "", nil
}<commit_msg>added custom status functions for customer Wait function<commit_after>package stacks

import (
	"fmt"
	"strings"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/cloudformation"
)

// StackExists - Returns true if stack exists in AWS Account, returns false if err when checking
func (s *Stack) StackExists() bool {
	svc := cloudformation.New(s.Session, &aws.Config{Credentials: s.creds()})

	describeStacksInput := &cloudformation.DescribeStacksInput{
		StackName: aws.String(s.Stackname),
	}

	Log.Debug(fmt.Sprintln("Calling [DescribeStacks] with parameters:", describeStacksInput))
	_, err := svc.DescribeStacks(describeStacksInput)

	if err == nil {
		return true
	}

	return false
}

// State - returns complete/failed/pending state of stack
func (s *Stack) State() (string, error) {
	svc := cloudformation.New(s.Session, &aws.Config{Credentials: s.creds()})

	describeStacksInput := &cloudformation.DescribeStacksInput{
		StackName: aws.String(s.Stackname),
	}

	Log.Debug(fmt.Sprintln("Calling [DescribeStacks] with parameters: ", describeStacksInput))
	status, err := svc.DescribeStacks(describeStacksInput)
	if err != nil {
		if strings.Contains(err.Error(), "not exist") {
			return state.pending, nil
		}
		return "", err
	}

	if strings.Contains(strings.ToLower(status.GoString()), "complete") {
		return state.complete, nil
	} else if strings.Contains(strings.ToLower(status.GoString()), "fail") {
		return state.failed, nil
	}
	return "", nil
}

// ChangeSetStatus - returns the literal change-set status
func (s *Stack) ChangeSetStatus(args ...string) (string, error) {
	svc := cloudformation.New(s.Session, &aws.Config{Credentials: s.creds()})

	params := &cloudformation.DescribeChangeSetInput{
		StackName:     aws.String(s.Stackname),
		ChangeSetName: &args[0],
	}

	Log.Debug(fmt.Sprintln("Calling [DescribeChangeSet] with parameters: ", params))
	status, err := svc.DescribeChangeSet(params)
	if err != nil {
		return "", err
	}

	return *status.Status, nil

}

// StackStatus - return the literal stack status
func (s *Stack) StackStatus(args ...string) (string, error) {
	svc := cloudformation.New(s.Session, &aws.Config{Credentials: s.creds()})
	params := &cloudformation.DescribeStacksInput{
		StackName: aws.String(s.Stackname),
	}

	Log.Debug(fmt.Sprintln("Calling [DescribeStacks] with parameters: ", params))
	status, err := svc.DescribeStacks(params)
	if err != nil {
		return "", err
	}

	return *status.Stacks[0].StackStatus, nil
}
{'fraction_non_alphanumeric': 0.14212152420185376, 'fraction_numerical': 0.0005149330587023687, 'mean_word_length': 4.8685800604229605, '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': '1824047', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1287, 'n_words': 285}