-
Notifications
You must be signed in to change notification settings - Fork 130
/
issue.go
91 lines (73 loc) · 2.36 KB
/
issue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package github
import (
"bytes"
"errors"
"fmt"
"html/template"
prShared "github.com/cli/cli/v2/pkg/cmd/pr/shared"
"github.com/skratchdot/open-golang/open"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/ui"
)
const (
BaseURL = "https://github.com/kubeshop/testkube/issues/new"
BugType = "bug 🐛"
Template = `
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Run '...'
2. Specify '...'
3. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Version / Cluster**
- Testkube CLI version: {{ .ClientVersion }}
- Testkube API server version: {{ .ServerVersion }}
- Kubernetes cluster version: {{ .ClusterVersion }}
**Screenshots**
If applicable, add CLI commands/output to help explain your problem.
**Additional context**
Add any other context about the problem here.
Attach the output of the **testkube debug info** command to provide more details.
`
)
// OpenTicket opens up a browser to create a Bug issue in the Testkube GitHub repository
func OpenTicket(d testkube.DebugInfo) error {
title, body, err := buildTicket(d)
if err != nil {
return fmt.Errorf("could not build issue: %w", err)
}
issue := prShared.IssueMetadataState{
Type: prShared.IssueMetadata,
Body: body,
Title: title,
Labels: []string{BugType},
}
openURL, err := prShared.WithPrAndIssueQueryParams(nil, nil, BaseURL, issue)
if err != nil {
return err
}
if !prShared.ValidURL(openURL) {
return fmt.Errorf("cannot open in browser: maximum URL length exceeded")
}
ui.Info(fmt.Sprintf("Opening %s in your browser.\n", BaseURL))
return open.Start(openURL)
}
// buildTicket builds up the title and the body of the ticket, completing the version numbers with data from the environment
func buildTicket(d testkube.DebugInfo) (string, string, error) {
if d.ClientVersion == "" || d.ClusterVersion == "" {
return "", "", errors.New("client version and cluster version must be populated to create debug message")
}
t, err := template.New("debug").Parse(Template)
if err != nil {
return "", "", fmt.Errorf("cannot create template: %w", err)
}
var result bytes.Buffer
err = t.Execute(&result, d)
if err != nil {
return "", "", fmt.Errorf("cannot parse template: %w", err)
}
return "New bug report", result.String(), nil
}