2021-10-16 10:21:16 -04:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-10-16 10:21:16 -04:00
|
|
|
|
|
|
|
package feed
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"html"
|
2022-03-13 12:40:47 -04:00
|
|
|
"net/http"
|
2021-10-16 10:21:16 -04:00
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2022-08-24 22:31:57 -04:00
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
2022-12-21 16:06:26 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-10-16 10:21:16 -04:00
|
|
|
"code.gitea.io/gitea/modules/context"
|
2022-03-12 17:05:12 -05:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2021-10-16 10:21:16 -04:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/templates"
|
2021-11-16 13:18:25 -05:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2021-10-16 10:21:16 -04:00
|
|
|
|
|
|
|
"github.com/gorilla/feeds"
|
|
|
|
)
|
|
|
|
|
2023-09-29 09:35:01 -04:00
|
|
|
func toBranchLink(ctx *context.Context, act *activities_model.Action) string {
|
|
|
|
return act.GetRepoAbsoluteLink(ctx) + "/src/branch/" + util.PathEscapeSegments(act.GetBranch())
|
2021-11-16 13:18:25 -05:00
|
|
|
}
|
|
|
|
|
2023-09-29 09:35:01 -04:00
|
|
|
func toTagLink(ctx *context.Context, act *activities_model.Action) string {
|
|
|
|
return act.GetRepoAbsoluteLink(ctx) + "/src/tag/" + util.PathEscapeSegments(act.GetTag())
|
2021-11-16 13:18:25 -05:00
|
|
|
}
|
|
|
|
|
2023-09-29 09:35:01 -04:00
|
|
|
func toIssueLink(ctx *context.Context, act *activities_model.Action) string {
|
|
|
|
return act.GetRepoAbsoluteLink(ctx) + "/issues/" + url.PathEscape(act.GetIssueInfos()[0])
|
2021-11-16 13:18:25 -05:00
|
|
|
}
|
|
|
|
|
2023-09-29 09:35:01 -04:00
|
|
|
func toPullLink(ctx *context.Context, act *activities_model.Action) string {
|
|
|
|
return act.GetRepoAbsoluteLink(ctx) + "/pulls/" + url.PathEscape(act.GetIssueInfos()[0])
|
2021-11-16 13:18:25 -05:00
|
|
|
}
|
|
|
|
|
2023-09-29 09:35:01 -04:00
|
|
|
func toSrcLink(ctx *context.Context, act *activities_model.Action) string {
|
|
|
|
return act.GetRepoAbsoluteLink(ctx) + "/src/" + util.PathEscapeSegments(act.GetBranch())
|
2021-11-16 13:18:25 -05:00
|
|
|
}
|
|
|
|
|
2023-09-29 09:35:01 -04:00
|
|
|
func toReleaseLink(ctx *context.Context, act *activities_model.Action) string {
|
|
|
|
return act.GetRepoAbsoluteLink(ctx) + "/releases/tag/" + util.PathEscapeSegments(act.GetBranch())
|
2021-11-16 13:18:25 -05:00
|
|
|
}
|
|
|
|
|
2022-03-12 17:05:12 -05:00
|
|
|
// renderMarkdown creates a minimal markdown render context from an action.
|
|
|
|
// If rendering fails, the original markdown text is returned
|
2022-08-24 22:31:57 -04:00
|
|
|
func renderMarkdown(ctx *context.Context, act *activities_model.Action, content string) string {
|
2022-03-12 17:05:12 -05:00
|
|
|
markdownCtx := &markup.RenderContext{
|
|
|
|
Ctx: ctx,
|
2023-09-29 09:35:01 -04:00
|
|
|
URLPrefix: act.GetRepoLink(ctx),
|
2022-03-12 17:05:12 -05:00
|
|
|
Type: markdown.MarkupName,
|
|
|
|
Metas: map[string]string{
|
2023-09-29 09:35:01 -04:00
|
|
|
"user": act.GetRepoUserName(ctx),
|
|
|
|
"repo": act.GetRepoName(ctx),
|
2022-03-12 17:05:12 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
markdown, err := markdown.RenderString(markdownCtx, content)
|
|
|
|
if err != nil {
|
|
|
|
return content
|
|
|
|
}
|
|
|
|
return markdown
|
|
|
|
}
|
|
|
|
|
2021-10-16 10:21:16 -04:00
|
|
|
// feedActionsToFeedItems convert gitea's Action feed to feeds Item
|
2022-08-24 22:31:57 -04:00
|
|
|
func feedActionsToFeedItems(ctx *context.Context, actions activities_model.ActionList) (items []*feeds.Item, err error) {
|
2021-10-16 10:21:16 -04:00
|
|
|
for _, act := range actions {
|
2022-12-02 21:48:26 -05:00
|
|
|
act.LoadActUser(ctx)
|
2021-10-16 10:21:16 -04:00
|
|
|
|
2022-06-20 06:02:49 -04:00
|
|
|
var content, desc, title string
|
2021-10-16 10:21:16 -04:00
|
|
|
|
2023-09-29 09:35:01 -04:00
|
|
|
link := &feeds.Link{Href: act.GetCommentHTMLURL(ctx)}
|
2021-10-16 10:21:16 -04:00
|
|
|
|
|
|
|
// title
|
|
|
|
title = act.ActUser.DisplayName() + " "
|
|
|
|
switch act.OpType {
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCreateRepo:
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.create_repo", act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
|
|
|
|
link.Href = act.GetRepoAbsoluteLink(ctx)
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionRenameRepo:
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.rename_repo", act.GetContent(), act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
|
|
|
|
link.Href = act.GetRepoAbsoluteLink(ctx)
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCommitRepo:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = toBranchLink(ctx, act)
|
2021-10-16 10:21:16 -04:00
|
|
|
if len(act.Content) != 0 {
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.commit_repo", act.GetRepoAbsoluteLink(ctx), link.Href, act.GetBranch(), act.ShortRepoPath(ctx))
|
2021-10-16 10:21:16 -04:00
|
|
|
} else {
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.create_branch", act.GetRepoAbsoluteLink(ctx), link.Href, act.GetBranch(), act.ShortRepoPath(ctx))
|
2021-10-16 10:21:16 -04:00
|
|
|
}
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCreateIssue:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = toIssueLink(ctx, act)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.create_issue", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCreatePullRequest:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = toPullLink(ctx, act)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.create_pull_request", link.Href, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionTransferRepo:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = act.GetRepoAbsoluteLink(ctx)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.transfer_repo", act.GetContent(), act.GetRepoAbsoluteLink(ctx), act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionPushTag:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = toTagLink(ctx, act)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.push_tag", act.GetRepoAbsoluteLink(ctx), link.Href, act.GetTag(), act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCommentIssue:
|
2023-09-29 09:35:01 -04:00
|
|
|
issueLink := toIssueLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = issueLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.comment_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionMergePullRequest:
|
2023-09-29 09:35:01 -04:00
|
|
|
pullLink := toPullLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = pullLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.merge_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-11-03 11:49:00 -04:00
|
|
|
case activities_model.ActionAutoMergePullRequest:
|
2023-09-29 09:35:01 -04:00
|
|
|
pullLink := toPullLink(ctx, act)
|
2022-11-03 11:49:00 -04:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = pullLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.auto_merge_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCloseIssue:
|
2023-09-29 09:35:01 -04:00
|
|
|
issueLink := toIssueLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = issueLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.close_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionReopenIssue:
|
2023-09-29 09:35:01 -04:00
|
|
|
issueLink := toIssueLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = issueLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.reopen_issue", issueLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionClosePullRequest:
|
2023-09-29 09:35:01 -04:00
|
|
|
pullLink := toPullLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = pullLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.close_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionReopenPullRequest:
|
2023-09-29 09:35:01 -04:00
|
|
|
pullLink := toPullLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = pullLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.reopen_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionDeleteTag:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = act.GetRepoAbsoluteLink(ctx)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.delete_tag", act.GetRepoAbsoluteLink(ctx), act.GetTag(), act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionDeleteBranch:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = act.GetRepoAbsoluteLink(ctx)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.delete_branch", act.GetRepoAbsoluteLink(ctx), html.EscapeString(act.GetBranch()), act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionMirrorSyncPush:
|
2023-09-29 09:35:01 -04:00
|
|
|
srcLink := toSrcLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = srcLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_push", act.GetRepoAbsoluteLink(ctx), srcLink, act.GetBranch(), act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionMirrorSyncCreate:
|
2023-09-29 09:35:01 -04:00
|
|
|
srcLink := toSrcLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = srcLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_create", act.GetRepoAbsoluteLink(ctx), srcLink, act.GetBranch(), act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionMirrorSyncDelete:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = act.GetRepoAbsoluteLink(ctx)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.mirror_sync_delete", act.GetRepoAbsoluteLink(ctx), act.GetBranch(), act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionApprovePullRequest:
|
2023-09-29 09:35:01 -04:00
|
|
|
pullLink := toPullLink(ctx, act)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.approve_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionRejectPullRequest:
|
2023-09-29 09:35:01 -04:00
|
|
|
pullLink := toPullLink(ctx, act)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.reject_pull_request", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCommentPull:
|
2023-09-29 09:35:01 -04:00
|
|
|
pullLink := toPullLink(ctx, act)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.comment_pull", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionPublishRelease:
|
2023-09-29 09:35:01 -04:00
|
|
|
releaseLink := toReleaseLink(ctx, act)
|
2021-11-16 13:18:25 -05:00
|
|
|
if link.Href == "#" {
|
|
|
|
link.Href = releaseLink
|
|
|
|
}
|
2023-09-29 09:35:01 -04:00
|
|
|
title += ctx.TrHTMLEscapeArgs("action.publish_release", act.GetRepoAbsoluteLink(ctx), releaseLink, act.ShortRepoPath(ctx), act.Content)
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionPullReviewDismissed:
|
2023-09-29 09:35:01 -04:00
|
|
|
pullLink := toPullLink(ctx, act)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.review_dismissed", pullLink, act.GetIssueInfos()[0], act.ShortRepoPath(ctx), act.GetIssueInfos()[1])
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionStarRepo:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = act.GetRepoAbsoluteLink(ctx)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.starred_repo", act.GetRepoAbsoluteLink(ctx), act.GetRepoPath(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionWatchRepo:
|
2023-09-29 09:35:01 -04:00
|
|
|
link.Href = act.GetRepoAbsoluteLink(ctx)
|
|
|
|
title += ctx.TrHTMLEscapeArgs("action.watched_repo", act.GetRepoAbsoluteLink(ctx), act.GetRepoPath(ctx))
|
2021-10-16 10:21:16 -04:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unknown action type: %v", act.OpType)
|
|
|
|
}
|
|
|
|
|
|
|
|
// description & content
|
|
|
|
{
|
|
|
|
switch act.OpType {
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCommitRepo, activities_model.ActionMirrorSyncPush:
|
2021-10-16 10:21:16 -04:00
|
|
|
push := templates.ActionContent2Commits(act)
|
2023-09-29 09:35:01 -04:00
|
|
|
repoLink := act.GetRepoAbsoluteLink(ctx)
|
2021-10-16 10:21:16 -04:00
|
|
|
|
|
|
|
for _, commit := range push.Commits {
|
|
|
|
if len(desc) != 0 {
|
|
|
|
desc += "\n\n"
|
|
|
|
}
|
|
|
|
desc += fmt.Sprintf("<a href=\"%s\">%s</a>\n%s",
|
2023-09-29 09:35:01 -04:00
|
|
|
html.EscapeString(fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(ctx), commit.Sha1)),
|
2021-10-16 10:21:16 -04:00
|
|
|
commit.Sha1,
|
2022-01-19 18:26:57 -05:00
|
|
|
templates.RenderCommitMessage(ctx, commit.Message, repoLink, nil),
|
2021-10-16 10:21:16 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if push.Len > 1 {
|
|
|
|
link = &feeds.Link{Href: fmt.Sprintf("%s/%s", setting.AppSubURL, push.CompareURL)}
|
|
|
|
} else if push.Len == 1 {
|
2023-09-29 09:35:01 -04:00
|
|
|
link = &feeds.Link{Href: fmt.Sprintf("%s/commit/%s", act.GetRepoAbsoluteLink(ctx), push.Commits[0].Sha1)}
|
2021-10-16 10:21:16 -04:00
|
|
|
}
|
|
|
|
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCreateIssue, activities_model.ActionCreatePullRequest:
|
2021-10-16 10:21:16 -04:00
|
|
|
desc = strings.Join(act.GetIssueInfos(), "#")
|
2023-07-22 10:14:27 -04:00
|
|
|
content = renderMarkdown(ctx, act, act.GetIssueContent(ctx))
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCommentIssue, activities_model.ActionApprovePullRequest, activities_model.ActionRejectPullRequest, activities_model.ActionCommentPull:
|
2023-09-29 09:35:01 -04:00
|
|
|
desc = act.GetIssueTitle(ctx)
|
2021-10-16 10:21:16 -04:00
|
|
|
comment := act.GetIssueInfos()[1]
|
|
|
|
if len(comment) != 0 {
|
2022-03-12 17:05:12 -05:00
|
|
|
desc += "\n\n" + renderMarkdown(ctx, act, comment)
|
2021-10-16 10:21:16 -04:00
|
|
|
}
|
2022-11-03 11:49:00 -04:00
|
|
|
case activities_model.ActionMergePullRequest, activities_model.ActionAutoMergePullRequest:
|
2021-10-16 10:21:16 -04:00
|
|
|
desc = act.GetIssueInfos()[1]
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionCloseIssue, activities_model.ActionReopenIssue, activities_model.ActionClosePullRequest, activities_model.ActionReopenPullRequest:
|
2023-09-29 09:35:01 -04:00
|
|
|
desc = act.GetIssueTitle(ctx)
|
2022-08-24 22:31:57 -04:00
|
|
|
case activities_model.ActionPullReviewDismissed:
|
2021-10-16 10:21:16 -04:00
|
|
|
desc = ctx.Tr("action.review_dismissed_reason") + "\n\n" + act.GetIssueInfos()[2]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(content) == 0 {
|
|
|
|
content = desc
|
|
|
|
}
|
|
|
|
|
|
|
|
items = append(items, &feeds.Item{
|
|
|
|
Title: title,
|
|
|
|
Link: link,
|
|
|
|
Description: desc,
|
|
|
|
Author: &feeds.Author{
|
|
|
|
Name: act.ActUser.DisplayName(),
|
|
|
|
Email: act.ActUser.GetEmail(),
|
|
|
|
},
|
2022-10-28 09:49:04 -04:00
|
|
|
Id: fmt.Sprintf("%v: %v", strconv.FormatInt(act.ID, 10), link.Href),
|
2021-10-16 10:21:16 -04:00
|
|
|
Created: act.CreatedUnix.AsTime(),
|
|
|
|
Content: content,
|
|
|
|
})
|
|
|
|
}
|
2022-06-20 06:02:49 -04:00
|
|
|
return items, err
|
2021-10-16 10:21:16 -04:00
|
|
|
}
|
2022-03-13 12:40:47 -04:00
|
|
|
|
|
|
|
// GetFeedType return if it is a feed request and altered name and feed type.
|
|
|
|
func GetFeedType(name string, req *http.Request) (bool, string, string) {
|
|
|
|
if strings.HasSuffix(name, ".rss") ||
|
|
|
|
strings.Contains(req.Header.Get("Accept"), "application/rss+xml") {
|
|
|
|
return true, strings.TrimSuffix(name, ".rss"), "rss"
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.HasSuffix(name, ".atom") ||
|
|
|
|
strings.Contains(req.Header.Get("Accept"), "application/atom+xml") {
|
|
|
|
return true, strings.TrimSuffix(name, ".atom"), "atom"
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, name, ""
|
|
|
|
}
|
2022-12-21 16:06:26 -05:00
|
|
|
|
|
|
|
// feedActionsToFeedItems convert gitea's Repo's Releases to feeds Item
|
|
|
|
func releasesToFeedItems(ctx *context.Context, releases []*repo_model.Release, isReleasesOnly bool) (items []*feeds.Item, err error) {
|
|
|
|
for _, rel := range releases {
|
|
|
|
err := rel.LoadAttributes(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var title, content string
|
|
|
|
|
|
|
|
if rel.IsTag {
|
|
|
|
title = rel.TagName
|
|
|
|
} else {
|
|
|
|
title = rel.Title
|
|
|
|
}
|
|
|
|
|
|
|
|
link := &feeds.Link{Href: rel.HTMLURL()}
|
|
|
|
content, err = markdown.RenderString(&markup.RenderContext{
|
|
|
|
Ctx: ctx,
|
|
|
|
URLPrefix: rel.Repo.Link(),
|
|
|
|
Metas: rel.Repo.ComposeMetas(),
|
|
|
|
}, rel.Note)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
items = append(items, &feeds.Item{
|
|
|
|
Title: title,
|
|
|
|
Link: link,
|
|
|
|
Created: rel.CreatedUnix.AsTime(),
|
|
|
|
Author: &feeds.Author{
|
|
|
|
Name: rel.Publisher.DisplayName(),
|
|
|
|
Email: rel.Publisher.GetEmail(),
|
|
|
|
},
|
|
|
|
Id: fmt.Sprintf("%v: %v", strconv.FormatInt(rel.ID, 10), link.Href),
|
|
|
|
Content: content,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return items, err
|
|
|
|
}
|