* INFRA-3703 : Houston side changes to accomodate QA use case * INFRA-3703 : UT failure fix * INFRA-3703 : Minor changes * INFRA-3703 : Unique constraint * INFRA-3703 : Edit migration file * INFRA-3703 : PR review comments and UT's * INFRA-3703 : Channel name resolution
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/spf13/viper"
|
|
envUtil "houston/common/util/env"
|
|
"strconv"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
func getBotNameFromEnv() string {
|
|
env := viper.GetString("env")
|
|
appName := viper.GetString(envUtil.APP_NAME)
|
|
if env == "prod" {
|
|
if appName == envUtil.QA_APP_NAME {
|
|
return "qa-tracker"
|
|
}
|
|
return "houston"
|
|
} else if env == "qa" {
|
|
if appName == envUtil.QA_APP_NAME {
|
|
return "np-qa-tracker"
|
|
}
|
|
return "test-issue"
|
|
}
|
|
|
|
return "dev-issue"
|
|
}
|
|
|
|
func getTruncatedTitle(title string) string {
|
|
builder := strings.Builder{}
|
|
truncatedTitleLengthLimit := viper.GetInt("TRUNCATED_TITLE_LENGTH_LIMIT")
|
|
|
|
for _, char := range title {
|
|
if len(builder.String()) >= truncatedTitleLengthLimit {
|
|
break
|
|
}
|
|
if unicode.IsLetter(char) {
|
|
builder.WriteRune(unicode.ToLower(char))
|
|
} else if unicode.IsDigit(char) || char == '-' {
|
|
builder.WriteRune(char)
|
|
} else if unicode.IsSpace(char) {
|
|
builder.WriteRune('-')
|
|
}
|
|
}
|
|
|
|
return builder.String()
|
|
}
|
|
|
|
func ConstructIncidentChannelName(incidentId uint, severityId uint, status string, title string) string {
|
|
var severityStatusPrefix string
|
|
var channelPrefix = "_"
|
|
switch status {
|
|
case "Investigating", "Identified":
|
|
severityStatusPrefix = "i"
|
|
case "Monitoring":
|
|
severityStatusPrefix = "m"
|
|
case "Resolved":
|
|
severityStatusPrefix = "r"
|
|
case "Duplicated":
|
|
severityStatusPrefix = "rd"
|
|
}
|
|
return fmt.Sprintf(
|
|
"%s%s%d-%s-%s-%s",
|
|
channelPrefix, severityStatusPrefix, severityId-1,
|
|
strconv.Itoa(int(incidentId)), getBotNameFromEnv(), getTruncatedTitle(title),
|
|
)
|
|
}
|