@@ -21,6 +21,7 @@ import (
2121 "code.gitea.io/gitea/modules/optional"
2222 "code.gitea.io/gitea/modules/setting"
2323 api "code.gitea.io/gitea/modules/structs"
24+ "code.gitea.io/gitea/modules/svg"
2425 "code.gitea.io/gitea/modules/timeutil"
2526 "code.gitea.io/gitea/modules/util"
2627
@@ -442,6 +443,30 @@ func (issue *Issue) PatchURL() string {
442443 return ""
443444}
444445
446+ /* the logic should be kept the same as getIssueIcon/getIssueColor in TS code */
447+ func (issue * Issue ) IconHTML (ctx context.Context ) template.HTML {
448+ if issue .IsPull {
449+ if issue .PullRequest == nil { // pull request should be loaded before calling this function
450+ return template .HTML ("No PullRequest" )
451+ }
452+ if issue .IsClosed {
453+ if issue .PullRequest .HasMerged {
454+ return svg .RenderHTML ("octicon-git-merge" , 16 , "text purple" )
455+ }
456+ return svg .RenderHTML ("octicon-git-pull-request-closed" , 16 , "text red" )
457+ }
458+ if issue .PullRequest .IsWorkInProgress (ctx ) {
459+ return svg .RenderHTML ("octicon-git-pull-request-draft" , 16 , "text grey" )
460+ }
461+ return svg .RenderHTML ("octicon-git-pull-request" , 16 , "text green" )
462+ }
463+
464+ if issue .IsClosed {
465+ return svg .RenderHTML ("octicon-issue-closed" , 16 , "text red" )
466+ }
467+ return svg .RenderHTML ("octicon-issue-opened" , 16 , "text green" )
468+ }
469+
445470// State returns string representation of issue status.
446471func (issue * Issue ) State () api.StateType {
447472 if issue .IsClosed {
0 commit comments