@@ -5,6 +5,7 @@ package git
55
66import  (
77	"context" 
8+ 	"sort" 
89
910	asymkey_model "code.gitea.io/gitea/models/asymkey" 
1011	"code.gitea.io/gitea/models/db" 
@@ -14,6 +15,7 @@ import (
1415	"code.gitea.io/gitea/modules/container" 
1516	"code.gitea.io/gitea/modules/git" 
1617	asymkey_service "code.gitea.io/gitea/services/asymkey" 
18+ 	"code.gitea.io/gitea/services/gitdiff" 
1719)
1820
1921// ParseCommitsWithSignature checks if signaute of commits are corresponding to users gpg keys. 
@@ -88,3 +90,69 @@ func ParseCommitsWithStatus(ctx context.Context, oldCommits []*asymkey_model.Sig
8890	}
8991	return  newCommits , nil 
9092}
93+ 
94+ func  CreateCommitComment (ctx  context.Context , doer  * user_model.User , gitRepo  * git.Repository , opts  git_model.CreateCommitDataOptions ) (* git_model.CommitData , error ) {
95+ 	comment , err  :=  git_model .CreateCommitData (ctx , & opts )
96+ 	if  err  !=  nil  {
97+ 		return  nil , err 
98+ 	}
99+ 	return  comment , nil 
100+ }
101+ 
102+ // LoadComments loads comments into each line 
103+ func  LoadCommitComments (ctx  context.Context , diff  * gitdiff.Diff , commitData  * git_model.CommitData , currentUser  * user_model.User ) error  {
104+ 	opts  :=  git_model.FindCommitDataOptions {
105+ 		CommitSHA : commitData .CommitSHA ,
106+ 	}
107+ 
108+ 	commitData , err  :=  git_model .GetCommitDataBySHA (ctx , commitData .RefRepoID , commitData .CommitSHA )
109+ 	if  err  !=  nil  {
110+ 		return  err 
111+ 	}
112+ 	commitComments , err  :=  git_model .FindCommitCommentsByCommit (ctx , & opts , commitData )
113+ 	if  err  !=  nil  {
114+ 		return  err 
115+ 	}
116+ 
117+ 	for  _ , file  :=  range  diff .Files  {
118+ 		for  _ , cc  :=  range  commitComments  {
119+ 			if  cc .FileName  ==  file .Name  {
120+ 				for  _ , section  :=  range  file .Sections  {
121+ 					for  _ , line  :=  range  section .Lines  {
122+ 						if  cc .Line  ==  int64 (line .LeftIdx * - 1 ) {
123+ 							line .CommitComments  =  append (line .CommitComments , cc )
124+ 							cc .Repo  =  commitData .Repo 
125+ 							cc .Poster  =  commitData .Poster 
126+ 						}
127+ 						if  cc .Line  ==  int64 (line .RightIdx ) {
128+ 							line .CommitComments  =  append (line .CommitComments , cc )
129+ 							cc .Repo  =  commitData .Repo 
130+ 							cc .Poster  =  commitData .Poster 
131+ 						}
132+ 						sort .SliceStable (line .CommitComments , func (i , j  int ) bool  {
133+ 							return  line .CommitComments [i ].CreatedUnix  <  line .CommitComments [j ].CreatedUnix 
134+ 						})
135+ 					}
136+ 				}
137+ 			}
138+ 		}
139+ 	}
140+ 	return  nil 
141+ }
142+ 
143+ // CreateCommentReaction creates a reaction on a comment. 
144+ func  CreateCommentReaction (ctx  context.Context , doer  * user_model.User , commitData  * git_model.CommitData , reaction  string ) error  {
145+ 	err  :=  git_model .CreateCommitCommentReaction (ctx , reaction , doer .ID , commitData )
146+ 	if  err  !=  nil  {
147+ 		return  err 
148+ 	}
149+ 	return  nil 
150+ }
151+ 
152+ func  DeleteCommentReaction (ctx  context.Context , doer  * user_model.User , commitData  * git_model.CommitData , reaction  string ) error  {
153+ 	err  :=  git_model .DeleteCommentReaction (ctx , reaction , doer .ID , commitData )
154+ 	if  err  !=  nil  {
155+ 		return  err 
156+ 	}
157+ 	return  nil 
158+ }
0 commit comments