summaryrefslogtreecommitdiffstats
path: root/models/repo.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-06-13 17:37:59 +0800
committerGitHub <noreply@github.com>2022-06-13 17:37:59 +0800
commit1a9821f57a0293db3adc0eab8aff08ca5fa1026c (patch)
tree3c3d02813eb63c0d0827ef6d9745f6dcdd2636cb /models/repo.go
parent3708ca8e2849ca7e36e6bd15ec6935a2a2d81e55 (diff)
downloadgitea-1a9821f57a0293db3adc0eab8aff08ca5fa1026c.tar.gz
gitea-1a9821f57a0293db3adc0eab8aff08ca5fa1026c.zip
Move issues related files into models/issues (#19931)
* Move access and repo permission to models/perm/access * fix test * fix git test * Move functions sequence * Some improvements per @KN4CK3R and @delvh * Move issues related code to models/issues * Move some issues related sub package * Merge * Fix test * Fix test * Fix test * Fix test * Rename some files
Diffstat (limited to 'models/repo.go')
-rw-r--r--models/repo.go20
1 files changed, 7 insertions, 13 deletions
diff --git a/models/repo.go b/models/repo.go
index a8aa18381d..e9d83f5f32 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -281,7 +281,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
&access_model.Access{RepoID: repo.ID},
&Action{RepoID: repo.ID},
&repo_model.Collaboration{RepoID: repoID},
- &Comment{RefRepoID: repoID},
+ &issues_model.Comment{RefRepoID: repoID},
&git_model.CommitStatus{RepoID: repoID},
&git_model.DeletedBranch{RepoID: repoID},
&webhook.HookTask{RepoID: repoID},
@@ -306,18 +306,18 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
}
// Delete Labels and related objects
- if err := deleteLabelsByRepoID(ctx, repoID); err != nil {
+ if err := issues_model.DeleteLabelsByRepoID(ctx, repoID); err != nil {
return err
}
// Delete Pulls and related objects
- if err := deletePullsByBaseRepoID(ctx, repoID); err != nil {
+ if err := issues_model.DeletePullsByBaseRepoID(ctx, repoID); err != nil {
return err
}
// Delete Issues and related objects
var attachmentPaths []string
- if attachmentPaths, err = deleteIssuesByRepoID(ctx, repoID); err != nil {
+ if attachmentPaths, err = issues_model.DeleteIssuesByRepoID(ctx, repoID); err != nil {
return err
}
@@ -576,16 +576,11 @@ func repoStatsCorrectNum(ctx context.Context, id int64, isPull bool, field strin
}
func repoStatsCorrectNumClosedIssues(ctx context.Context, id int64) error {
- return repoStatsCorrectNumClosed(ctx, id, false, "num_closed_issues")
+ return repo_model.StatsCorrectNumClosed(ctx, id, false, "num_closed_issues")
}
func repoStatsCorrectNumClosedPulls(ctx context.Context, id int64) error {
- return repoStatsCorrectNumClosed(ctx, id, true, "num_closed_pulls")
-}
-
-func repoStatsCorrectNumClosed(ctx context.Context, id int64, isPull bool, field string) error {
- _, err := db.GetEngine(ctx).Exec("UPDATE `repository` SET "+field+"=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, isPull, id)
- return err
+ return repo_model.StatsCorrectNumClosed(ctx, id, true, "num_closed_pulls")
}
func statsQuery(args ...interface{}) func(context.Context) ([]map[string][]byte, error) {
@@ -687,12 +682,11 @@ func CheckRepoStats(ctx context.Context) error {
continue
}
- rawResult, err := e.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID)
+ _, err = e.SQL("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID).Get(&repo.NumForks)
if err != nil {
log.Error("Select count of forks[%d]: %v", repo.ID, err)
continue
}
- repo.NumForks = int(parseCountResult(rawResult))
if _, err = e.ID(repo.ID).Cols("num_forks").Update(repo); err != nil {
log.Error("UpdateRepository[%d]: %v", id, err)