-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Load mentionValues asynchronously
#36739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
4a9939a
Lazy-load mentionValues via JSON endpoint instead of inline template
silverwind 01e438c
Address review comments on mention values endpoint and caching
silverwind f642326
Address review: rename to GetMentions, move getMentionableTeams to me…
silverwind b639fcb
Add permission check for mentions endpoint
silverwind 3e9ead2
Use dedicated permission check for mentions endpoint
silverwind f9e8a34
Add org-level mentions endpoint for project pages
silverwind 339be61
Fix mock response in matchMention test
silverwind 6cc1905
always show the @ button
silverwind 448438c
Merge branch 'main' into asyncmention
silverwind dc2117f
Extract shared mention helpers to reduce duplication
silverwind bdb59cc
Add permission check to org mentions endpoint
silverwind 91048f1
Rename reqUnitCommentWriter to reqUnitCommentsReader
silverwind 30bf6e9
Rename reqUnitCommentsReader to reqUnitsWithMentions
silverwind 6d84f78
Merge branch 'main' into asyncmention
silverwind ace6125
Merge branch 'main' into asyncmention
silverwind 059c011
Use util.SliceNilAsEmpty instead of custom ResultOrEmpty method
silverwind ebfcd1c
Merge branch 'main' into asyncmention
silverwind 1447dc9
Pass mentions URL from server via data attribute
silverwind 801127d
Merge branch 'main' into asyncmention
silverwind 2824ead
do not create strange dependencies between unrelated modules
wxiaoguang 186a7e9
do not create strange dependencies between unrelated modules
wxiaoguang 6d5f18c
refactor
wxiaoguang 5ec22c9
fix
wxiaoguang 01da8d2
null safe
wxiaoguang 9870285
comment "markdown preview context path" problem
wxiaoguang af66a12
fine tune error handling
wxiaoguang ffc7841
Merge branch 'main' into asyncmention
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package org | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "code.gitea.io/gitea/models/organization" | ||
| "code.gitea.io/gitea/modules/util" | ||
| shared_mention "code.gitea.io/gitea/routers/web/shared/mention" | ||
| "code.gitea.io/gitea/services/context" | ||
| ) | ||
|
|
||
| // GetMentionsInOwner returns JSON data for mention autocomplete on owner-level pages. | ||
| func GetMentionsInOwner(ctx *context.Context) { | ||
| // for individual users, we don't have a concept of "mentionable" users or teams, so just return an empty list | ||
| if !ctx.ContextUser.IsOrganization() { | ||
| ctx.JSON(http.StatusOK, []shared_mention.Mention{}) | ||
| return | ||
| } | ||
|
|
||
| // for org, return members and teams | ||
| c := shared_mention.NewCollector() | ||
| org := organization.OrgFromUser(ctx.ContextUser) | ||
|
|
||
| // Get org members | ||
| members, _, err := org.GetMembers(ctx, ctx.Doer) | ||
| if err != nil { | ||
| ctx.ServerError("GetMembers", err) | ||
| return | ||
| } | ||
| c.AddUsers(ctx, members) | ||
|
|
||
| // Get mentionable teams | ||
| if err := c.AddMentionableTeams(ctx, ctx.Doer, ctx.ContextUser); err != nil { | ||
| ctx.ServerError("AddMentionableTeams", err) | ||
| return | ||
| } | ||
|
|
||
| ctx.JSON(http.StatusOK, util.SliceNilAsEmpty(c.Result)) | ||
| } | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package repo | ||
|
|
||
| import ( | ||
| "errors" | ||
| "net/http" | ||
|
|
||
| issues_model "code.gitea.io/gitea/models/issues" | ||
| repo_model "code.gitea.io/gitea/models/repo" | ||
| user_model "code.gitea.io/gitea/models/user" | ||
| "code.gitea.io/gitea/modules/util" | ||
| shared_mention "code.gitea.io/gitea/routers/web/shared/mention" | ||
| "code.gitea.io/gitea/services/context" | ||
| ) | ||
|
|
||
| // GetMentionsInRepo returns JSON data for mention autocomplete (assignees, participants, mentionable teams). | ||
| func GetMentionsInRepo(ctx *context.Context) { | ||
| c := shared_mention.NewCollector() | ||
|
|
||
| // Get participants if issue_index is provided | ||
| if issueIndex := ctx.FormInt64("issue_index"); issueIndex > 0 { | ||
| issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, issueIndex) | ||
| if err != nil && !errors.Is(err, util.ErrNotExist) { | ||
| ctx.ServerError("GetIssueByIndex", err) | ||
| return | ||
| } | ||
| if issue != nil { | ||
| userIDs, err := issue.GetParticipantIDsByIssue(ctx) | ||
| if err != nil { | ||
| ctx.ServerError("GetParticipantIDsByIssue", err) | ||
| return | ||
| } | ||
| users, err := user_model.GetUsersByIDs(ctx, userIDs) | ||
| if err != nil { | ||
| ctx.ServerError("GetUsersByIDs", err) | ||
| return | ||
| } | ||
| c.AddUsers(ctx, users) | ||
| } | ||
| } | ||
|
|
||
| // Get repo assignees | ||
| assignees, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository) | ||
| if err != nil { | ||
| ctx.ServerError("GetRepoAssignees", err) | ||
| return | ||
| } | ||
| c.AddUsers(ctx, assignees) | ||
|
|
||
| // Get mentionable teams for org repos | ||
| if err := c.AddMentionableTeams(ctx, ctx.Doer, ctx.Repo.Owner); err != nil { | ||
| ctx.ServerError("AddMentionableTeams", err) | ||
| return | ||
| } | ||
|
|
||
| ctx.JSON(http.StatusOK, util.SliceNilAsEmpty(c.Result)) | ||
| } | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package mention | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "code.gitea.io/gitea/models/organization" | ||
| user_model "code.gitea.io/gitea/models/user" | ||
| ) | ||
|
|
||
| // Mention is the JSON structure returned by mention autocomplete endpoints. | ||
| type Mention struct { | ||
| Key string `json:"key"` | ||
| Value string `json:"value"` | ||
| Name string `json:"name"` | ||
| FullName string `json:"fullname"` | ||
| Avatar string `json:"avatar"` | ||
| } | ||
|
|
||
| // Collector builds a deduplicated list of Mention entries. | ||
| type Collector struct { | ||
| seen map[string]bool | ||
| Result []Mention | ||
| } | ||
|
|
||
| // NewCollector creates a new Collector. | ||
| func NewCollector() *Collector { | ||
| return &Collector{seen: make(map[string]bool)} | ||
| } | ||
|
|
||
| // AddUsers adds user mentions, skipping duplicates. | ||
| func (c *Collector) AddUsers(ctx context.Context, users []*user_model.User) { | ||
| for _, u := range users { | ||
| if !c.seen[u.Name] { | ||
| c.seen[u.Name] = true | ||
| c.Result = append(c.Result, Mention{ | ||
| Key: u.Name + " " + u.FullName, | ||
| Value: u.Name, | ||
| Name: u.Name, | ||
| FullName: u.FullName, | ||
| Avatar: u.AvatarLink(ctx), | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // AddMentionableTeams loads and adds team mentions for the given owner (if it's an org). | ||
| func (c *Collector) AddMentionableTeams(ctx context.Context, doer, owner *user_model.User) error { | ||
| if doer == nil || !owner.IsOrganization() { | ||
| return nil | ||
| } | ||
|
|
||
| org := organization.OrgFromUser(owner) | ||
| isAdmin := doer.IsAdmin | ||
| if !isAdmin { | ||
| var err error | ||
| isAdmin, err = org.IsOwnedBy(ctx, doer.ID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| var teams []*organization.Team | ||
| var err error | ||
| if isAdmin { | ||
| teams, err = org.LoadTeams(ctx) | ||
| } else { | ||
| teams, err = org.GetUserTeams(ctx, doer.ID) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| for _, team := range teams { | ||
| key := owner.Name + "/" + team.Name | ||
| if !c.seen[key] { | ||
| c.seen[key] = true | ||
| c.Result = append(c.Result, Mention{ | ||
| Key: key, | ||
| Value: key, | ||
| Name: key, | ||
| Avatar: owner.AvatarLink(ctx), | ||
| }) | ||
| } | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.