New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bug command #921
Merged
Merged
Add bug command #921
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,13 @@ | ||
### What version of Traefik are you using (`traefik version`)? | ||
|
||
|
||
### What is your environment & configuration (arguments, toml...)? | ||
|
||
|
||
### What did you do? | ||
|
||
|
||
### What did you expect to see? | ||
|
||
|
||
### What did you see instead? |
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,110 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/containous/flaeg" | ||
"github.com/mvdan/xurls" | ||
"net/url" | ||
"os/exec" | ||
"regexp" | ||
"runtime" | ||
"text/template" | ||
) | ||
|
||
var ( | ||
bugtracker = "https://github.com/containous/traefik/issues/new" | ||
bugTemplate = `### What version of Traefik are you using? | ||
` + "```" + ` | ||
{{.Version}} | ||
` + "```" + ` | ||
|
||
### What is your environment & configuration (arguments, toml...)? | ||
` + "```" + ` | ||
{{.Configuration}} | ||
` + "```" + ` | ||
|
||
### What did you do? | ||
|
||
|
||
### What did you expect to see? | ||
|
||
|
||
### What did you see instead? | ||
` | ||
) | ||
|
||
// NewBugCmd builds a new Bug command | ||
func NewBugCmd(traefikConfiguration interface{}, traefikPointersConfiguration interface{}) *flaeg.Command { | ||
|
||
//version Command init | ||
return &flaeg.Command{ | ||
Name: "bug", | ||
Description: `Report an issue on Traefik bugtracker`, | ||
Config: traefikConfiguration, | ||
DefaultPointersConfig: traefikPointersConfiguration, | ||
Run: func() error { | ||
var version bytes.Buffer | ||
if err := getVersionPrint(&version); err != nil { | ||
return err | ||
} | ||
|
||
tmpl, err := template.New("").Parse(bugTemplate) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
configJSON, err := json.MarshalIndent(traefikConfiguration, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
v := struct { | ||
Version string | ||
Configuration string | ||
}{ | ||
Version: version.String(), | ||
Configuration: anonymize(string(configJSON)), | ||
} | ||
|
||
var bug bytes.Buffer | ||
if err := tmpl.Execute(&bug, v); err != nil { | ||
return err | ||
} | ||
|
||
body := bug.String() | ||
url := bugtracker + "?body=" + url.QueryEscape(body) | ||
if err := openBrowser(url); err != nil { | ||
fmt.Print("Please file a new issue at " + bugtracker + " using this template:\n\n") | ||
fmt.Print(body) | ||
} | ||
|
||
return nil | ||
}, | ||
Metadata: map[string]string{ | ||
"parseAllSources": "true", | ||
}, | ||
} | ||
} | ||
|
||
func openBrowser(url string) error { | ||
var err error | ||
switch runtime.GOOS { | ||
case "linux": | ||
err = exec.Command("xdg-open", url).Start() | ||
case "windows": | ||
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() | ||
case "darwin": | ||
err = exec.Command("open", url).Start() | ||
default: | ||
err = fmt.Errorf("unsupported platform") | ||
} | ||
return err | ||
} | ||
|
||
func anonymize(input string) string { | ||
replace := "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
mailExp := regexp.MustCompile(`\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3}"`) | ||
return xurls.Relaxed.ReplaceAllString(mailExp.ReplaceAllString(input, replace), replace) | ||
} |
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,62 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/containous/flaeg" | ||
"github.com/containous/traefik/version" | ||
"io" | ||
"os" | ||
"runtime" | ||
"text/template" | ||
) | ||
|
||
var versionTemplate = `Version: {{.Version}} | ||
Codename: {{.Codename}} | ||
Go version: {{.GoVersion}} | ||
Built: {{.BuildTime}} | ||
OS/Arch: {{.Os}}/{{.Arch}}` | ||
|
||
// NewVersionCmd builds a new Version command | ||
func NewVersionCmd() *flaeg.Command { | ||
|
||
//version Command init | ||
return &flaeg.Command{ | ||
Name: "version", | ||
Description: `Print version`, | ||
Config: struct{}{}, | ||
DefaultPointersConfig: struct{}{}, | ||
Run: func() error { | ||
if err := getVersionPrint(os.Stdout); err != nil { | ||
return err | ||
} | ||
fmt.Printf("\n") | ||
return nil | ||
|
||
}, | ||
} | ||
} | ||
|
||
func getVersionPrint(wr io.Writer) error { | ||
tmpl, err := template.New("").Parse(versionTemplate) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
v := struct { | ||
Version string | ||
Codename string | ||
GoVersion string | ||
BuildTime string | ||
Os string | ||
Arch string | ||
}{ | ||
Version: version.Version, | ||
Codename: version.Codename, | ||
GoVersion: runtime.Version(), | ||
BuildTime: version.BuildDate, | ||
Os: runtime.GOOS, | ||
Arch: runtime.GOARCH, | ||
} | ||
|
||
return tmpl.Execute(wr, v) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could print a link to click on that would "pre-populate" stuff for it though right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you seen https://github.com/containous/traefik/pull/921/files/ae4773f7e6abc3da20673740903827eb6ab8deb3#diff-bef061fb576c06749b26aebf8b9f5e5fR79 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😝