Skip to content

Commit

Permalink
Avoid using user.Current() during OAuth process
Browse files Browse the repository at this point in the history
Detect current username without resorting to cgo
  • Loading branch information
mislav committed Jan 22, 2016
1 parent 9048d4f commit f6bc4d7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
"net/url"
"os"
"os/user"
"os/exec"
"strings"

"github.com/octokit/go-octokit/octokit"
Expand Down Expand Up @@ -697,12 +697,21 @@ func warnExistenceOfRepo(project *Project, ee error) (err error) {
}

func authTokenNote(num int) (string, error) {
u, err := user.Current()
if err != nil {
return "", err
n := os.Getenv("USER")

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()
if err != nil {
return "", err
Expand Down

0 comments on commit f6bc4d7

Please sign in to comment.