提交 a4698bcf 编写于 作者: J Jingwen Owen Ou

Add hub version to crash report

This adds hub version to crash report. It includes refactoring of hub version to the `version` package for reusability in `commands` package and `github` package.
上级 a5cf30e9
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
"github.com/github/hub/github" "github.com/github/hub/github"
"github.com/github/hub/ui" "github.com/github/hub/ui"
"github.com/github/hub/utils" "github.com/github/hub/utils"
"github.com/github/hub/version"
) )
const ( const (
...@@ -27,15 +28,15 @@ const ( ...@@ -27,15 +28,15 @@ const (
var EnableAutoUpdate = false var EnableAutoUpdate = false
func NewUpdater() *Updater { func NewUpdater() *Updater {
version := os.Getenv("HUB_VERSION") ver := os.Getenv("HUB_VERSION")
if version == "" { if ver == "" {
version = Version ver = version.Version
} }
timestampPath := filepath.Join(os.Getenv("HOME"), ".config", "hub-update") timestampPath := filepath.Join(os.Getenv("HOME"), ".config", "hub-update")
return &Updater{ return &Updater{
Host: github.DefaultGitHubHost(), Host: github.DefaultGitHubHost(),
CurrentVersion: version, CurrentVersion: ver,
timestampPath: timestampPath, timestampPath: timestampPath,
} }
} }
......
package commands package commands
import ( import (
"fmt"
"os" "os"
"github.com/github/hub/git"
"github.com/github/hub/ui" "github.com/github/hub/ui"
"github.com/github/hub/utils" "github.com/github/hub/version"
) )
var Version = "2.2.1"
var cmdVersion = &Command{ var cmdVersion = &Command{
Run: runVersion, Run: runVersion,
Usage: "version", Usage: "version",
...@@ -23,13 +19,6 @@ func init() { ...@@ -23,13 +19,6 @@ func init() {
} }
func runVersion(cmd *Command, args *Args) { func runVersion(cmd *Command, args *Args) {
gitVersion, err := git.Version() ui.Println(version.FullVersion())
utils.Check(err)
ghVersion := fmt.Sprintf("hub version %s", Version)
ui.Println(gitVersion)
ui.Println(ghVersion)
os.Exit(0) os.Exit(0)
} }
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"github.com/github/hub/git" "github.com/github/hub/git"
"github.com/github/hub/ui" "github.com/github/hub/ui"
"github.com/github/hub/utils" "github.com/github/hub/utils"
"github.com/github/hub/version"
) )
const ( const (
...@@ -74,19 +75,31 @@ func report(reportedError error, stack string) { ...@@ -74,19 +75,31 @@ func report(reportedError error, stack string) {
ui.Println(issue.HTMLURL) ui.Println(issue.HTMLURL)
} }
func reportTitleAndBody(reportedError error, stack string) (title, body string, err error) { const crashReportTmpl = "Crash report - %v\n\n" +
message := "Crash report - %v\n\nError (%s): `%v`\n\nStack:\n\n```\n%s\n```\n\nRuntime:\n\n```\n%s\n```\n\n" "Error (%s): `%v`\n\n" +
message += ` "Stack:\n\n```\n%s\n```\n\n" +
"Runtime:\n\n```\n%s\n```\n\n" +
"Version:\n\n```\n%s\n```\n" +
`
# Creating crash report: # Creating crash report:
# #
# This information will be posted as a new issue under jingweno/gh. # This information will be posted as a new issue under github/hub.
# We're NOT including any information about the command that you were executing, # We're NOT including any information about the command that you were executing,
# but knowing a little bit more about it would really help us to solve this problem. # but knowing a little bit more about it would really help us to solve this problem.
# Feel free to modify the title and the description for this issue. # Feel free to modify the title and the description for this issue.
` `
func reportTitleAndBody(reportedError error, stack string) (title, body string, err error) {
errType := reflect.TypeOf(reportedError).String() errType := reflect.TypeOf(reportedError).String()
message = fmt.Sprintf(message, reportedError, errType, reportedError, stack, runtimeInfo()) message := fmt.Sprintf(
crashReportTmpl,
reportedError,
errType,
reportedError,
stack,
runtimeInfo(),
version.FullVersion(),
)
editor, err := NewEditor("CRASH_REPORT", "crash report", message) editor, err := NewEditor("CRASH_REPORT", "crash report", message)
if err != nil { if err != nil {
......
...@@ -41,7 +41,7 @@ up_to_date() { ...@@ -41,7 +41,7 @@ up_to_date() {
build_hub() { build_hub() {
setup_gopath setup_gopath
[ -n "$1" ] && (up_to_date "$1" || go build -ldflags "-X github.com/github/hub/commands.Version `./script/version`" -o "$1") [ -n "$1" ] && (up_to_date "$1" || go build -ldflags "-X github.com/github/hub/version.Version `./script/version`" -o "$1")
} }
test_hub() { test_hub() {
......
...@@ -100,7 +100,7 @@ class Packer ...@@ -100,7 +100,7 @@ class Packer
end end
def parse_version! def parse_version!
content = File.read root_path("commands", "version.go") content = File.read root_path("version", "version.go")
match = /var Version = "(.+)"/.match content match = /var Version = "(.+)"/.match content
raise "Fail to parse Hub version" unless match raise "Fail to parse Hub version" unless match
...@@ -137,7 +137,7 @@ class Packer ...@@ -137,7 +137,7 @@ class Packer
# specifying osarch for Windows # specifying osarch for Windows
# see https://github.com/mitchellh/gox/issues/19#issuecomment-68117016 # see https://github.com/mitchellh/gox/issues/19#issuecomment-68117016
osarch = OS.windows? ? "windows/#{OS.windows_64? ? "amd64" : "386"}" : "" osarch = OS.windows? ? "windows/#{OS.windows_64? ? "amd64" : "386"}" : ""
cmd = "gox -os=#{OS.type} -output=#{output} -ldflags \"-X github.com/github/hub/commands.Version #{release_version}\"" cmd = "gox -os=#{OS.type} -output=#{output} -ldflags \"-X github.com/github/hub/version.Version #{release_version}\""
cmd += " -osarch=#{osarch}" unless osarch.empty? cmd += " -osarch=#{osarch}" unless osarch.empty?
exec!(cmd) exec!(cmd)
end end
......
package version
import (
"fmt"
"github.com/github/hub/git"
"github.com/github/hub/utils"
)
var Version = "2.2.0"
func FullVersion() string {
gitVersion, err := git.Version()
utils.Check(err)
return fmt.Sprintf("%s\nhub version %s", gitVersion, Version)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册