Skip to content

Commit 82a7cb9

Browse files
committed
simplified code via func
1 parent a134401 commit 82a7cb9

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

models/issue_comment.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,16 @@ func CreatePullPushComment(doer *User, repo *Repository, issue *Issue, commit *P
639639
return err
640640
}
641641

642+
func updateCommentRepoFullName(e Engine, repoID int64, newRepoFullName string) error {
643+
_, err := e.Where("issue_id IN (SELECT id FROM issue WHERE repo_id = ?)", repoID).
644+
And("`type` = ?", CommentTypePullPushCommit).
645+
Cols("repo_full_name").
646+
Update(&Comment{
647+
RepoFullName: newRepoFullName,
648+
})
649+
return err
650+
}
651+
642652
// GetCommentByID returns the comment by given ID.
643653
func GetCommentByID(id int64) (*Comment, error) {
644654
c := new(Comment)

models/repo.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,13 +1478,8 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
14781478
}
14791479

14801480
// Update comment repofullname
1481-
if _, err := sess.Where("issue_id IN (SELECT id FROM issue WHERE repo_id = ?)", repo.ID).
1482-
And("`type` = ?", CommentTypePullPushCommit).
1483-
Cols("repo_full_name").
1484-
Update(&Comment{
1485-
RepoFullName: repo.FullName(),
1486-
}); err != nil {
1487-
return fmt.Errorf("update comment: %v", err)
1481+
if err := updateCommentRepoFullName(sess, repo.ID, repo.FullName()); err != nil {
1482+
return fmt.Errorf("updateCommentRepoFullName: %v", err)
14881483
}
14891484

14901485
// Remove redundant collaborators.
@@ -1605,14 +1600,7 @@ func ChangeRepositoryName(repo *Repository, oldRepoName, newRepoName string) (er
16051600
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalUncycloPath())
16061601
}
16071602

1608-
_, err = x.Where("issue_id IN (SELECT id FROM issue WHERE repo_id = ?)", repo.ID).
1609-
And("`type` = ?", CommentTypePullPushCommit).
1610-
Cols("repo_full_name").
1611-
Update(&Comment{
1612-
RepoFullName: u.Name + "/" + newRepoName,
1613-
})
1614-
1615-
return err
1603+
return updateCommentRepoFullName(x, repo.ID, u.Name+"/"+newRepoName)
16161604
}
16171605

16181606
func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {

models/user.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,7 @@ func ChangeUserName(u *User, newUserName string) (err error) {
806806
Iterate(new(Repository), func(idx int, bean interface{}) error {
807807
repo := bean.(*Repository)
808808
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalUncycloPath())
809-
_, err := x.Where("issue_id IN (SELECT id FROM issue WHERE repo_id = ?)", repo.ID).
810-
And("`type` = ?", CommentTypePullPushCommit).
811-
Cols("repo_full_name").
812-
Update(&Comment{
813-
RepoFullName: newUserName + "/" + repo.Name,
814-
})
815-
return err
809+
return updateCommentRepoFullName(x, repo.ID, newUserName+"/"+repo.Name)
816810
}); err != nil {
817811
return fmt.Errorf("Delete repository wiki local copy: %v", err)
818812
}

0 commit comments

Comments
 (0)