[PR #4930] [MERGED] Use native go method to get current user rather than environment variable #17554

Closed
opened 2025-11-02 14:01:26 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-gitea/gitea/pull/4930
Author: @SagePtr
Created: 9/13/2018
Status: Merged
Merged: 10/18/2018
Merged by: @lunny

Base: masterHead: golang-currentuser


📝 Commits (4)

  • 70a9f4d Use native go method to get current user rather than environment var
  • 02b4617 Use t.Skip instead of return in test
  • e8d104a Merge branch 'master' into golang-currentuser
  • 1ea5eea Merge branch 'master' into golang-currentuser

📊 Changes

2 files changed (+48 additions, -10 deletions)

View changed files

📝 modules/user/user.go (+20 -1)
📝 modules/user/user_test.go (+28 -9)

📄 Description

Fixes #1640, #4894

Native "os/user" go package has good function to retrieve current user, rather than relying on USER environment variable.

If getting current user doesn't work on target OS (for example, not yet implemented for it) - it falls back to old implementation with environment variables.

Unit test also changed, old one won't work because USER environment variable spoofing doesn't work anymore (unless os/user is not implemented for OS under which tests are run), now it just compares CurrentUser() with whoami command output (skipped on Windows where whoami behaves different way).

For Windows OS with "domain\username" format, only second part (username) is returned to match previous behavior and trim unnecessary prefix.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-gitea/gitea/pull/4930 **Author:** [@SagePtr](https://github.com/SagePtr) **Created:** 9/13/2018 **Status:** ✅ Merged **Merged:** 10/18/2018 **Merged by:** [@lunny](https://github.com/lunny) **Base:** `master` ← **Head:** `golang-currentuser` --- ### 📝 Commits (4) - [`70a9f4d`](https://github.com/go-gitea/gitea/commit/70a9f4dffda9bad7644e32309a964629984a2d86) Use native go method to get current user rather than environment var - [`02b4617`](https://github.com/go-gitea/gitea/commit/02b461735acb6d4780ec0ab7e34b9147a6b67d07) Use t.Skip instead of return in test - [`e8d104a`](https://github.com/go-gitea/gitea/commit/e8d104a7580b8b6feb4497e302f256ffd6d7470e) Merge branch 'master' into golang-currentuser - [`1ea5eea`](https://github.com/go-gitea/gitea/commit/1ea5eea9ab3da46d10665ee211585df393626d03) Merge branch 'master' into golang-currentuser ### 📊 Changes **2 files changed** (+48 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `modules/user/user.go` (+20 -1) 📝 `modules/user/user_test.go` (+28 -9) </details> ### 📄 Description Fixes #1640, #4894 Native "os/user" go package has good function to retrieve current user, rather than relying on USER environment variable. If getting current user doesn't work on target OS (for example, not yet implemented for it) - it falls back to old implementation with environment variables. Unit test also changed, old one won't work because USER environment variable spoofing doesn't work anymore (unless os/user is not implemented for OS under which tests are run), now it just compares CurrentUser() with `whoami` command output (skipped on Windows where whoami behaves different way). For Windows OS with "domain\username" format, only second part (username) is returned to match previous behavior and trim unnecessary prefix. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-02 14:01:26 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#17554