Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First implementation of git appraise #733

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ func runWeb(ctx *cli.Context) error {
m.Get("/releases", repo.Releases)
m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue)
m.Get("/reviews", repo.RetrieveLabels, repo.Reviews)
m.Get("/reviews/:index", context.RepoRef(), repo.SetEditorconfigIfExists, repo.ViewReview)
m.Get("/labels/", repo.RetrieveLabels, repo.Labels)
m.Get("/milestones", repo.Milestones)
}, context.RepoRef())
Expand Down Expand Up @@ -564,6 +566,12 @@ func runWeb(ctx *cli.Context) error {
m.Post("/merge", reqRepoWriter, repo.MergePullRequest)
}, repo.MustAllowPulls)

m.Group("/reviews/:index", func() {
m.Get("/commits", context.RepoRef(), repo.ViewReviewCommits)
m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ViewReviewFiles)
m.Post("/merge", reqRepoWriter, repo.MergePullRequest)
}, repo.MustAllowReviews)

m.Group("", func() {
m.Get("/src/*", repo.SetEditorconfigIfExists, repo.Home)
m.Get("/raw/*", repo.SingleDownload)
Expand Down
12 changes: 11 additions & 1 deletion models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package models
import (
"errors"
"fmt"
"strconv"
"strings"
"time"

Expand All @@ -29,6 +30,7 @@ type Issue struct {
RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"`
Repo *Repository `xorm:"-"`
Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository.
Revision string `xorm:"-"` // revision for appraise requests
PosterID int64 `xorm:"INDEX"`
Poster *User `xorm:"-"`
Title string `xorm:"name"`
Expand All @@ -43,6 +45,7 @@ type Issue struct {
IsClosed bool `xorm:"INDEX"`
IsRead bool `xorm:"-"`
IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not.
IsReview bool `xorm:"-"` // Indicates whether is a review or not.
PullRequest *PullRequest `xorm:"-"`
NumComments int

Expand Down Expand Up @@ -236,6 +239,14 @@ func (issue *Issue) APIFormat() *api.Issue {
return apiIssue
}

// GetIndex returns string index for templates
func (issue *Issue) GetIndex() string {
if issue.IsReview {
return issue.Revision
}
return strconv.Itoa(int(issue.Index))
}

// HashTag returns unique hash tag for issue.
func (issue *Issue) HashTag() string {
return "issue-" + com.ToStr(issue.ID)
Expand Down Expand Up @@ -1734,4 +1745,3 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
}
return sess.Commit()
}

5 changes: 5 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package models

import (
"fmt"
gotemplate "html/template"
"strings"
"time"

Expand Down Expand Up @@ -61,6 +62,10 @@ type Comment struct {
Content string `xorm:"TEXT"`
RenderedContent string `xorm:"-"`

FileContent gotemplate.HTML `xorm:"-"`
LineNums gotemplate.HTML `xorm:"-"`
HighlightClass string `xorm:"-"`

Created time.Time `xorm:"-"`
CreatedUnix int64 `xorm:"INDEX"`
Updated time.Time `xorm:"-"`
Expand Down
26 changes: 17 additions & 9 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ type Repository struct {
NumPulls int
NumClosedPulls int
NumOpenPulls int `xorm:"-"`
NumOpenReviews int `xorm:"-"`
NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
NumOpenMilestones int `xorm:"-"`
Expand All @@ -211,6 +212,7 @@ type Repository struct {
ExternalTrackerStyle string
ExternalMetas map[string]string `xorm:"-"`
EnablePulls bool `xorm:"NOT NULL DEFAULT true"`
EnableReviews bool `xorm:"NOT NULL DEFAULT true"`

IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
ForkID int64 `xorm:"INDEX"`
Expand Down Expand Up @@ -485,6 +487,11 @@ func (repo *Repository) AllowsPulls() bool {
return repo.CanEnablePulls() && repo.EnablePulls
}

// AllowsReviews returns true if repository meets the requirements of accepting pulls and has them enabled.
func (repo *Repository) AllowsReviews() bool {
return repo.EnableReviews
}

// CanEnableEditor returns true if repository meets the requirements of web editor.
func (repo *Repository) CanEnableEditor() bool {
return !repo.IsMirror
Expand Down Expand Up @@ -1035,15 +1042,16 @@ func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error
}

repo := &Repository{
OwnerID: u.ID,
Owner: u,
Name: opts.Name,
LowerName: strings.ToLower(opts.Name),
Description: opts.Description,
IsPrivate: opts.IsPrivate,
EnableWiki: true,
EnableIssues: true,
EnablePulls: true,
OwnerID: u.ID,
Owner: u,
Name: opts.Name,
LowerName: strings.ToLower(opts.Name),
Description: opts.Description,
IsPrivate: opts.IsPrivate,
EnableWiki: true,
EnableIssues: true,
EnablePulls: true,
EnableReviews: true,
}

sess := x.NewSession()
Expand Down
5 changes: 3 additions & 2 deletions modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type RepoSettingForm struct {
TrackerURLFormat string
TrackerIssueStyle string
EnablePulls bool
EnableReviews bool
}

// Validate valideates the fields
Expand Down Expand Up @@ -267,7 +268,7 @@ type NewReleaseForm struct {
Content string
Draft string
Prerelease bool
Files []string
Files []string
}

// Validate valideates the fields
Expand All @@ -281,7 +282,7 @@ type EditReleaseForm struct {
Content string `form:"content"`
Draft string `form:"draft"`
Prerelease bool `form:"prerelease"`
Files []string
Files []string
}

// Validate valideates the fields
Expand Down
11 changes: 11 additions & 0 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"github.com/Unknwon/com"
"github.com/google/git-appraise/repository"
"github.com/google/git-appraise/review"
editorconfig "gopkg.in/editorconfig/editorconfig-core-go.v1"
macaron "gopkg.in/macaron.v1"
)
Expand Down Expand Up @@ -286,6 +288,15 @@ func RepoAssignment(args ...bool) macaron.Handler {
ctx.Data["Branches"] = brs
ctx.Data["BrancheCount"] = len(brs)

// Count open reviews
if repo.AllowsReviews() {
appraiseRepo, err := repository.NewGitRepo(ctx.Repo.GitRepo.Path)
if err != nil {
ctx.Handle(500, "OpenGitRepository", err)
}
ctx.Repo.Repository.NumOpenReviews = len(review.ListOpen(appraiseRepo))
}

// If not branch selected, try default one.
// If default branch doesn't exists, fall back to some other branch.
if len(ctx.Repo.BranchName) == 0 {
Expand Down
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ branches = Branches
tags = Tags
issues = Issues
pulls = Pull Requests
reviews = Reviews
labels = Labels
milestones = Milestones
commits = Commits
Expand Down Expand Up @@ -708,6 +709,7 @@ settings.tracker_issue_style.numeric = Numeric
settings.tracker_issue_style.alphanumeric = Alphanumeric
settings.tracker_url_format_desc = You can use placeholder <code>{user} {repo} {index}</code> for user name, repository name and issue index.
settings.pulls_desc = Enable pull requests to accept public contributions
settings.reviews_desc = Enable appraise reviews
settings.danger_zone = Danger Zone
settings.new_owner_has_same_repo = The new owner already has a repository with same name. Please choose another name.
settings.convert = Convert To Regular Repository
Expand Down
73 changes: 43 additions & 30 deletions public/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -1315,64 +1315,64 @@ footer .ui.language .menu {
.repository.file.list #file-content .view-raw img {
padding: 5px 5px 0 5px;
}
.repository.file.list #file-content .code-view * {
.code-view * {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
line-height: 20px;
}
.repository.file.list #file-content .code-view table {
.code-view table {
width: 100%;
}
.repository.file.list #file-content .code-view .lines-num {
.code-view .lines-num {
vertical-align: top;
text-align: right;
color: #999;
background: #f5f5f5;
width: 1%;
}
.repository.file.list #file-content .code-view .lines-num span {
.code-view .lines-num span {
line-height: 20px;
padding: 0 10px;
cursor: pointer;
display: block;
}
.repository.file.list #file-content .code-view .lines-num,
.repository.file.list #file-content .code-view .lines-code {
.code-view .lines-num,
.code-view .lines-code {
padding: 0;
}
.repository.file.list #file-content .code-view .lines-num pre,
.repository.file.list #file-content .code-view .lines-code pre,
.repository.file.list #file-content .code-view .lines-num ol,
.repository.file.list #file-content .code-view .lines-code ol,
.repository.file.list #file-content .code-view .lines-num .hljs,
.repository.file.list #file-content .code-view .lines-code .hljs {
.code-view .lines-num pre,
.code-view .lines-code pre,
.code-view .lines-num ol,
.code-view .lines-code ol,
.code-view .lines-num .hljs,
.code-view .lines-code .hljs {
background-color: white;
margin: 0;
padding: 0 !important;
}
.repository.file.list #file-content .code-view .lines-num pre li,
.repository.file.list #file-content .code-view .lines-code pre li,
.repository.file.list #file-content .code-view .lines-num ol li,
.repository.file.list #file-content .code-view .lines-code ol li,
.repository.file.list #file-content .code-view .lines-num .hljs li,
.repository.file.list #file-content .code-view .lines-code .hljs li {
.code-view .lines-num pre li,
.code-view .lines-code pre li,
.code-view .lines-num ol li,
.code-view .lines-code ol li,
.code-view .lines-num .hljs li,
.code-view .lines-code .hljs li {
display: inline-block;
width: 100%;
}
.repository.file.list #file-content .code-view .lines-num pre li.active,
.repository.file.list #file-content .code-view .lines-code pre li.active,
.repository.file.list #file-content .code-view .lines-num ol li.active,
.repository.file.list #file-content .code-view .lines-code ol li.active,
.repository.file.list #file-content .code-view .lines-num .hljs li.active,
.repository.file.list #file-content .code-view .lines-code .hljs li.active {
.code-view .lines-num pre li.active,
.code-view .lines-code pre li.active,
.code-view .lines-num ol li.active,
.code-view .lines-code ol li.active,
.code-view .lines-num .hljs li.active,
.code-view .lines-code .hljs li.active {
background: #ffffdd;
}
.repository.file.list #file-content .code-view .lines-num pre li:before,
.repository.file.list #file-content .code-view .lines-code pre li:before,
.repository.file.list #file-content .code-view .lines-num ol li:before,
.repository.file.list #file-content .code-view .lines-code ol li:before,
.repository.file.list #file-content .code-view .lines-num .hljs li:before,
.repository.file.list #file-content .code-view .lines-code .hljs li:before {
.code-view .lines-num pre li:before,
.code-view .lines-code pre li:before,
.code-view .lines-num ol li:before,
.code-view .lines-code ol li:before,
.code-view .lines-num .hljs li:before,
.code-view .lines-code .hljs li:before {
content: ' ';
}
.repository.file.list .sidebar {
Expand Down Expand Up @@ -1514,6 +1514,11 @@ footer .ui.language .menu {
font-size: 2.3rem;
margin-bottom: 5px;
}
.repository.view.issue .title .revision {
top: -1rem;
padding-top: 0;
padding-bottom: 5px;
}
.repository.view.issue .title h1 .ui.input {
font-size: 0.5em;
vertical-align: top;
Expand All @@ -1531,6 +1536,7 @@ footer .ui.language .menu {
}
.repository.view.issue .title .label {
margin-right: 10px;
margin-left: 0px;
}
.repository.view.issue .title .edit-zone {
margin-top: 10px;
Expand Down Expand Up @@ -2265,6 +2271,13 @@ footer .ui.language .menu {
font-weight: bold;
margin: 0 6px;
}
.issue.list > .item .title.review {
margin: 0 0;
}
.issue.list > .item .revision {
font-size: 12px;
color: #aaa;
}
.issue.list > .item .title:hover {
color: #000;
}
Expand Down
Loading