code.gitea.io/gitea@v1.21.7/routers/web/feed/branch.go (about)

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