gitea源码

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package feed
  4. import (
  5. "strings"
  6. "time"
  7. "code.gitea.io/gitea/models/repo"
  8. "code.gitea.io/gitea/modules/git"
  9. "code.gitea.io/gitea/services/context"
  10. "github.com/gorilla/feeds"
  11. )
  12. // ShowBranchFeed shows tags and/or releases on the repo as RSS / Atom feed
  13. func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType string) {
  14. var commits []*git.Commit
  15. var err error
  16. if ctx.Repo.Commit != nil {
  17. commits, err = ctx.Repo.Commit.CommitsByRange(0, 10, "", "", "")
  18. if err != nil {
  19. ctx.ServerError("ShowBranchFeed", err)
  20. return
  21. }
  22. }
  23. title := "Latest commits for branch " + ctx.Repo.BranchName
  24. link := &feeds.Link{Href: repo.HTMLURL() + "/" + ctx.Repo.RefTypeNameSubURL()}
  25. feed := &feeds.Feed{
  26. Title: title,
  27. Link: link,
  28. Description: repo.Description,
  29. Created: time.Now(),
  30. }
  31. for _, commit := range commits {
  32. feed.Items = append(feed.Items, &feeds.Item{
  33. Id: commit.ID.String(),
  34. Title: strings.TrimSpace(strings.Split(commit.Message(), "\n")[0]),
  35. Link: &feeds.Link{Href: repo.HTMLURL() + "/commit/" + commit.ID.String()},
  36. Author: &feeds.Author{
  37. Name: commit.Author.Name,
  38. Email: commit.Author.Email,
  39. },
  40. Description: commit.Message(),
  41. Content: commit.Message(),
  42. Created: commit.Committer.When,
  43. })
  44. }
  45. writeFeed(ctx, feed, formatType)
  46. }