-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
bug_report.go
62 lines (50 loc) · 1.59 KB
/
bug_report.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
package cmd
import (
"bytes"
"fmt"
"net/url"
"github.com/spf13/cobra"
)
func newBugReportCmd() *cobra.Command {
return &cobra.Command{
Use: "bug-report",
Short: "Submit a bug report at GitHub",
Long: "bug-report opens the default browser to start a bug report which will include useful system information.",
Example: " gup bug-report",
Run: func(cmd *cobra.Command, args []string) {
OsExit(bugReport(cmd, args, openBrowser))
},
}
}
// openBrowserFunc is a function that opens a browser to the specified URL.
type openBrowserFunc func(string) bool
// bugReport opens the default browser to start a bug report which will include useful system information.
func bugReport(cmd *cobra.Command, _ []string, openBrowser openBrowserFunc) int { //nolint
var buf bytes.Buffer
const (
description = `## Description (About the problem)
A clear description of the bug encountered.
`
toReproduce = `## Steps to reproduce
Steps to reproduce the bug.
`
expectedBehavior = `## Expected behavior
Expected behavior.
`
additionalDetails = `## Additional details**
Any other useful data to share.
`
)
buf.WriteString(fmt.Sprintf("## gup version\n%s\n\n", cmd.Version))
buf.WriteString(description)
buf.WriteString(toReproduce)
buf.WriteString(expectedBehavior)
buf.WriteString(additionalDetails)
body := buf.String()
url := "https://github.com/nao1215/gup/issues/new?title=[Bug Report] Title&body=" + url.QueryEscape(body)
if !openBrowser(url) {
fmt.Print("Please file a new issue at https://github.com/nao1215/gup/issues/new using this template:\n\n")
fmt.Print(body)
}
return 0
}