Skip to content

Commit 519fa2f

Browse files
committed
Allow attachments on review comments.
1 parent fb55033 commit 519fa2f

File tree

9 files changed

+35
-13
lines changed

9 files changed

+35
-13
lines changed

models/issue_comment.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ func updateCommentInfos(e *xorm.Session, opts *CreateCommentOptions, comment *Co
762762
}
763763
}
764764
fallthrough
765+
case CommentTypeReview:
766+
fallthrough
765767
case CommentTypeComment:
766768
if _, err = e.Exec("UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", opts.Issue.ID); err != nil {
767769
return err

models/review.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func IsContentEmptyErr(err error) bool {
347347
}
348348

349349
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
350-
func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool) (*Review, *Comment, error) {
350+
func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
351351
sess := x.NewSession()
352352
defer sess.Close()
353353
if err := sess.Begin(); err != nil {
@@ -419,12 +419,13 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content, comm
419419
}
420420

421421
comm, err := createComment(sess, &CreateCommentOptions{
422-
Type: CommentTypeReview,
423-
Doer: doer,
424-
Content: review.Content,
425-
Issue: issue,
426-
Repo: issue.Repo,
427-
ReviewID: review.ID,
422+
Type: CommentTypeReview,
423+
Doer: doer,
424+
Content: review.Content,
425+
Issue: issue,
426+
Repo: issue.Repo,
427+
ReviewID: review.ID,
428+
Attachments: attachmentUUIDs,
428429
})
429430
if err != nil || comm == nil {
430431
return nil, nil, err

routers/api/v1/repo/pull_review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func CreatePullReview(ctx *context.APIContext) {
359359
}
360360

361361
// create review and associate all pending review comments
362-
review, _, err := pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID)
362+
review, _, err := pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
363363
if err != nil {
364364
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
365365
return
@@ -447,7 +447,7 @@ func SubmitPullReview(ctx *context.APIContext) {
447447
}
448448

449449
// create review and associate all pending review comments
450-
review, _, err = pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID)
450+
review, _, err = pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
451451
if err != nil {
452452
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
453453
return

routers/repo/pull.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ func ViewPullFiles(ctx *context.Context) {
694694
getBranchData(ctx, issue)
695695
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID)
696696
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
697+
698+
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
699+
upload.AddUploadContext(ctx, "comment")
700+
697701
ctx.HTML(http.StatusOK, tplPullFiles)
698702
}
699703

routers/repo/pull_review.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models"
1212
"code.gitea.io/gitea/modules/base"
1313
"code.gitea.io/gitea/modules/context"
14+
"code.gitea.io/gitea/modules/setting"
1415
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/web"
1617
"code.gitea.io/gitea/services/forms"
@@ -211,7 +212,12 @@ func SubmitReview(ctx *context.Context) {
211212
}
212213
}
213214

214-
_, comm, err := pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, issue, reviewType, form.Content, form.CommitID)
215+
var attachments []string
216+
if setting.Attachment.Enabled {
217+
attachments = form.Files
218+
}
219+
220+
_, comm, err := pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, issue, reviewType, form.Content, form.CommitID, attachments)
215221
if err != nil {
216222
if models.IsContentEmptyErr(err) {
217223
ctx.Flash.Error(ctx.Tr("repo.issues.review.content.empty"))

services/forms/repo_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ type SubmitReviewForm struct {
582582
Content string
583583
Type string `binding:"Required;In(approve,comment,reject)"`
584584
CommitID string
585+
Files []string
585586
}
586587

587588
// Validate validates the fields

services/pull/review.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
100100

101101
if !isReview && !existsReview {
102102
// Submit the review we've just created so the comment shows up in the issue view
103-
if _, _, err = SubmitReview(doer, gitRepo, issue, models.ReviewTypeComment, "", latestCommitID); err != nil {
103+
if _, _, err = SubmitReview(doer, gitRepo, issue, models.ReviewTypeComment, "", latestCommitID, nil); err != nil {
104104
return nil, err
105105
}
106106
}
@@ -215,7 +215,7 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
215215
}
216216

217217
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
218-
func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string) (*models.Review, *models.Comment, error) {
218+
func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string, attachmentUUIDs []string) (*models.Review, *models.Comment, error) {
219219
pr, err := issue.GetPullRequest()
220220
if err != nil {
221221
return nil, nil, err
@@ -240,7 +240,7 @@ func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issu
240240
}
241241
}
242242

243-
review, comm, err := models.SubmitReview(doer, issue, reviewType, content, commitID, stale)
243+
review, comm, err := models.SubmitReview(doer, issue, reviewType, content, commitID, stale, attachmentUUIDs)
244244
if err != nil {
245245
return nil, nil, err
246246
}

templates/repo/diff/new_review.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<div class="ui field">
1616
<textarea name="content" tabindex="0" rows="2" placeholder="{{$.i18n.Tr "repo.diff.review.placeholder"}}"></textarea>
1717
</div>
18+
{{if .IsAttachmentEnabled}}
19+
<div class="field">
20+
{{template "repo/upload" .}}
21+
</div>
22+
{{end}}
1823
<div class="ui divider"></div>
1924
<button type="submit" name="type" value="approve" {{ if and $.IsSigned ($.Issue.IsPoster $.SignedUser.ID) }} disabled {{ end }} class="ui submit green tiny button btn-submit">{{$.i18n.Tr "repo.diff.review.approve"}}</button>
2025
<button type="submit" name="type" value="comment" class="ui submit tiny basic button btn-submit">{{$.i18n.Tr "repo.diff.review.comment"}}</button>

templates/repo/issue/view_content/comments.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@
449449
<span class="no-content">{{$.i18n.Tr "repo.issues.no_content"}}</span>
450450
{{end}}
451451
</div>
452+
{{if .Attachments}}
453+
{{template "repo/issue/view_content/attachments" Dict "ctx" $ "Attachments" .Attachments "Content" .RenderedContent}}
454+
{{end}}
452455
</div>
453456
</div>
454457
</div>

0 commit comments

Comments
 (0)