Skip to content

Commit

Permalink
commit to feature/add-homerun-survey
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-hermann-sva committed Jan 19, 2025
1 parent 07b637d commit 5b5c5df
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 38 deletions.
42 changes: 30 additions & 12 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ var pushCmd = &cobra.Command{
values["authors"] = authorNames
values["authorAddresses"] = authorAddresses
values["allUsecases"] = demo.Usecases
values["messageTemplates"] = demo.MessageTemplates

fmt.Println(demo.MessageTemplates["INFO"]["run"])

fmt.Println("USECASE", demo.Usecases["gitlab"][1])

Expand All @@ -187,7 +190,6 @@ var pushCmd = &cobra.Command{
return input + " Hello from push"
},
"random": func(input []string) string {
//severities := []string{"INFO", "WARNING", "CRITICAL", "ERROR"}
rand.Seed(time.Now().UnixNano())
return input[rand.Intn(len(input))]
},
Expand All @@ -198,23 +200,39 @@ var pushCmd = &cobra.Command{
"getValueFromStringMap": func(key string, keyValues map[string]string) string {
return keyValues[key]
},
"textBlock": func(severity string, verb string, template map[string]map[string]string) string {
return template[severity][verb]
},
"randomUsecase": func(system string, usecases map[string][]string) string {
//severities := []string{"INFO", "WARNING", "CRITICAL", "ERROR"}
rand.Seed(time.Now().UnixNano())
systemUsecases := usecases[system]
return systemUsecases[rand.Intn(len(systemUsecases))]

allUsecaseNames := []string{}

// LOOP OVER USECASES
for _, usecase := range systemUsecases {
usecasesplit := strings.Split(usecase, ":")
allUsecaseNames = append(allUsecaseNames, usecasesplit[0])
}

return allUsecaseNames[rand.Intn(len(allUsecaseNames))]
},
// "randomFromSlice": func(inputSlice []string) string {
// // Check if the slice is empty
// if len(inputSlice) == 0 {
// return "" // Return empty string if the slice is empty
// }
"getUsecaseVerb": func(usecaseName string, system string, usecases map[string][]string) string {
rand.Seed(time.Now().UnixNano())

verb := "Verb not found for usecase: " + usecaseName
systemUsecases := usecases[system]

// rand.Seed(uint64(time.Now().UnixNano()))
// randomIndex := rand.Intn(len(inputSlice))
// LOOP OVER USECASES
for _, usecase := range systemUsecases {
usecasesplit := strings.Split(usecase, ":")
if usecasesplit[0] == usecaseName {
verb = usecasesplit[1]
}
}

// return inputSlice[randomIndex]
// },
return verb
},
}

fmt.Println(demo.BodyTemplate)
Expand Down
46 changes: 27 additions & 19 deletions profiles/homerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ preSurvey:
name: severity
options:
- "INFO"
- "WARNING"
- "ERROR"
- "SUCCESS"

# surveys:
# - tests/{{ .system }}-survey.yaml
Expand All @@ -22,38 +22,46 @@ aliases:
- "github-survey:git"

bodyTemplate: |
{{ $object := randomUsecase .system .allUsecases }}
{{ $verb := getUsecaseVerb $object .system .allUsecases }}
{{ $author := random .authors }}
{{ $assignee := random .authors }}
{
"System": "{{ .system }}",
{{ $object := randomUsecase .system .allUsecases }}
"Title": "{{ $object }}",
"Title": "{{ $object }} {{ $verb }}",
"Message": "{{ $object }} {{ textBlock .severity $verb .messageTemplates }}",
"Severity": "{{ .severity }}"
{{ $author := random .authors }}
"Author": "{{ $author }}",
"Tags": "{{ random .authors }}",
"Timestamp": "{{ timestamp }}",
{{ $assignee := random .authors }}
"AssigneeName": "{{ $assignee }}",
"AssigneeAddress": "{{ getValueFromStringMap $assignee .authorAddresses }}",
}
messageTemplates:
INFO:
run: "is running"
create: "was created"
ERROR:
run: "did not run successfully"
create: "was not created successfully"
SUCCESS:
run: "did run successfully"
create: "was created successfully"


usecases:
gitlab:
- "PullRequest"
- "PipelineRun"
- "Issue"
- "PullRequest:create"
- "PipelineRun:run"
- "Issue:create"
github:
- "PullRequest"
- "WorflowRun"
- "Issue"
- "MergeRequest:create"
- "WorflowRun:run"
- "Issue:create"
ansible:
- "PlaybookRun"
- "CollecionBuild"

events:
PullRequest:
title: "PullRequest {{ .objectTitle }} was created on {{ .system }}"
message: PullRequest {{ .objectTitle }} was created on {{ .system }} by {{ .author }}

- "PlaybookRun:run"
- "CollecionBuild:run"

authors:
- "mark:mark@blink182.com"
Expand Down
15 changes: 8 additions & 7 deletions surveys/surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ func ReadYAML(filename string, out interface{}) error {

// HomerunDemo REPRESENTS THE STRUCTURE OF THE YAML FILE
type HomerunDemo struct {
Surveys []string `yaml:"surveys"`
Templates []string `yaml:"templates"`
Values []string `yaml:"values"`
Aliases []string `yaml:"aliases"`
BodyTemplate string `yaml:"bodyTemplate"`
Authors []string `yaml:"authors"`
Usecases map[string][]string `yaml:"usecases"`
Surveys []string `yaml:"surveys"`
Templates []string `yaml:"templates"`
Values []string `yaml:"values"`
Aliases []string `yaml:"aliases"`
BodyTemplate string `yaml:"bodyTemplate"`
Authors []string `yaml:"authors"`
Usecases map[string][]string `yaml:"usecases"`
MessageTemplates map[string]map[string]string `yaml:"messageTemplates"`
}

// BUILD THE SURVEY FUNCTION WITH THE NEW RANDOM SETUP
Expand Down

0 comments on commit 5b5c5df

Please sign in to comment.