|
| 1 | +// Copyright 2014 The Gogs Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package repo |
| 6 | + |
| 7 | +import ( |
| 8 | + "strconv" |
| 9 | + "strings" |
| 10 | + "time" |
| 11 | + |
| 12 | + "github.com/google/git-appraise/repository" |
| 13 | + "github.com/google/git-appraise/review" |
| 14 | + |
| 15 | + "code.gitea.io/gitea/models" |
| 16 | + "code.gitea.io/gitea/modules/base" |
| 17 | + "code.gitea.io/gitea/modules/context" |
| 18 | +) |
| 19 | + |
| 20 | +const ( |
| 21 | + tplReviews base.TplName = "repo/review/list" |
| 22 | +) |
| 23 | + |
| 24 | +// MustAllowReviews check if repository enable reviews |
| 25 | +func MustAllowReviews(ctx *context.Context) { |
| 26 | + if !ctx.Repo.Repository.AllowsReviews() { |
| 27 | + ctx.Handle(404, "MustAllowReviews", nil) |
| 28 | + return |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +// Review struct to Issue representation |
| 33 | +type Review struct { |
| 34 | + Index string |
| 35 | + Poster *models.User |
| 36 | + Title string |
| 37 | + Labels []*models.Label |
| 38 | + Milestone *models.Milestone |
| 39 | + Assignee *models.User |
| 40 | + NumComments int |
| 41 | + Created time.Time |
| 42 | + CreatedUnix int64 |
| 43 | + Updated time.Time |
| 44 | + UpdatedUnix int64 |
| 45 | + IsClosed bool |
| 46 | + IsRead bool |
| 47 | + IsPull bool |
| 48 | +} |
| 49 | + |
| 50 | +// Reviews render issues page |
| 51 | +func Reviews(ctx *context.Context) { |
| 52 | + repo, err := repository.NewGitRepo(ctx.Repo.GitRepo.Path) |
| 53 | + if err != nil { |
| 54 | + ctx.Handle(500, "OpenGitRepository", err) |
| 55 | + } |
| 56 | + total := review.ListAll(repo) |
| 57 | + |
| 58 | + issues := []*Review{} |
| 59 | + |
| 60 | + for _, review := range total { |
| 61 | + timestamp, _ := strconv.Atoi(review.Request.Timestamp) |
| 62 | + time := time.Unix(int64(timestamp), 0) |
| 63 | + user, err := models.GetUserByEmail(review.Request.Requester) |
| 64 | + read := false |
| 65 | + if review.Resolved != nil && *review.Resolved { |
| 66 | + read = true |
| 67 | + } |
| 68 | + if err != nil { |
| 69 | + user = &models.User{Name: review.Request.Requester} |
| 70 | + } |
| 71 | + issue := Review{ |
| 72 | + Index: review.Revision, |
| 73 | + Title: strings.Split(review.Request.Description, "\n\n")[0], |
| 74 | + Poster: user, |
| 75 | + Created: time, |
| 76 | + CreatedUnix: int64(timestamp), |
| 77 | + IsClosed: review.Submitted, |
| 78 | + IsRead: read, |
| 79 | + IsPull: true, |
| 80 | + } |
| 81 | + if !review.Submitted { |
| 82 | + issues = append(issues, &issue) |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + ctx.Data["Title"] = ctx.Tr("repo.reviews") |
| 87 | + ctx.Data["PageIsReviewList"] = true |
| 88 | + // ctx.Data["Page"] = 0 |
| 89 | + ctx.Data["Issues"] = issues |
| 90 | + // ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID) |
| 91 | + // ctx.Data["Assignees"], err = repo.GetAssignees() |
| 92 | + ctx.Data["IssueStats"] = models.IssueStats{ |
| 93 | + OpenCount: int64(len(issues)), |
| 94 | + ClosedCount: int64(len(total) - len(issues)), |
| 95 | + /*AllCount: int64(len(total))*/} |
| 96 | + // ctx.Data["SelectLabels"] = com.StrTo(selectLabels).MustInt64() |
| 97 | + ctx.Data["ViewType"] = "all" |
| 98 | + ctx.Data["SortType"] = "" |
| 99 | + // ctx.Data["MilestoneID"] = milestoneID |
| 100 | + // ctx.Data["AssigneeID"] = assigneeID |
| 101 | + ctx.Data["IsShowClosed"] = false |
| 102 | + ctx.HTML(200, tplIssues) |
| 103 | +} |
0 commit comments