提交 f6bc4d73 编写于 作者: M Mislav Marohnić

Avoid using `user.Current()` during OAuth process

Detect current username without resorting to cgo
上级 9048d4fb
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"io" "io"
"net/url" "net/url"
"os" "os"
"os/user" "os/exec"
"strings" "strings"
"github.com/octokit/go-octokit/octokit" "github.com/octokit/go-octokit/octokit"
...@@ -697,12 +697,21 @@ func warnExistenceOfRepo(project *Project, ee error) (err error) { ...@@ -697,12 +697,21 @@ func warnExistenceOfRepo(project *Project, ee error) (err error) {
} }
func authTokenNote(num int) (string, error) { func authTokenNote(num int) (string, error) {
u, err := user.Current() n := os.Getenv("USER")
if err != nil {
return "", err if n == "" {
n = os.Getenv("USERNAME")
}
if n == "" {
whoami := exec.Command("whoami")
whoamiOut, err := whoami.Output()
if err != nil {
return "", err
}
n = strings.TrimSpace(string(whoamiOut))
} }
n := u.Username
h, err := os.Hostname() h, err := os.Hostname()
if err != nil { if err != nil {
return "", err return "", err
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册