aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo
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
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')
-rw-r--r--models/repo/repo.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/models/repo/repo.go b/models/repo/repo.go
index 57d85435eb..f6097d2d6a 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -25,6 +25,22 @@ import (
"code.gitea.io/gitea/modules/util"
)
+// ErrUserDoesNotHaveAccessToRepo represets an error where the user doesn't has access to a given repo.
+type ErrUserDoesNotHaveAccessToRepo struct {
+ UserID int64
+ RepoName string
+}
+
+// IsErrUserDoesNotHaveAccessToRepo checks if an error is a ErrRepoFileAlreadyExists.
+func IsErrUserDoesNotHaveAccessToRepo(err error) bool {
+ _, ok := err.(ErrUserDoesNotHaveAccessToRepo)
+ return ok
+}
+
+func (err ErrUserDoesNotHaveAccessToRepo) Error() string {
+ return fmt.Sprintf("user doesn't have access to repo [user_id: %d, repo_name: %s]", err.UserID, err.RepoName)
+}
+
var (
reservedRepoNames = []string{".", "..", "-"}
reservedRepoPatterns = []string{"*.git", "*.wiki", "*.rss", "*.atom"}
@@ -743,3 +759,34 @@ func CountRepositories(ctx context.Context, opts CountRepositoryOptions) (int64,
}
return count, nil
}
+
+// StatsCorrectNumClosed update repository's issue related numbers
+func StatsCorrectNumClosed(ctx context.Context, id int64, isPull bool, field string) error {
+ _, err := db.Exec(ctx, "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
+}
+
+// UpdateRepoIssueNumbers update repository issue numbers
+func UpdateRepoIssueNumbers(ctx context.Context, repoID int64, isPull, isClosed bool) error {
+ e := db.GetEngine(ctx)
+ if isPull {
+ if _, err := e.ID(repoID).Decr("num_pulls").Update(new(Repository)); err != nil {
+ return err
+ }
+ if isClosed {
+ if _, err := e.ID(repoID).Decr("num_closed_pulls").Update(new(Repository)); err != nil {
+ return err
+ }
+ }
+ } else {
+ if _, err := e.ID(repoID).Decr("num_issues").Update(new(Repository)); err != nil {
+ return err
+ }
+ if isClosed {
+ if _, err := e.ID(repoID).Decr("num_closed_issues").Update(new(Repository)); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}