diff options
Diffstat (limited to 'routers/web/feed/convert.go')
-rw-r--r-- | routers/web/feed/convert.go | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/routers/web/feed/convert.go b/routers/web/feed/convert.go index 978469d125..e16c54b8d8 100644 --- a/routers/web/feed/convert.go +++ b/routers/web/feed/convert.go @@ -12,7 +12,7 @@ import ( "strconv" "strings" - "code.gitea.io/gitea/models" + activities_model "code.gitea.io/gitea/models/activities" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" @@ -23,33 +23,33 @@ import ( "github.com/gorilla/feeds" ) -func toBranchLink(act *models.Action) string { +func toBranchLink(act *activities_model.Action) string { return act.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(act.GetBranch()) } -func toTagLink(act *models.Action) string { +func toTagLink(act *activities_model.Action) string { return act.GetRepoLink() + "/src/tag/" + util.PathEscapeSegments(act.GetTag()) } -func toIssueLink(act *models.Action) string { +func toIssueLink(act *activities_model.Action) string { return act.GetRepoLink() + "/issues/" + url.PathEscape(act.GetIssueInfos()[0]) } -func toPullLink(act *models.Action) string { +func toPullLink(act *activities_model.Action) string { return act.GetRepoLink() + "/pulls/" + url.PathEscape(act.GetIssueInfos()[0]) } -func toSrcLink(act *models.Action) string { +func toSrcLink(act *activities_model.Action) string { return act.GetRepoLink() + "/src/" + util.PathEscapeSegments(act.GetBranch()) } -func toReleaseLink(act *models.Action) string { +func toReleaseLink(act *activities_model.Action) string { return act.GetRepoLink() + "/releases/tag/" + util.PathEscapeSegments(act.GetBranch()) } // renderMarkdown creates a minimal markdown render context from an action. // If rendering fails, the original markdown text is returned -func renderMarkdown(ctx *context.Context, act *models.Action, content string) string { +func renderMarkdown(ctx *context.Context, act *activities_model.Action, content string) string { markdownCtx := &markup.RenderContext{ Ctx: ctx, URLPrefix: act.GetRepoLink(), @@ -67,7 +67,7 @@ func renderMarkdown(ctx *context.Context, act *models.Action, content string) st } // feedActionsToFeedItems convert gitea's Action feed to feeds Item -func feedActionsToFeedItems(ctx *context.Context, actions models.ActionList) (items []*feeds.Item, err error) { +func feedActionsToFeedItems(ctx *context.Context, actions activities_model.ActionList) (items []*feeds.Item, err error) { for _, act := range actions { act.LoadActUser() @@ -78,110 +78,110 @@ func feedActionsToFeedItems(ctx *context.Context, actions models.ActionList) (it // title title = act.ActUser.DisplayName() + " " switch act.OpType { - case models.ActionCreateRepo: + case activities_model.ActionCreateRepo: title += ctx.TrHTMLEscapeArgs("action.create_repo", act.GetRepoLink(), act.ShortRepoPath()) link.Href = act.GetRepoLink() - case models.ActionRenameRepo: + case activities_model.ActionRenameRepo: title += ctx.TrHTMLEscapeArgs("action.rename_repo", act.GetContent(), act.GetRepoLink(), act.ShortRepoPath()) link.Href = act.GetRepoLink() - case models.ActionCommitRepo: + case activities_model.ActionCommitRepo: link.Href = toBranchLink(act) if len(act.Content) != 0 { title += ctx.TrHTMLEscapeArgs("action.commit_repo", act.GetRepoLink(), link.Href, act.GetBranch(), act.ShortRepoPath()) } else { title += ctx.TrHTMLEscapeArgs("action.create_branch", act.GetRepoLink(), link.Href, act.GetBranch(), act.ShortRepoPath()) } - case models.ActionCreateIssue: + case activities_model.ActionCreateIssue: link.Href = toIssueLink(act) title += ctx.TrHTMLEscapeArgs("action.create_issue", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionCreatePullRequest: + case activities_model.ActionCreatePullRequest: link.Href = toPullLink(act) title += ctx.TrHTMLEscapeArgs("action.create_pull_request", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionTransferRepo: + case activities_model.ActionTransferRepo: link.Href = act.GetRepoLink() title += ctx.TrHTMLEscapeArgs("action.transfer_repo", act.GetContent(), act.GetRepoLink(), act.ShortRepoPath()) - case models.ActionPushTag: + case activities_model.ActionPushTag: link.Href = toTagLink(act) title += ctx.TrHTMLEscapeArgs("action.push_tag", act.GetRepoLink(), link.Href, act.GetTag(), act.ShortRepoPath()) - case models.ActionCommentIssue: + case activities_model.ActionCommentIssue: issueLink := toIssueLink(act) if link.Href == "#" { link.Href = issueLink } title += ctx.TrHTMLEscapeArgs("action.comment_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionMergePullRequest: + case activities_model.ActionMergePullRequest: pullLink := toPullLink(act) if link.Href == "#" { link.Href = pullLink } title += ctx.TrHTMLEscapeArgs("action.merge_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionCloseIssue: + case activities_model.ActionCloseIssue: issueLink := toIssueLink(act) if link.Href == "#" { link.Href = issueLink } title += ctx.TrHTMLEscapeArgs("action.close_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionReopenIssue: + case activities_model.ActionReopenIssue: issueLink := toIssueLink(act) if link.Href == "#" { link.Href = issueLink } title += ctx.TrHTMLEscapeArgs("action.reopen_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionClosePullRequest: + case activities_model.ActionClosePullRequest: pullLink := toPullLink(act) if link.Href == "#" { link.Href = pullLink } title += ctx.TrHTMLEscapeArgs("action.close_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionReopenPullRequest: + case activities_model.ActionReopenPullRequest: pullLink := toPullLink(act) if link.Href == "#" { link.Href = pullLink } title += ctx.TrHTMLEscapeArgs("action.reopen_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionDeleteTag: + case activities_model.ActionDeleteTag: link.Href = act.GetRepoLink() title += ctx.TrHTMLEscapeArgs("action.delete_tag", act.GetRepoLink(), act.GetTag(), act.ShortRepoPath()) - case models.ActionDeleteBranch: + case activities_model.ActionDeleteBranch: link.Href = act.GetRepoLink() title += ctx.TrHTMLEscapeArgs("action.delete_branch", act.GetRepoLink(), html.EscapeString(act.GetBranch()), act.ShortRepoPath()) - case models.ActionMirrorSyncPush: + case activities_model.ActionMirrorSyncPush: srcLink := toSrcLink(act) if link.Href == "#" { link.Href = srcLink } title += ctx.TrHTMLEscapeArgs("action.mirror_sync_push", act.GetRepoLink(), srcLink, act.GetBranch(), act.ShortRepoPath()) - case models.ActionMirrorSyncCreate: + case activities_model.ActionMirrorSyncCreate: srcLink := toSrcLink(act) if link.Href == "#" { link.Href = srcLink } title += ctx.TrHTMLEscapeArgs("action.mirror_sync_create", act.GetRepoLink(), srcLink, act.GetBranch(), act.ShortRepoPath()) - case models.ActionMirrorSyncDelete: + case activities_model.ActionMirrorSyncDelete: link.Href = act.GetRepoLink() title += ctx.TrHTMLEscapeArgs("action.mirror_sync_delete", act.GetRepoLink(), act.GetBranch(), act.ShortRepoPath()) - case models.ActionApprovePullRequest: + case activities_model.ActionApprovePullRequest: pullLink := toPullLink(act) title += ctx.TrHTMLEscapeArgs("action.approve_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionRejectPullRequest: + case activities_model.ActionRejectPullRequest: pullLink := toPullLink(act) title += ctx.TrHTMLEscapeArgs("action.reject_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionCommentPull: + case activities_model.ActionCommentPull: pullLink := toPullLink(act) title += ctx.TrHTMLEscapeArgs("action.comment_pull", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath()) - case models.ActionPublishRelease: + case activities_model.ActionPublishRelease: releaseLink := toReleaseLink(act) if link.Href == "#" { link.Href = releaseLink } title += ctx.TrHTMLEscapeArgs("action.publish_release", act.GetRepoLink(), releaseLink, act.ShortRepoPath(), act.Content) - case models.ActionPullReviewDismissed: + case activities_model.ActionPullReviewDismissed: pullLink := toPullLink(act) title += ctx.TrHTMLEscapeArgs("action.review_dismissed", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(), act.GetIssueInfos()[1]) - case models.ActionStarRepo: + case activities_model.ActionStarRepo: link.Href = act.GetRepoLink() title += ctx.TrHTMLEscapeArgs("action.starred_repo", act.GetRepoLink(), act.GetRepoPath()) - case models.ActionWatchRepo: + case activities_model.ActionWatchRepo: link.Href = act.GetRepoLink() title += ctx.TrHTMLEscapeArgs("action.watched_repo", act.GetRepoLink(), act.GetRepoPath()) default: @@ -191,7 +191,7 @@ func feedActionsToFeedItems(ctx *context.Context, actions models.ActionList) (it // description & content { switch act.OpType { - case models.ActionCommitRepo, models.ActionMirrorSyncPush: + case activities_model.ActionCommitRepo, activities_model.ActionMirrorSyncPush: push := templates.ActionContent2Commits(act) repoLink := act.GetRepoLink() @@ -212,20 +212,20 @@ func feedActionsToFeedItems(ctx *context.Context, actions models.ActionList) (it link = &feeds.Link{Href: fmt.Sprintf("%s/commit/%s", act.GetRepoLink(), push.Commits[0].Sha1)} } - case models.ActionCreateIssue, models.ActionCreatePullRequest: + case activities_model.ActionCreateIssue, activities_model.ActionCreatePullRequest: desc = strings.Join(act.GetIssueInfos(), "#") content = renderMarkdown(ctx, act, act.GetIssueContent()) - case models.ActionCommentIssue, models.ActionApprovePullRequest, models.ActionRejectPullRequest, models.ActionCommentPull: + case activities_model.ActionCommentIssue, activities_model.ActionApprovePullRequest, activities_model.ActionRejectPullRequest, activities_model.ActionCommentPull: desc = act.GetIssueTitle() comment := act.GetIssueInfos()[1] if len(comment) != 0 { desc += "\n\n" + renderMarkdown(ctx, act, comment) } - case models.ActionMergePullRequest: + case activities_model.ActionMergePullRequest: desc = act.GetIssueInfos()[1] - case models.ActionCloseIssue, models.ActionReopenIssue, models.ActionClosePullRequest, models.ActionReopenPullRequest: + case activities_model.ActionCloseIssue, activities_model.ActionReopenIssue, activities_model.ActionClosePullRequest, activities_model.ActionReopenPullRequest: desc = act.GetIssueTitle() - case models.ActionPullReviewDismissed: + case activities_model.ActionPullReviewDismissed: desc = ctx.Tr("action.review_dismissed_reason") + "\n\n" + act.GetIssueInfos()[2] } } |