2017-09-14 06:51:32 +00:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2014-07-26 04:24:27 +00:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2014-07-26 04:24:27 +00:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2021-10-08 13:08:22 +00:00
|
|
|
gocontext "context"
|
2024-09-10 02:23:07 +00:00
|
|
|
"errors"
|
2016-08-09 19:56:00 +00:00
|
|
|
"fmt"
|
2023-12-17 14:38:54 +00:00
|
|
|
"html/template"
|
2021-01-22 17:49:13 +00:00
|
|
|
"io"
|
2021-04-05 15:30:52 +00:00
|
|
|
"net/http"
|
2019-10-13 13:23:14 +00:00
|
|
|
"net/url"
|
2014-07-26 04:24:27 +00:00
|
|
|
"strings"
|
2021-10-08 13:08:22 +00:00
|
|
|
"time"
|
2014-07-26 04:24:27 +00:00
|
|
|
|
2023-07-31 05:04:45 +00:00
|
|
|
_ "image/gif" // for processing gif images
|
|
|
|
_ "image/jpeg" // for processing jpeg images
|
|
|
|
_ "image/png" // for processing png images
|
|
|
|
|
2022-08-25 02:31:57 +00:00
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
|
|
|
admin_model "code.gitea.io/gitea/models/admin"
|
2021-12-10 08:14:24 +00:00
|
|
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
2021-09-24 11:32:56 +00:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-12 15:51:54 +00:00
|
|
|
git_model "code.gitea.io/gitea/models/git"
|
2021-12-10 01:27:50 +00:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-09 19:57:58 +00:00
|
|
|
unit_model "code.gitea.io/gitea/models/unit"
|
2021-11-24 09:49:20 +00:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2016-11-10 16:24:48 +00:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
2019-08-15 12:07:28 +00:00
|
|
|
"code.gitea.io/gitea/modules/charset"
|
2019-03-27 09:33:00 +00:00
|
|
|
"code.gitea.io/gitea/modules/git"
|
2016-12-26 01:16:37 +00:00
|
|
|
"code.gitea.io/gitea/modules/lfs"
|
2016-11-10 16:24:48 +00:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2017-04-21 07:01:08 +00:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2016-11-10 16:24:48 +00:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-06-30 19:14:53 +00:00
|
|
|
"code.gitea.io/gitea/modules/structs"
|
2021-06-05 12:32:19 +00:00
|
|
|
"code.gitea.io/gitea/modules/typesniffer"
|
2021-10-24 21:12:43 +00:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2024-02-27 07:12:22 +00:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2024-10-01 19:25:08 +00:00
|
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
2023-07-31 05:04:45 +00:00
|
|
|
|
|
|
|
_ "golang.org/x/image/bmp" // for processing bmp images
|
|
|
|
_ "golang.org/x/image/webp" // for processing webp images
|
2014-07-26 04:24:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-10-08 13:08:22 +00:00
|
|
|
tplRepoEMPTY base.TplName = "repo/empty"
|
|
|
|
tplRepoHome base.TplName = "repo/home"
|
|
|
|
tplRepoViewList base.TplName = "repo/view_list"
|
|
|
|
tplWatchers base.TplName = "repo/watchers"
|
|
|
|
tplForks base.TplName = "repo/forks"
|
|
|
|
tplMigrating base.TplName = "repo/migrate/migrating"
|
2014-07-26 04:24:27 +00:00
|
|
|
)
|
|
|
|
|
2022-12-14 10:11:11 +00:00
|
|
|
type fileInfo struct {
|
|
|
|
isTextFile bool
|
|
|
|
isLFSFile bool
|
|
|
|
fileSize int64
|
|
|
|
lfsMeta *lfs.Pointer
|
|
|
|
st typesniffer.SniffedType
|
|
|
|
}
|
2016-08-30 09:08:38 +00:00
|
|
|
|
2023-07-24 03:47:27 +00:00
|
|
|
func getFileReader(ctx gocontext.Context, repoID int64, blob *git.Blob) ([]byte, io.ReadCloser, *fileInfo, error) {
|
2022-12-14 10:11:11 +00:00
|
|
|
dataRc, err := blob.DataAsync()
|
2022-04-26 20:31:15 +00:00
|
|
|
if err != nil {
|
2022-12-14 10:11:11 +00:00
|
|
|
return nil, nil, nil, err
|
2022-04-26 20:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf := make([]byte, 1024)
|
|
|
|
n, _ := util.ReadAtMost(dataRc, buf)
|
|
|
|
buf = buf[:n]
|
|
|
|
|
|
|
|
st := typesniffer.DetectContentType(buf)
|
|
|
|
isTextFile := st.IsText()
|
|
|
|
|
|
|
|
// FIXME: what happens when README file is an image?
|
2022-12-14 10:11:11 +00:00
|
|
|
if !isTextFile || !setting.LFS.StartServer {
|
|
|
|
return buf, dataRc, &fileInfo{isTextFile, false, blob.Size(), nil, st}, nil
|
|
|
|
}
|
2022-04-26 20:31:15 +00:00
|
|
|
|
2022-12-14 10:11:11 +00:00
|
|
|
pointer, _ := lfs.ReadPointerFromBuffer(buf)
|
|
|
|
if !pointer.IsValid() { // fallback to plain file
|
|
|
|
return buf, dataRc, &fileInfo{isTextFile, false, blob.Size(), nil, st}, nil
|
|
|
|
}
|
2019-02-21 20:57:16 +00:00
|
|
|
|
2023-07-24 03:47:27 +00:00
|
|
|
meta, err := git_model.GetLFSMetaObjectByOid(ctx, repoID, pointer.Oid)
|
2024-08-14 21:50:09 +00:00
|
|
|
if err != nil { // fallback to plain file
|
|
|
|
log.Warn("Unable to access LFS pointer %s in repo %d: %v", pointer.Oid, repoID, err)
|
2022-12-14 10:11:11 +00:00
|
|
|
return buf, dataRc, &fileInfo{isTextFile, false, blob.Size(), nil, st}, nil
|
|
|
|
}
|
2019-02-21 20:57:16 +00:00
|
|
|
|
2022-12-14 10:11:11 +00:00
|
|
|
dataRc.Close()
|
2019-02-21 20:57:16 +00:00
|
|
|
|
2022-12-14 10:11:11 +00:00
|
|
|
dataRc, err = lfs.ReadMetaObject(pointer)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, nil, err
|
2022-04-26 20:31:15 +00:00
|
|
|
}
|
2019-02-21 20:57:16 +00:00
|
|
|
|
2022-12-14 10:11:11 +00:00
|
|
|
buf = make([]byte, 1024)
|
|
|
|
n, err = util.ReadAtMost(dataRc, buf)
|
|
|
|
if err != nil {
|
|
|
|
dataRc.Close()
|
|
|
|
return nil, nil, nil, err
|
|
|
|
}
|
|
|
|
buf = buf[:n]
|
|
|
|
|
|
|
|
st = typesniffer.DetectContentType(buf)
|
|
|
|
|
|
|
|
return buf, dataRc, &fileInfo{st.IsText(), true, meta.Size, &meta.Pointer, st}, nil
|
|
|
|
}
|
|
|
|
|
2024-01-15 16:42:15 +00:00
|
|
|
func loadLatestCommitData(ctx *context.Context, latestCommit *git.Commit) bool {
|
|
|
|
// Show latest commit info of repository in table header,
|
|
|
|
// or of directory if not in root directory.
|
|
|
|
ctx.Data["LatestCommit"] = latestCommit
|
|
|
|
if latestCommit != nil {
|
|
|
|
verification := asymkey_model.ParseCommitWithSignature(ctx, latestCommit)
|
|
|
|
|
|
|
|
if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) {
|
|
|
|
return repo_model.IsOwnerMemberCollaborator(ctx, ctx.Repo.Repository, user.ID)
|
|
|
|
}, nil); err != nil {
|
|
|
|
ctx.ServerError("CalculateTrustStatus", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
ctx.Data["LatestCommitVerification"] = verification
|
|
|
|
ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(ctx, latestCommit)
|
|
|
|
|
2024-03-22 12:53:52 +00:00
|
|
|
statuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, latestCommit.ID.String(), db.ListOptionsAll)
|
2024-01-15 16:42:15 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error("GetLatestCommitStatus: %v", err)
|
|
|
|
}
|
2024-07-28 15:11:40 +00:00
|
|
|
if !ctx.Repo.CanRead(unit_model.TypeActions) {
|
|
|
|
git_model.CommitStatusesHideActionsURL(ctx, statuses)
|
|
|
|
}
|
2024-01-15 16:42:15 +00:00
|
|
|
|
|
|
|
ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(statuses)
|
|
|
|
ctx.Data["LatestCommitStatuses"] = statuses
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-12-17 14:38:54 +00:00
|
|
|
func markupRender(ctx *context.Context, renderCtx *markup.RenderContext, input io.Reader) (escaped *charset.EscapeStatus, output template.HTML, err error) {
|
2022-08-13 18:32:34 +00:00
|
|
|
markupRd, markupWr := io.Pipe()
|
|
|
|
defer markupWr.Close()
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
sb := &strings.Builder{}
|
|
|
|
// We allow NBSP here this is rendered
|
|
|
|
escaped, _ = charset.EscapeControlReader(markupRd, sb, ctx.Locale, charset.RuneNBSP)
|
2023-12-17 14:38:54 +00:00
|
|
|
output = template.HTML(sb.String())
|
2022-08-13 18:32:34 +00:00
|
|
|
close(done)
|
|
|
|
}()
|
|
|
|
err = markup.Render(renderCtx, input, markupWr)
|
|
|
|
_ = markupWr.CloseWithError(err)
|
|
|
|
<-done
|
|
|
|
return escaped, output, err
|
|
|
|
}
|
|
|
|
|
2021-10-08 13:08:22 +00:00
|
|
|
func checkHomeCodeViewable(ctx *context.Context) {
|
2024-04-17 15:58:37 +00:00
|
|
|
if ctx.Repo.HasUnits() {
|
2019-10-13 13:23:14 +00:00
|
|
|
if ctx.Repo.Repository.IsBeingCreated() {
|
2023-09-16 14:39:12 +00:00
|
|
|
task, err := admin_model.GetMigratingTask(ctx, ctx.Repo.Repository.ID)
|
2019-10-13 13:23:14 +00:00
|
|
|
if err != nil {
|
2022-08-25 02:31:57 +00:00
|
|
|
if admin_model.IsErrTaskDoesNotExist(err) {
|
2021-11-13 11:28:50 +00:00
|
|
|
ctx.Data["Repo"] = ctx.Repo
|
|
|
|
ctx.Data["CloneAddr"] = ""
|
|
|
|
ctx.Data["Failed"] = true
|
|
|
|
ctx.HTML(http.StatusOK, tplMigrating)
|
|
|
|
return
|
|
|
|
}
|
2019-10-13 13:23:14 +00:00
|
|
|
ctx.ServerError("models.GetMigratingTask", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cfg, err := task.MigrateConfig()
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("task.MigrateConfig", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["Repo"] = ctx.Repo
|
|
|
|
ctx.Data["MigrateTask"] = task
|
2023-09-16 16:03:02 +00:00
|
|
|
ctx.Data["CloneAddr"], _ = util.SanitizeURL(cfg.CloneAddr)
|
2021-06-30 19:14:53 +00:00
|
|
|
ctx.Data["Failed"] = task.Status == structs.TaskStatusFailed
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.HTML(http.StatusOK, tplMigrating)
|
2019-10-13 13:23:14 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-01 00:47:30 +00:00
|
|
|
if ctx.IsSigned {
|
|
|
|
// Set repo notification-status read if unread
|
2022-08-25 02:31:57 +00:00
|
|
|
if err := activities_model.SetRepoReadBy(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID); err != nil {
|
2021-03-01 00:47:30 +00:00
|
|
|
ctx.ServerError("ReadBy", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-09 19:57:58 +00:00
|
|
|
var firstUnit *unit_model.Unit
|
2024-04-17 08:31:37 +00:00
|
|
|
for _, repoUnitType := range ctx.Repo.Permission.ReadableUnitTypes() {
|
|
|
|
if repoUnitType == unit_model.TypeCode {
|
2024-04-17 15:58:37 +00:00
|
|
|
// we are doing this check in "code" unit related pages, so if the code unit is readable, no need to do any further redirection
|
2017-10-01 13:50:56 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-04-17 08:31:37 +00:00
|
|
|
unit, ok := unit_model.Units[repoUnitType]
|
2017-10-01 13:50:56 +00:00
|
|
|
if ok && (firstUnit == nil || !firstUnit.IsLessThan(unit)) {
|
|
|
|
firstUnit = &unit
|
|
|
|
}
|
2017-05-18 14:54:24 +00:00
|
|
|
}
|
|
|
|
|
2017-10-01 13:50:56 +00:00
|
|
|
if firstUnit != nil {
|
2021-11-16 18:18:25 +00:00
|
|
|
ctx.Redirect(fmt.Sprintf("%s%s", ctx.Repo.Repository.Link(), firstUnit.URI))
|
2017-05-18 14:54:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-10 02:23:07 +00:00
|
|
|
ctx.NotFound("Home", errors.New(ctx.Locale.TrString("units.error.no_unit_allowed_repo")))
|
2017-05-18 14:54:24 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 13:08:22 +00:00
|
|
|
// LastCommit returns lastCommit data for the provided branch/tag/commit and directory (in url) and filenames in body
|
|
|
|
func LastCommit(ctx *context.Context) {
|
|
|
|
checkHomeCodeViewable(ctx)
|
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDirectoryFiles(ctx, 0)
|
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var treeNames []string
|
|
|
|
paths := make([]string, 0, 5)
|
|
|
|
if len(ctx.Repo.TreePath) > 0 {
|
|
|
|
treeNames = strings.Split(ctx.Repo.TreePath, "/")
|
|
|
|
for i := range treeNames {
|
|
|
|
paths = append(paths, strings.Join(treeNames[:i+1], "/"))
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["HasParentPath"] = true
|
|
|
|
if len(paths)-2 >= 0 {
|
|
|
|
ctx.Data["ParentPath"] = "/" + paths[len(paths)-2]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
|
|
|
ctx.Data["BranchLink"] = branchLink
|
|
|
|
|
|
|
|
ctx.HTML(http.StatusOK, tplRepoViewList)
|
|
|
|
}
|
|
|
|
|
|
|
|
func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entries {
|
|
|
|
tree, err := ctx.Repo.Commit.SubTree(ctx.Repo.TreePath)
|
|
|
|
if err != nil {
|
2023-09-29 07:42:39 +00:00
|
|
|
HandleGitError(ctx, "Repo.Commit.SubTree", err)
|
2021-10-08 13:08:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-16 18:18:25 +00:00
|
|
|
ctx.Data["LastCommitLoaderURL"] = ctx.Repo.RepoLink + "/lastcommit/" + url.PathEscape(ctx.Repo.CommitID) + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
|
2021-10-08 13:08:22 +00:00
|
|
|
|
|
|
|
// Get current entry user currently looking at.
|
|
|
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
|
|
|
if err != nil {
|
2023-09-29 07:42:39 +00:00
|
|
|
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
|
2021-10-08 13:08:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !entry.IsDir() {
|
2023-09-29 07:42:39 +00:00
|
|
|
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
|
2021-10-08 13:08:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
allEntries, err := tree.ListEntries()
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("ListEntries", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
allEntries.CustomSort(base.NaturalSortLess)
|
|
|
|
|
|
|
|
commitInfoCtx := gocontext.Context(ctx)
|
|
|
|
if timeout > 0 {
|
|
|
|
var cancel gocontext.CancelFunc
|
|
|
|
commitInfoCtx, cancel = gocontext.WithTimeout(ctx, timeout)
|
|
|
|
defer cancel()
|
|
|
|
}
|
|
|
|
|
2024-03-02 19:31:59 +00:00
|
|
|
files, latestCommit, err := allEntries.GetCommitsInfo(commitInfoCtx, ctx.Repo.Commit, ctx.Repo.TreePath)
|
2021-10-08 13:08:22 +00:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetCommitsInfo", err)
|
|
|
|
return nil
|
|
|
|
}
|
2024-03-02 19:31:59 +00:00
|
|
|
ctx.Data["Files"] = files
|
|
|
|
for _, f := range files {
|
|
|
|
if f.Commit == nil {
|
|
|
|
ctx.Data["HasFilesWithoutLatestCommit"] = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-10-08 13:08:22 +00:00
|
|
|
|
2024-01-15 16:42:15 +00:00
|
|
|
if !loadLatestCommitData(ctx, latestCommit) {
|
|
|
|
return nil
|
2022-07-15 13:01:32 +00:00
|
|
|
}
|
2021-10-08 13:08:22 +00:00
|
|
|
|
|
|
|
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
|
|
|
treeLink := branchLink
|
|
|
|
|
|
|
|
if len(ctx.Repo.TreePath) > 0 {
|
2021-11-16 18:18:25 +00:00
|
|
|
treeLink += "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
|
2021-10-08 13:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["TreeLink"] = treeLink
|
|
|
|
ctx.Data["SSHDomain"] = setting.SSH.Domain
|
|
|
|
|
|
|
|
return allEntries
|
|
|
|
}
|
|
|
|
|
2021-07-08 11:38:13 +00:00
|
|
|
// RenderUserCards render a page show users according the input template
|
2021-11-24 09:49:20 +00:00
|
|
|
func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOptions) ([]*user_model.User, error), tpl base.TplName) {
|
2021-07-29 01:42:15 +00:00
|
|
|
page := ctx.FormInt("page")
|
2015-11-17 04:28:46 +00:00
|
|
|
if page <= 0 {
|
|
|
|
page = 1
|
|
|
|
}
|
2022-06-12 15:51:54 +00:00
|
|
|
pager := context.NewPagination(total, setting.ItemsPerPage, page, 5)
|
2015-11-17 04:28:46 +00:00
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
|
2021-09-24 11:32:56 +00:00
|
|
|
items, err := getter(db.ListOptions{
|
2021-02-04 17:23:46 +00:00
|
|
|
Page: pager.Paginater.Current(),
|
2022-06-12 15:51:54 +00:00
|
|
|
PageSize: setting.ItemsPerPage,
|
2021-02-04 17:23:46 +00:00
|
|
|
})
|
2015-11-17 04:28:46 +00:00
|
|
|
if err != nil {
|
2018-01-10 21:34:17 +00:00
|
|
|
ctx.ServerError("getter", err)
|
2015-11-17 04:28:46 +00:00
|
|
|
return
|
|
|
|
}
|
2015-12-21 12:24:11 +00:00
|
|
|
ctx.Data["Cards"] = items
|
2015-11-17 04:28:46 +00:00
|
|
|
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.HTML(http.StatusOK, tpl)
|
2015-11-17 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 10:03:29 +00:00
|
|
|
// Watchers render repository's watch users
|
2016-03-11 16:56:52 +00:00
|
|
|
func Watchers(ctx *context.Context) {
|
2015-11-17 04:28:46 +00:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.watchers")
|
2015-12-21 12:24:11 +00:00
|
|
|
ctx.Data["CardsTitle"] = ctx.Tr("repo.watchers")
|
2021-12-10 01:27:50 +00:00
|
|
|
RenderUserCards(ctx, ctx.Repo.Repository.NumWatches, func(opts db.ListOptions) ([]*user_model.User, error) {
|
2023-09-15 06:13:19 +00:00
|
|
|
return repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, opts)
|
2021-12-10 01:27:50 +00:00
|
|
|
}, tplWatchers)
|
2015-11-17 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 10:03:29 +00:00
|
|
|
// Stars render repository's starred users
|
2016-03-11 16:56:52 +00:00
|
|
|
func Stars(ctx *context.Context) {
|
2015-11-17 04:28:46 +00:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.stargazers")
|
2015-12-21 12:24:11 +00:00
|
|
|
ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers")
|
2021-11-24 09:49:20 +00:00
|
|
|
RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*user_model.User, error) {
|
2023-09-15 06:13:19 +00:00
|
|
|
return repo_model.GetStargazers(ctx, ctx.Repo.Repository, opts)
|
2021-11-22 15:21:55 +00:00
|
|
|
}, tplWatchers)
|
2015-11-17 04:28:46 +00:00
|
|
|
}
|
2015-11-17 04:33:40 +00:00
|
|
|
|
2016-11-21 10:03:29 +00:00
|
|
|
// Forks render repository's forked users
|
2016-03-11 16:56:52 +00:00
|
|
|
func Forks(ctx *context.Context) {
|
2023-04-17 20:41:06 +00:00
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.forks")
|
2015-11-17 04:33:40 +00:00
|
|
|
|
2021-11-18 14:45:56 +00:00
|
|
|
page := ctx.FormInt("page")
|
|
|
|
if page <= 0 {
|
|
|
|
page = 1
|
|
|
|
}
|
2024-11-18 03:06:25 +00:00
|
|
|
pageSize := setting.ItemsPerPage
|
2021-11-18 14:45:56 +00:00
|
|
|
|
2024-11-18 03:06:25 +00:00
|
|
|
forks, total, err := repo_service.FindForks(ctx, ctx.Repo.Repository, ctx.Doer, db.ListOptions{
|
|
|
|
Page: page,
|
|
|
|
PageSize: pageSize,
|
2021-11-18 14:45:56 +00:00
|
|
|
})
|
2015-11-17 04:33:40 +00:00
|
|
|
if err != nil {
|
2024-11-18 03:06:25 +00:00
|
|
|
ctx.ServerError("FindForks", err)
|
2015-11-17 04:33:40 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-11-18 03:06:25 +00:00
|
|
|
if err := repo_model.RepositoryList(forks).LoadOwners(ctx); err != nil {
|
|
|
|
ctx.ServerError("LoadAttributes", err)
|
|
|
|
return
|
2015-11-17 04:33:40 +00:00
|
|
|
}
|
2021-11-18 14:45:56 +00:00
|
|
|
|
2024-11-18 03:06:25 +00:00
|
|
|
pager := context.NewPagination(int(total), pageSize, page, 5)
|
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
|
2015-11-17 04:33:40 +00:00
|
|
|
ctx.Data["Forks"] = forks
|
|
|
|
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.HTML(http.StatusOK, tplForks)
|
2015-11-17 04:33:40 +00:00
|
|
|
}
|