Skip to content

Commit 2ac6ca6

Browse files
authored
Merge branch 'master' into default-board
2 parents a967a57 + bcb7f35 commit 2ac6ca6

File tree

25 files changed

+268
-114
lines changed

25 files changed

+268
-114
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.14
55
require (
66
code.gitea.io/gitea-vet v0.2.1
77
code.gitea.io/sdk/gitea v0.13.1
8-
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27
8+
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee
99
gitea.com/lunny/levelqueue v0.3.0
1010
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
1111
gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFj
4040
code.gitea.io/sdk/gitea v0.13.1 h1:Y7bpH2iO6Q0KhhMJfjP/LZ0AmiYITeRQlCD8b0oYqhk=
4141
code.gitea.io/sdk/gitea v0.13.1/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
4242
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
43-
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27 h1:cdb1OTNXGLwQ55gg+9tIPWufdsnrHWcIq8Qs+j/E8JU=
44-
gitea.com/go-chi/session v0.0.0-20201218134809-7209fa084f27/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
43+
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee h1:9U6HuKUBt/cGK6T/64dEuz0r7Yp97WAAEJvXHDlY3ws=
44+
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee/go.mod h1:Ozg8IchVNb/Udg+ui39iHRYqVHSvf3C99ixdpLR8Vu0=
4545
gitea.com/lunny/levelqueue v0.3.0 h1:MHn1GuSZkxvVEDMyAPqlc7A3cOW+q8RcGhRgH/xtm6I=
4646
gitea.com/lunny/levelqueue v0.3.0/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
4747
gitea.com/lunny/log v0.0.0-20190322053110-01b5df579c4e h1:r1en/D7xJmcY24VkHkjkcJFa+7ZWubVWPBrvsHkmHxk=

integrations/pull_merge_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func TestCantMergeConflict(t *testing.T) {
246246
err = pull.Merge(pr, user1, gitRepo, models.MergeStyleRebase, "CONFLICT")
247247
assert.Error(t, err, "Merge should return an error due to conflict")
248248
assert.True(t, models.IsErrRebaseConflicts(err), "Merge error is not a conflict error")
249+
gitRepo.Close()
249250
})
250251
}
251252

@@ -329,5 +330,6 @@ func TestCantMergeUnrelated(t *testing.T) {
329330
err = pull.Merge(pr, user1, gitRepo, models.MergeStyleMerge, "UNRELATED")
330331
assert.Error(t, err, "Merge should return an error due to unrelated")
331332
assert.True(t, models.IsErrMergeUnrelatedHistories(err), "Merge error is not a unrelated histories error")
333+
gitRepo.Close()
332334
})
333335
}

models/issue_comment.go

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ func (opts *FindCommentsOptions) toConds() builder.Cond {
979979
if opts.Type != CommentTypeUnknown {
980980
cond = cond.And(builder.Eq{"comment.type": opts.Type})
981981
}
982-
if opts.Line > 0 {
982+
if opts.Line != 0 {
983983
cond = cond.And(builder.Eq{"comment.line": opts.Line})
984984
}
985985
if len(opts.TreePath) > 0 {
@@ -1078,18 +1078,35 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
10781078
if review == nil {
10791079
review = &Review{ID: 0}
10801080
}
1081-
//Find comments
10821081
opts := FindCommentsOptions{
10831082
Type: CommentTypeCode,
10841083
IssueID: issue.ID,
10851084
ReviewID: review.ID,
10861085
}
1086+
1087+
comments, err := findCodeComments(e, opts, issue, currentUser, review)
1088+
if err != nil {
1089+
return nil, err
1090+
}
1091+
1092+
for _, comment := range comments {
1093+
if pathToLineToComment[comment.TreePath] == nil {
1094+
pathToLineToComment[comment.TreePath] = make(map[int64][]*Comment)
1095+
}
1096+
pathToLineToComment[comment.TreePath][comment.Line] = append(pathToLineToComment[comment.TreePath][comment.Line], comment)
1097+
}
1098+
return pathToLineToComment, nil
1099+
}
1100+
1101+
func findCodeComments(e Engine, opts FindCommentsOptions, issue *Issue, currentUser *User, review *Review) ([]*Comment, error) {
1102+
var comments []*Comment
1103+
if review == nil {
1104+
review = &Review{ID: 0}
1105+
}
10871106
conds := opts.toConds()
10881107
if review.ID == 0 {
10891108
conds = conds.And(builder.Eq{"invalidated": false})
10901109
}
1091-
1092-
var comments []*Comment
10931110
if err := e.Where(conds).
10941111
Asc("comment.created_unix").
10951112
Asc("comment.id").
@@ -1117,7 +1134,19 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
11171134
return nil, err
11181135
}
11191136

1137+
n := 0
11201138
for _, comment := range comments {
1139+
if re, ok := reviews[comment.ReviewID]; ok && re != nil {
1140+
// If the review is pending only the author can see the comments (except if the review is set)
1141+
if review.ID == 0 && re.Type == ReviewTypePending &&
1142+
(currentUser == nil || currentUser.ID != re.ReviewerID) {
1143+
continue
1144+
}
1145+
comment.Review = re
1146+
}
1147+
comments[n] = comment
1148+
n++
1149+
11211150
if err := comment.LoadResolveDoer(); err != nil {
11221151
return nil, err
11231152
}
@@ -1126,25 +1155,21 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
11261155
return nil, err
11271156
}
11281157

1129-
if re, ok := reviews[comment.ReviewID]; ok && re != nil {
1130-
// If the review is pending only the author can see the comments (except the review is set)
1131-
if review.ID == 0 {
1132-
if re.Type == ReviewTypePending &&
1133-
(currentUser == nil || currentUser.ID != re.ReviewerID) {
1134-
continue
1135-
}
1136-
}
1137-
comment.Review = re
1138-
}
1139-
11401158
comment.RenderedContent = string(markdown.Render([]byte(comment.Content), issue.Repo.Link(),
11411159
issue.Repo.ComposeMetas()))
1142-
if pathToLineToComment[comment.TreePath] == nil {
1143-
pathToLineToComment[comment.TreePath] = make(map[int64][]*Comment)
1144-
}
1145-
pathToLineToComment[comment.TreePath][comment.Line] = append(pathToLineToComment[comment.TreePath][comment.Line], comment)
11461160
}
1147-
return pathToLineToComment, nil
1161+
return comments[:n], nil
1162+
}
1163+
1164+
// FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
1165+
func FetchCodeCommentsByLine(issue *Issue, currentUser *User, treePath string, line int64) ([]*Comment, error) {
1166+
opts := FindCommentsOptions{
1167+
Type: CommentTypeCode,
1168+
IssueID: issue.ID,
1169+
TreePath: treePath,
1170+
Line: line,
1171+
}
1172+
return findCodeComments(x, opts, issue, currentUser, nil)
11481173
}
11491174

11501175
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line

models/migrations/v156.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ func fixPublisherIDforTagReleases(x *xorm.Engine) error {
137137
return err
138138
}
139139
}
140+
if gitRepo != nil {
141+
gitRepo.Close()
142+
}
140143

141144
if err := sess.Commit(); err != nil {
142145
return err

modules/auth/repo_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Error
548548

549549
// CodeCommentForm form for adding code comments for PRs
550550
type CodeCommentForm struct {
551+
Origin string `binding:"Required;In(timeline,diff)"`
551552
Content string `binding:"Required"`
552553
Side string `binding:"Required;In(previous,proposed)"`
553554
Line int64

modules/lfs/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,8 @@ func PutHandler(ctx *context.Context) {
413413
}
414414

415415
contentStore := &ContentStore{ObjectStorage: storage.LFS}
416-
bodyReader := ctx.Req.Body().ReadCloser()
417-
defer bodyReader.Close()
418-
if err := contentStore.Put(meta, bodyReader); err != nil {
416+
defer ctx.Req.Request.Body.Close()
417+
if err := contentStore.Put(meta, ctx.Req.Request.Body); err != nil {
419418
// Put will log the error itself
420419
ctx.Resp.WriteHeader(500)
421420
if err == errSizeMismatch || err == errHashMismatch {

options/locale/locale_cs-CZ.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ my_mirrors=Má zrcadla
216216
view_home=Zobrazit %s
217217
search_repos=Nalézt repozitář…
218218
filter=Ostatní filtry
219+
filter_by_team_repositories=Filtrovat podle repozitářů týmu
219220

220221
show_archived=Archivováno
221222
show_both_archived_unarchived=Zobrazeny jak archivované tak nearchivované
@@ -555,6 +556,7 @@ principal_state_desc=Tento SSH Principal certifikát byl použit během posledn
555556
show_openid=Zobrazit na profilu
556557
hide_openid=Odstranit z profilu
557558
ssh_disabled=SSH zakázáno
559+
ssh_externally_managed=Tento SSH klíč je spravován externě pro tohoto uživatele
558560
manage_social=Správa propojených účtů sociálních sítí
559561
social_desc=Tyto účty sociálních síti jsou propojeny s vaším Gitea účtem. Ujistěte se, že je všechny znáte, protože mohou být použity k přihlášení do vašeho Gitea účtu.
560562
unbind=Odpojit
@@ -2113,6 +2115,7 @@ users.delete_account=Smazat uživatelský účet
21132115
users.still_own_repo=Tento uživatel stále vlastní jeden nebo více repozitářů. Tyto repozitáře nejprve smažte nebo je převeďte.
21142116
users.still_has_org=Uživatel je člen organizace. Nejprve odstraňte uživatele ze všech organizací.
21152117
users.deletion_success=Uživatelský účet byl smazán.
2118+
users.reset_2fa=Resetovat 2FA
21162119

21172120
emails.email_manage_panel=Správa e-mailů uživatele
21182121
emails.primary=Hlavní
@@ -2200,6 +2203,7 @@ auths.enable_tls=Povolit šifrování TLS
22002203
auths.skip_tls_verify=Přeskočit ověření TLS
22012204
auths.pam_service_name=Název služby PAM
22022205
auths.oauth2_provider=Poskytovatel OAuth2
2206+
auths.oauth2_icon_url=URL ikony
22032207
auths.oauth2_clientID=Klientské ID (klíč)
22042208
auths.oauth2_clientSecret=Tajný klíč klienta
22052209
auths.openIdConnectAutoDiscoveryURL=OpenID URL pro automatické objevování
@@ -2491,6 +2495,7 @@ mirror_sync_delete=synchronizoval(a) a smazal(a) referenci <code>%[2]s</code> v
24912495
approve_pull_request=`schválil(a) <a href="%s/pulls/%s">%s#%[2]s</a>`
24922496
reject_pull_request=`navrhl(a) změny pro <a href="%s/pulls/%s">%s#%[2]s</a>`
24932497
publish_release=`vydána značka <a href="%s/releases/tag/%s"> "%[4]s" </a> v <a href="%[1]s">%[3]s</a>`
2498+
create_branch=vytvořena větev <a href="%[1]s/src/branch/%[2]s">%[3]s</a> v <a href="%[1]s">%[4]s</a>
24942499

24952500
[tool]
24962501
ago=před %s

options/locale/locale_ja-JP.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,7 @@ users.delete_account=ユーザーアカウントを削除
21152115
users.still_own_repo=このユーザーはまだ1つ以上のリポジトリを所有しています。 先にそれらのリポジトリを削除するか移転してください。
21162116
users.still_has_org=このユーザーは組織のメンバーになっています。 先に組織からこのユーザーを削除してください。
21172117
users.deletion_success=ユーザーアカウントを削除しました。
2118+
users.reset_2fa=2要素認証をリセット
21182119

21192120
emails.email_manage_panel=ユーザーメールアドレスの管理
21202121
emails.primary=プライマリー
@@ -2494,6 +2495,7 @@ mirror_sync_delete=が <a href="%[1]s">%[3]s</a> の参照 <code>%[2]s</code>
24942495
approve_pull_request=`が <a href="%s/pulls/%s">%s#%[2]s</a> を承認しました`
24952496
reject_pull_request=`が <a href="%s/pulls/%s">%s#%[2]s</a> について変更を求めました`
24962497
publish_release=`が <a href="%[1]s">%[3]s</a> の <a href="%[1]s/releases/tag/%[2]s"> "%[4]s" </a> をリリースしました`
2498+
create_branch=が <a href="%[1]s">%[4]s</a> にブランチ <a href="%[1]s/src/branch/%[2]s">%[3]s</a> を作成しました
24972499

24982500
[tool]
24992501
ago=%s前

routers/repo/lfs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,16 @@ func LFSLocks(ctx *context.Context) {
120120
}); err != nil {
121121
log.Error("Failed to clone repository: %s (%v)", ctx.Repo.Repository.FullName(), err)
122122
ctx.ServerError("LFSLocks", fmt.Errorf("Failed to clone repository: %s (%v)", ctx.Repo.Repository.FullName(), err))
123+
return
123124
}
124125

125126
gitRepo, err := git.OpenRepository(tmpBasePath)
126127
if err != nil {
127128
log.Error("Unable to open temporary repository: %s (%v)", tmpBasePath, err)
128129
ctx.ServerError("LFSLocks", fmt.Errorf("Failed to open new temporary repository in: %s %v", tmpBasePath, err))
130+
return
129131
}
132+
defer gitRepo.Close()
130133

131134
filenames := make([]string, len(lfsLocks))
132135

@@ -137,6 +140,7 @@ func LFSLocks(ctx *context.Context) {
137140
if err := gitRepo.ReadTreeToIndex(ctx.Repo.Repository.DefaultBranch); err != nil {
138141
log.Error("Unable to read the default branch to the index: %s (%v)", ctx.Repo.Repository.DefaultBranch, err)
139142
ctx.ServerError("LFSLocks", fmt.Errorf("Unable to read the default branch to the index: %s (%v)", ctx.Repo.Repository.DefaultBranch, err))
143+
return
140144
}
141145

142146
name2attribute2info, err := gitRepo.CheckAttribute(git.CheckAttributeOpts{
@@ -147,6 +151,7 @@ func LFSLocks(ctx *context.Context) {
147151
if err != nil {
148152
log.Error("Unable to check attributes in %s (%v)", tmpBasePath, err)
149153
ctx.ServerError("LFSLocks", err)
154+
return
150155
}
151156

152157
lockables := make([]bool, len(lfsLocks))
@@ -166,6 +171,7 @@ func LFSLocks(ctx *context.Context) {
166171
if err != nil {
167172
log.Error("Unable to lsfiles in %s (%v)", tmpBasePath, err)
168173
ctx.ServerError("LFSLocks", err)
174+
return
169175
}
170176

171177
filemap := make(map[string]bool, len(filelist))

routers/repo/pull_review.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,40 @@ import (
99

1010
"code.gitea.io/gitea/models"
1111
"code.gitea.io/gitea/modules/auth"
12+
"code.gitea.io/gitea/modules/base"
1213
"code.gitea.io/gitea/modules/context"
1314
"code.gitea.io/gitea/modules/log"
1415
pull_service "code.gitea.io/gitea/services/pull"
1516
)
1617

18+
const (
19+
tplConversation base.TplName = "repo/diff/conversation"
20+
tplNewComment base.TplName = "repo/diff/new_comment"
21+
)
22+
23+
// RenderNewCodeCommentForm will render the form for creating a new review comment
24+
func RenderNewCodeCommentForm(ctx *context.Context) {
25+
issue := GetActionIssue(ctx)
26+
if !issue.IsPull {
27+
return
28+
}
29+
currentReview, err := models.GetCurrentReview(ctx.User, issue)
30+
if err != nil && !models.IsErrReviewNotExist(err) {
31+
ctx.ServerError("GetCurrentReview", err)
32+
return
33+
}
34+
ctx.Data["PageIsPullFiles"] = true
35+
ctx.Data["Issue"] = issue
36+
ctx.Data["CurrentReview"] = currentReview
37+
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(issue.PullRequest.GetGitRefName())
38+
if err != nil {
39+
ctx.ServerError("GetRefCommitID", err)
40+
return
41+
}
42+
ctx.Data["AfterCommitID"] = pullHeadCommitID
43+
ctx.HTML(200, tplNewComment)
44+
}
45+
1746
// CreateCodeComment will create a code comment including an pending review if required
1847
func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
1948
issue := GetActionIssue(ctx)
@@ -58,11 +87,17 @@ func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
5887
}
5988

6089
log.Trace("Comment created: %-v #%d[%d] Comment[%d]", ctx.Repo.Repository, issue.Index, issue.ID, comment.ID)
90+
91+
if form.Origin == "diff" {
92+
renderConversation(ctx, comment)
93+
return
94+
}
6195
ctx.Redirect(comment.HTMLURL())
6296
}
6397

6498
// UpdateResolveConversation add or remove an Conversation resolved mark
6599
func UpdateResolveConversation(ctx *context.Context) {
100+
origin := ctx.Query("origin")
66101
action := ctx.Query("action")
67102
commentID := ctx.QueryInt64("comment_id")
68103

@@ -103,11 +138,38 @@ func UpdateResolveConversation(ctx *context.Context) {
103138
return
104139
}
105140

141+
if origin == "diff" {
142+
renderConversation(ctx, comment)
143+
return
144+
}
106145
ctx.JSON(200, map[string]interface{}{
107146
"ok": true,
108147
})
109148
}
110149

150+
func renderConversation(ctx *context.Context, comment *models.Comment) {
151+
comments, err := models.FetchCodeCommentsByLine(comment.Issue, ctx.User, comment.TreePath, comment.Line)
152+
if err != nil {
153+
ctx.ServerError("FetchCodeCommentsByLine", err)
154+
return
155+
}
156+
ctx.Data["PageIsPullFiles"] = true
157+
ctx.Data["comments"] = comments
158+
ctx.Data["CanMarkConversation"] = true
159+
ctx.Data["Issue"] = comment.Issue
160+
if err = comment.Issue.LoadPullRequest(); err != nil {
161+
ctx.ServerError("comment.Issue.LoadPullRequest", err)
162+
return
163+
}
164+
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(comment.Issue.PullRequest.GetGitRefName())
165+
if err != nil {
166+
ctx.ServerError("GetRefCommitID", err)
167+
return
168+
}
169+
ctx.Data["AfterCommitID"] = pullHeadCommitID
170+
ctx.HTML(200, tplConversation)
171+
}
172+
111173
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
112174
func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) {
113175
issue := GetActionIssue(ctx)

0 commit comments

Comments
 (0)