Skip to content

Commit

Permalink
Show bot label next to username when rendering autor link if the us…
Browse files Browse the repository at this point in the history
…er is a bot (#24943)

If the user is a bot, we'll add a label next to the author link that
says `bot`. I didn't localize `bot` because passing `locale` into the
`autorlink` template would require changing all calls.

# Example
`yardenshoham` is a bot.
## Before

![image](https://github.com/go-gitea/gitea/assets/20454870/77390780-b763-4f0f-b358-bbccdbf17a5d)

## After

![image](https://github.com/go-gitea/gitea/assets/20454870/72af342f-ee76-4337-95ad-4ecaba853fed)

---------

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
  • Loading branch information
yardenshoham authored May 26, 2023
1 parent 85fa954 commit abccb86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ func (u *User) IsIndividual() bool {
return u.Type == UserTypeIndividual
}

// IsBot returns whether or not the user is of type bot
func (u *User) IsBot() bool {
return u.Type == UserTypeBot
}

// DisplayName returns full name if it's not empty,
// returns username otherwise.
func (u *User) DisplayName() string {
Expand Down
2 changes: 1 addition & 1 deletion templates/shared/user/authorlink.tmpl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<a class="author text black gt-font-semibold muted"{{if gt .ID 0}} href="{{.HomeLink}}"{{end}}>{{.GetDisplayName}}</a>
<a class="author text black gt-font-semibold muted"{{if gt .ID 0}} href="{{.HomeLink}}"{{end}}>{{.GetDisplayName}}</a>{{if .IsBot}}<span class="ui basic label gt-p-2">bot</span>{{end}}

0 comments on commit abccb86

Please sign in to comment.