mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-19 16:18:11 +00:00
refactor: clarify GOOS detection (#39620)
Introduce `consts.IsWindows`, now it's clearer to see how Windows build works
This commit is contained in:
@@ -6,19 +6,20 @@ package user
|
||||
import (
|
||||
"os"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"gitea.dev/modules/consts"
|
||||
)
|
||||
|
||||
// CurrentUsername return current login OS user name
|
||||
// CurrentUsername return current login OS username
|
||||
func CurrentUsername() string {
|
||||
userinfo, err := user.Current()
|
||||
if err != nil {
|
||||
return fallbackCurrentUsername()
|
||||
}
|
||||
username := userinfo.Username
|
||||
if runtime.GOOS == "windows" {
|
||||
parts := strings.Split(username, "\\")
|
||||
if consts.IsWindows {
|
||||
parts := strings.Split(username, "\\") // remove domain if present
|
||||
username = parts[len(parts)-1]
|
||||
}
|
||||
return username
|
||||
|
||||
@@ -5,10 +5,11 @@ package user
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/consts"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -26,7 +27,7 @@ func TestCurrentUsername(t *testing.T) {
|
||||
require.NotEmpty(t, user)
|
||||
|
||||
// Windows whoami is weird, so just skip remaining tests
|
||||
if runtime.GOOS == "windows" {
|
||||
if consts.IsWindows {
|
||||
t.Skip("skipped test because of weird whoami on Windows")
|
||||
}
|
||||
whoami, err := getWhoamiOutput()
|
||||
|
||||
Reference in New Issue
Block a user