88 "errors"
99 "fmt"
1010 "html/template"
11+ "maps"
1112 "net/http"
1213 "path"
1314 "strconv"
@@ -431,14 +432,14 @@ func Diff(ctx *context.Context) {
431432 ctx .Data ["MergedPRIssueNumber" ] = pr .Index
432433 }
433434
434- commitData , err := git_model .GetCommitDataBySHA (ctx , ctx .Repo .Repository .ID , commitID )
435+ commitComment , err := git_model .GetCommitDataBySHA (ctx , ctx .Repo .Repository .ID , commitID )
435436 if err != nil {
436- ctx .ServerError ("PostProcessCommitMessage " , err )
437+ ctx .ServerError ("GetCommitDataBySHA " , err )
437438 return
438439 }
439440
440- if commitData != nil {
441- err := git_service .LoadCommitComments (ctx , diff , commitData , ctx .Doer )
441+ if commitComment != nil {
442+ err := git_service .LoadCommitComments (ctx , diff , commitComment , ctx .Doer )
442443 if err != nil {
443444 ctx .ServerError ("LoadCommitComments" , err )
444445 return
@@ -523,24 +524,25 @@ func CreateCommitComment(ctx *context.Context) {
523524 if form .Side == "previous" {
524525 signedLine *= - 1
525526 }
526-
527+ replyid := form . Reply
527528 attachmentsMap := make (git_model.AttachmentMap )
528529
529530 if ctx .Session .Get ("attachmentsMaps" ) != nil {
530531 attachmentsMap = ctx .Session .Get ("attachmentsMaps" ).(git_model.AttachmentMap )
531532 }
532533
533534 opts := git_model.CreateCommitDataOptions {
534- RefRepoID : ctx .Repo .Repository .ID ,
535- Repo : ctx .Repo .Repository ,
536- Doer : ctx .Doer ,
537- Comment : form .Content ,
538- FileName : form .TreePath ,
539- LineNum : signedLine ,
540- CommitSHA : form .LatestCommitID ,
541- Attachments : attachmentsMap ,
542- }
543- commitdata , err := git_service .CreateCommitComment (ctx ,
535+ RefRepoID : ctx .Repo .Repository .ID ,
536+ Repo : ctx .Repo .Repository ,
537+ Doer : ctx .Doer ,
538+ Comment : form .Content ,
539+ FileName : form .TreePath ,
540+ LineNum : signedLine ,
541+ ReplyToCommentID : replyid ,
542+ CommitSHA : form .LatestCommitID ,
543+ Attachments : attachmentsMap ,
544+ }
545+ commitComment , err := git_service .CreateCommitComment (ctx ,
544546 ctx .Doer ,
545547 ctx .Repo .GitRepo ,
546548 opts ,
@@ -556,17 +558,17 @@ func CreateCommitComment(ctx *context.Context) {
556558 return
557559 }
558560 }
559- renderCommitData (ctx , commitdata , form .Origin , signedLine )
561+ renderCommitData (ctx , commitComment , form .Origin , signedLine )
560562}
561563
562- func renderCommitData (ctx * context.Context , commitData * git_model.CommitData , origin string , signedLine int64 ) {
564+ func renderCommitData (ctx * context.Context , commitComment * git_model.CommitComment , origin string , signedLine int64 ) {
563565 ctx .Data ["PageIsDiff" ] = true
564566
565567 opts := git_model.FindCommitDataOptions {
566- CommitSHA : commitData .CommitSHA ,
568+ CommitSHA : commitComment .CommitSHA ,
567569 Line : signedLine ,
568570 }
569- comments , err := git_model .FindCommitCommentsByLine (ctx , & opts , commitData )
571+ comments , err := git_model .FindCommitCommentsByLine (ctx , & opts , commitComment )
570572 if err != nil {
571573 ctx .ServerError ("FetchCodeCommentsByLine" , err )
572574 return
@@ -581,7 +583,7 @@ func renderCommitData(ctx *context.Context, commitData *git_model.CommitData, or
581583
582584 upload .AddUploadContext (ctx , "comment" )
583585 ctx .Data ["comments" ] = comments
584- ctx .Data ["AfterCommitID" ] = commitData .CommitSHA
586+ ctx .Data ["AfterCommitID" ] = commitComment .CommitSHA
585587 ctx .Data ["CanBlockUser" ] = func (blocker , blockee * user_model.User ) bool {
586588 return user_service .CanBlockUser (ctx , ctx .Doer , blocker , blockee )
587589 }
@@ -598,16 +600,16 @@ func renderCommitData(ctx *context.Context, commitData *git_model.CommitData, or
598600
599601// DeleteCommitComment delete comment of commit
600602func DeleteCommitComment (ctx * context.Context ) {
601- commitData , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
603+ commitComment , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
602604 if err != nil {
603605 return
604606 }
605- if ! ctx .IsSigned || (ctx .Doer .ID != commitData .PosterID ) {
607+ if ! ctx .IsSigned || (ctx .Doer .ID != commitComment .PosterID ) {
606608 ctx .HTTPError (http .StatusForbidden )
607609 return
608610 }
609611
610- if err = git_model .DeleteCommitComment (ctx , commitData ); err != nil {
612+ if err = git_model .DeleteCommitComment (ctx , commitComment ); err != nil {
611613 ctx .ServerError ("GetCommitDataByID" , err )
612614 return
613615 }
@@ -616,22 +618,22 @@ func DeleteCommitComment(ctx *context.Context) {
616618}
617619
618620func UpdateCommitComment (ctx * context.Context ) {
619- commitData , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
621+ commitComment , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
620622 if err != nil {
621623 ctx .ServerError ("GetCommitDataByID" , err )
622624 return
623625 }
624626
625- if ! ctx .IsSigned || (ctx .Doer .ID != commitData .PosterID ) {
627+ if ! ctx .IsSigned || (ctx .Doer .ID != commitComment .PosterID ) {
626628 ctx .HTTPError (http .StatusForbidden )
627629 return
628630 }
629631
630632 newContent := ctx .FormString ("content" )
631633
632- if newContent != commitData .Comment {
633- commitData .Comment = newContent
634- commitData .ContentVersion ++
634+ if newContent != commitComment .Comment {
635+ commitComment .Comment = newContent
636+ commitComment .ContentVersion ++
635637 }
636638 files := ctx .FormStrings ("files[]" )
637639 filesMap := make (map [string ]struct {})
@@ -645,7 +647,7 @@ func UpdateCommitComment(ctx *context.Context) {
645647 }
646648
647649 attachmentMap := make (git_model.AttachmentMap )
648- err = json .Unmarshal ([]byte (commitData .Attachments ), & attachmentMap )
650+ err = json .Unmarshal ([]byte (commitComment .Attachments ), & attachmentMap )
649651 if err != nil {
650652 ctx .ServerError ("UpdateCommitComment" , err )
651653 return
@@ -657,21 +659,19 @@ func UpdateCommitComment(ctx *context.Context) {
657659 delete (attachmentMap , key )
658660 }
659661 }
660- for uuid , attachment := range uploadedAttachments {
661- attachmentMap [uuid ] = attachment
662- }
663- err = git_model .UpdateCommitData (ctx , & attachmentMap , commitData )
662+ maps .Copy (attachmentMap , uploadedAttachments )
663+ err = git_model .UpdateCommitData (ctx , & attachmentMap , commitComment )
664664 if err != nil {
665665 ctx .ServerError ("UpdateCommitComment" , err )
666666 return
667667 }
668668
669669 var renderedContent template.HTML
670- if commitData .Comment != "" {
670+ if commitComment .Comment != "" {
671671 rctx := renderhelper .NewRenderContextRepoComment (ctx , ctx .Repo .Repository , renderhelper.RepoCommentOptions {
672- FootnoteContextID : strconv .FormatInt (commitData .ID , 10 ),
672+ FootnoteContextID : strconv .FormatInt (commitComment .ID , 10 ),
673673 })
674- renderedContent , err = markdown .RenderString (rctx , commitData .Comment )
674+ renderedContent , err = markdown .RenderString (rctx , commitComment .Comment )
675675 if err != nil {
676676 ctx .ServerError ("RenderString" , err )
677677 return
@@ -682,9 +682,8 @@ func UpdateCommitComment(ctx *context.Context) {
682682 }
683683
684684 attachHTML , err := ctx .RenderToHTML (tplCommitAttachment , map [string ]any {
685- "ctx" : ctx .Data ,
686- "Attachments" : attachmentMap ,
687- "CommitData" : commitData ,
685+ "Attachments" : attachmentMap ,
686+ "CommitComment" : commitComment ,
688687 })
689688 if err != nil {
690689 ctx .ServerError ("attachmentsHTML.HTMLString" , err )
@@ -701,36 +700,38 @@ func UpdateCommitComment(ctx *context.Context) {
701700 upload .AddUploadContext (ctx , "comment" )
702701 ctx .JSON (http .StatusOK , map [string ]any {
703702 "content" : renderedContent ,
704- "contentVersion" : commitData .ContentVersion ,
703+ "contentVersion" : commitComment .ContentVersion ,
705704 "attachments" : attachHTML ,
706705 })
707706}
708707
709708func CancelCommitComment (ctx * context.Context ) {
710709 if ctx .Session .Get ("attachmentsMaps" ) != nil {
711710 err := ctx .Session .Delete ("attachmentsMaps" )
712- ctx .ServerError ("CancelCommitComment" , err )
713- return
711+ if err != nil {
712+ ctx .ServerError ("CancelCommitComment" , err )
713+ return
714+ }
714715 }
715716}
716717
717718func ChangeCommitCommentReaction (ctx * context.Context ) {
718719 form := web .GetForm (ctx ).(* forms.ReactionForm )
719- commitData , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
720+ commitComment , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
720721 if err != nil {
721722 ctx .ServerError ("GetCommitDataByID" , err )
722723 return
723724 }
724725
725726 action := ctx .PathParam ("action" )
726727
727- if ! ctx .IsSigned || (ctx .Doer .ID != commitData .PosterID ) {
728+ if ! ctx .IsSigned || (ctx .Doer .ID != commitComment .PosterID ) {
728729 if log .IsTrace () {
729730 if ctx .IsSigned {
730731 log .Trace ("Permission Denied: User %-v not the Poster (ID: %d) and cannot read %s in Repo %-v.\n " +
731732 "User in Repo has Permissions: %-+v" ,
732733 ctx .Doer ,
733- commitData .PosterID ,
734+ commitComment .PosterID ,
734735 ctx .Repo .Repository ,
735736 ctx .Repo .Permission )
736737 } else {
@@ -744,14 +745,14 @@ func ChangeCommitCommentReaction(ctx *context.Context) {
744745
745746 switch action {
746747 case "react" :
747- err := git_service .CreateCommentReaction (ctx , ctx .Doer , commitData , form .Content )
748+ err := git_service .CreateCommentReaction (ctx , ctx .Doer , commitComment , form .Content )
748749 if err != nil {
749750 log .Info ("CreateCommentReaction: %s" , err )
750751 break
751752 }
752753
753754 case "unreact" :
754- if err := git_service .DeleteCommentReaction (ctx , ctx .Doer , commitData , form .Content ); err != nil {
755+ if err := git_service .DeleteCommentReaction (ctx , ctx .Doer , commitComment , form .Content ); err != nil {
755756 ctx .ServerError ("DeleteCommentReaction" , err )
756757 return
757758 }
@@ -761,18 +762,18 @@ func ChangeCommitCommentReaction(ctx *context.Context) {
761762 return
762763 }
763764
764- if len (commitData .Reactions ) == 0 {
765+ if len (commitComment .Reactions ) == 0 {
765766 ctx .JSON (http .StatusOK , map [string ]any {
766767 "empty" : true ,
767768 "html" : "" ,
768769 })
769770 return
770771 }
771- reactions , _ := commitData .GroupReactionsByType ()
772+ reactions , _ := commitComment .GroupReactionsByType ()
772773 html , err := ctx .RenderToHTML (tplCommitCommentReactions , map [string ]any {
773- "ActionURL" : fmt .Sprintf ("%s/commit/%s/comments/%d/reactions" , ctx .Repo .RepoLink , commitData .CommitSHA , commitData .ID ),
774- "Reactions" : reactions ,
775- "CommitData " : commitData ,
774+ "ActionURL" : fmt .Sprintf ("%s/commit/%s/comments/%d/reactions" , ctx .Repo .RepoLink , commitComment .CommitSHA , commitComment .ID ),
775+ "Reactions" : reactions ,
776+ "CommitComment " : commitComment ,
776777 })
777778 if err != nil {
778779 ctx .ServerError ("ChangeCommentReaction.HTMLString" , err )
@@ -865,19 +866,19 @@ func DeleteCommitAttachment(ctx *context.Context) {
865866}
866867
867868func GetCommitAttachmentByUUID (ctx * context.Context ) {
868- commitData , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
869+ commitComment , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
869870 if err != nil {
870871 return
871872 }
872873
873- repository , err := repo_model .GetRepositoryByID (ctx , commitData .RefRepoID )
874+ repository , err := repo_model .GetRepositoryByID (ctx , commitComment .RefRepoID )
874875 if err != nil {
875876 ctx .ServerError ("GetRepositoryByID" , err )
876877 return
877878 }
878879
879880 attachmentMap := make (git_model.AttachmentMap )
880- err = json .Unmarshal ([]byte (commitData .Attachments ), & attachmentMap )
881+ err = json .Unmarshal ([]byte (commitComment .Attachments ), & attachmentMap )
881882 if err != nil {
882883 ctx .ServerError ("GetCommitAttachmentByUUID" , err )
883884 return
@@ -909,16 +910,16 @@ func GetCommitAttachmentByUUID(ctx *context.Context) {
909910 }
910911 defer fr .Close ()
911912
912- common .ServeContentByReadSeeker (ctx .Base , attachment .FileName , util .ToPointer (commitData .CreatedUnix .AsTime ()), fr )
913+ common .ServeContentByReadSeeker (ctx .Base , attachment .FileName , util .ToPointer (commitComment .CreatedUnix .AsTime ()), fr )
913914}
914915
915916func GetCommitAttachments (ctx * context.Context ) {
916- commitData , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
917+ commitComment , err := git_model .GetCommitDataByID (ctx , ctx .Repo .Repository .ID , ctx .PathParamInt64 ("id" ))
917918 if err != nil {
918919 return
919920 }
920921
921- repository , err := repo_model .GetRepositoryByID (ctx , commitData .RefRepoID )
922+ repository , err := repo_model .GetRepositoryByID (ctx , commitComment .RefRepoID )
922923 if err != nil {
923924 ctx .ServerError ("GetRepositoryByID" , err )
924925 return
@@ -937,7 +938,7 @@ func GetCommitAttachments(ctx *context.Context) {
937938 }
938939
939940 attachmentMap := make (git_model.AttachmentMap )
940- err = json .Unmarshal ([]byte (commitData .Attachments ), & attachmentMap )
941+ err = json .Unmarshal ([]byte (commitComment .Attachments ), & attachmentMap )
941942 if err != nil {
942943 ctx .ServerError ("GetCommitAttachments" , err )
943944 return
0 commit comments