@@ -779,8 +779,8 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) {
779
779
return err
780
780
}
781
781
782
- // CreateCommentCtx creates comment with context
783
- func CreateCommentCtx (ctx context.Context , opts * CreateCommentOptions ) (_ * Comment , err error ) {
782
+ // CreateComment creates comment with context
783
+ func CreateComment (ctx context.Context , opts * CreateCommentOptions ) (_ * Comment , err error ) {
784
784
e := db .GetEngine (ctx )
785
785
var LabelID int64
786
786
if opts .Label != nil {
@@ -915,7 +915,7 @@ func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Is
915
915
Issue : issue ,
916
916
Content : content ,
917
917
}
918
- comment , err := CreateCommentCtx (ctx , opts )
918
+ comment , err := CreateComment (ctx , opts )
919
919
if err != nil {
920
920
return nil , err
921
921
}
@@ -940,7 +940,7 @@ func createIssueDependencyComment(ctx context.Context, doer *user_model.User, is
940
940
Issue : issue ,
941
941
DependentIssueID : dependentIssue .ID ,
942
942
}
943
- if _ , err = CreateCommentCtx (ctx , opts ); err != nil {
943
+ if _ , err = CreateComment (ctx , opts ); err != nil {
944
944
return
945
945
}
946
946
@@ -951,7 +951,7 @@ func createIssueDependencyComment(ctx context.Context, doer *user_model.User, is
951
951
Issue : dependentIssue ,
952
952
DependentIssueID : issue .ID ,
953
953
}
954
- _ , err = CreateCommentCtx (ctx , opts )
954
+ _ , err = CreateComment (ctx , opts )
955
955
return err
956
956
}
957
957
@@ -993,55 +993,6 @@ type CreateCommentOptions struct {
993
993
Invalidated bool
994
994
}
995
995
996
- // CreateComment creates comment of issue or commit.
997
- func CreateComment (opts * CreateCommentOptions ) (comment * Comment , err error ) {
998
- ctx , committer , err := db .TxContext (db .DefaultContext )
999
- if err != nil {
1000
- return nil , err
1001
- }
1002
- defer committer .Close ()
1003
-
1004
- comment , err = CreateCommentCtx (ctx , opts )
1005
- if err != nil {
1006
- return nil , err
1007
- }
1008
-
1009
- if err = committer .Commit (); err != nil {
1010
- return nil , err
1011
- }
1012
-
1013
- return comment , nil
1014
- }
1015
-
1016
- // CreateRefComment creates a commit reference comment to issue.
1017
- func CreateRefComment (doer * user_model.User , repo * repo_model.Repository , issue * Issue , content , commitSHA string ) error {
1018
- if len (commitSHA ) == 0 {
1019
- return fmt .Errorf ("cannot create reference with empty commit SHA" )
1020
- }
1021
-
1022
- // Check if same reference from same commit has already existed.
1023
- has , err := db .GetEngine (db .DefaultContext ).Get (& Comment {
1024
- Type : CommentTypeCommitRef ,
1025
- IssueID : issue .ID ,
1026
- CommitSHA : commitSHA ,
1027
- })
1028
- if err != nil {
1029
- return fmt .Errorf ("check reference comment: %w" , err )
1030
- } else if has {
1031
- return nil
1032
- }
1033
-
1034
- _ , err = CreateComment (& CreateCommentOptions {
1035
- Type : CommentTypeCommitRef ,
1036
- Doer : doer ,
1037
- Repo : repo ,
1038
- Issue : issue ,
1039
- CommitSHA : commitSHA ,
1040
- Content : content ,
1041
- })
1042
- return err
1043
- }
1044
-
1045
996
// GetCommentByID returns the comment by given ID.
1046
997
func GetCommentByID (ctx context.Context , id int64 ) (* Comment , error ) {
1047
998
c := new (Comment )
@@ -1317,39 +1268,6 @@ func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID
1317
1268
return err
1318
1269
}
1319
1270
1320
- // CreatePushPullComment create push code to pull base comment
1321
- func CreatePushPullComment (ctx context.Context , pusher * user_model.User , pr * PullRequest , oldCommitID , newCommitID string ) (comment * Comment , err error ) {
1322
- if pr .HasMerged || oldCommitID == "" || newCommitID == "" {
1323
- return nil , nil
1324
- }
1325
-
1326
- ops := & CreateCommentOptions {
1327
- Type : CommentTypePullRequestPush ,
1328
- Doer : pusher ,
1329
- Repo : pr .BaseRepo ,
1330
- }
1331
-
1332
- var data PushActionContent
1333
-
1334
- data .CommitIDs , data .IsForcePush , err = getCommitIDsFromRepo (ctx , pr .BaseRepo , oldCommitID , newCommitID , pr .BaseBranch )
1335
- if err != nil {
1336
- return nil , err
1337
- }
1338
-
1339
- ops .Issue = pr .Issue
1340
-
1341
- dataJSON , err := json .Marshal (data )
1342
- if err != nil {
1343
- return nil , err
1344
- }
1345
-
1346
- ops .Content = string (dataJSON )
1347
-
1348
- comment , err = CreateComment (ops )
1349
-
1350
- return comment , err
1351
- }
1352
-
1353
1271
// CreateAutoMergeComment is a internal function, only use it for CommentTypePRScheduledToAutoMerge and CommentTypePRUnScheduledToAutoMerge CommentTypes
1354
1272
func CreateAutoMergeComment (ctx context.Context , typ CommentType , pr * PullRequest , doer * user_model.User ) (comment * Comment , err error ) {
1355
1273
if typ != CommentTypePRScheduledToAutoMerge && typ != CommentTypePRUnScheduledToAutoMerge {
@@ -1363,7 +1281,7 @@ func CreateAutoMergeComment(ctx context.Context, typ CommentType, pr *PullReques
1363
1281
return
1364
1282
}
1365
1283
1366
- comment , err = CreateCommentCtx (ctx , & CreateCommentOptions {
1284
+ comment , err = CreateComment (ctx , & CreateCommentOptions {
1367
1285
Type : typ ,
1368
1286
Doer : doer ,
1369
1287
Repo : pr .BaseRepo ,
@@ -1372,120 +1290,6 @@ func CreateAutoMergeComment(ctx context.Context, typ CommentType, pr *PullReques
1372
1290
return comment , err
1373
1291
}
1374
1292
1375
- // getCommitsFromRepo get commit IDs from repo in between oldCommitID and newCommitID
1376
- // isForcePush will be true if oldCommit isn't on the branch
1377
- // Commit on baseBranch will skip
1378
- func getCommitIDsFromRepo (ctx context.Context , repo * repo_model.Repository , oldCommitID , newCommitID , baseBranch string ) (commitIDs []string , isForcePush bool , err error ) {
1379
- repoPath := repo .RepoPath ()
1380
- gitRepo , closer , err := git .RepositoryFromContextOrOpen (ctx , repoPath )
1381
- if err != nil {
1382
- return nil , false , err
1383
- }
1384
- defer closer .Close ()
1385
-
1386
- oldCommit , err := gitRepo .GetCommit (oldCommitID )
1387
- if err != nil {
1388
- return nil , false , err
1389
- }
1390
-
1391
- if err = oldCommit .LoadBranchName (); err != nil {
1392
- return nil , false , err
1393
- }
1394
-
1395
- if len (oldCommit .Branch ) == 0 {
1396
- commitIDs = make ([]string , 2 )
1397
- commitIDs [0 ] = oldCommitID
1398
- commitIDs [1 ] = newCommitID
1399
-
1400
- return commitIDs , true , err
1401
- }
1402
-
1403
- newCommit , err := gitRepo .GetCommit (newCommitID )
1404
- if err != nil {
1405
- return nil , false , err
1406
- }
1407
-
1408
- commits , err := newCommit .CommitsBeforeUntil (oldCommitID )
1409
- if err != nil {
1410
- return nil , false , err
1411
- }
1412
-
1413
- commitIDs = make ([]string , 0 , len (commits ))
1414
- commitChecks := make (map [string ]* commitBranchCheckItem )
1415
-
1416
- for _ , commit := range commits {
1417
- commitChecks [commit .ID .String ()] = & commitBranchCheckItem {
1418
- Commit : commit ,
1419
- Checked : false ,
1420
- }
1421
- }
1422
-
1423
- if err = commitBranchCheck (gitRepo , newCommit , oldCommitID , baseBranch , commitChecks ); err != nil {
1424
- return
1425
- }
1426
-
1427
- for i := len (commits ) - 1 ; i >= 0 ; i -- {
1428
- commitID := commits [i ].ID .String ()
1429
- if item , ok := commitChecks [commitID ]; ok && item .Checked {
1430
- commitIDs = append (commitIDs , commitID )
1431
- }
1432
- }
1433
-
1434
- return commitIDs , isForcePush , err
1435
- }
1436
-
1437
- type commitBranchCheckItem struct {
1438
- Commit * git.Commit
1439
- Checked bool
1440
- }
1441
-
1442
- func commitBranchCheck (gitRepo * git.Repository , startCommit * git.Commit , endCommitID , baseBranch string , commitList map [string ]* commitBranchCheckItem ) error {
1443
- if startCommit .ID .String () == endCommitID {
1444
- return nil
1445
- }
1446
-
1447
- checkStack := make ([]string , 0 , 10 )
1448
- checkStack = append (checkStack , startCommit .ID .String ())
1449
-
1450
- for len (checkStack ) > 0 {
1451
- commitID := checkStack [0 ]
1452
- checkStack = checkStack [1 :]
1453
-
1454
- item , ok := commitList [commitID ]
1455
- if ! ok {
1456
- continue
1457
- }
1458
-
1459
- if item .Commit .ID .String () == endCommitID {
1460
- continue
1461
- }
1462
-
1463
- if err := item .Commit .LoadBranchName (); err != nil {
1464
- return err
1465
- }
1466
-
1467
- if item .Commit .Branch == baseBranch {
1468
- continue
1469
- }
1470
-
1471
- if item .Checked {
1472
- continue
1473
- }
1474
-
1475
- item .Checked = true
1476
-
1477
- parentNum := item .Commit .ParentCount ()
1478
- for i := 0 ; i < parentNum ; i ++ {
1479
- parentCommit , err := item .Commit .Parent (i )
1480
- if err != nil {
1481
- return err
1482
- }
1483
- checkStack = append (checkStack , parentCommit .ID .String ())
1484
- }
1485
- }
1486
- return nil
1487
- }
1488
-
1489
1293
// RemapExternalUser ExternalUserRemappable interface
1490
1294
func (c * Comment ) RemapExternalUser (externalName string , externalID , userID int64 ) error {
1491
1295
c .OriginalAuthor = externalName
0 commit comments