refactor: clarify GOOS detection (#39620)

Introduce `consts.IsWindows`, now it's clearer to see how Windows build works
This commit is contained in:
wxiaoguang
2026-10-06 08:22:36 +00:00
committed by GitHub
parent 052f660ba5
commit 1065f03454
16 changed files with 44 additions and 37 deletions
+5 -4
View File
@@ -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
+3 -2
View File
@@ -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()