diff --git a/models/issues/milestone.go b/models/issues/milestone.go index ffe5c8eb509ba..acad3b28c6e6c 100644 --- a/models/issues/milestone.go +++ b/models/issues/milestone.go @@ -123,6 +123,22 @@ func NewMilestone(m *Milestone) (err error) { return committer.Commit() } +// LoadRepo loads milestones repository +func (m *Milestone) LoadRepo(ctx context.Context) (err error) { + if m.Repo == nil && m.RepoID != 0 { + m.Repo, err = repo_model.GetRepositoryByID(ctx, m.RepoID) + if err != nil { + return fmt.Errorf("getRepositoryByID [%d]: %w", m.RepoID, err) + } + } + return nil +} + +// Link returns the milestone Link +func (m *Milestone) Link() string { + return fmt.Sprintf("%s/milestone/%d", m.Repo.HTMLURL(), m.ID) +} + // HasMilestoneByRepoID returns if the milestone exists in the repository. func HasMilestoneByRepoID(ctx context.Context, repoID, id int64) (bool, error) { return db.GetEngine(ctx).ID(id).Where("repo_id=?", repoID).Exist(new(Milestone)) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index cbb2e20314489..de0439b4273cd 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1554,6 +1554,21 @@ func ViewIssue(ctx *context.Context) { if comment.MilestoneID > 0 && comment.Milestone == nil { comment.Milestone = ghostMilestone } + + if comment.Milestone != nil && comment.Milestone.ID != -1 { + err = comment.Milestone.LoadRepo(ctx) + if err != nil { + ctx.ServerError("LoadMilestoneRepo", err) + return + } + } + if comment.OldMilestone != nil && comment.OldMilestone.ID != -1 { + err = comment.OldMilestone.LoadRepo(ctx) + if err != nil { + ctx.ServerError("LoadMilestoneRepo", err) + return + } + } } else if comment.Type == issues_model.CommentTypeProject { if err = comment.LoadProject(); err != nil { diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 0652198adfd37..6536511729640 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -195,7 +195,15 @@ {{template "shared/user/avatarlink" dict "Context" $.Context "user" .Poster}} {{template "shared/user/authorlink" .Poster}} - {{if gt .OldMilestoneID 0}}{{if gt .MilestoneID 0}}{{$.locale.Tr "repo.issues.change_milestone_at" (.OldMilestone.Name|Escape) (.Milestone.Name|Escape) $createdStr | Safe}}{{else}}{{$.locale.Tr "repo.issues.remove_milestone_at" (.OldMilestone.Name|Escape) $createdStr | Safe}}{{end}}{{else if gt .MilestoneID 0}}{{$.locale.Tr "repo.issues.add_milestone_at" (.Milestone.Name|Escape) $createdStr | Safe}}{{end}} + {{if gt .OldMilestoneID 0}} + {{if gt .MilestoneID 0}} + {{$.locale.Tr "repo.issues.change_milestone_at" (printf `%s` .OldMilestone.Link (.OldMilestone.Name|Escape)) (printf `%s` .Milestone.Link (.Milestone.Name|Escape)) $createdStr | Safe}} + {{else}} + {{$.locale.Tr "repo.issues.remove_milestone_at" (printf `%s` .OldMilestone.Link (.OldMilestone.Name|Escape)) $createdStr | Safe}} + {{end}} + {{else if gt .MilestoneID 0}} + {{$.locale.Tr "repo.issues.add_milestone_at" (printf `%s` .Milestone.Link (.Milestone.Name|Escape)) $createdStr | Safe}} + {{end}} {{else if eq .Type 9}} @@ -209,7 +217,7 @@ {{if eq .Poster.ID .Assignee.ID}} {{$.locale.Tr "repo.issues.remove_self_assignment" $createdStr | Safe}} {{else}} - {{$.locale.Tr "repo.issues.remove_assignee_at" (.Poster.GetDisplayName|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.remove_assignee_at" (printf `%s` .Poster.HomeLink (.Poster.GetDisplayName|Escape)) $createdStr | Safe}} {{end}} {{else}} @@ -219,7 +227,7 @@ {{if eq .Poster.ID .AssigneeID}} {{$.locale.Tr "repo.issues.self_assign_at" $createdStr | Safe}} {{else}} - {{$.locale.Tr "repo.issues.add_assignee_at" (.Poster.GetDisplayName|Escape) $createdStr | Safe}} + {{$.locale.Tr "repo.issues.add_assignee_at" (printf `%s` .Poster.HomeLink (.Poster.GetDisplayName|Escape)) $createdStr | Safe}} {{end}} {{end}} @@ -743,12 +751,12 @@ {{$oldProjectDisplayHtml := "Unknown Project"}} {{if .OldProject}} {{$trKey := printf "projects.type-%d.display_name" .OldProject.Type}} - {{$oldProjectDisplayHtml = printf `%s` ($.locale.Tr $trKey | Escape) (.OldProject.Title | Escape)}} + {{$oldProjectDisplayHtml = printf `%s` .OldProject.Link ($.locale.Tr $trKey | Escape) (.OldProject.Title | Escape)}} {{end}} {{$newProjectDisplayHtml := "Unknown Project"}} {{if .Project}} {{$trKey := printf "projects.type-%d.display_name" .Project.Type}} - {{$newProjectDisplayHtml = printf `%s` ($.locale.Tr $trKey | Escape) (.Project.Title | Escape)}} + {{$newProjectDisplayHtml = printf `%s` .Project.Link ($.locale.Tr $trKey | Escape) (.Project.Title | Escape)}} {{end}} {{if and (gt .OldProjectID 0) (gt .ProjectID 0)}} {{$.locale.Tr "repo.issues.change_project_at" $oldProjectDisplayHtml $newProjectDisplayHtml $createdStr | Safe}}