Repository navigation
Add GetAuthenticatedUser to the Forge interface - #197
Open
abhinavgautam01 wants to merge 2 commits into
Open
abhinavgautam01 wants to merge 2 commits into
abhinavgautam01 wants to merge 2 commits into
Conversation
andrew
requested changes
Nov 1, 2026
andrew
left a comment
Contributor
There was a problem hiding this comment.
Thanks, the shape is right and the per-backend tests are thorough. Two changes before merging.
Contributor
Author
|
Thanks! Both changes are pushed: Gitea errors go through |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #47
Summary
Adds
GetAuthenticatedUser(ctx) (*forge.User, error)to theForgeinterface. It returns the profile of the user the client's token belongs to. This lets apps that sign users in with OAuth show the user's username, name, avatar and email without calling each forge's API themselves.It returns the existing
forge.Usertype, so there are no new types.Per-backend behaviour
GET /userLogin,Name,Email,AvatarURL,HTMLURLGET /api/v4/userLogin,Name,Email,AvatarURL,HTMLURLGET /api/v1/userLogin,Name,Email,AvatarURL,HTMLURLGET /2.0/userLogin,Name,AvatarURL,HTMLURLGET /accounts/self(/a/accounts/selfwhen a token is set)Login,Name,EmailErrNotSupportedErrNotSupportederrorNotes:
Emailis left empty because Bitbucket only returns email addresses from the separate/user/emailsendpoint.GetMyUserInfo, the same way the other Gitea services call the SDK. The SDK call takes no context.Compatibility
This adds a method to the
Forgeinterface, so code outside this repo that implementsForgeneeds to add it, the same as whenGetRateLimitwas added. The in-repo mocks inforges_test.goandinternal/cli/pr_checkout_test.goare updated.Tests
forge.User. The GitLab, Gitea, Bitbucket and Gerrit tests also check that the token is sent in that forge's auth header.ErrNotSupported.TestTinyGoServicesReturnUnsupportednow coversGetAuthenticatedUser.go test -race ./...,go test -tags=tinygo ./gitlab, the js/wasm and wasip1 builds andgolangci-lintv2.14.0 all pass locally.