Skip to content

Commit 8b2bd6f

Browse files
myitcvbradfitz
authored andcommitted
cmd/go: update go bug to be more consistent with Github issue template
As a result of using go env, the following new environment variables are shown as part of the env section: +CGO_CFLAGS="-g -O2" +CGO_CPPFLAGS="" +CGO_CXXFLAGS="-g -O2" +CGO_FFLAGS="-g -O2" +CGO_LDFLAGS="-g -O2" +PKG_CONFIG="pkg-config" +GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build612849170=/tmp/go-build -gno-record-gcc-switches" The diff between the web-based template and the result of go bug is now: +GOROOT/bin/go version: go version devel +478f3a5384 Wed Mar 27 16:21:00 2019 +0000 linux/amd64 +GOROOT/bin/go tool compile -V: compile version devel +478f3a5384 Wed Mar 27 16:21:00 2019 +0000 +uname -sr: Linux 4.15.0-46-generic +Distributor ID: Ubuntu +Description: Ubuntu 18.04.2 LTS +Release: 18.04 +Codename: bionic +/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1) stable release version 2.27. Fixes #26751 Change-Id: I32baca1c3c06d08068dad0041a43a1f5532bd91e Reviewed-on: https://go-review.googlesource.com/c/go/+/127495 Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Daniel Martí <[email protected]>
1 parent 0a4d352 commit 8b2bd6f

File tree

2 files changed

+80
-51
lines changed

2 files changed

+80
-51
lines changed

src/cmd/go/internal/bug/bug.go

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
"cmd/go/internal/base"
2222
"cmd/go/internal/cfg"
23-
"cmd/go/internal/envcmd"
2423
"cmd/go/internal/web"
2524
)
2625

@@ -44,23 +43,10 @@ func runBug(cmd *base.Command, args []string) {
4443
}
4544
var buf bytes.Buffer
4645
buf.WriteString(bugHeader)
47-
inspectGoVersion(&buf)
48-
fmt.Fprint(&buf, "#### System details\n\n")
49-
fmt.Fprintln(&buf, "```")
50-
fmt.Fprintf(&buf, "go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
51-
env := cfg.CmdEnv
52-
env = append(env, envcmd.ExtraEnvVars()...)
53-
for _, e := range env {
54-
// Hide the TERM environment variable from "go bug".
55-
// See issue #18128
56-
if e.Name != "TERM" {
57-
fmt.Fprintf(&buf, "%s=\"%s\"\n", e.Name, e.Value)
58-
}
59-
}
60-
printGoDetails(&buf)
61-
printOSDetails(&buf)
62-
printCDetails(&buf)
63-
fmt.Fprintln(&buf, "```")
46+
printGoVersion(&buf)
47+
buf.WriteString("### Does this issue reproduce with the latest release?\n\n\n")
48+
printEnvDetails(&buf)
49+
buf.WriteString(bugFooter)
6450

6551
body := buf.String()
6652
url := "https://github.com/golang/go/issues/new?body=" + urlpkg.QueryEscape(body)
@@ -70,22 +56,47 @@ func runBug(cmd *base.Command, args []string) {
7056
}
7157
}
7258

73-
const bugHeader = `Please answer these questions before submitting your issue. Thanks!
59+
const bugHeader = `<!-- Please answer these questions before submitting your issue. Thanks! -->
60+
61+
`
62+
const bugFooter = `### What did you do?
7463
75-
#### What did you do?
64+
<!--
7665
If possible, provide a recipe for reproducing the error.
7766
A complete runnable program is good.
7867
A link on play.golang.org is best.
68+
-->
69+
7970
8071
81-
#### What did you expect to see?
72+
### What did you expect to see?
8273
8374
84-
#### What did you see instead?
8575
76+
### What did you see instead?
8677
8778
`
8879

80+
func printGoVersion(w io.Writer) {
81+
fmt.Fprintf(w, "### What version of Go are you using (`go version`)?\n\n")
82+
fmt.Fprintf(w, "<pre>\n")
83+
fmt.Fprintf(w, "$ go version\n")
84+
printCmdOut(w, "", "go", "version")
85+
fmt.Fprintf(w, "</pre>\n")
86+
fmt.Fprintf(w, "\n")
87+
}
88+
89+
func printEnvDetails(w io.Writer) {
90+
fmt.Fprintf(w, "### What operating system and processor architecture are you using (`go env`)?\n\n")
91+
fmt.Fprintf(w, "<details><summary><code>go env</code> Output</summary><br><pre>\n")
92+
fmt.Fprintf(w, "$ go env\n")
93+
printCmdOut(w, "", "go", "env")
94+
printGoDetails(w)
95+
printOSDetails(w)
96+
printCDetails(w)
97+
fmt.Fprintf(w, "</pre></details>\n\n")
98+
}
99+
89100
func printGoDetails(w io.Writer) {
90101
printCmdOut(w, "GOROOT/bin/go version: ", filepath.Join(runtime.GOROOT(), "bin/go"), "version")
91102
printCmdOut(w, "GOROOT/bin/go tool compile -V: ", filepath.Join(runtime.GOROOT(), "bin/go"), "tool", "compile", "-V")
@@ -132,35 +143,6 @@ func printCDetails(w io.Writer) {
132143
}
133144
}
134145

135-
func inspectGoVersion(w io.Writer) {
136-
data, err := web.GetBytes(&urlpkg.URL{
137-
Scheme: "https",
138-
Host: "golang.org",
139-
Path: "/VERSION",
140-
RawQuery: "?m=text",
141-
})
142-
if err != nil {
143-
if cfg.BuildV {
144-
fmt.Printf("failed to read from golang.org/VERSION: %v\n", err)
145-
}
146-
return
147-
}
148-
149-
// golang.org/VERSION currently returns a whitespace-free string,
150-
// but just in case, protect against that changing.
151-
// Similarly so for runtime.Version.
152-
release := string(bytes.TrimSpace(data))
153-
vers := strings.TrimSpace(runtime.Version())
154-
155-
if vers == release {
156-
// Up to date
157-
return
158-
}
159-
160-
// Devel version or outdated release. Either way, this request is apropos.
161-
fmt.Fprintf(w, "#### Does this issue reproduce with the latest release (%s)?\n\n\n", release)
162-
}
163-
164146
// printCmdOut prints the output of running the given command.
165147
// It ignores failures; 'go bug' is best effort.
166148
func printCmdOut(w io.Writer, prefix, path string, args ...string) {

src/cmd/go/testdata/script/bug.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Verify that go bug creates the appropriate URL issue body
2+
3+
[!linux] skip
4+
5+
go install
6+
env BROWSER=$GOPATH/bin/browser
7+
go bug
8+
exists $TMPDIR/browser
9+
grep '^go version' $TMPDIR/browser
10+
grep '^GOROOT/bin/go version: go version' $TMPDIR/browser
11+
grep '^GOROOT/bin/go tool compile -V: compile version' $TMPDIR/browser
12+
grep '^uname -sr: Linux' $TMPDIR/browser
13+
grep 'GNU C Library' $TMPDIR/browser
14+
15+
-- go.mod --
16+
module browser
17+
18+
-- main.go --
19+
package main
20+
21+
import (
22+
"fmt"
23+
"net/url"
24+
"os"
25+
"path/filepath"
26+
)
27+
28+
func main() {
29+
u, err := url.Parse(os.Args[1])
30+
if err != nil {
31+
panic(err)
32+
}
33+
body, err := url.PathUnescape(u.Query().Get("body"))
34+
if err != nil {
35+
panic(err)
36+
}
37+
out := filepath.Join(os.TempDir(), "browser")
38+
f, err := os.Create(out)
39+
if err != nil {
40+
panic(err)
41+
}
42+
fmt.Fprintln(f, body)
43+
if err := f.Close(); err != nil {
44+
panic(err)
45+
}
46+
}
47+

0 commit comments

Comments
 (0)