Skip to content

Commit

Permalink
added push to homerun
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-hermann-sva committed Jan 20, 2025
1 parent dfbe2ce commit bcb5b1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
62 changes: 25 additions & 37 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,57 +238,45 @@ var pushCmd = &cobra.Command{

return allObjects[rand.Intn(len(allObjects))]
},
// "getArtifacts": func(usecaseName string, objects map[string][]string) string {
// rand.Seed(time.Now().UnixNano())
// allObjects := objects[usecaseName]

// allObjectNames := []string{}

// // LOOP OVER USECASES
// for _, usecase := range allObjects {
// objectsplit := strings.Split(usecase, ":")
// allObjectNames = append(allObjectNames, objectsplit[1])
// }

// return allObjectNames[rand.Intn(len(allObjectNames))]
// },
}

fmt.Println(demo.BodyTemplate)

rendered, err := surveys.RenderTemplateInlineWithFunctions(funcMap, demo.BodyTemplate, values)

if err != nil {
log.Fatalf("Failed to render template: %v", err)
}

fmt.Println(string(rendered))
// LOAD ALL QUESTION FILES
// for _, questionFile := range gitConfig.Questions {

// // RENDER QUESTION FILE
// renderedQuestionFilePath, err := sthingsBase.RenderTemplateInline(questionFile, renderOption, brackets[bracketFormat].begin, brackets[bracketFormat].end, allValues)
// if err != nil {
// log.Error("ERROR RENDERING QUESTION FILE: ", err)
// }
// log.Info("LOADING QUESTION FILE: ", string(renderedQuestionFilePath))

// questions, _ := modules.LoadQuestionFile(string(renderedQuestionFilePath))

// if len(questions) > 0 {
// log.Info("LOADED QUESTIONS FROM FILE: ", len(questions))
// } else {
// log.Warn("NO QUESTIONS FOUND IN FILE: ", string(renderedQuestionFilePath))
// }
// CREATE HTTP-Request
req, err := http.NewRequest("POST", destination, bytes.NewBuffer([]byte(rendered)))
if err != nil {
fmt.Println("faiulure at creating requests:", err)
return
}

// allQuestions = append(allQuestions, questions...)
// }
// ADD HEADER
req.Header.Set("Content-Type", contentType)
req.Header.Set("X-Auth-Token", token)

// READ SURVEYS + RUN SURVEYS
// CREATE HTTP-Client + SEND REQUEST
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("error at sending request:", err)
return
}
defer resp.Body.Close()

// RENDER THE FIELDS
// READ THE ANSWER
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("error reading answer:", err)
return
}

// SEND MESSAGE
log.Info("ANSWER STATUS: ", resp.Status)
log.Info("ANSWER BODY: ", string(body))

case "homerun":

Expand Down
10 changes: 5 additions & 5 deletions profiles/homerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ bodyTemplate: |
{{ $author := random .authors }}
{{ $assignee := random .authors }}
{
"System": "{{ .system }}",
"Title": "{{ $usecase }} {{ textBlock .severity $verb .messageTemplates }}",
"Message": "{{ $usecase }}: {{ getObject $usecase .allObjects }} {{ textBlock .severity $verb .messageTemplates }} on System: {{ .system }}",
"Severity": "{{ .severity }}"
"Severity": "{{ .severity }}",
"Author": "{{ $author }}",
"Tags": "{{ .system }},{{ $usecase }}",
"Timestamp": "{{ timestamp }}",
"AssigneeName": "{{ $assignee }}",
"System": "{{ .system }}",
"Tags": "{{ .system }};{{ $usecase }}",
"AssigneeAddress": "{{ getValueFromStringMap $assignee .authorAddresses }}",
"AssigneeName": "{{ $assignee }}",
"Artifacts": "{{ getArtifact $usecase .allArtifacts }}",
"Url": "{{ getArtifact $usecase .allUrls }}",
"Url": "{{ getArtifact $usecase .allUrls }}"
}
messageTemplates:
Expand Down

0 comments on commit bcb5b1b

Please sign in to comment.