-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
382 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" | ||
debuginfo "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/debug" | ||
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/github" | ||
"github.com/kubeshop/testkube/pkg/ui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCreateTicketCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "create-ticket", | ||
Short: "Create bug ticket", | ||
Long: "Create an issue of type bug in the Testkube repository", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
client, _ := common.GetClient(cmd) | ||
debug, err := debuginfo.GetDebugInfo(client) | ||
ui.ExitOnError("get debug info", err) | ||
ui.ExitOnError("opening GitHub ticket", github.OpenTicket(debug)) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package github | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"html/template" | ||
|
||
prShared "github.com/cli/cli/v2/pkg/cmd/pr/shared" | ||
"github.com/cli/cli/v2/utils" | ||
"github.com/kubeshop/testkube/pkg/api/v1/testkube" | ||
"github.com/kubeshop/testkube/pkg/ui" | ||
"github.com/skratchdot/open-golang/open" | ||
) | ||
|
||
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 !utils.ValidURL(openURL) { | ||
return fmt.Errorf("cannot open in browser: maximum URL length exceeded") | ||
} | ||
|
||
ui.Info(fmt.Sprintf("Opening %s in your browser.\n", utils.DisplayURL(openURL))) | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package github | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kubeshop/testkube/pkg/api/v1/testkube" | ||
) | ||
|
||
func TestBuildTicket(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
debugInfo testkube.DebugInfo | ||
wantTitle string | ||
wantBody string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Empty DebugInfo", | ||
debugInfo: testkube.DebugInfo{}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Debug info populated", | ||
debugInfo: testkube.DebugInfo{ | ||
ClientVersion: "v0.test", | ||
ServerVersion: "v1.test", | ||
ClusterVersion: "v2.test", | ||
ApiLogs: []string{"api logline1", "api logline2"}, | ||
OperatorLogs: []string{"operator logline1", "operator logline2", "operator logline3"}, | ||
ExecutionLogs: map[string][]string{ | ||
"execution1": {"execution logline1"}, | ||
"execution2": {"execution logline1", "execution logline2"}, | ||
}, | ||
}, | ||
wantTitle: "New bug report", | ||
wantBody: ` | ||
**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: v0.test | ||
- Testkube API server version: v1.test | ||
- Kubernetes cluster version: v2.test | ||
**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. | ||
`, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotTitle, gotBody, err := buildTicket(tt.debugInfo) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("BuildTicket() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if gotTitle != tt.wantTitle { | ||
t.Errorf("BuildTicket() title = %v, want %v", gotTitle, tt.wantTitle) | ||
} | ||
if gotBody != tt.wantBody { | ||
t.Errorf("BuildTicket() body = %v, want %v", gotBody, tt.wantBody) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## kubectl-testkube debug create-ticket | ||
|
||
Create bug ticket | ||
|
||
### Synopsis | ||
|
||
Create an issue of type bug in the Testkube repository | ||
|
||
``` | ||
kubectl-testkube debug create-ticket [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for info | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-a, --api-uri string api uri, default value read from config if set (default "http://localhost:8088") | ||
-c, --client string client used for connecting to Testkube API one of proxy|direct (default "proxy") | ||
--namespace string Kubernetes namespace, default value read from config if set (default "testkube") | ||
--oauth-enabled enable oauth | ||
--telemetry-enabled enable collection of anonumous telemetry data | ||
--verbose show additional debug messages | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubectl-testkube](kubectl-testkube.md) - Testkube entrypoint for kubectl plugin | ||
* [kubectl-testkube debug](kubectl-testkube_debug.md) - Debug Testkube |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.