github.com/crossplane/upjet@v1.3.0/pkg/common.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package pkg
     6  
     7  import "strings"
     8  
     9  const (
    10  	descriptionSeparator = "."
    11  	TerraformKeyword     = "terraform"
    12  )
    13  
    14  // FilterDescription filters given keyword in description by deleting the whole
    15  // sentence.
    16  func FilterDescription(description, keyword string) string {
    17  	var result []string
    18  	sentences := strings.Split(description, descriptionSeparator)
    19  	for _, s := range sentences {
    20  		if !strings.Contains(strings.ToLower(s), keyword) {
    21  			result = append(result, s)
    22  		}
    23  	}
    24  	if len(result) == 0 {
    25  		return strings.ReplaceAll(strings.ToLower(description), keyword, "provider")
    26  	}
    27  	return strings.Join(result, descriptionSeparator)
    28  }