* Move access and repo permission to models/perm/access * fix test * Move some git related files into sub package models/git * Fix build * fix git test * move lfs to sub package * move more git related functions to models/git * Move functions sequence * Some improvements per @KN4CK3R and @delvh
Unified · Split
| @@ -9,8 +9,8 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | "fmt" |
| 10 | 10 | "strings" |
| 11 | 11 | |
| 12 | − "code.gitea.io/gitea/models" | |
| 13 | 12 | "code.gitea.io/gitea/models/db" |
| 13 | + git_model "code.gitea.io/gitea/models/git" | |
| 14 | 14 | "code.gitea.io/gitea/models/migrations" |
| 15 | 15 | repo_model "code.gitea.io/gitea/models/repo" |
| 16 | 16 | user_model "code.gitea.io/gitea/models/user" |
| @@ -88,7 +88,7 @@ func migrateAttachments(dstStorage storage.ObjectStorage) error { · 71 unmodified lines | ||
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | func migrateLFS(dstStorage storage.ObjectStorage) error { |
| 91 | − return models.IterateLFS(func(mo *models.LFSMetaObject) error { | |
| 91 | + return git_model.IterateLFS(func(mo *git_model.LFSMetaObject) error { | |
| 92 | 92 | _, err := storage.Copy(dstStorage, mo.RelativePath(), storage.LFS, mo.RelativePath()) |
| 93 | 93 | return err |
| 94 | 94 | }) |
| @@ -17,8 +17,8 @@ import ( · 16 unmodified lines | ||
| 17 | 17 | "strings" |
| 18 | 18 | "time" |
| 19 | 19 | |
| 20 | − "code.gitea.io/gitea/models" | |
| 21 | 20 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 21 | + git_model "code.gitea.io/gitea/models/git" | |
| 22 | 22 | "code.gitea.io/gitea/models/perm" |
| 23 | 23 | "code.gitea.io/gitea/modules/git" |
| 24 | 24 | "code.gitea.io/gitea/modules/json" |
| @@ -276,7 +276,7 @@ func runServ(c *cli.Context) error { · 251 unmodified lines | ||
| 276 | 276 | return fail("Internal error", "Failed to sign JWT token: %v", err) |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | − tokenAuthentication := &models.LFSTokenResponse{ | |
| 279 | + tokenAuthentication := &git_model.LFSTokenResponse{ | |
| 280 | 280 | Header: make(map[string]string), |
| 281 | 281 | Href: url, |
| 282 | 282 | } |
| @@ -12,7 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "strings" |
| 13 | 13 | "testing" |
| 14 | 14 | |
| 15 | − "code.gitea.io/gitea/models" | |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 16 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 17 | "code.gitea.io/gitea/models/unittest" |
| 18 | 18 | user_model "code.gitea.io/gitea/models/user" |
| @@ -76,7 +76,7 @@ func TestAPILFSBatch(t *testing.T) { · 57 unmodified lines | ||
| 76 | 76 | |
| 77 | 77 | content := []byte("dummy1") |
| 78 | 78 | oid := storeObjectInRepo(t, repo.ID, &content) |
| 79 | − defer models.RemoveLFSMetaObjectByOid(repo.ID, oid) | |
| 79 | + defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid) | |
| 80 | 80 | |
| 81 | 81 | session := loginUser(t, "user2") |
| 82 | 82 | |
| @@ -260,9 +260,9 @@ func TestAPILFSBatch(t *testing.T) { · 177 unmodified lines | ||
| 260 | 260 | content := []byte("dummy0") |
| 261 | 261 | storeObjectInRepo(t, repo2.ID, &content) |
| 262 | 262 | |
| 263 | − meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 263 | + meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 264 | 264 | assert.Nil(t, meta) |
| 265 | − assert.Equal(t, models.ErrLFSObjectNotExist, err) | |
| 265 | + assert.Equal(t, git_model.ErrLFSObjectNotExist, err) | |
| 266 | 266 | |
| 267 | 267 | req := newRequest(t, &lfs.BatchRequest{ |
| 268 | 268 | Operation: "upload", |
| @@ -275,7 +275,7 @@ func TestAPILFSBatch(t *testing.T) { · 6 unmodified lines | ||
| 275 | 275 | assert.Nil(t, br.Objects[0].Error) |
| 276 | 276 | assert.Empty(t, br.Objects[0].Actions) |
| 277 | 277 | |
| 278 | − meta, err = models.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 278 | + meta, err = git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 279 | 279 | assert.NoError(t, err) |
| 280 | 280 | assert.NotNil(t, meta) |
| 281 | 281 | |
| @@ -336,7 +336,7 @@ func TestAPILFSUpload(t *testing.T) { · 54 unmodified lines | ||
| 336 | 336 | |
| 337 | 337 | content := []byte("dummy3") |
| 338 | 338 | oid := storeObjectInRepo(t, repo.ID, &content) |
| 339 | − defer models.RemoveLFSMetaObjectByOid(repo.ID, oid) | |
| 339 | + defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid) | |
| 340 | 340 | |
| 341 | 341 | session := loginUser(t, "user2") |
| 342 | 342 | |
| @@ -365,9 +365,9 @@ func TestAPILFSUpload(t *testing.T) { · 22 unmodified lines | ||
| 365 | 365 | err = contentStore.Put(p, bytes.NewReader([]byte("dummy5"))) |
| 366 | 366 | assert.NoError(t, err) |
| 367 | 367 | |
| 368 | − meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 368 | + meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 369 | 369 | assert.Nil(t, meta) |
| 370 | − assert.Equal(t, models.ErrLFSObjectNotExist, err) | |
| 370 | + assert.Equal(t, git_model.ErrLFSObjectNotExist, err) | |
| 371 | 371 | |
| 372 | 372 | t.Run("InvalidAccess", func(t *testing.T) { |
| 373 | 373 | req := newRequest(t, p, "invalid") |
| @@ -378,7 +378,7 @@ func TestAPILFSUpload(t *testing.T) { · 4 unmodified lines | ||
| 378 | 378 | req := newRequest(t, p, "dummy5") |
| 379 | 379 | |
| 380 | 380 | session.MakeRequest(t, req, http.StatusOK) |
| 381 | − meta, err = models.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 381 | + meta, err = git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 382 | 382 | assert.NoError(t, err) |
| 383 | 383 | assert.NotNil(t, meta) |
| 384 | 384 | }) |
| @@ -426,7 +426,7 @@ func TestAPILFSUpload(t *testing.T) { · 41 unmodified lines | ||
| 426 | 426 | assert.NoError(t, err) |
| 427 | 427 | assert.True(t, exist) |
| 428 | 428 | |
| 429 | − meta, err := models.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 429 | + meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, p.Oid) | |
| 430 | 430 | assert.NoError(t, err) |
| 431 | 431 | assert.NotNil(t, meta) |
| 432 | 432 | }) |
| @@ -441,7 +441,7 @@ func TestAPILFSVerify(t *testing.T) { · 8 unmodified lines | ||
| 441 | 441 | |
| 442 | 442 | content := []byte("dummy3") |
| 443 | 443 | oid := storeObjectInRepo(t, repo.ID, &content) |
| 444 | − defer models.RemoveLFSMetaObjectByOid(repo.ID, oid) | |
| 444 | + defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid) | |
| 445 | 445 | |
| 446 | 446 | session := loginUser(t, "user2") |
| 447 | 447 | |
| @@ -12,7 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "net/http/httptest" |
| 13 | 13 | "testing" |
| 14 | 14 | |
| 15 | − "code.gitea.io/gitea/models" | |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 16 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 17 | "code.gitea.io/gitea/modules/git" |
| 18 | 18 | "code.gitea.io/gitea/modules/json" |
| @@ -28,7 +28,7 @@ func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string · 9 unmodified lines | ||
| 28 | 28 | pointer, err := lfs.GeneratePointer(bytes.NewReader(*content)) |
| 29 | 29 | assert.NoError(t, err) |
| 30 | 30 | |
| 31 | − _, err = models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: pointer, RepositoryID: repositoryID}) | |
| 31 | + _, err = git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: pointer, RepositoryID: repositoryID}) | |
| 32 | 32 | assert.NoError(t, err) |
| 33 | 33 | contentStore := lfs.NewContentStore() |
| 34 | 34 | exist, err := contentStore.Exists(pointer) |
| @@ -44,7 +44,7 @@ func storeAndGetLfs(t *testing.T, content *[]byte, extraHeader *http.Header, exp · 9 unmodified lines | ||
| 44 | 44 | repo, err := repo_model.GetRepositoryByOwnerAndName("user2", "repo1") |
| 45 | 45 | assert.NoError(t, err) |
| 46 | 46 | oid := storeObjectInRepo(t, repo.ID, content) |
| 47 | − defer models.RemoveLFSMetaObjectByOid(repo.ID, oid) | |
| 47 | + defer git_model.RemoveLFSMetaObjectByOid(repo.ID, oid) | |
| 48 | 48 | |
| 49 | 49 | session := loginUser(t, "user2") |
| 50 | 50 | |
| @@ -10,6 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | "testing" |
| 11 | 11 | |
| 12 | 12 | "code.gitea.io/gitea/models" |
| 13 | + git_model "code.gitea.io/gitea/models/git" | |
| 13 | 14 | repo_model "code.gitea.io/gitea/models/repo" |
| 14 | 15 | "code.gitea.io/gitea/models/unittest" |
| 15 | 16 | user_model "code.gitea.io/gitea/models/user" |
| @@ -32,12 +33,12 @@ func TestCreateNewTagProtected(t *testing.T) { · 16 unmodified lines | ||
| 32 | 33 | err := release.CreateNewTag(git.DefaultContext, owner, repo, "master", "v-1", "first tag") |
| 33 | 34 | assert.NoError(t, err) |
| 34 | 35 | |
| 35 | − err = models.InsertProtectedTag(&models.ProtectedTag{ | |
| 36 | + err = git_model.InsertProtectedTag(&git_model.ProtectedTag{ | |
| 36 | 37 | RepoID: repo.ID, |
| 37 | 38 | NamePattern: "v-*", |
| 38 | 39 | }) |
| 39 | 40 | assert.NoError(t, err) |
| 40 | − err = models.InsertProtectedTag(&models.ProtectedTag{ | |
| 41 | + err = git_model.InsertProtectedTag(&git_model.ProtectedTag{ | |
| 41 | 42 | RepoID: repo.ID, |
| 42 | 43 | NamePattern: "v-1.1", |
| 43 | 44 | AllowlistUserIDs: []int64{repo.OwnerID}, |
| @@ -87,11 +88,11 @@ func TestCreateNewTagProtected(t *testing.T) { · 43 unmodified lines | ||
| 87 | 88 | assert.NoError(t, err) |
| 88 | 89 | } |
| 89 | 90 | |
| 90 | − protectedTags, err := models.GetProtectedTags(repo.ID) | |
| 91 | + protectedTags, err := git_model.GetProtectedTags(repo.ID) | |
| 91 | 92 | assert.NoError(t, err) |
| 92 | 93 | |
| 93 | 94 | for _, protectedTag := range protectedTags { |
| 94 | − err = models.DeleteProtectedTag(protectedTag) | |
| 95 | + err = git_model.DeleteProtectedTag(protectedTag) | |
| 95 | 96 | assert.NoError(t, err) |
| 96 | 97 | } |
| 97 | 98 | } |
| @@ -0,0 +1,80 @@ | ||
| 1 | +// Copyright 2022 The Gitea Authors. All rights reserved. | |
| 2 | +// Use of this source code is governed by a MIT-style | |
| 3 | +// license that can be found in the LICENSE file. | |
| 4 | + | |
| 5 | +package models | |
| 6 | + | |
| 7 | +import ( | |
| 8 | + "context" | |
| 9 | + | |
| 10 | + "code.gitea.io/gitea/models/db" | |
| 11 | + git_model "code.gitea.io/gitea/models/git" | |
| 12 | + "code.gitea.io/gitea/modules/log" | |
| 13 | +) | |
| 14 | + | |
| 15 | +// HasEnoughApprovals returns true if pr has enough granted approvals. | |
| 16 | +func HasEnoughApprovals(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool { | |
| 17 | + if protectBranch.RequiredApprovals == 0 { | |
| 18 | + return true | |
| 19 | + } | |
| 20 | + return GetGrantedApprovalsCount(ctx, protectBranch, pr) >= protectBranch.RequiredApprovals | |
| 21 | +} | |
| 22 | + | |
| 23 | +// GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist. | |
| 24 | +func GetGrantedApprovalsCount(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) int64 { | |
| 25 | + sess := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | |
| 26 | + And("type = ?", ReviewTypeApprove). | |
| 27 | + And("official = ?", true). | |
| 28 | + And("dismissed = ?", false) | |
| 29 | + if protectBranch.DismissStaleApprovals { | |
| 30 | + sess = sess.And("stale = ?", false) | |
| 31 | + } | |
| 32 | + approvals, err := sess.Count(new(Review)) | |
| 33 | + if err != nil { | |
| 34 | + log.Error("GetGrantedApprovalsCount: %v", err) | |
| 35 | + return 0 | |
| 36 | + } | |
| 37 | + | |
| 38 | + return approvals | |
| 39 | +} | |
| 40 | + | |
| 41 | +// MergeBlockedByRejectedReview returns true if merge is blocked by rejected reviews | |
| 42 | +func MergeBlockedByRejectedReview(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool { | |
| 43 | + if !protectBranch.BlockOnRejectedReviews { | |
| 44 | + return false | |
| 45 | + } | |
| 46 | + rejectExist, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | |
| 47 | + And("type = ?", ReviewTypeReject). | |
| 48 | + And("official = ?", true). | |
| 49 | + And("dismissed = ?", false). | |
| 50 | + Exist(new(Review)) | |
| 51 | + if err != nil { | |
| 52 | + log.Error("MergeBlockedByRejectedReview: %v", err) | |
| 53 | + return true | |
| 54 | + } | |
| 55 | + | |
| 56 | + return rejectExist | |
| 57 | +} | |
| 58 | + | |
| 59 | +// MergeBlockedByOfficialReviewRequests block merge because of some review request to official reviewer | |
| 60 | +// of from official review | |
| 61 | +func MergeBlockedByOfficialReviewRequests(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool { | |
| 62 | + if !protectBranch.BlockOnOfficialReviewRequests { | |
| 63 | + return false | |
| 64 | + } | |
| 65 | + has, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | |
| 66 | + And("type = ?", ReviewTypeRequest). | |
| 67 | + And("official = ?", true). | |
| 68 | + Exist(new(Review)) | |
| 69 | + if err != nil { | |
| 70 | + log.Error("MergeBlockedByOfficialReviewRequests: %v", err) | |
| 71 | + return true | |
| 72 | + } | |
| 73 | + | |
| 74 | + return has | |
| 75 | +} | |
| 76 | + | |
| 77 | +// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch | |
| 78 | +func MergeBlockedByOutdatedBranch(protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool { | |
| 79 | + return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0 | |
| 80 | +} | |
| @@ -1,26 +0,0 @@ | ||
| 1 | −// Copyright 2021 Gitea. All rights reserved. | |
| 2 | −// Use of this source code is governed by a MIT-style | |
| 3 | −// license that can be found in the LICENSE file. | |
| 4 | − | |
| 5 | −package models | |
| 6 | − | |
| 7 | −import ( | |
| 8 | − asymkey_model "code.gitea.io/gitea/models/asymkey" | |
| 9 | − repo_model "code.gitea.io/gitea/models/repo" | |
| 10 | − user_model "code.gitea.io/gitea/models/user" | |
| 11 | − "code.gitea.io/gitea/modules/git" | |
| 12 | −) | |
| 13 | − | |
| 14 | −// ConvertFromGitCommit converts git commits into SignCommitWithStatuses | |
| 15 | −func ConvertFromGitCommit(commits []*git.Commit, repo *repo_model.Repository) []*SignCommitWithStatuses { | |
| 16 | − return ParseCommitsWithStatus( | |
| 17 | − asymkey_model.ParseCommitsWithSignature( | |
| 18 | − user_model.ValidateCommitsWithEmails(commits), | |
| 19 | − repo.GetTrustModel(), | |
| 20 | − func(user *user_model.User) (bool, error) { | |
| 21 | − return IsOwnerMemberCollaborator(repo, user.ID) | |
| 22 | − }, | |
| 23 | − ), | |
| 24 | − repo, | |
| 25 | − ) | |
| 26 | −} | |
| @@ -8,7 +8,6 @@ package models · 7 unmodified lines | ||
| 8 | 8 | import ( |
| 9 | 9 | "fmt" |
| 10 | 10 | |
| 11 | − "code.gitea.io/gitea/models/perm" | |
| 12 | 11 | repo_model "code.gitea.io/gitea/models/repo" |
| 13 | 12 | "code.gitea.io/gitea/modules/git" |
| 14 | 13 | ) |
| @@ -145,83 +144,6 @@ func (err ErrAccessTokenEmpty) Error() string { · 130 unmodified lines | ||
| 145 | 144 | return "access token is empty" |
| 146 | 145 | } |
| 147 | 146 | |
| 148 | −//.____ ____________________ | |
| 149 | −//| | \_ _____/ _____/ | |
| 150 | −//| | | __) \_____ \ | |
| 151 | −//| |___| \ / \ | |
| 152 | −//|_______ \___ / /_______ / | |
| 153 | −// \/ \/ \/ | |
| 154 | − | |
| 155 | −// ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error. | |
| 156 | −type ErrLFSLockNotExist struct { | |
| 157 | − ID int64 | |
| 158 | − RepoID int64 | |
| 159 | − Path string | |
| 160 | −} | |
| 161 | − | |
| 162 | −// IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist. | |
| 163 | −func IsErrLFSLockNotExist(err error) bool { | |
| 164 | − _, ok := err.(ErrLFSLockNotExist) | |
| 165 | − return ok | |
| 166 | −} | |
| 167 | − | |
| 168 | −func (err ErrLFSLockNotExist) Error() string { | |
| 169 | − return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path) | |
| 170 | −} | |
| 171 | − | |
| 172 | −// ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error. | |
| 173 | −type ErrLFSUnauthorizedAction struct { | |
| 174 | − RepoID int64 | |
| 175 | − UserName string | |
| 176 | − Mode perm.AccessMode | |
| 177 | −} | |
| 178 | − | |
| 179 | −// IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction. | |
| 180 | −func IsErrLFSUnauthorizedAction(err error) bool { | |
| 181 | − _, ok := err.(ErrLFSUnauthorizedAction) | |
| 182 | − return ok | |
| 183 | −} | |
| 184 | − | |
| 185 | −func (err ErrLFSUnauthorizedAction) Error() string { | |
| 186 | − if err.Mode == perm.AccessModeWrite { | |
| 187 | − return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID) | |
| 188 | − } | |
| 189 | − return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID) | |
| 190 | −} | |
| 191 | − | |
| 192 | −// ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error. | |
| 193 | −type ErrLFSLockAlreadyExist struct { | |
| 194 | − RepoID int64 | |
| 195 | − Path string | |
| 196 | −} | |
| 197 | − | |
| 198 | −// IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist. | |
| 199 | −func IsErrLFSLockAlreadyExist(err error) bool { | |
| 200 | − _, ok := err.(ErrLFSLockAlreadyExist) | |
| 201 | − return ok | |
| 202 | −} | |
| 203 | − | |
| 204 | −func (err ErrLFSLockAlreadyExist) Error() string { | |
| 205 | − return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path) | |
| 206 | −} | |
| 207 | − | |
| 208 | −// ErrLFSFileLocked represents a "LFSFileLocked" kind of error. | |
| 209 | −type ErrLFSFileLocked struct { | |
| 210 | − RepoID int64 | |
| 211 | − Path string | |
| 212 | − UserName string | |
| 213 | −} | |
| 214 | − | |
| 215 | −// IsErrLFSFileLocked checks if an error is a ErrLFSFileLocked. | |
| 216 | −func IsErrLFSFileLocked(err error) bool { | |
| 217 | − _, ok := err.(ErrLFSFileLocked) | |
| 218 | − return ok | |
| 219 | −} | |
| 220 | − | |
| 221 | −func (err ErrLFSFileLocked) Error() string { | |
| 222 | − return fmt.Sprintf("File is lfs locked [repo: %d, locked by: %s, path: %s]", err.RepoID, err.UserName, err.Path) | |
| 223 | −} | |
| 224 | − | |
| 225 | 147 | // ErrNoPendingRepoTransfer is an error type for repositories without a pending |
| 226 | 148 | // transfer request |
| 227 | 149 | type ErrNoPendingRepoTransfer struct { |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | // Use of this source code is governed by a MIT-style |
| 3 | 3 | // license that can be found in the LICENSE file. |
| 4 | 4 | |
| 5 | −package models | |
| 5 | +package git | |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | 8 | "context" |
| @@ -129,10 +129,11 @@ func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch, · 120 unmodified lines | ||
| 129 | 129 | |
| 130 | 130 | // IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals) |
| 131 | 131 | func IsUserOfficialReviewer(protectBranch *ProtectedBranch, user *user_model.User) (bool, error) { |
| 132 | − return isUserOfficialReviewer(db.DefaultContext, protectBranch, user) | |
| 132 | + return IsUserOfficialReviewerCtx(db.DefaultContext, protectBranch, user) | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | −func isUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) { | |
| 135 | +// IsUserOfficialReviewerCtx check if user is official reviewer for the branch (counts towards required approvals) | |
| 136 | +func IsUserOfficialReviewerCtx(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) { | |
| 136 | 137 | repo, err := repo_model.GetRepositoryByIDCtx(ctx, protectBranch.RepoID) |
| 137 | 138 | if err != nil { |
| 138 | 139 | return false, err |
| @@ -159,73 +160,6 @@ func isUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, · 20 unmodified lines | ||
| 159 | 160 | return inTeam, nil |
| 160 | 161 | } |
| 161 | 162 | |
| 162 | −// HasEnoughApprovals returns true if pr has enough granted approvals. | |
| 163 | −func (protectBranch *ProtectedBranch) HasEnoughApprovals(ctx context.Context, pr *PullRequest) bool { | |
| 164 | − if protectBranch.RequiredApprovals == 0 { | |
| 165 | − return true | |
| 166 | − } | |
| 167 | − return protectBranch.GetGrantedApprovalsCount(ctx, pr) >= protectBranch.RequiredApprovals | |
| 168 | −} | |
| 169 | − | |
| 170 | −// GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist. | |
| 171 | −func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(ctx context.Context, pr *PullRequest) int64 { | |
| 172 | − sess := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | |
| 173 | − And("type = ?", ReviewTypeApprove). | |
| 174 | − And("official = ?", true). | |
| 175 | − And("dismissed = ?", false) | |
| 176 | − if protectBranch.DismissStaleApprovals { | |
| 177 | − sess = sess.And("stale = ?", false) | |
| 178 | − } | |
| 179 | − approvals, err := sess.Count(new(Review)) | |
| 180 | − if err != nil { | |
| 181 | − log.Error("GetGrantedApprovalsCount: %v", err) | |
| 182 | − return 0 | |
| 183 | − } | |
| 184 | − | |
| 185 | − return approvals | |
| 186 | −} | |
| 187 | − | |
| 188 | −// MergeBlockedByRejectedReview returns true if merge is blocked by rejected reviews | |
| 189 | −func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(ctx context.Context, pr *PullRequest) bool { | |
| 190 | − if !protectBranch.BlockOnRejectedReviews { | |
| 191 | − return false | |
| 192 | − } | |
| 193 | − rejectExist, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | |
| 194 | − And("type = ?", ReviewTypeReject). | |
| 195 | − And("official = ?", true). | |
| 196 | − And("dismissed = ?", false). | |
| 197 | − Exist(new(Review)) | |
| 198 | − if err != nil { | |
| 199 | − log.Error("MergeBlockedByRejectedReview: %v", err) | |
| 200 | − return true | |
| 201 | − } | |
| 202 | − | |
| 203 | − return rejectExist | |
| 204 | −} | |
| 205 | − | |
| 206 | −// MergeBlockedByOfficialReviewRequests block merge because of some review request to official reviewer | |
| 207 | −// of from official review | |
| 208 | −func (protectBranch *ProtectedBranch) MergeBlockedByOfficialReviewRequests(ctx context.Context, pr *PullRequest) bool { | |
| 209 | − if !protectBranch.BlockOnOfficialReviewRequests { | |
| 210 | − return false | |
| 211 | − } | |
| 212 | − has, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | |
| 213 | − And("type = ?", ReviewTypeRequest). | |
| 214 | − And("official = ?", true). | |
| 215 | − Exist(new(Review)) | |
| 216 | − if err != nil { | |
| 217 | − log.Error("MergeBlockedByOfficialReviewRequests: %v", err) | |
| 218 | − return true | |
| 219 | − } | |
| 220 | − | |
| 221 | − return has | |
| 222 | −} | |
| 223 | − | |
| 224 | −// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch | |
| 225 | −func (protectBranch *ProtectedBranch) MergeBlockedByOutdatedBranch(pr *PullRequest) bool { | |
| 226 | − return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0 | |
| 227 | −} | |
| 228 | − | |
| 229 | 163 | // GetProtectedFilePatterns parses a semicolon separated list of protected file patterns and returns a glob.Glob slice |
| 230 | 164 | func (protectBranch *ProtectedBranch) GetProtectedFilePatterns() []glob.Glob { |
| 231 | 165 | return getFilePatterns(protectBranch.ProtectedFilePatterns) |
| @@ -252,13 +186,13 @@ func getFilePatterns(filePatterns string) []glob.Glob { · 20 unmodified lines | ||
| 252 | 186 | } |
| 253 | 187 | |
| 254 | 188 | // MergeBlockedByProtectedFiles returns true if merge is blocked by protected files change |
| 255 | −func (protectBranch *ProtectedBranch) MergeBlockedByProtectedFiles(pr *PullRequest) bool { | |
| 189 | +func (protectBranch *ProtectedBranch) MergeBlockedByProtectedFiles(changedProtectedFiles []string) bool { | |
| 256 | 190 | glob := protectBranch.GetProtectedFilePatterns() |
| 257 | 191 | if len(glob) == 0 { |
| 258 | 192 | return false |
| 259 | 193 | } |
| 260 | 194 | |
| 261 | − return len(pr.ChangedProtectedFiles) > 0 | |
| 195 | + return len(changedProtectedFiles) > 0 | |
| 262 | 196 | } |
| 263 | 197 | |
| 264 | 198 | // IsProtectedFile return if path is protected |
| @@ -642,7 +576,7 @@ func RenameBranch(repo *repo_model.Repository, from, to string, gitAction func(i · 377 unmodified lines | ||
| 642 | 576 | } |
| 643 | 577 | |
| 644 | 578 | // 3. Update all not merged pull request base branch name |
| 645 | − _, err = sess.Table(new(PullRequest)).Where("base_repo_id=? AND base_branch=? AND has_merged=?", | |
| 579 | + _, err = sess.Table("pull_request").Where("base_repo_id=? AND base_branch=? AND has_merged=?", | |
| 646 | 580 | repo.ID, from, false). |
| 647 | 581 | Update(map[string]interface{}{"base_branch": to}) |
| 648 | 582 | if err != nil { |
| @@ -2,12 +2,14 @@ · 1 unmodified line | ||
| 2 | 2 | // Use of this source code is governed by a MIT-style |
| 3 | 3 | // license that can be found in the LICENSE file. |
| 4 | 4 | |
| 5 | −package models | |
| 5 | +package git_test | |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | 8 | "testing" |
| 9 | 9 | |
| 10 | + "code.gitea.io/gitea/models" | |
| 10 | 11 | "code.gitea.io/gitea/models/db" |
| 12 | + git_model "code.gitea.io/gitea/models/git" | |
| 11 | 13 | repo_model "code.gitea.io/gitea/models/repo" |
| 12 | 14 | "code.gitea.io/gitea/models/unittest" |
| 13 | 15 | |
| @@ -17,24 +19,24 @@ import ( · 3 unmodified lines | ||
| 17 | 19 | func TestAddDeletedBranch(t *testing.T) { |
| 18 | 20 | assert.NoError(t, unittest.PrepareTestDatabase()) |
| 19 | 21 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) |
| 20 | − firstBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch) | |
| 22 | + firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 1}).(*git_model.DeletedBranch) | |
| 21 | 23 | |
| 22 | − assert.Error(t, AddDeletedBranch(repo.ID, firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID)) | |
| 23 | − assert.NoError(t, AddDeletedBranch(repo.ID, "test", "5655464564554545466464656", int64(1))) | |
| 24 | + assert.Error(t, git_model.AddDeletedBranch(repo.ID, firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID)) | |
| 25 | + assert.NoError(t, git_model.AddDeletedBranch(repo.ID, "test", "5655464564554545466464656", int64(1))) | |
| 24 | 26 | } |
| 25 | 27 | |
| 26 | 28 | func TestGetDeletedBranches(t *testing.T) { |
| 27 | 29 | assert.NoError(t, unittest.PrepareTestDatabase()) |
| 28 | 30 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) |
| 29 | 31 | |
| 30 | − branches, err := GetDeletedBranches(repo.ID) | |
| 32 | + branches, err := git_model.GetDeletedBranches(repo.ID) | |
| 31 | 33 | assert.NoError(t, err) |
| 32 | 34 | assert.Len(t, branches, 2) |
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | func TestGetDeletedBranch(t *testing.T) { |
| 36 | 38 | assert.NoError(t, unittest.PrepareTestDatabase()) |
| 37 | − firstBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch) | |
| 39 | + firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 1}).(*git_model.DeletedBranch) | |
| 38 | 40 | |
| 39 | 41 | assert.NotNil(t, getDeletedBranch(t, firstBranch)) |
| 40 | 42 | } |
| @@ -42,8 +44,8 @@ func TestGetDeletedBranch(t *testing.T) { · 1 unmodified line | ||
| 42 | 44 | func TestDeletedBranchLoadUser(t *testing.T) { |
| 43 | 45 | assert.NoError(t, unittest.PrepareTestDatabase()) |
| 44 | 46 | |
| 45 | − firstBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch) | |
| 46 | − secondBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2}).(*DeletedBranch) | |
| 47 | + firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 1}).(*git_model.DeletedBranch) | |
| 48 | + secondBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 2}).(*git_model.DeletedBranch) | |
| 47 | 49 | |
| 48 | 50 | branch := getDeletedBranch(t, firstBranch) |
| 49 | 51 | assert.Nil(t, branch.DeletedBy) |
| @@ -62,18 +64,18 @@ func TestRemoveDeletedBranch(t *testing.T) { · 12 unmodified lines | ||
| 62 | 64 | assert.NoError(t, unittest.PrepareTestDatabase()) |
| 63 | 65 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) |
| 64 | 66 | |
| 65 | − firstBranch := unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch) | |
| 67 | + firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 1}).(*git_model.DeletedBranch) | |
| 66 | 68 | |
| 67 | − err := RemoveDeletedBranchByID(repo.ID, 1) | |
| 69 | + err := git_model.RemoveDeletedBranchByID(repo.ID, 1) | |
| 68 | 70 | assert.NoError(t, err) |
| 69 | 71 | unittest.AssertNotExistsBean(t, firstBranch) |
| 70 | − unittest.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2}) | |
| 72 | + unittest.AssertExistsAndLoadBean(t, &git_model.DeletedBranch{ID: 2}) | |
| 71 | 73 | } |
| 72 | 74 | |
| 73 | −func getDeletedBranch(t *testing.T, branch *DeletedBranch) *DeletedBranch { | |
| 75 | +func getDeletedBranch(t *testing.T, branch *git_model.DeletedBranch) *git_model.DeletedBranch { | |
| 74 | 76 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) |
| 75 | 77 | |
| 76 | − deletedBranch, err := GetDeletedBranchByID(repo.ID, branch.ID) | |
| 78 | + deletedBranch, err := git_model.GetDeletedBranchByID(repo.ID, branch.ID) | |
| 77 | 79 | assert.NoError(t, err) |
| 78 | 80 | assert.Equal(t, branch.ID, deletedBranch.ID) |
| 79 | 81 | assert.Equal(t, branch.Name, deletedBranch.Name) |
| @@ -85,12 +87,12 @@ func getDeletedBranch(t *testing.T, branch *DeletedBranch) *DeletedBranch { · 5 unmodified lines | ||
| 85 | 87 | |
| 86 | 88 | func TestFindRenamedBranch(t *testing.T) { |
| 87 | 89 | assert.NoError(t, unittest.PrepareTestDatabase()) |
| 88 | − branch, exist, err := FindRenamedBranch(1, "dev") | |
| 90 | + branch, exist, err := git_model.FindRenamedBranch(1, "dev") | |
| 89 | 91 | assert.NoError(t, err) |
| 90 | 92 | assert.Equal(t, true, exist) |
| 91 | 93 | assert.Equal(t, "master", branch.To) |
| 92 | 94 | |
| 93 | − _, exist, err = FindRenamedBranch(1, "unknow") | |
| 95 | + _, exist, err = git_model.FindRenamedBranch(1, "unknow") | |
| 94 | 96 | assert.NoError(t, err) |
| 95 | 97 | assert.Equal(t, false, exist) |
| 96 | 98 | } |
| @@ -103,13 +105,13 @@ func TestRenameBranch(t *testing.T) { · 6 unmodified lines | ||
| 103 | 105 | ctx, committer, err := db.TxContext() |
| 104 | 106 | defer committer.Close() |
| 105 | 107 | assert.NoError(t, err) |
| 106 | − assert.NoError(t, UpdateProtectBranch(ctx, repo1, &ProtectedBranch{ | |
| 108 | + assert.NoError(t, git_model.UpdateProtectBranch(ctx, repo1, &git_model.ProtectedBranch{ | |
| 107 | 109 | RepoID: repo1.ID, |
| 108 | 110 | BranchName: "master", |
| 109 | − }, WhitelistOptions{})) | |
| 111 | + }, git_model.WhitelistOptions{})) | |
| 110 | 112 | assert.NoError(t, committer.Commit()) |
| 111 | 113 | |
| 112 | − assert.NoError(t, RenameBranch(repo1, "master", "main", func(isDefault bool) error { | |
| 114 | + assert.NoError(t, git_model.RenameBranch(repo1, "master", "main", func(isDefault bool) error { | |
| 113 | 115 | _isDefault = isDefault |
| 114 | 116 | return nil |
| 115 | 117 | })) |
| @@ -118,18 +120,18 @@ func TestRenameBranch(t *testing.T) { · 2 unmodified lines | ||
| 118 | 120 | repo1 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) |
| 119 | 121 | assert.Equal(t, "main", repo1.DefaultBranch) |
| 120 | 122 | |
| 121 | − pull := unittest.AssertExistsAndLoadBean(t, &PullRequest{ID: 1}).(*PullRequest) // merged | |
| 123 | + pull := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest) // merged | |
| 122 | 124 | assert.Equal(t, "master", pull.BaseBranch) |
| 123 | 125 | |
| 124 | − pull = unittest.AssertExistsAndLoadBean(t, &PullRequest{ID: 2}).(*PullRequest) // open | |
| 126 | + pull = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest) // open | |
| 125 | 127 | assert.Equal(t, "main", pull.BaseBranch) |
| 126 | 128 | |
| 127 | − renamedBranch := unittest.AssertExistsAndLoadBean(t, &RenamedBranch{ID: 2}).(*RenamedBranch) | |
| 129 | + renamedBranch := unittest.AssertExistsAndLoadBean(t, &git_model.RenamedBranch{ID: 2}).(*git_model.RenamedBranch) | |
| 128 | 130 | assert.Equal(t, "master", renamedBranch.From) |
| 129 | 131 | assert.Equal(t, "main", renamedBranch.To) |
| 130 | 132 | assert.Equal(t, int64(1), renamedBranch.RepoID) |
| 131 | 133 | |
| 132 | − unittest.AssertExistsAndLoadBean(t, &ProtectedBranch{ | |
| 134 | + unittest.AssertExistsAndLoadBean(t, &git_model.ProtectedBranch{ | |
| 133 | 135 | RepoID: repo1.ID, |
| 134 | 136 | BranchName: "main", |
| 135 | 137 | }) |
| @@ -143,7 +145,7 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { · 7 unmodified lines | ||
| 143 | 145 | // is actually on repo with ID 1. |
| 144 | 146 | repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository) |
| 145 | 147 | |
| 146 | − deletedBranch, err := GetDeletedBranchByID(repo2.ID, 1) | |
| 148 | + deletedBranch, err := git_model.GetDeletedBranchByID(repo2.ID, 1) | |
| 147 | 149 | |
| 148 | 150 | // Expect no error, and the returned branch is nil. |
| 149 | 151 | assert.NoError(t, err) |
| @@ -153,7 +155,7 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { · 3 unmodified lines | ||
| 153 | 155 | // This should return the deletedBranch. |
| 154 | 156 | repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) |
| 155 | 157 | |
| 156 | − deletedBranch, err = GetDeletedBranchByID(repo1.ID, 1) | |
| 158 | + deletedBranch, err = git_model.GetDeletedBranchByID(repo1.ID, 1) | |
| 157 | 159 | |
| 158 | 160 | // Expect no error, and the returned branch to be not nil. |
| 159 | 161 | assert.NoError(t, err) |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | // Use of this source code is governed by a MIT-style |
| 3 | 3 | // license that can be found in the LICENSE file. |
| 4 | 4 | |
| 5 | −package models | |
| 5 | +package git | |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | 8 | "context" |
| @@ -16,6 +16,7 @@ import ( · 7 unmodified lines | ||
| 16 | 16 | "code.gitea.io/gitea/models/db" |
| 17 | 17 | repo_model "code.gitea.io/gitea/models/repo" |
| 18 | 18 | user_model "code.gitea.io/gitea/models/user" |
| 19 | + "code.gitea.io/gitea/modules/git" | |
| 19 | 20 | "code.gitea.io/gitea/modules/log" |
| 20 | 21 | "code.gitea.io/gitea/modules/setting" |
| 21 | 22 | api "code.gitea.io/gitea/modules/structs" |
| @@ -178,7 +179,7 @@ func GetCommitStatuses(repo *repo_model.Repository, sha string, opts *CommitStat · 156 unmodified lines | ||
| 178 | 179 | opts.Page = 1 |
| 179 | 180 | } |
| 180 | 181 | if opts.PageSize <= 0 { |
| 181 | − opts.Page = ItemsPerPage | |
| 182 | + opts.Page = setting.ItemsPerPage | |
| 182 | 183 | } |
| 183 | 184 | |
| 184 | 185 | countSession := listCommitStatusesStatement(repo, sha, opts) |
| @@ -353,3 +354,17 @@ func ParseCommitsWithStatus(oldCommits []*asymkey_model.SignCommit, repo *repo_m · 168 unmodified lines | ||
| 353 | 354 | func hashCommitStatusContext(context string) string { |
| 354 | 355 | return fmt.Sprintf("%x", sha1.Sum([]byte(context))) |
| 355 | 356 | } |
| 357 | + | |
| 358 | +// ConvertFromGitCommit converts git commits into SignCommitWithStatuses | |
| 359 | +func ConvertFromGitCommit(commits []*git.Commit, repo *repo_model.Repository) []*SignCommitWithStatuses { | |
| 360 | + return ParseCommitsWithStatus( | |
| 361 | + asymkey_model.ParseCommitsWithSignature( | |
| 362 | + user_model.ValidateCommitsWithEmails(commits), | |
| 363 | + repo.GetTrustModel(), | |
| 364 | + func(user *user_model.User) (bool, error) { | |
| 365 | + return repo_model.IsOwnerMemberCollaborator(repo, user.ID) | |
| 366 | + }, | |
| 367 | + ), | |
| 368 | + repo, | |
| 369 | + ) | |
| 370 | +} | |
| @@ -2,12 +2,13 @@ · 1 unmodified line | ||
| 2 | 2 | // Use of this source code is governed by a MIT-style |
| 3 | 3 | // license that can be found in the LICENSE file. |
| 4 | 4 | |
| 5 | −package models | |
| 5 | +package git_test | |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | 8 | "testing" |
| 9 | 9 | |
| 10 | 10 | "code.gitea.io/gitea/models/db" |
| 11 | + git_model "code.gitea.io/gitea/models/git" | |
| 11 | 12 | repo_model "code.gitea.io/gitea/models/repo" |
| 12 | 13 | "code.gitea.io/gitea/models/unittest" |
| 13 | 14 | "code.gitea.io/gitea/modules/structs" |
| @@ -22,7 +23,7 @@ func TestGetCommitStatuses(t *testing.T) { · 8 unmodified lines | ||
| 22 | 23 | |
| 23 | 24 | sha1 := "1234123412341234123412341234123412341234" |
| 24 | 25 | |
| 25 | − statuses, maxResults, err := GetCommitStatuses(repo1, sha1, &CommitStatusOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 50}}) | |
| 26 | + statuses, maxResults, err := git_model.GetCommitStatuses(repo1, sha1, &git_model.CommitStatusOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 50}}) | |
| 26 | 27 | assert.NoError(t, err) |
| 27 | 28 | assert.Equal(t, int(maxResults), 5) |
| 28 | 29 | assert.Len(t, statuses, 5) |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | // Use of this source code is governed by a MIT-style |
| 3 | 3 | // license that can be found in the LICENSE file. |
| 4 | 4 | |
| 5 | −package models | |
| 5 | +package git | |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | 8 | "context" |
| @@ -10,6 +10,7 @@ import ( · 1 unmodified line | ||
| 10 | 10 | "fmt" |
| 11 | 11 | |
| 12 | 12 | "code.gitea.io/gitea/models/db" |
| 13 | + "code.gitea.io/gitea/models/perm" | |
| 13 | 14 | repo_model "code.gitea.io/gitea/models/repo" |
| 14 | 15 | user_model "code.gitea.io/gitea/models/user" |
| 15 | 16 | "code.gitea.io/gitea/modules/lfs" |
| @@ -19,6 +20,76 @@ import ( · 3 unmodified lines | ||
| 19 | 20 | "xorm.io/builder" |
| 20 | 21 | ) |
| 21 | 22 | |
| 23 | +// ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error. | |
| 24 | +type ErrLFSLockNotExist struct { | |
| 25 | + ID int64 | |
| 26 | + RepoID int64 | |
| 27 | + Path string | |
| 28 | +} | |
| 29 | + | |
| 30 | +// IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist. | |
| 31 | +func IsErrLFSLockNotExist(err error) bool { | |
| 32 | + _, ok := err.(ErrLFSLockNotExist) | |
| 33 | + return ok | |
| 34 | +} | |
| 35 | + | |
| 36 | +func (err ErrLFSLockNotExist) Error() string { | |
| 37 | + return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path) | |
| 38 | +} | |
| 39 | + | |
| 40 | +// ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error. | |
| 41 | +type ErrLFSUnauthorizedAction struct { | |
| 42 | + RepoID int64 | |
| 43 | + UserName string | |
| 44 | + Mode perm.AccessMode | |
| 45 | +} | |
| 46 | + | |
| 47 | +// IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction. | |
| 48 | +func IsErrLFSUnauthorizedAction(err error) bool { | |
| 49 | + _, ok := err.(ErrLFSUnauthorizedAction) | |
| 50 | + return ok | |
| 51 | +} | |
| 52 | + | |
| 53 | +func (err ErrLFSUnauthorizedAction) Error() string { | |
| 54 | + if err.Mode == perm.AccessModeWrite { | |
| 55 | + return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID) | |
| 56 | + } | |
| 57 | + return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID) | |
| 58 | +} | |
| 59 | + | |
| 60 | +// ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error. | |
| 61 | +type ErrLFSLockAlreadyExist struct { | |
| 62 | + RepoID int64 | |
| 63 | + Path string | |
| 64 | +} | |
| 65 | + | |
| 66 | +// IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist. | |
| 67 | +func IsErrLFSLockAlreadyExist(err error) bool { | |
| 68 | + _, ok := err.(ErrLFSLockAlreadyExist) | |
| 69 | + return ok | |
| 70 | +} | |
| 71 | + | |
| 72 | +func (err ErrLFSLockAlreadyExist) Error() string { | |
| 73 | + return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path) | |
| 74 | +} | |
| 75 | + | |
| 76 | +// ErrLFSFileLocked represents a "LFSFileLocked" kind of error. | |
| 77 | +type ErrLFSFileLocked struct { | |
| 78 | + RepoID int64 | |
| 79 | + Path string | |
| 80 | + UserName string | |
| 81 | +} | |
| 82 | + | |
| 83 | +// IsErrLFSFileLocked checks if an error is a ErrLFSFileLocked. | |
| 84 | +func IsErrLFSFileLocked(err error) bool { | |
| 85 | + _, ok := err.(ErrLFSFileLocked) | |
| 86 | + return ok | |
| 87 | +} | |
| 88 | + | |
| 89 | +func (err ErrLFSFileLocked) Error() string { | |
| 90 | + return fmt.Sprintf("File is lfs locked [repo: %d, locked by: %s, path: %s]", err.RepoID, err.UserName, err.Path) | |
| 91 | +} | |
| 92 | + | |
| 22 | 93 | // LFSMetaObject stores metadata for LFS tracked files. |
| 23 | 94 | type LFSMetaObject struct { |
| 24 | 95 | ID int64 `xorm:"pk autoincr"` |
| @@ -239,7 +310,7 @@ func CopyLFS(ctx context.Context, newRepo, oldRepo *repo_model.Repository) error · 214 unmodified lines | ||
| 239 | 310 | for _, v := range lfsObjects { |
| 240 | 311 | v.ID = 0 |
| 241 | 312 | v.RepositoryID = newRepo.ID |
| 242 | − if _, err := db.GetEngine(ctx).Insert(v); err != nil { | |
| 313 | + if err := db.Insert(ctx, v); err != nil { | |
| 243 | 314 | return err |
| 244 | 315 | } |
| 245 | 316 | } |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | // Use of this source code is governed by a MIT-style |
| 3 | 3 | // license that can be found in the LICENSE file. |
| 4 | 4 | |
| 5 | −package models | |
| 5 | +package git | |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | 8 | "context" |
| @@ -0,0 +1,18 @@ | ||
| 1 | +// Copyright 2020 The Gitea Authors. All rights reserved. | |
| 2 | +// Use of this source code is governed by a MIT-style | |
| 3 | +// license that can be found in the LICENSE file. | |
| 4 | + | |
| 5 | +package git_test | |
| 6 | + | |
| 7 | +import ( | |
| 8 | + "path/filepath" | |
| 9 | + "testing" | |
| 10 | + | |
| 11 | + "code.gitea.io/gitea/models/unittest" | |
| 12 | +) | |
| 13 | + | |
| 14 | +func TestMain(m *testing.M) { | |
| 15 | + unittest.MainTest(m, &unittest.TestOptions{ | |
| 16 | + GiteaRootPath: filepath.Join("..", ".."), | |
| 17 | + }) | |
| 18 | +} | |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | // Use of this source code is governed by a MIT-style |
| 3 | 3 | // license that can be found in the LICENSE file. |
| 4 | 4 | |
| 5 | −package models | |
| 5 | +package git | |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | 8 | "regexp" |
| @@ -2,11 +2,12 @@ · 1 unmodified line | ||
| 2 | 2 | // Use of this source code is governed by a MIT-style |
| 3 | 3 | // license that can be found in the LICENSE file. |
| 4 | 4 | |
| 5 | −package models | |
| 5 | +package git_test | |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | 8 | "testing" |
| 9 | 9 | |
| 10 | + git_model "code.gitea.io/gitea/models/git" | |
| 10 | 11 | "code.gitea.io/gitea/models/unittest" |
| 11 | 12 | |
| 12 | 13 | "github.com/stretchr/testify/assert" |
| @@ -15,42 +16,42 @@ import ( · 2 unmodified lines | ||
| 15 | 16 | func TestIsUserAllowed(t *testing.T) { |
| 16 | 17 | assert.NoError(t, unittest.PrepareTestDatabase()) |
| 17 | 18 | |
| 18 | − pt := &ProtectedTag{} | |
| 19 | − allowed, err := IsUserAllowedModifyTag(pt, 1) | |
| 19 | + pt := &git_model.ProtectedTag{} | |
| 20 | + allowed, err := git_model.IsUserAllowedModifyTag(pt, 1) | |
| 20 | 21 | assert.NoError(t, err) |
| 21 | 22 | assert.False(t, allowed) |
| 22 | 23 | |
| 23 | − pt = &ProtectedTag{ | |
| 24 | + pt = &git_model.ProtectedTag{ | |
| 24 | 25 | AllowlistUserIDs: []int64{1}, |
| 25 | 26 | } |
| 26 | − allowed, err = IsUserAllowedModifyTag(pt, 1) | |
| 27 | + allowed, err = git_model.IsUserAllowedModifyTag(pt, 1) | |
| 27 | 28 | assert.NoError(t, err) |
| 28 | 29 | assert.True(t, allowed) |
| 29 | 30 | |
| 30 | − allowed, err = IsUserAllowedModifyTag(pt, 2) | |
| 31 | + allowed, err = git_model.IsUserAllowedModifyTag(pt, 2) | |
| 31 | 32 | assert.NoError(t, err) |
| 32 | 33 | assert.False(t, allowed) |
| 33 | 34 | |
| 34 | − pt = &ProtectedTag{ | |
| 35 | + pt = &git_model.ProtectedTag{ | |
| 35 | 36 | AllowlistTeamIDs: []int64{1}, |
| 36 | 37 | } |
| 37 | − allowed, err = IsUserAllowedModifyTag(pt, 1) | |
| 38 | + allowed, err = git_model.IsUserAllowedModifyTag(pt, 1) | |
| 38 | 39 | assert.NoError(t, err) |
| 39 | 40 | assert.False(t, allowed) |
| 40 | 41 | |
| 41 | − allowed, err = IsUserAllowedModifyTag(pt, 2) | |
| 42 | + allowed, err = git_model.IsUserAllowedModifyTag(pt, 2) | |
| 42 | 43 | assert.NoError(t, err) |
| 43 | 44 | assert.True(t, allowed) |
| 44 | 45 | |
| 45 | − pt = &ProtectedTag{ | |
| 46 | + pt = &git_model.ProtectedTag{ | |
| 46 | 47 | AllowlistUserIDs: []int64{1}, |
| 47 | 48 | AllowlistTeamIDs: []int64{1}, |
| 48 | 49 | } |
| 49 | − allowed, err = IsUserAllowedModifyTag(pt, 1) | |
| 50 | + allowed, err = git_model.IsUserAllowedModifyTag(pt, 1) | |
| 50 | 51 | assert.NoError(t, err) |
| 51 | 52 | assert.True(t, allowed) |
| 52 | 53 | |
| 53 | − allowed, err = IsUserAllowedModifyTag(pt, 2) | |
| 54 | + allowed, err = git_model.IsUserAllowedModifyTag(pt, 2) | |
| 54 | 55 | assert.NoError(t, err) |
| 55 | 56 | assert.True(t, allowed) |
| 56 | 57 | } |
| @@ -119,7 +120,7 @@ func TestIsUserAllowedToControlTag(t *testing.T) { · 62 unmodified lines | ||
| 119 | 120 | } |
| 120 | 121 | |
| 121 | 122 | t.Run("Glob", func(t *testing.T) { |
| 122 | − protectedTags := []*ProtectedTag{ | |
| 123 | + protectedTags := []*git_model.ProtectedTag{ | |
| 123 | 124 | { |
| 124 | 125 | NamePattern: `*gitea`, |
| 125 | 126 | AllowlistUserIDs: []int64{1}, |
| @@ -134,14 +135,14 @@ func TestIsUserAllowedToControlTag(t *testing.T) { · 8 unmodified lines | ||
| 134 | 135 | } |
| 135 | 136 | |
| 136 | 137 | for n, c := range cases { |
| 137 | − isAllowed, err := IsUserAllowedToControlTag(protectedTags, c.name, c.userid) | |
| 138 | + isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, c.name, c.userid) | |
| 138 | 139 | assert.NoError(t, err) |
| 139 | 140 | assert.Equal(t, c.allowed, isAllowed, "case %d: error should match", n) |
| 140 | 141 | } |
| 141 | 142 | }) |
| 142 | 143 | |
| 143 | 144 | t.Run("Regex", func(t *testing.T) { |
| 144 | − protectedTags := []*ProtectedTag{ | |
| 145 | + protectedTags := []*git_model.ProtectedTag{ | |
| 145 | 146 | { |
| 146 | 147 | NamePattern: `/gitea\z/`, |
| 147 | 148 | AllowlistUserIDs: []int64{1}, |
| @@ -156,7 +157,7 @@ func TestIsUserAllowedToControlTag(t *testing.T) { · 8 unmodified lines | ||
| 156 | 157 | } |
| 157 | 158 | |
| 158 | 159 | for n, c := range cases { |
| 159 | − isAllowed, err := IsUserAllowedToControlTag(protectedTags, c.name, c.userid) | |
| 160 | + isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, c.name, c.userid) | |
| 160 | 161 | assert.NoError(t, err) |
| 161 | 162 | assert.Equal(t, c.allowed, isAllowed, "case %d: error should match", n) |
| 162 | 163 | } |
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | "unicode/utf8" |
| 16 | 16 | |
| 17 | 17 | "code.gitea.io/gitea/models/db" |
| 18 | + git_model "code.gitea.io/gitea/models/git" | |
| 18 | 19 | issues_model "code.gitea.io/gitea/models/issues" |
| 19 | 20 | "code.gitea.io/gitea/models/organization" |
| 20 | 21 | project_model "code.gitea.io/gitea/models/project" |
| @@ -271,11 +272,11 @@ type Comment struct { · 250 unmodified lines | ||
| 271 | 272 | RefIssue *Issue `xorm:"-"` |
| 272 | 273 | RefComment *Comment `xorm:"-"` |
| 273 | 274 | |
| 274 | − Commits []*SignCommitWithStatuses `xorm:"-"` | |
| 275 | − OldCommit string `xorm:"-"` | |
| 276 | − NewCommit string `xorm:"-"` | |
| 277 | − CommitsNum int64 `xorm:"-"` | |
| 278 | − IsForcePush bool `xorm:"-"` | |
| 275 | + Commits []*git_model.SignCommitWithStatuses `xorm:"-"` | |
| 276 | + OldCommit string `xorm:"-"` | |
| 277 | + NewCommit string `xorm:"-"` | |
| 278 | + CommitsNum int64 `xorm:"-"` | |
| 279 | + IsForcePush bool `xorm:"-"` | |
| 279 | 280 | } |
| 280 | 281 | |
| 281 | 282 | func init() { |
| @@ -761,7 +762,7 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) { · 479 unmodified lines | ||
| 761 | 762 | } |
| 762 | 763 | defer closer.Close() |
| 763 | 764 | |
| 764 | − c.Commits = ConvertFromGitCommit(gitRepo.GetCommitsFromIDs(data.CommitIDs), c.Issue.Repo) | |
| 765 | + c.Commits = git_model.ConvertFromGitCommit(gitRepo.GetCommitsFromIDs(data.CommitIDs), c.Issue.Repo) | |
| 765 | 766 | c.CommitsNum = int64(len(c.Commits)) |
| 766 | 767 | } |
| 767 | 768 | |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "strings" |
| 13 | 13 | |
| 14 | 14 | "code.gitea.io/gitea/models/db" |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 15 | 16 | "code.gitea.io/gitea/models/organization" |
| 16 | 17 | access_model "code.gitea.io/gitea/models/perm/access" |
| 17 | 18 | repo_model "code.gitea.io/gitea/models/repo" |
| @@ -412,7 +413,7 @@ func DeleteTeam(t *organization.Team) error { · 394 unmodified lines | ||
| 412 | 413 | |
| 413 | 414 | // update branch protections |
| 414 | 415 | { |
| 415 | − protections := make([]*ProtectedBranch, 0, 10) | |
| 416 | + protections := make([]*git_model.ProtectedBranch, 0, 10) | |
| 416 | 417 | err := sess.In("repo_id", |
| 417 | 418 | builder.Select("id").From("repository").Where(builder.Eq{"owner_id": t.OrgID})). |
| 418 | 419 | Find(&protections) |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "strings" |
| 13 | 13 | |
| 14 | 14 | "code.gitea.io/gitea/models/db" |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 15 | 16 | pull_model "code.gitea.io/gitea/models/pull" |
| 16 | 17 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 18 | user_model "code.gitea.io/gitea/models/user" |
| @@ -78,9 +79,9 @@ type PullRequest struct { · 60 unmodified lines | ||
| 78 | 79 | HeadBranch string |
| 79 | 80 | HeadCommitID string `xorm:"-"` |
| 80 | 81 | BaseBranch string |
| 81 | − ProtectedBranch *ProtectedBranch `xorm:"-"` | |
| 82 | − MergeBase string `xorm:"VARCHAR(40)"` | |
| 83 | − AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"` | |
| 82 | + ProtectedBranch *git_model.ProtectedBranch `xorm:"-"` | |
| 83 | + MergeBase string `xorm:"VARCHAR(40)"` | |
| 84 | + AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"` | |
| 84 | 85 | |
| 85 | 86 | HasMerged bool `xorm:"INDEX"` |
| 86 | 87 | MergedCommitID string `xorm:"VARCHAR(40)"` |
| @@ -242,7 +243,7 @@ func (pr *PullRequest) LoadProtectedBranchCtx(ctx context.Context) (err error) { · 155 unmodified lines | ||
| 242 | 243 | return |
| 243 | 244 | } |
| 244 | 245 | } |
| 245 | − pr.ProtectedBranch, err = GetProtectedBranchBy(ctx, pr.BaseRepo.ID, pr.BaseBranch) | |
| 246 | + pr.ProtectedBranch, err = git_model.GetProtectedBranchBy(ctx, pr.BaseRepo.ID, pr.BaseBranch) | |
| 246 | 247 | } |
| 247 | 248 | return |
| 248 | 249 | } |
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | admin_model "code.gitea.io/gitea/models/admin" |
| 16 | 16 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 17 | 17 | "code.gitea.io/gitea/models/db" |
| 18 | + git_model "code.gitea.io/gitea/models/git" | |
| 18 | 19 | issues_model "code.gitea.io/gitea/models/issues" |
| 19 | 20 | "code.gitea.io/gitea/models/organization" |
| 20 | 21 | "code.gitea.io/gitea/models/perm" |
| @@ -34,9 +35,6 @@ import ( · 13 unmodified lines | ||
| 34 | 35 | "xorm.io/builder" |
| 35 | 36 | ) |
| 36 | 37 | |
| 37 | −// ItemsPerPage maximum items per page in forks, watchers and stars of a repo | |
| 38 | −var ItemsPerPage = 40 | |
| 39 | − | |
| 40 | 38 | // NewRepoContext creates a new repository context |
| 41 | 39 | func NewRepoContext() { |
| 42 | 40 | unit.LoadUnitConfig() |
| @@ -284,16 +282,16 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { · 241 unmodified lines | ||
| 284 | 282 | &Action{RepoID: repo.ID}, |
| 285 | 283 | &repo_model.Collaboration{RepoID: repoID}, |
| 286 | 284 | &Comment{RefRepoID: repoID}, |
| 287 | − &CommitStatus{RepoID: repoID}, | |
| 288 | − &DeletedBranch{RepoID: repoID}, | |
| 285 | + &git_model.CommitStatus{RepoID: repoID}, | |
| 286 | + &git_model.DeletedBranch{RepoID: repoID}, | |
| 289 | 287 | &webhook.HookTask{RepoID: repoID}, |
| 290 | − &LFSLock{RepoID: repoID}, | |
| 288 | + &git_model.LFSLock{RepoID: repoID}, | |
| 291 | 289 | &repo_model.LanguageStat{RepoID: repoID}, |
| 292 | 290 | &issues_model.Milestone{RepoID: repoID}, |
| 293 | 291 | &repo_model.Mirror{RepoID: repoID}, |
| 294 | 292 | &Notification{RepoID: repoID}, |
| 295 | − &ProtectedBranch{RepoID: repoID}, | |
| 296 | − &ProtectedTag{RepoID: repoID}, | |
| 293 | + &git_model.ProtectedBranch{RepoID: repoID}, | |
| 294 | + &git_model.ProtectedTag{RepoID: repoID}, | |
| 297 | 295 | &repo_model.PushMirror{RepoID: repoID}, |
| 298 | 296 | &Release{RepoID: repoID}, |
| 299 | 297 | &repo_model.RepoIndexerStatus{RepoID: repoID}, |
| @@ -357,14 +355,14 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { · 57 unmodified lines | ||
| 357 | 355 | } |
| 358 | 356 | |
| 359 | 357 | // Remove LFS objects |
| 360 | − var lfsObjects []*LFSMetaObject | |
| 358 | + var lfsObjects []*git_model.LFSMetaObject | |
| 361 | 359 | if err = sess.Where("repository_id=?", repoID).Find(&lfsObjects); err != nil { |
| 362 | 360 | return err |
| 363 | 361 | } |
| 364 | 362 | |
| 365 | 363 | lfsPaths := make([]string, 0, len(lfsObjects)) |
| 366 | 364 | for _, v := range lfsObjects { |
| 367 | − count, err := db.CountByBean(ctx, &LFSMetaObject{Pointer: lfs.Pointer{Oid: v.Oid}}) | |
| 365 | + count, err := db.CountByBean(ctx, &git_model.LFSMetaObject{Pointer: lfs.Pointer{Oid: v.Oid}}) | |
| 368 | 366 | if err != nil { |
| 369 | 367 | return err |
| 370 | 368 | } |
| @@ -375,7 +373,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error { · 4 unmodified lines | ||
| 375 | 373 | lfsPaths = append(lfsPaths, v.RelativePath()) |
| 376 | 374 | } |
| 377 | 375 | |
| 378 | − if _, err := db.DeleteByBean(ctx, &LFSMetaObject{RepositoryID: repoID}); err != nil { | |
| 376 | + if _, err := db.DeleteByBean(ctx, &git_model.LFSMetaObject{RepositoryID: repoID}); err != nil { | |
| 379 | 377 | return err |
| 380 | 378 | } |
| 381 | 379 | |
| @@ -10,6 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | |
| 11 | 11 | "code.gitea.io/gitea/models/db" |
| 12 | 12 | "code.gitea.io/gitea/models/perm" |
| 13 | + "code.gitea.io/gitea/models/unit" | |
| 13 | 14 | user_model "code.gitea.io/gitea/models/user" |
| 14 | 15 | "code.gitea.io/gitea/modules/log" |
| 15 | 16 | "code.gitea.io/gitea/modules/timeutil" |
| @@ -149,3 +150,23 @@ func ChangeCollaborationAccessMode(repo *Repository, uid int64, mode perm.Access · 133 unmodified lines | ||
| 149 | 150 | |
| 150 | 151 | return committer.Commit() |
| 151 | 152 | } |
| 153 | + | |
| 154 | +// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository | |
| 155 | +func IsOwnerMemberCollaborator(repo *Repository, userID int64) (bool, error) { | |
| 156 | + if repo.OwnerID == userID { | |
| 157 | + return true, nil | |
| 158 | + } | |
| 159 | + teamMember, err := db.GetEngine(db.DefaultContext).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id"). | |
| 160 | + Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id"). | |
| 161 | + Where("team_repo.repo_id = ?", repo.ID). | |
| 162 | + And("team_unit.`type` = ?", unit.TypeCode). | |
| 163 | + And("team_user.uid = ?", userID).Table("team_user").Exist() | |
| 164 | + if err != nil { | |
| 165 | + return false, err | |
| 166 | + } | |
| 167 | + if teamMember { | |
| 168 | + return true, nil | |
| 169 | + } | |
| 170 | + | |
| 171 | + return db.GetEngine(db.DefaultContext).Get(&Collaboration{RepoID: repo.ID, UserID: userID}) | |
| 172 | +} | |
| @@ -10,11 +10,9 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | "fmt" |
| 11 | 11 | |
| 12 | 12 | "code.gitea.io/gitea/models/db" |
| 13 | − "code.gitea.io/gitea/models/organization" | |
| 14 | 13 | "code.gitea.io/gitea/models/perm" |
| 15 | 14 | access_model "code.gitea.io/gitea/models/perm/access" |
| 16 | 15 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | − "code.gitea.io/gitea/models/unit" | |
| 18 | 16 | user_model "code.gitea.io/gitea/models/user" |
| 19 | 17 | |
| 20 | 18 | "xorm.io/builder" |
| @@ -120,23 +118,3 @@ func reconsiderWatches(ctx context.Context, repo *repo_model.Repository, uid int · 99 unmodified lines | ||
| 120 | 118 | // Remove all IssueWatches a user has subscribed to in the repository |
| 121 | 119 | return removeIssueWatchersByRepoID(ctx, uid, repo.ID) |
| 122 | 120 | } |
| 123 | − | |
| 124 | −// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository | |
| 125 | −func IsOwnerMemberCollaborator(repo *repo_model.Repository, userID int64) (bool, error) { | |
| 126 | − if repo.OwnerID == userID { | |
| 127 | − return true, nil | |
| 128 | − } | |
| 129 | − teamMember, err := db.GetEngine(db.DefaultContext).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id"). | |
| 130 | − Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id"). | |
| 131 | − Where("team_repo.repo_id = ?", repo.ID). | |
| 132 | − And("team_unit.`type` = ?", unit.TypeCode). | |
| 133 | − And("team_user.uid = ?", userID).Table("team_user").Exist(&organization.TeamUser{}) | |
| 134 | − if err != nil { | |
| 135 | − return false, err | |
| 136 | − } | |
| 137 | − if teamMember { | |
| 138 | − return true, nil | |
| 139 | − } | |
| 140 | − | |
| 141 | − return db.GetEngine(db.DefaultContext).Get(&repo_model.Collaboration{RepoID: repo.ID, UserID: userID}) | |
| 142 | −} | |
| @@ -10,6 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | "strings" |
| 11 | 11 | |
| 12 | 12 | "code.gitea.io/gitea/models/db" |
| 13 | + git_model "code.gitea.io/gitea/models/git" | |
| 13 | 14 | "code.gitea.io/gitea/models/organization" |
| 14 | 15 | "code.gitea.io/gitea/models/perm" |
| 15 | 16 | access_model "code.gitea.io/gitea/models/perm/access" |
| @@ -234,7 +235,7 @@ func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewers ...*user_mo · 218 unmodified lines | ||
| 234 | 235 | } |
| 235 | 236 | |
| 236 | 237 | for _, reviewer := range reviewers { |
| 237 | − official, err := isUserOfficialReviewer(ctx, pr.ProtectedBranch, reviewer) | |
| 238 | + official, err := git_model.IsUserOfficialReviewerCtx(ctx, pr.ProtectedBranch, reviewer) | |
| 238 | 239 | if official || err != nil { |
| 239 | 240 | return official, err |
| 240 | 241 | } |
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 16 | 16 | auth_model "code.gitea.io/gitea/models/auth" |
| 17 | 17 | "code.gitea.io/gitea/models/db" |
| 18 | + git_model "code.gitea.io/gitea/models/git" | |
| 18 | 19 | "code.gitea.io/gitea/models/issues" |
| 19 | 20 | "code.gitea.io/gitea/models/organization" |
| 20 | 21 | access_model "code.gitea.io/gitea/models/perm/access" |
| @@ -125,7 +126,7 @@ func DeleteUser(ctx context.Context, u *user_model.User) (err error) { · 104 unmodified lines | ||
| 125 | 126 | { |
| 126 | 127 | const batchSize = 50 |
| 127 | 128 | for start := 0; ; start += batchSize { |
| 128 | − protections := make([]*ProtectedBranch, 0, batchSize) | |
| 129 | + protections := make([]*git_model.ProtectedBranch, 0, batchSize) | |
| 129 | 130 | // @perf: We can't filter on DB side by u.ID, as those IDs are serialized as JSON strings. |
| 130 | 131 | // We could filter down with `WHERE repo_id IN (reposWithPushPermission(u))`, |
| 131 | 132 | // though that query will be quite complex and tricky to maintain (compare `getRepoAssignees()`). |
| @@ -17,6 +17,7 @@ import ( · 16 unmodified lines | ||
| 17 | 17 | |
| 18 | 18 | "code.gitea.io/gitea/models" |
| 19 | 19 | "code.gitea.io/gitea/models/db" |
| 20 | + git_model "code.gitea.io/gitea/models/git" | |
| 20 | 21 | access_model "code.gitea.io/gitea/models/perm/access" |
| 21 | 22 | repo_model "code.gitea.io/gitea/models/repo" |
| 22 | 23 | unit_model "code.gitea.io/gitea/models/unit" |
| @@ -118,7 +119,7 @@ type CanCommitToBranchResults struct { · 95 unmodified lines | ||
| 118 | 119 | // CanCommitToBranch returns true if repository is editable and user has proper access level |
| 119 | 120 | // and branch is not protected for push |
| 120 | 121 | func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.User) (CanCommitToBranchResults, error) { |
| 121 | − protectedBranch, err := models.GetProtectedBranchBy(ctx, r.Repository.ID, r.BranchName) | |
| 122 | + protectedBranch, err := git_model.GetProtectedBranchBy(ctx, r.Repository.ID, r.BranchName) | |
| 122 | 123 | if err != nil { |
| 123 | 124 | return CanCommitToBranchResults{}, err |
| 124 | 125 | } |
| @@ -825,7 +826,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string { · 700 unmodified lines | ||
| 825 | 826 | if len(ref) == 0 { |
| 826 | 827 | // maybe it's a renamed branch |
| 827 | 828 | return getRefNameFromPath(ctx, path, func(s string) bool { |
| 828 | − b, exist, err := models.FindRenamedBranch(ctx.Repo.Repository.ID, s) | |
| 829 | + b, exist, err := git_model.FindRenamedBranch(ctx.Repo.Repository.ID, s) | |
| 829 | 830 | if err != nil { |
| 830 | 831 | log.Error("FindRenamedBranch", err) |
| 831 | 832 | return false |
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 16 | 16 | "code.gitea.io/gitea/models/auth" |
| 17 | 17 | "code.gitea.io/gitea/models/db" |
| 18 | + git_model "code.gitea.io/gitea/models/git" | |
| 18 | 19 | "code.gitea.io/gitea/models/organization" |
| 19 | 20 | "code.gitea.io/gitea/models/perm" |
| 20 | 21 | access_model "code.gitea.io/gitea/models/perm/access" |
| @@ -39,7 +40,7 @@ func ToEmail(email *user_model.EmailAddress) *api.Email { · 18 unmodified lines | ||
| 39 | 40 | } |
| 40 | 41 | |
| 41 | 42 | // ToBranch convert a git.Commit and git.Branch to an api.Branch |
| 42 | −func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { | |
| 43 | +func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *git_model.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { | |
| 43 | 44 | if bp == nil { |
| 44 | 45 | var hasPerm bool |
| 45 | 46 | var canPush bool |
| @@ -88,14 +89,14 @@ func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *mod · 42 unmodified lines | ||
| 88 | 89 | return nil, err |
| 89 | 90 | } |
| 90 | 91 | branch.UserCanPush = bp.CanUserPush(user.ID) |
| 91 | − branch.UserCanMerge = models.IsUserMergeWhitelisted(db.DefaultContext, bp, user.ID, permission) | |
| 92 | + branch.UserCanMerge = git_model.IsUserMergeWhitelisted(db.DefaultContext, bp, user.ID, permission) | |
| 92 | 93 | } |
| 93 | 94 | |
| 94 | 95 | return branch, nil |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | // ToBranchProtection convert a ProtectedBranch to api.BranchProtection |
| 98 | −func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection { | |
| 99 | +func ToBranchProtection(bp *git_model.ProtectedBranch) *api.BranchProtection { | |
| 99 | 100 | pushWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.WhitelistUserIDs) |
| 100 | 101 | if err != nil { |
| 101 | 102 | log.Error("GetUserNamesByIDs (WhitelistUserIDs): %v", err) |
| @@ -399,7 +400,7 @@ func ToOAuth2Application(app *auth.OAuth2Application) *api.OAuth2Application { · 297 unmodified lines | ||
| 399 | 400 | } |
| 400 | 401 | |
| 401 | 402 | // ToLFSLock convert a LFSLock to api.LFSLock |
| 402 | −func ToLFSLock(l *models.LFSLock) *api.LFSLock { | |
| 403 | +func ToLFSLock(l *git_model.LFSLock) *api.LFSLock { | |
| 403 | 404 | u, err := user_model.GetUserByID(l.OwnerID) |
| 404 | 405 | if err != nil { |
| 405 | 406 | return nil |
| @@ -5,13 +5,13 @@ · 4 unmodified lines | ||
| 5 | 5 | package convert |
| 6 | 6 | |
| 7 | 7 | import ( |
| 8 | − "code.gitea.io/gitea/models" | |
| 8 | + git_model "code.gitea.io/gitea/models/git" | |
| 9 | 9 | user_model "code.gitea.io/gitea/models/user" |
| 10 | 10 | api "code.gitea.io/gitea/modules/structs" |
| 11 | 11 | ) |
| 12 | 12 | |
| 13 | −// ToCommitStatus converts models.CommitStatus to api.CommitStatus | |
| 14 | −func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { | |
| 13 | +// ToCommitStatus converts git_model.CommitStatus to api.CommitStatus | |
| 14 | +func ToCommitStatus(status *git_model.CommitStatus) *api.CommitStatus { | |
| 15 | 15 | apiStatus := &api.CommitStatus{ |
| 16 | 16 | Created: status.CreatedUnix.AsTime(), |
| 17 | 17 | Updated: status.CreatedUnix.AsTime(), |
| @@ -32,7 +32,7 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { · 14 unmodified lines | ||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // ToCombinedStatus converts List of CommitStatus to a CombinedStatus |
| 35 | −func ToCombinedStatus(statuses []*models.CommitStatus, repo *api.Repository) *api.CombinedStatus { | |
| 35 | +func ToCombinedStatus(statuses []*git_model.CommitStatus, repo *api.Repository) *api.CombinedStatus { | |
| 36 | 36 | if len(statuses) == 0 { |
| 37 | 37 | return nil |
| 38 | 38 | } |
| @@ -9,9 +9,9 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | "fmt" |
| 10 | 10 | "strings" |
| 11 | 11 | |
| 12 | − "code.gitea.io/gitea/models" | |
| 13 | 12 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 14 | 13 | "code.gitea.io/gitea/models/db" |
| 14 | + git_model "code.gitea.io/gitea/models/git" | |
| 15 | 15 | repo_model "code.gitea.io/gitea/models/repo" |
| 16 | 16 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 17 | "code.gitea.io/gitea/modules/git" |
| @@ -117,14 +117,14 @@ func (graph *Graph) LoadAndProcessCommits(repository *repo_model.Repository, git · 99 unmodified lines | ||
| 117 | 117 | c.Verification = asymkey_model.ParseCommitWithSignature(c.Commit) |
| 118 | 118 | |
| 119 | 119 | _ = asymkey_model.CalculateTrustStatus(c.Verification, repository.GetTrustModel(), func(user *user_model.User) (bool, error) { |
| 120 | − return models.IsOwnerMemberCollaborator(repository, user.ID) | |
| 120 | + return repo_model.IsOwnerMemberCollaborator(repository, user.ID) | |
| 121 | 121 | }, &keyMap) |
| 122 | 122 | |
| 123 | − statuses, _, err := models.GetLatestCommitStatus(db.DefaultContext, repository.ID, c.Commit.ID.String(), db.ListOptions{}) | |
| 123 | + statuses, _, err := git_model.GetLatestCommitStatus(db.DefaultContext, repository.ID, c.Commit.ID.String(), db.ListOptions{}) | |
| 124 | 124 | if err != nil { |
| 125 | 125 | log.Error("GetLatestCommitStatus: %v", err) |
| 126 | 126 | } else { |
| 127 | − c.Status = models.CalcCommitStatus(statuses) | |
| 127 | + c.Status = git_model.CalcCommitStatus(statuses) | |
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | return nil |
| @@ -240,7 +240,7 @@ type Commit struct { · 109 unmodified lines | ||
| 240 | 240 | Commit *git.Commit |
| 241 | 241 | User *user_model.User |
| 242 | 242 | Verification *asymkey_model.CommitVerification |
| 243 | − Status *models.CommitStatus | |
| 243 | + Status *git_model.CommitStatus | |
| 244 | 244 | Flow int64 |
| 245 | 245 | Row int |
| 246 | 246 | Column int |
| @@ -113,7 +113,7 @@ func (s *ContentStore) Verify(pointer Pointer) (bool, error) { · 112 unmodified lines | ||
| 113 | 113 | return true, nil |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | −// ReadMetaObject will read a models.LFSMetaObject and return a reader | |
| 116 | +// ReadMetaObject will read a git_model.LFSMetaObject and return a reader | |
| 117 | 117 | func ReadMetaObject(pointer Pointer) (io.ReadCloser, error) { |
| 118 | 118 | contentStore := NewContentStore() |
| 119 | 119 | return contentStore.Get(pointer) |
| @@ -14,6 +14,7 @@ import ( · 13 unmodified lines | ||
| 14 | 14 | |
| 15 | 15 | "code.gitea.io/gitea/models" |
| 16 | 16 | "code.gitea.io/gitea/models/db" |
| 17 | + git_model "code.gitea.io/gitea/models/git" | |
| 17 | 18 | access_model "code.gitea.io/gitea/models/perm/access" |
| 18 | 19 | repo_model "code.gitea.io/gitea/models/repo" |
| 19 | 20 | user_model "code.gitea.io/gitea/models/user" |
| @@ -146,7 +147,7 @@ func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error { · 126 unmodified lines | ||
| 146 | 147 | return fmt.Errorf("updateSize: %v", err) |
| 147 | 148 | } |
| 148 | 149 | |
| 149 | − lfsSize, err := models.GetRepoLFSSize(ctx, repo.ID) | |
| 150 | + lfsSize, err := git_model.GetRepoLFSSize(ctx, repo.ID) | |
| 150 | 151 | if err != nil { |
| 151 | 152 | return fmt.Errorf("updateSize: GetLFSMetaObjects: %v", err) |
| 152 | 153 | } |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | "time" |
| 17 | 17 | |
| 18 | 18 | "code.gitea.io/gitea/models" |
| 19 | + git_model "code.gitea.io/gitea/models/git" | |
| 19 | 20 | repo_model "code.gitea.io/gitea/models/repo" |
| 20 | 21 | user_model "code.gitea.io/gitea/models/user" |
| 21 | 22 | "code.gitea.io/gitea/modules/git" |
| @@ -278,7 +279,7 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *repo_mo · 256 unmodified lines | ||
| 278 | 279 | return fmt.Errorf("failed to update size for repository: %v", err) |
| 279 | 280 | } |
| 280 | 281 | |
| 281 | − if err := models.CopyLFS(ctx, generateRepo, templateRepo); err != nil { | |
| 282 | + if err := git_model.CopyLFS(ctx, generateRepo, templateRepo); err != nil { | |
| 282 | 283 | return fmt.Errorf("failed to copy LFS: %v", err) |
| 283 | 284 | } |
| 284 | 285 | return nil |
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | "code.gitea.io/gitea/models" |
| 17 | 17 | "code.gitea.io/gitea/models/db" |
| 18 | + git_model "code.gitea.io/gitea/models/git" | |
| 18 | 19 | "code.gitea.io/gitea/models/organization" |
| 19 | 20 | repo_model "code.gitea.io/gitea/models/repo" |
| 20 | 21 | user_model "code.gitea.io/gitea/models/user" |
| @@ -390,7 +391,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re · 369 unmodified lines | ||
| 390 | 391 | |
| 391 | 392 | defer content.Close() |
| 392 | 393 | |
| 393 | − _, err := models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: p, RepositoryID: repo.ID}) | |
| 394 | + _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repo.ID}) | |
| 394 | 395 | if err != nil { |
| 395 | 396 | log.Error("Repo[%-v]: Error creating LFS meta object %-v: %v", repo, p, err) |
| 396 | 397 | return err |
| @@ -398,7 +399,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re · 1 unmodified line | ||
| 398 | 399 | |
| 399 | 400 | if err := contentStore.Put(p, content); err != nil { |
| 400 | 401 | log.Error("Repo[%-v]: Error storing content for LFS meta object %-v: %v", repo, p, err) |
| 401 | − if _, err2 := models.RemoveLFSMetaObjectByOid(repo.ID, p.Oid); err2 != nil { | |
| 402 | + if _, err2 := git_model.RemoveLFSMetaObjectByOid(repo.ID, p.Oid); err2 != nil { | |
| 402 | 403 | log.Error("Repo[%-v]: Error removing LFS meta object %-v: %v", repo, p, err2) |
| 403 | 404 | } |
| 404 | 405 | return err |
| @@ -417,8 +418,8 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re · 12 unmodified lines | ||
| 417 | 418 | |
| 418 | 419 | var batch []lfs.Pointer |
| 419 | 420 | for pointerBlob := range pointerChan { |
| 420 | − meta, err := models.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid) | |
| 421 | − if err != nil && err != models.ErrLFSObjectNotExist { | |
| 421 | + meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid) | |
| 422 | + if err != nil && err != git_model.ErrLFSObjectNotExist { | |
| 422 | 423 | log.Error("Repo[%-v]: Error querying LFS meta object %-v: %v", repo, pointerBlob.Pointer, err) |
| 423 | 424 | return err |
| 424 | 425 | } |
| @@ -437,7 +438,7 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re · 12 unmodified lines | ||
| 437 | 438 | |
| 438 | 439 | if exist { |
| 439 | 440 | log.Trace("Repo[%-v]: LFS object %-v already present; creating meta object", repo, pointerBlob.Pointer) |
| 440 | − _, err := models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: pointerBlob.Pointer, RepositoryID: repo.ID}) | |
| 441 | + _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: pointerBlob.Pointer, RepositoryID: repo.ID}) | |
| 441 | 442 | if err != nil { |
| 442 | 443 | log.Error("Repo[%-v]: Error creating LFS meta object %-v: %v", repo, pointerBlob.Pointer, err) |
| 443 | 444 | return err |
| @@ -20,6 +20,9 @@ const ( · 19 unmodified lines | ||
| 20 | 20 | RepoCreatingPublic = "public" |
| 21 | 21 | ) |
| 22 | 22 | |
| 23 | +// ItemsPerPage maximum items per page in forks, watchers and stars of a repo | |
| 24 | +const ItemsPerPage = 40 | |
| 25 | + | |
| 23 | 26 | // Repository settings |
| 24 | 27 | var ( |
| 25 | 28 | Repository = struct { |
| @@ -11,6 +11,7 @@ import ( · 10 unmodified lines | ||
| 11 | 11 | "net/http" |
| 12 | 12 | |
| 13 | 13 | "code.gitea.io/gitea/models" |
| 14 | + git_model "code.gitea.io/gitea/models/git" | |
| 14 | 15 | "code.gitea.io/gitea/models/organization" |
| 15 | 16 | user_model "code.gitea.io/gitea/models/user" |
| 16 | 17 | "code.gitea.io/gitea/modules/context" |
| @@ -70,7 +71,7 @@ func GetBranch(ctx *context.APIContext) { · 53 unmodified lines | ||
| 70 | 71 | return |
| 71 | 72 | } |
| 72 | 73 | |
| 73 | − branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branchName) | |
| 74 | + branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branchName) | |
| 74 | 75 | if err != nil { |
| 75 | 76 | ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) |
| 76 | 77 | return |
| @@ -206,7 +207,7 @@ func CreateBranch(ctx *context.APIContext) { · 129 unmodified lines | ||
| 206 | 207 | return |
| 207 | 208 | } |
| 208 | 209 | |
| 209 | − branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch.Name) | |
| 210 | + branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch.Name) | |
| 210 | 211 | if err != nil { |
| 211 | 212 | ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) |
| 212 | 213 | return |
| @@ -271,7 +272,7 @@ func ListBranches(ctx *context.APIContext) { · 58 unmodified lines | ||
| 271 | 272 | ctx.Error(http.StatusInternalServerError, "GetCommit", err) |
| 272 | 273 | return |
| 273 | 274 | } |
| 274 | − branchProtection, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name) | |
| 275 | + branchProtection, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branches[i].Name) | |
| 275 | 276 | if err != nil { |
| 276 | 277 | ctx.Error(http.StatusInternalServerError, "GetBranchProtection", err) |
| 277 | 278 | return |
| @@ -320,7 +321,7 @@ func GetBranchProtection(ctx *context.APIContext) { · 42 unmodified lines | ||
| 320 | 321 | |
| 321 | 322 | repo := ctx.Repo.Repository |
| 322 | 323 | bpName := ctx.Params(":name") |
| 323 | − bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName) | |
| 324 | + bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName) | |
| 324 | 325 | if err != nil { |
| 325 | 326 | ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) |
| 326 | 327 | return |
| @@ -356,7 +357,7 @@ func ListBranchProtections(ctx *context.APIContext) { · 29 unmodified lines | ||
| 356 | 357 | // "$ref": "#/responses/BranchProtectionList" |
| 357 | 358 | |
| 358 | 359 | repo := ctx.Repo.Repository |
| 359 | − bps, err := models.GetProtectedBranches(repo.ID) | |
| 360 | + bps, err := git_model.GetProtectedBranches(repo.ID) | |
| 360 | 361 | if err != nil { |
| 361 | 362 | ctx.Error(http.StatusInternalServerError, "GetProtectedBranches", err) |
| 362 | 363 | return |
| @@ -412,7 +413,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 49 unmodified lines | ||
| 412 | 413 | return |
| 413 | 414 | } |
| 414 | 415 | |
| 415 | − protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, form.BranchName) | |
| 416 | + protectBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, form.BranchName) | |
| 416 | 417 | if err != nil { |
| 417 | 418 | ctx.Error(http.StatusInternalServerError, "GetProtectBranchOfRepoByName", err) |
| 418 | 419 | return |
| @@ -484,7 +485,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 65 unmodified lines | ||
| 484 | 485 | } |
| 485 | 486 | } |
| 486 | 487 | |
| 487 | − protectBranch = &models.ProtectedBranch{ | |
| 488 | + protectBranch = &git_model.ProtectedBranch{ | |
| 488 | 489 | RepoID: ctx.Repo.Repository.ID, |
| 489 | 490 | BranchName: form.BranchName, |
| 490 | 491 | CanPush: form.EnablePush, |
| @@ -504,7 +505,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 13 unmodified lines | ||
| 504 | 505 | BlockOnOutdatedBranch: form.BlockOnOutdatedBranch, |
| 505 | 506 | } |
| 506 | 507 | |
| 507 | − err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{ | |
| 508 | + err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{ | |
| 508 | 509 | UserIDs: whitelistUsers, |
| 509 | 510 | TeamIDs: whitelistTeams, |
| 510 | 511 | MergeUserIDs: mergeWhitelistUsers, |
| @@ -523,7 +524,7 @@ func CreateBranchProtection(ctx *context.APIContext) { · 12 unmodified lines | ||
| 523 | 524 | } |
| 524 | 525 | |
| 525 | 526 | // Reload from db to get all whitelists |
| 526 | − bp, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, form.BranchName) | |
| 527 | + bp, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, form.BranchName) | |
| 527 | 528 | if err != nil { |
| 528 | 529 | ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) |
| 529 | 530 | return |
| @@ -575,7 +576,7 @@ func EditBranchProtection(ctx *context.APIContext) { · 45 unmodified lines | ||
| 575 | 576 | form := web.GetForm(ctx).(*api.EditBranchProtectionOption) |
| 576 | 577 | repo := ctx.Repo.Repository |
| 577 | 578 | bpName := ctx.Params(":name") |
| 578 | − protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName) | |
| 579 | + protectBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName) | |
| 579 | 580 | if err != nil { |
| 580 | 581 | ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) |
| 581 | 582 | return |
| @@ -739,7 +740,7 @@ func EditBranchProtection(ctx *context.APIContext) { · 157 unmodified lines | ||
| 739 | 740 | } |
| 740 | 741 | } |
| 741 | 742 | |
| 742 | − err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{ | |
| 743 | + err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{ | |
| 743 | 744 | UserIDs: whitelistUsers, |
| 744 | 745 | TeamIDs: whitelistTeams, |
| 745 | 746 | MergeUserIDs: mergeWhitelistUsers, |
| @@ -758,7 +759,7 @@ func EditBranchProtection(ctx *context.APIContext) { · 12 unmodified lines | ||
| 758 | 759 | } |
| 759 | 760 | |
| 760 | 761 | // Reload from db to ensure get all whitelists |
| 761 | − bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName) | |
| 762 | + bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName) | |
| 762 | 763 | if err != nil { |
| 763 | 764 | ctx.Error(http.StatusInternalServerError, "GetProtectedBranchBy", err) |
| 764 | 765 | return |
| @@ -802,7 +803,7 @@ func DeleteBranchProtection(ctx *context.APIContext) { · 37 unmodified lines | ||
| 802 | 803 | |
| 803 | 804 | repo := ctx.Repo.Repository |
| 804 | 805 | bpName := ctx.Params(":name") |
| 805 | − bp, err := models.GetProtectedBranchBy(ctx, repo.ID, bpName) | |
| 806 | + bp, err := git_model.GetProtectedBranchBy(ctx, repo.ID, bpName) | |
| 806 | 807 | if err != nil { |
| 807 | 808 | ctx.Error(http.StatusInternalServerError, "GetProtectedBranchByID", err) |
| 808 | 809 | return |
| @@ -812,7 +813,7 @@ func DeleteBranchProtection(ctx *context.APIContext) { · 3 unmodified lines | ||
| 812 | 813 | return |
| 813 | 814 | } |
| 814 | 815 | |
| 815 | − if err := models.DeleteProtectedBranch(ctx.Repo.Repository.ID, bp.ID); err != nil { | |
| 816 | + if err := git_model.DeleteProtectedBranch(ctx.Repo.Repository.ID, bp.ID); err != nil { | |
| 816 | 817 | ctx.Error(http.StatusInternalServerError, "DeleteProtectedBranch", err) |
| 817 | 818 | return |
| 818 | 819 | } |
| @@ -15,6 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | "time" |
| 16 | 16 | |
| 17 | 17 | "code.gitea.io/gitea/models" |
| 18 | + git_model "code.gitea.io/gitea/models/git" | |
| 18 | 19 | repo_model "code.gitea.io/gitea/models/repo" |
| 19 | 20 | "code.gitea.io/gitea/models/unit" |
| 20 | 21 | "code.gitea.io/gitea/modules/cache" |
| @@ -173,10 +174,10 @@ func GetRawFileOrLFS(ctx *context.APIContext) { · 152 unmodified lines | ||
| 173 | 174 | } |
| 174 | 175 | |
| 175 | 176 | // Now check if there is a meta object for this pointer |
| 176 | − meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) | |
| 177 | + meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) | |
| 177 | 178 | |
| 178 | 179 | // If there isn't one just serve the data directly |
| 179 | − if err == models.ErrLFSObjectNotExist { | |
| 180 | + if err == git_model.ErrLFSObjectNotExist { | |
| 180 | 181 | // Handle caching for the blob SHA (not the LFS object OID) |
| 181 | 182 | if httpcache.HandleGenericETagTimeCache(ctx.Req, ctx.Resp, `"`+blob.ID.String()+`"`, lastModified) { |
| 182 | 183 | return |
| @@ -8,7 +8,7 @@ import ( · 7 unmodified lines | ||
| 8 | 8 | "fmt" |
| 9 | 9 | "net/http" |
| 10 | 10 | |
| 11 | − "code.gitea.io/gitea/models" | |
| 11 | + git_model "code.gitea.io/gitea/models/git" | |
| 12 | 12 | "code.gitea.io/gitea/modules/context" |
| 13 | 13 | "code.gitea.io/gitea/modules/convert" |
| 14 | 14 | api "code.gitea.io/gitea/modules/structs" |
| @@ -56,7 +56,7 @@ func NewCommitStatus(ctx *context.APIContext) { · 41 unmodified lines | ||
| 56 | 56 | ctx.Error(http.StatusBadRequest, "sha not given", nil) |
| 57 | 57 | return |
| 58 | 58 | } |
| 59 | − status := &models.CommitStatus{ | |
| 59 | + status := &git_model.CommitStatus{ | |
| 60 | 60 | State: api.CommitStatusState(form.State), |
| 61 | 61 | TargetURL: form.TargetURL, |
| 62 | 62 | Description: form.Description, |
| @@ -188,7 +188,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) { · 125 unmodified lines | ||
| 188 | 188 | |
| 189 | 189 | listOptions := utils.GetListOptions(ctx) |
| 190 | 190 | |
| 191 | − statuses, maxResults, err := models.GetCommitStatuses(repo, sha, &models.CommitStatusOptions{ | |
| 191 | + statuses, maxResults, err := git_model.GetCommitStatuses(repo, sha, &git_model.CommitStatusOptions{ | |
| 192 | 192 | ListOptions: listOptions, |
| 193 | 193 | SortType: ctx.FormTrim("sort"), |
| 194 | 194 | State: ctx.FormTrim("state"), |
| @@ -253,7 +253,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) { · 58 unmodified lines | ||
| 253 | 253 | |
| 254 | 254 | repo := ctx.Repo.Repository |
| 255 | 255 | |
| 256 | − statuses, count, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx)) | |
| 256 | + statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, utils.GetListOptions(ctx)) | |
| 257 | 257 | if err != nil { |
| 258 | 258 | ctx.Error(http.StatusInternalServerError, "GetLatestCommitStatus", fmt.Errorf("GetLatestCommitStatus[%s, %s]: %v", repo.FullName(), sha, err)) |
| 259 | 259 | return |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | "code.gitea.io/gitea/models" |
| 15 | 15 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 16 | + git_model "code.gitea.io/gitea/models/git" | |
| 16 | 17 | perm_model "code.gitea.io/gitea/models/perm" |
| 17 | 18 | access_model "code.gitea.io/gitea/models/perm/access" |
| 18 | 19 | "code.gitea.io/gitea/models/unit" |
| @@ -40,7 +41,7 @@ type preReceiveContext struct { · 21 unmodified lines | ||
| 40 | 41 | canWriteCode bool |
| 41 | 42 | checkedCanWriteCode bool |
| 42 | 43 | |
| 43 | − protectedTags []*models.ProtectedTag | |
| 44 | + protectedTags []*git_model.ProtectedTag | |
| 44 | 45 | gotProtectedTags bool |
| 45 | 46 | |
| 46 | 47 | env []string |
| @@ -155,7 +156,7 @@ func preReceiveBranch(ctx *preReceiveContext, oldCommitID, newCommitID, refFullN · 108 unmodified lines | ||
| 155 | 156 | return |
| 156 | 157 | } |
| 157 | 158 | |
| 158 | − protectBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, branchName) | |
| 159 | + protectBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, branchName) | |
| 159 | 160 | if err != nil { |
| 160 | 161 | log.Error("Unable to get protected branch: %s in %-v Error: %v", branchName, repo, err) |
| 161 | 162 | ctx.JSON(http.StatusInternalServerError, private.Response{ |
| @@ -370,7 +371,7 @@ func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID, refFullName · 208 unmodified lines | ||
| 370 | 371 | |
| 371 | 372 | if !ctx.gotProtectedTags { |
| 372 | 373 | var err error |
| 373 | − ctx.protectedTags, err = models.GetProtectedTags(ctx.Repo.Repository.ID) | |
| 374 | + ctx.protectedTags, err = git_model.GetProtectedTags(ctx.Repo.Repository.ID) | |
| 374 | 375 | if err != nil { |
| 375 | 376 | log.Error("Unable to get protected tags for %-v Error: %v", ctx.Repo.Repository, err) |
| 376 | 377 | ctx.JSON(http.StatusInternalServerError, private.Response{ |
| @@ -381,7 +382,7 @@ func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID, refFullName · 4 unmodified lines | ||
| 381 | 382 | ctx.gotProtectedTags = true |
| 382 | 383 | } |
| 383 | 384 | |
| 384 | − isAllowed, err := models.IsUserAllowedToControlTag(ctx.protectedTags, tagName, ctx.opts.UserID) | |
| 385 | + isAllowed, err := git_model.IsUserAllowedToControlTag(ctx.protectedTags, tagName, ctx.opts.UserID) | |
| 385 | 386 | if err != nil { |
| 386 | 387 | ctx.JSON(http.StatusInternalServerError, private.Response{ |
| 387 | 388 | Err: err.Error(), |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "strings" |
| 13 | 13 | |
| 14 | 14 | "code.gitea.io/gitea/models" |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 15 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 16 | 17 | "code.gitea.io/gitea/models/unit" |
| 17 | 18 | "code.gitea.io/gitea/modules/base" |
| @@ -40,7 +41,7 @@ type Branch struct { · 22 unmodified lines | ||
| 40 | 41 | IsProtected bool |
| 41 | 42 | IsDeleted bool |
| 42 | 43 | IsIncluded bool |
| 43 | − DeletedBranch *models.DeletedBranch | |
| 44 | + DeletedBranch *git_model.DeletedBranch | |
| 44 | 45 | CommitsAhead int |
| 45 | 46 | CommitsBehind int |
| 46 | 47 | LatestPullRequest *models.PullRequest |
| @@ -119,7 +120,7 @@ func RestoreBranchPost(ctx *context.Context) { · 72 unmodified lines | ||
| 119 | 120 | branchID := ctx.FormInt64("branch_id") |
| 120 | 121 | branchName := ctx.FormString("name") |
| 121 | 122 | |
| 122 | − deletedBranch, err := models.GetDeletedBranchByID(ctx.Repo.Repository.ID, branchID) | |
| 123 | + deletedBranch, err := git_model.GetDeletedBranchByID(ctx.Repo.Repository.ID, branchID) | |
| 123 | 124 | if err != nil { |
| 124 | 125 | log.Error("GetDeletedBranchByID: %v", err) |
| 125 | 126 | ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", branchName)) |
| @@ -184,7 +185,7 @@ func loadBranches(ctx *context.Context, skip, limit int) (*Branch, []*Branch, in · 58 unmodified lines | ||
| 184 | 185 | return nil, nil, 0 |
| 185 | 186 | } |
| 186 | 187 | |
| 187 | − protectedBranches, err := models.GetProtectedBranches(ctx.Repo.Repository.ID) | |
| 188 | + protectedBranches, err := git_model.GetProtectedBranches(ctx.Repo.Repository.ID) | |
| 188 | 189 | if err != nil { |
| 189 | 190 | ctx.ServerError("GetProtectedBranches", err) |
| 190 | 191 | return nil, nil, 0 |
| @@ -231,7 +232,7 @@ func loadBranches(ctx *context.Context, skip, limit int) (*Branch, []*Branch, in · 40 unmodified lines | ||
| 231 | 232 | return defaultBranchBranch, branches, totalNumOfBranches |
| 232 | 233 | } |
| 233 | 234 | |
| 234 | −func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, protectedBranches []*models.ProtectedBranch, | |
| 235 | +func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, protectedBranches []*git_model.ProtectedBranch, | |
| 235 | 236 | repoIDToRepo map[int64]*repo_model.Repository, |
| 236 | 237 | repoIDToGitRepo map[int64]*git.Repository, |
| 237 | 238 | ) *Branch { |
| @@ -326,7 +327,7 @@ func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, p · 88 unmodified lines | ||
| 326 | 327 | func getDeletedBranches(ctx *context.Context) ([]*Branch, error) { |
| 327 | 328 | branches := []*Branch{} |
| 328 | 329 | |
| 329 | − deletedBranches, err := models.GetDeletedBranches(ctx.Repo.Repository.ID) | |
| 330 | + deletedBranches, err := git_model.GetDeletedBranches(ctx.Repo.Repository.ID) | |
| 330 | 331 | if err != nil { |
| 331 | 332 | return branches, err |
| 332 | 333 | } |
| @@ -11,9 +11,10 @@ import ( · 10 unmodified lines | ||
| 11 | 11 | "net/http" |
| 12 | 12 | "strings" |
| 13 | 13 | |
| 14 | − "code.gitea.io/gitea/models" | |
| 15 | 14 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 16 | 15 | "code.gitea.io/gitea/models/db" |
| 16 | + git_model "code.gitea.io/gitea/models/git" | |
| 17 | + repo_model "code.gitea.io/gitea/models/repo" | |
| 17 | 18 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 19 | "code.gitea.io/gitea/modules/base" |
| 19 | 20 | "code.gitea.io/gitea/modules/charset" |
| @@ -75,7 +76,7 @@ func Commits(ctx *context.Context) { · 55 unmodified lines | ||
| 75 | 76 | ctx.ServerError("CommitsByRange", err) |
| 76 | 77 | return |
| 77 | 78 | } |
| 78 | − ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository) | |
| 79 | + ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository) | |
| 79 | 80 | |
| 80 | 81 | ctx.Data["Username"] = ctx.Repo.Owner.Name |
| 81 | 82 | ctx.Data["Reponame"] = ctx.Repo.Repository.Name |
| @@ -194,7 +195,7 @@ func SearchCommits(ctx *context.Context) { · 112 unmodified lines | ||
| 194 | 195 | return |
| 195 | 196 | } |
| 196 | 197 | ctx.Data["CommitCount"] = len(commits) |
| 197 | − ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository) | |
| 198 | + ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository) | |
| 198 | 199 | |
| 199 | 200 | ctx.Data["Keyword"] = query |
| 200 | 201 | if all { |
| @@ -235,7 +236,7 @@ func FileHistory(ctx *context.Context) { · 34 unmodified lines | ||
| 235 | 236 | ctx.ServerError("CommitsByFileAndRange", err) |
| 236 | 237 | return |
| 237 | 238 | } |
| 238 | − ctx.Data["Commits"] = models.ConvertFromGitCommit(commits, ctx.Repo.Repository) | |
| 239 | + ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commits, ctx.Repo.Repository) | |
| 239 | 240 | |
| 240 | 241 | ctx.Data["Username"] = ctx.Repo.Owner.Name |
| 241 | 242 | ctx.Data["Reponame"] = ctx.Repo.Repository.Name |
| @@ -335,12 +336,12 @@ func Diff(ctx *context.Context) { · 93 unmodified lines | ||
| 335 | 336 | ctx.Data["Commit"] = commit |
| 336 | 337 | ctx.Data["Diff"] = diff |
| 337 | 338 | |
| 338 | − statuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, commitID, db.ListOptions{}) | |
| 339 | + statuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, commitID, db.ListOptions{}) | |
| 339 | 340 | if err != nil { |
| 340 | 341 | log.Error("GetLatestCommitStatus: %v", err) |
| 341 | 342 | } |
| 342 | 343 | |
| 343 | − ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses) | |
| 344 | + ctx.Data["CommitStatus"] = git_model.CalcCommitStatus(statuses) | |
| 344 | 345 | ctx.Data["CommitStatuses"] = statuses |
| 345 | 346 | |
| 346 | 347 | verification := asymkey_model.ParseCommitWithSignature(commit) |
| @@ -350,7 +351,7 @@ func Diff(ctx *context.Context) { · 3 unmodified lines | ||
| 350 | 351 | ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0 |
| 351 | 352 | |
| 352 | 353 | if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) { |
| 353 | − return models.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID) | |
| 354 | + return repo_model.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID) | |
| 354 | 355 | }, nil); err != nil { |
| 355 | 356 | ctx.ServerError("CalculateTrustStatus", err) |
| 356 | 357 | return |
| @@ -18,6 +18,7 @@ import ( · 17 unmodified lines | ||
| 18 | 18 | "strings" |
| 19 | 19 | |
| 20 | 20 | "code.gitea.io/gitea/models" |
| 21 | + git_model "code.gitea.io/gitea/models/git" | |
| 21 | 22 | access_model "code.gitea.io/gitea/models/perm/access" |
| 22 | 23 | repo_model "code.gitea.io/gitea/models/repo" |
| 23 | 24 | "code.gitea.io/gitea/models/unit" |
| @@ -636,7 +637,7 @@ func PrepareCompareDiff( · 612 unmodified lines | ||
| 636 | 637 | return false |
| 637 | 638 | } |
| 638 | 639 | |
| 639 | − commits := models.ConvertFromGitCommit(ci.CompareInfo.Commits, ci.HeadRepo) | |
| 640 | + commits := git_model.ConvertFromGitCommit(ci.CompareInfo.Commits, ci.HeadRepo) | |
| 640 | 641 | ctx.Data["Commits"] = commits |
| 641 | 642 | ctx.Data["CommitCount"] = len(commits) |
| 642 | 643 | |
| @@ -9,7 +9,7 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | "path" |
| 10 | 10 | "time" |
| 11 | 11 | |
| 12 | − "code.gitea.io/gitea/models" | |
| 12 | + git_model "code.gitea.io/gitea/models/git" | |
| 13 | 13 | "code.gitea.io/gitea/modules/cache" |
| 14 | 14 | "code.gitea.io/gitea/modules/context" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| @@ -43,7 +43,7 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob, lastModified time.Time · 27 unmodified lines | ||
| 43 | 43 | |
| 44 | 44 | pointer, _ := lfs.ReadPointer(dataRc) |
| 45 | 45 | if pointer.IsValid() { |
| 46 | − meta, _ := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) | |
| 46 | + meta, _ := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) | |
| 47 | 47 | if meta == nil { |
| 48 | 48 | if err = dataRc.Close(); err != nil { |
| 49 | 49 | log.Error("ServeBlobOrLFS: Close: %v", err) |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "strings" |
| 13 | 13 | |
| 14 | 14 | "code.gitea.io/gitea/models" |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 15 | 16 | "code.gitea.io/gitea/models/unit" |
| 16 | 17 | "code.gitea.io/gitea/modules/base" |
| 17 | 18 | "code.gitea.io/gitea/modules/charset" |
| @@ -253,9 +254,9 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b · 235 unmodified lines | ||
| 253 | 254 | // This is where we handle all the errors thrown by files_service.CreateOrUpdateRepoFile |
| 254 | 255 | if git.IsErrNotExist(err) { |
| 255 | 256 | ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", ctx.Repo.TreePath), tplEditFile, &form) |
| 256 | − } else if models.IsErrLFSFileLocked(err) { | |
| 257 | + } else if git_model.IsErrLFSFileLocked(err) { | |
| 257 | 258 | ctx.Data["Err_TreePath"] = true |
| 258 | − ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(models.ErrLFSFileLocked).Path, err.(models.ErrLFSFileLocked).UserName), tplEditFile, &form) | |
| 259 | + ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(git_model.ErrLFSFileLocked).Path, err.(git_model.ErrLFSFileLocked).UserName), tplEditFile, &form) | |
| 259 | 260 | } else if models.IsErrFilenameInvalid(err) { |
| 260 | 261 | ctx.Data["Err_TreePath"] = true |
| 261 | 262 | ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_invalid", form.TreePath), tplEditFile, &form) |
| @@ -660,9 +661,9 @@ func UploadFilePost(ctx *context.Context) { · 398 unmodified lines | ||
| 660 | 661 | Files: form.Files, |
| 661 | 662 | Signoff: form.Signoff, |
| 662 | 663 | }); err != nil { |
| 663 | − if models.IsErrLFSFileLocked(err) { | |
| 664 | + if git_model.IsErrLFSFileLocked(err) { | |
| 664 | 665 | ctx.Data["Err_TreePath"] = true |
| 665 | − ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(models.ErrLFSFileLocked).Path, err.(models.ErrLFSFileLocked).UserName), tplUploadFile, &form) | |
| 666 | + ctx.RenderWithErr(ctx.Tr("repo.editor.upload_file_is_locked", err.(git_model.ErrLFSFileLocked).Path, err.(git_model.ErrLFSFileLocked).UserName), tplUploadFile, &form) | |
| 666 | 667 | } else if models.IsErrFilenameInvalid(err) { |
| 667 | 668 | ctx.Data["Err_TreePath"] = true |
| 668 | 669 | ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_invalid", form.TreePath), tplUploadFile, &form) |
| @@ -21,6 +21,7 @@ import ( · 20 unmodified lines | ||
| 21 | 21 | |
| 22 | 22 | "code.gitea.io/gitea/models" |
| 23 | 23 | "code.gitea.io/gitea/models/db" |
| 24 | + git_model "code.gitea.io/gitea/models/git" | |
| 24 | 25 | issues_model "code.gitea.io/gitea/models/issues" |
| 25 | 26 | "code.gitea.io/gitea/models/organization" |
| 26 | 27 | access_model "code.gitea.io/gitea/models/perm/access" |
| @@ -1536,7 +1537,7 @@ func ViewIssue(ctx *context.Context) { · 1509 unmodified lines | ||
| 1536 | 1537 | if perm.CanWrite(unit.TypeCode) { |
| 1537 | 1538 | // Check if branch is not protected |
| 1538 | 1539 | if pull.HeadBranch != pull.HeadRepo.DefaultBranch { |
| 1539 | − if protected, err := models.IsProtectedBranch(pull.HeadRepo.ID, pull.HeadBranch); err != nil { | |
| 1540 | + if protected, err := git_model.IsProtectedBranch(pull.HeadRepo.ID, pull.HeadBranch); err != nil { | |
| 1540 | 1541 | log.Error("IsProtectedBranch: %v", err) |
| 1541 | 1542 | } else if !protected { |
| 1542 | 1543 | canDelete = true |
| @@ -1620,11 +1621,11 @@ func ViewIssue(ctx *context.Context) { · 77 unmodified lines | ||
| 1620 | 1621 | if ctx.Doer != nil { |
| 1621 | 1622 | showMergeInstructions = pull.ProtectedBranch.CanUserPush(ctx.Doer.ID) |
| 1622 | 1623 | } |
| 1623 | − ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(ctx, pull) | |
| 1624 | − ctx.Data["IsBlockedByRejection"] = pull.ProtectedBranch.MergeBlockedByRejectedReview(ctx, pull) | |
| 1625 | − ctx.Data["IsBlockedByOfficialReviewRequests"] = pull.ProtectedBranch.MergeBlockedByOfficialReviewRequests(ctx, pull) | |
| 1626 | − ctx.Data["IsBlockedByOutdatedBranch"] = pull.ProtectedBranch.MergeBlockedByOutdatedBranch(pull) | |
| 1627 | − ctx.Data["GrantedApprovals"] = pull.ProtectedBranch.GetGrantedApprovalsCount(ctx, pull) | |
| 1624 | + ctx.Data["IsBlockedByApprovals"] = !models.HasEnoughApprovals(ctx, pull.ProtectedBranch, pull) | |
| 1625 | + ctx.Data["IsBlockedByRejection"] = models.MergeBlockedByRejectedReview(ctx, pull.ProtectedBranch, pull) | |
| 1626 | + ctx.Data["IsBlockedByOfficialReviewRequests"] = models.MergeBlockedByOfficialReviewRequests(ctx, pull.ProtectedBranch, pull) | |
| 1627 | + ctx.Data["IsBlockedByOutdatedBranch"] = models.MergeBlockedByOutdatedBranch(pull.ProtectedBranch, pull) | |
| 1628 | + ctx.Data["GrantedApprovals"] = models.GetGrantedApprovalsCount(ctx, pull.ProtectedBranch, pull) | |
| 1628 | 1629 | ctx.Data["RequireSigned"] = pull.ProtectedBranch.RequireSignedCommits |
| 1629 | 1630 | ctx.Data["ChangedProtectedFiles"] = pull.ChangedProtectedFiles |
| 1630 | 1631 | ctx.Data["IsBlockedByChangedProtectedFiles"] = len(pull.ChangedProtectedFiles) != 0 |
| @@ -15,7 +15,7 @@ import ( · 14 unmodified lines | ||
| 15 | 15 | "strconv" |
| 16 | 16 | "strings" |
| 17 | 17 | |
| 18 | − "code.gitea.io/gitea/models" | |
| 18 | + git_model "code.gitea.io/gitea/models/git" | |
| 19 | 19 | "code.gitea.io/gitea/modules/base" |
| 20 | 20 | "code.gitea.io/gitea/modules/charset" |
| 21 | 21 | "code.gitea.io/gitea/modules/context" |
| @@ -48,7 +48,7 @@ func LFSFiles(ctx *context.Context) { · 26 unmodified lines | ||
| 48 | 48 | if page <= 1 { |
| 49 | 49 | page = 1 |
| 50 | 50 | } |
| 51 | − total, err := models.CountLFSMetaObjects(ctx.Repo.Repository.ID) | |
| 51 | + total, err := git_model.CountLFSMetaObjects(ctx.Repo.Repository.ID) | |
| 52 | 52 | if err != nil { |
| 53 | 53 | ctx.ServerError("LFSFiles", err) |
| 54 | 54 | return |
| @@ -58,7 +58,7 @@ func LFSFiles(ctx *context.Context) { · 3 unmodified lines | ||
| 58 | 58 | pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5) |
| 59 | 59 | ctx.Data["Title"] = ctx.Tr("repo.settings.lfs") |
| 60 | 60 | ctx.Data["PageIsSettingsLFS"] = true |
| 61 | − lfsMetaObjects, err := models.GetLFSMetaObjects(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum) | |
| 61 | + lfsMetaObjects, err := git_model.GetLFSMetaObjects(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum) | |
| 62 | 62 | if err != nil { |
| 63 | 63 | ctx.ServerError("LFSFiles", err) |
| 64 | 64 | return |
| @@ -80,7 +80,7 @@ func LFSLocks(ctx *context.Context) { · 15 unmodified lines | ||
| 80 | 80 | if page <= 1 { |
| 81 | 81 | page = 1 |
| 82 | 82 | } |
| 83 | − total, err := models.CountLFSLockByRepoID(ctx.Repo.Repository.ID) | |
| 83 | + total, err := git_model.CountLFSLockByRepoID(ctx.Repo.Repository.ID) | |
| 84 | 84 | if err != nil { |
| 85 | 85 | ctx.ServerError("LFSLocks", err) |
| 86 | 86 | return |
| @@ -90,7 +90,7 @@ func LFSLocks(ctx *context.Context) { · 3 unmodified lines | ||
| 90 | 90 | pager := context.NewPagination(int(total), setting.UI.ExplorePagingNum, page, 5) |
| 91 | 91 | ctx.Data["Title"] = ctx.Tr("repo.settings.lfs_locks") |
| 92 | 92 | ctx.Data["PageIsSettingsLFS"] = true |
| 93 | − lfsLocks, err := models.GetLFSLockByRepoID(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum) | |
| 93 | + lfsLocks, err := git_model.GetLFSLockByRepoID(ctx.Repo.Repository.ID, pager.Paginater.Current(), setting.UI.ExplorePagingNum) | |
| 94 | 94 | if err != nil { |
| 95 | 95 | ctx.ServerError("LFSLocks", err) |
| 96 | 96 | return |
| @@ -216,12 +216,12 @@ func LFSLockFile(ctx *context.Context) { · 119 unmodified lines | ||
| 216 | 216 | return |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | − _, err := models.CreateLFSLock(ctx.Repo.Repository, &models.LFSLock{ | |
| 219 | + _, err := git_model.CreateLFSLock(ctx.Repo.Repository, &git_model.LFSLock{ | |
| 220 | 220 | Path: lockPath, |
| 221 | 221 | OwnerID: ctx.Doer.ID, |
| 222 | 222 | }) |
| 223 | 223 | if err != nil { |
| 224 | − if models.IsErrLFSLockAlreadyExist(err) { | |
| 224 | + if git_model.IsErrLFSLockAlreadyExist(err) { | |
| 225 | 225 | ctx.Flash.Error(ctx.Tr("repo.settings.lfs_lock_already_exists", originalPath)) |
| 226 | 226 | ctx.Redirect(ctx.Repo.RepoLink + "/settings/lfs/locks") |
| 227 | 227 | return |
| @@ -238,7 +238,7 @@ func LFSUnlock(ctx *context.Context) { · 10 unmodified lines | ||
| 238 | 238 | ctx.NotFound("LFSUnlock", nil) |
| 239 | 239 | return |
| 240 | 240 | } |
| 241 | − _, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.Doer, true) | |
| 241 | + _, err := git_model.DeleteLFSLockByID(ctx.ParamsInt64("lid"), ctx.Repo.Repository, ctx.Doer, true) | |
| 242 | 242 | if err != nil { |
| 243 | 243 | ctx.ServerError("LFSUnlock", err) |
| 244 | 244 | return |
| @@ -263,9 +263,9 @@ func LFSFileGet(ctx *context.Context) { · 18 unmodified lines | ||
| 263 | 263 | |
| 264 | 264 | ctx.Data["Title"] = oid |
| 265 | 265 | ctx.Data["PageIsSettingsLFS"] = true |
| 266 | − meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid) | |
| 266 | + meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid) | |
| 267 | 267 | if err != nil { |
| 268 | − if err == models.ErrLFSObjectNotExist { | |
| 268 | + if err == git_model.ErrLFSObjectNotExist { | |
| 269 | 269 | ctx.NotFound("LFSFileGet", nil) |
| 270 | 270 | return |
| 271 | 271 | } |
| @@ -357,7 +357,7 @@ func LFSDelete(ctx *context.Context) { · 85 unmodified lines | ||
| 357 | 357 | return |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | − count, err := models.RemoveLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid) | |
| 360 | + count, err := git_model.RemoveLFSMetaObjectByOid(ctx.Repo.Repository.ID, oid) | |
| 361 | 361 | if err != nil { |
| 362 | 362 | ctx.ServerError("LFSDelete", err) |
| 363 | 363 | return |
| @@ -456,8 +456,8 @@ func LFSPointerFiles(ctx *context.Context) { · 92 unmodified lines | ||
| 456 | 456 | Size: pointerBlob.Size, |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | − if _, err := models.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid); err != nil { | |
| 460 | − if err != models.ErrLFSObjectNotExist { | |
| 459 | + if _, err := git_model.GetLFSMetaObjectByOid(repo.ID, pointerBlob.Oid); err != nil { | |
| 460 | + if err != git_model.ErrLFSObjectNotExist { | |
| 461 | 461 | return err |
| 462 | 462 | } |
| 463 | 463 | } else { |
| @@ -474,12 +474,12 @@ func LFSPointerFiles(ctx *context.Context) { · 10 unmodified lines | ||
| 474 | 474 | // Can we fix? |
| 475 | 475 | // OK well that's "simple" |
| 476 | 476 | // - we need to check whether current user has access to a repo that has access to the file |
| 477 | − result.Associatable, err = models.LFSObjectAccessible(ctx.Doer, pointerBlob.Oid) | |
| 477 | + result.Associatable, err = git_model.LFSObjectAccessible(ctx.Doer, pointerBlob.Oid) | |
| 478 | 478 | if err != nil { |
| 479 | 479 | return err |
| 480 | 480 | } |
| 481 | 481 | if !result.Associatable { |
| 482 | − associated, err := models.LFSObjectIsAssociated(pointerBlob.Oid) | |
| 482 | + associated, err := git_model.LFSObjectIsAssociated(pointerBlob.Oid) | |
| 483 | 483 | if err != nil { |
| 484 | 484 | return err |
| 485 | 485 | } |
| @@ -532,7 +532,7 @@ func LFSAutoAssociate(ctx *context.Context) { · 46 unmodified lines | ||
| 532 | 532 | return |
| 533 | 533 | } |
| 534 | 534 | oids := ctx.FormStrings("oid") |
| 535 | − metas := make([]*models.LFSMetaObject, len(oids)) | |
| 535 | + metas := make([]*git_model.LFSMetaObject, len(oids)) | |
| 536 | 536 | for i, oid := range oids { |
| 537 | 537 | idx := strings.IndexRune(oid, ' ') |
| 538 | 538 | if idx < 0 || idx+1 > len(oid) { |
| @@ -540,7 +540,7 @@ func LFSAutoAssociate(ctx *context.Context) { · 1 unmodified line | ||
| 540 | 540 | return |
| 541 | 541 | } |
| 542 | 542 | var err error |
| 543 | − metas[i] = &models.LFSMetaObject{} | |
| 543 | + metas[i] = &git_model.LFSMetaObject{} | |
| 544 | 544 | metas[i].Size, err = strconv.ParseInt(oid[idx+1:], 10, 64) |
| 545 | 545 | if err != nil { |
| 546 | 546 | ctx.ServerError("LFSAutoAssociate", fmt.Errorf("illegal oid input: %s %v", oid, err)) |
| @@ -549,7 +549,7 @@ func LFSAutoAssociate(ctx *context.Context) { · 2 unmodified lines | ||
| 549 | 549 | metas[i].Oid = oid[:idx] |
| 550 | 550 | // metas[i].RepositoryID = ctx.Repo.Repository.ID |
| 551 | 551 | } |
| 552 | − if err := models.LFSAutoAssociate(metas, ctx.Doer, ctx.Repo.Repository.ID); err != nil { | |
| 552 | + if err := git_model.LFSAutoAssociate(metas, ctx.Doer, ctx.Repo.Repository.ID); err != nil { | |
| 553 | 553 | ctx.ServerError("LFSAutoAssociate", err) |
| 554 | 554 | return |
| 555 | 555 | } |
| @@ -18,6 +18,7 @@ import ( · 17 unmodified lines | ||
| 18 | 18 | |
| 19 | 19 | "code.gitea.io/gitea/models" |
| 20 | 20 | "code.gitea.io/gitea/models/db" |
| 21 | + git_model "code.gitea.io/gitea/models/git" | |
| 21 | 22 | "code.gitea.io/gitea/models/organization" |
| 22 | 23 | access_model "code.gitea.io/gitea/models/perm/access" |
| 23 | 24 | pull_model "code.gitea.io/gitea/models/pull" |
| @@ -379,14 +380,14 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C · 355 unmodified lines | ||
| 379 | 380 | |
| 380 | 381 | if len(compareInfo.Commits) != 0 { |
| 381 | 382 | sha := compareInfo.Commits[0].ID.String() |
| 382 | − commitStatuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, sha, db.ListOptions{}) | |
| 383 | + commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, sha, db.ListOptions{}) | |
| 383 | 384 | if err != nil { |
| 384 | 385 | ctx.ServerError("GetLatestCommitStatus", err) |
| 385 | 386 | return nil |
| 386 | 387 | } |
| 387 | 388 | if len(commitStatuses) != 0 { |
| 388 | 389 | ctx.Data["LatestCommitStatuses"] = commitStatuses |
| 389 | − ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses) | |
| 390 | + ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses) | |
| 390 | 391 | } |
| 391 | 392 | } |
| 392 | 393 | |
| @@ -440,14 +441,14 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare · 47 unmodified lines | ||
| 440 | 441 | ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err) |
| 441 | 442 | return nil |
| 442 | 443 | } |
| 443 | − commitStatuses, _, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{}) | |
| 444 | + commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{}) | |
| 444 | 445 | if err != nil { |
| 445 | 446 | ctx.ServerError("GetLatestCommitStatus", err) |
| 446 | 447 | return nil |
| 447 | 448 | } |
| 448 | 449 | if len(commitStatuses) > 0 { |
| 449 | 450 | ctx.Data["LatestCommitStatuses"] = commitStatuses |
| 450 | − ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses) | |
| 451 | + ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses) | |
| 451 | 452 | } |
| 452 | 453 | |
| 453 | 454 | compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(), |
| @@ -530,14 +531,14 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare · 76 unmodified lines | ||
| 530 | 531 | return nil |
| 531 | 532 | } |
| 532 | 533 | |
| 533 | − commitStatuses, _, err := models.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{}) | |
| 534 | + commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptions{}) | |
| 534 | 535 | if err != nil { |
| 535 | 536 | ctx.ServerError("GetLatestCommitStatus", err) |
| 536 | 537 | return nil |
| 537 | 538 | } |
| 538 | 539 | if len(commitStatuses) > 0 { |
| 539 | 540 | ctx.Data["LatestCommitStatuses"] = commitStatuses |
| 540 | − ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses) | |
| 541 | + ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(commitStatuses) | |
| 541 | 542 | } |
| 542 | 543 | |
| 543 | 544 | if pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck { |
| @@ -629,7 +630,7 @@ func ViewPullCommits(ctx *context.Context) { · 85 unmodified lines | ||
| 629 | 630 | ctx.Data["Username"] = ctx.Repo.Owner.Name |
| 630 | 631 | ctx.Data["Reponame"] = ctx.Repo.Repository.Name |
| 631 | 632 | |
| 632 | − commits := models.ConvertFromGitCommit(prInfo.Commits, ctx.Repo.Repository) | |
| 633 | + commits := git_model.ConvertFromGitCommit(prInfo.Commits, ctx.Repo.Repository) | |
| 633 | 634 | ctx.Data["Commits"] = commits |
| 634 | 635 | ctx.Data["CommitCount"] = len(commits) |
| 635 | 636 | |
| @@ -10,7 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | "strings" |
| 11 | 11 | "time" |
| 12 | 12 | |
| 13 | − "code.gitea.io/gitea/models" | |
| 13 | + git_model "code.gitea.io/gitea/models/git" | |
| 14 | 14 | "code.gitea.io/gitea/models/organization" |
| 15 | 15 | "code.gitea.io/gitea/models/perm" |
| 16 | 16 | access_model "code.gitea.io/gitea/models/perm/access" |
| @@ -32,7 +32,7 @@ func ProtectedBranch(ctx *context.Context) { · 15 unmodified lines | ||
| 32 | 32 | ctx.Data["Title"] = ctx.Tr("repo.settings") |
| 33 | 33 | ctx.Data["PageIsSettingsBranches"] = true |
| 34 | 34 | |
| 35 | − protectedBranches, err := models.GetProtectedBranches(ctx.Repo.Repository.ID) | |
| 35 | + protectedBranches, err := git_model.GetProtectedBranches(ctx.Repo.Repository.ID) | |
| 36 | 36 | if err != nil { |
| 37 | 37 | ctx.ServerError("GetProtectedBranches", err) |
| 38 | 38 | return |
| @@ -111,7 +111,7 @@ func SettingsProtectedBranch(c *context.Context) { · 72 unmodified lines | ||
| 111 | 111 | c.Data["Title"] = c.Tr("repo.settings.protected_branch") + " - " + branch |
| 112 | 112 | c.Data["PageIsSettingsBranches"] = true |
| 113 | 113 | |
| 114 | − protectBranch, err := models.GetProtectedBranchBy(c, c.Repo.Repository.ID, branch) | |
| 114 | + protectBranch, err := git_model.GetProtectedBranchBy(c, c.Repo.Repository.ID, branch) | |
| 115 | 115 | if err != nil { |
| 116 | 116 | if !git.IsErrBranchNotExist(err) { |
| 117 | 117 | c.ServerError("GetProtectBranchOfRepoByName", err) |
| @@ -121,7 +121,7 @@ func SettingsProtectedBranch(c *context.Context) { · 3 unmodified lines | ||
| 121 | 121 | |
| 122 | 122 | if protectBranch == nil { |
| 123 | 123 | // No options found, create defaults. |
| 124 | − protectBranch = &models.ProtectedBranch{ | |
| 124 | + protectBranch = &git_model.ProtectedBranch{ | |
| 125 | 125 | BranchName: branch, |
| 126 | 126 | } |
| 127 | 127 | } |
| @@ -135,7 +135,7 @@ func SettingsProtectedBranch(c *context.Context) { · 7 unmodified lines | ||
| 135 | 135 | c.Data["whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.WhitelistUserIDs), ",") |
| 136 | 136 | c.Data["merge_whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.MergeWhitelistUserIDs), ",") |
| 137 | 137 | c.Data["approvals_whitelist_users"] = strings.Join(base.Int64sToStrings(protectBranch.ApprovalsWhitelistUserIDs), ",") |
| 138 | − contexts, _ := models.FindRepoRecentCommitStatusContexts(c.Repo.Repository.ID, 7*24*time.Hour) // Find last week status check contexts | |
| 138 | + contexts, _ := git_model.FindRepoRecentCommitStatusContexts(c.Repo.Repository.ID, 7*24*time.Hour) // Find last week status check contexts | |
| 139 | 139 | for _, ctx := range protectBranch.StatusCheckContexts { |
| 140 | 140 | var found bool |
| 141 | 141 | for i := range contexts { |
| @@ -184,7 +184,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { · 42 unmodified lines | ||
| 184 | 184 | return |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | − protectBranch, err := models.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch) | |
| 187 | + protectBranch, err := git_model.GetProtectedBranchBy(ctx, ctx.Repo.Repository.ID, branch) | |
| 188 | 188 | if err != nil { |
| 189 | 189 | if !git.IsErrBranchNotExist(err) { |
| 190 | 190 | ctx.ServerError("GetProtectBranchOfRepoByName", err) |
| @@ -195,7 +195,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { · 4 unmodified lines | ||
| 195 | 195 | if f.Protected { |
| 196 | 196 | if protectBranch == nil { |
| 197 | 197 | // No options found, create defaults. |
| 198 | − protectBranch = &models.ProtectedBranch{ | |
| 198 | + protectBranch = &git_model.ProtectedBranch{ | |
| 199 | 199 | RepoID: ctx.Repo.Repository.ID, |
| 200 | 200 | BranchName: branch, |
| 201 | 201 | } |
| @@ -262,7 +262,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { · 60 unmodified lines | ||
| 262 | 262 | protectBranch.UnprotectedFilePatterns = f.UnprotectedFilePatterns |
| 263 | 263 | protectBranch.BlockOnOutdatedBranch = f.BlockOnOutdatedBranch |
| 264 | 264 | |
| 265 | − err = models.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, models.WhitelistOptions{ | |
| 265 | + err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{ | |
| 266 | 266 | UserIDs: whitelistUsers, |
| 267 | 267 | TeamIDs: whitelistTeams, |
| 268 | 268 | MergeUserIDs: mergeWhitelistUsers, |
| @@ -282,7 +282,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) { · 13 unmodified lines | ||
| 282 | 282 | ctx.Redirect(fmt.Sprintf("%s/settings/branches/%s", ctx.Repo.RepoLink, util.PathEscapeSegments(branch))) |
| 283 | 283 | } else { |
| 284 | 284 | if protectBranch != nil { |
| 285 | − if err := models.DeleteProtectedBranch(ctx.Repo.Repository.ID, protectBranch.ID); err != nil { | |
| 285 | + if err := git_model.DeleteProtectedBranch(ctx.Repo.Repository.ID, protectBranch.ID); err != nil { | |
| 286 | 286 | ctx.ServerError("DeleteProtectedBranch", err) |
| 287 | 287 | return |
| 288 | 288 | } |
| @@ -9,7 +9,7 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | "net/http" |
| 10 | 10 | "strings" |
| 11 | 11 | |
| 12 | − "code.gitea.io/gitea/models" | |
| 12 | + git_model "code.gitea.io/gitea/models/git" | |
| 13 | 13 | "code.gitea.io/gitea/models/organization" |
| 14 | 14 | "code.gitea.io/gitea/models/perm" |
| 15 | 15 | access_model "code.gitea.io/gitea/models/perm/access" |
| @@ -43,7 +43,7 @@ func NewProtectedTagPost(ctx *context.Context) { · 27 unmodified lines | ||
| 43 | 43 | repo := ctx.Repo.Repository |
| 44 | 44 | form := web.GetForm(ctx).(*forms.ProtectTagForm) |
| 45 | 45 | |
| 46 | − pt := &models.ProtectedTag{ | |
| 46 | + pt := &git_model.ProtectedTag{ | |
| 47 | 47 | RepoID: repo.ID, |
| 48 | 48 | NamePattern: strings.TrimSpace(form.NamePattern), |
| 49 | 49 | } |
| @@ -55,7 +55,7 @@ func NewProtectedTagPost(ctx *context.Context) { · 5 unmodified lines | ||
| 55 | 55 | pt.AllowlistTeamIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistTeams, ",")) |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | − if err := models.InsertProtectedTag(pt); err != nil { | |
| 58 | + if err := git_model.InsertProtectedTag(pt); err != nil { | |
| 59 | 59 | ctx.ServerError("InsertProtectedTag", err) |
| 60 | 60 | return |
| 61 | 61 | } |
| @@ -108,7 +108,7 @@ func EditProtectedTagPost(ctx *context.Context) { · 46 unmodified lines | ||
| 108 | 108 | pt.AllowlistUserIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistUsers, ",")) |
| 109 | 109 | pt.AllowlistTeamIDs, _ = base.StringsToInt64s(strings.Split(form.AllowlistTeams, ",")) |
| 110 | 110 | |
| 111 | − if err := models.UpdateProtectedTag(pt); err != nil { | |
| 111 | + if err := git_model.UpdateProtectedTag(pt); err != nil { | |
| 112 | 112 | ctx.ServerError("UpdateProtectedTag", err) |
| 113 | 113 | return |
| 114 | 114 | } |
| @@ -124,7 +124,7 @@ func DeleteProtectedTagPost(ctx *context.Context) { · 9 unmodified lines | ||
| 124 | 124 | return |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | − if err := models.DeleteProtectedTag(pt); err != nil { | |
| 127 | + if err := git_model.DeleteProtectedTag(pt); err != nil { | |
| 128 | 128 | ctx.ServerError("DeleteProtectedTag", err) |
| 129 | 129 | return |
| 130 | 130 | } |
| @@ -137,7 +137,7 @@ func setTagsContext(ctx *context.Context) error { · 6 unmodified lines | ||
| 137 | 137 | ctx.Data["Title"] = ctx.Tr("repo.settings") |
| 138 | 138 | ctx.Data["PageIsSettingsTags"] = true |
| 139 | 139 | |
| 140 | − protectedTags, err := models.GetProtectedTags(ctx.Repo.Repository.ID) | |
| 140 | + protectedTags, err := git_model.GetProtectedTags(ctx.Repo.Repository.ID) | |
| 141 | 141 | if err != nil { |
| 142 | 142 | ctx.ServerError("GetProtectedTags", err) |
| 143 | 143 | return err |
| @@ -163,13 +163,13 @@ func setTagsContext(ctx *context.Context) error { · 19 unmodified lines | ||
| 163 | 163 | return nil |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | −func selectProtectedTagByContext(ctx *context.Context) *models.ProtectedTag { | |
| 166 | +func selectProtectedTagByContext(ctx *context.Context) *git_model.ProtectedTag { | |
| 167 | 167 | id := ctx.FormInt64("id") |
| 168 | 168 | if id == 0 { |
| 169 | 169 | id = ctx.ParamsInt64(":id") |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | − tag, err := models.GetProtectedTagByID(id) | |
| 172 | + tag, err := git_model.GetProtectedTagByID(id) | |
| 173 | 173 | if err != nil { |
| 174 | 174 | ctx.ServerError("GetProtectedTagByID", err) |
| 175 | 175 | return nil |
| @@ -22,6 +22,7 @@ import ( · 21 unmodified lines | ||
| 22 | 22 | "code.gitea.io/gitea/models" |
| 23 | 23 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 24 | 24 | "code.gitea.io/gitea/models/db" |
| 25 | + git_model "code.gitea.io/gitea/models/git" | |
| 25 | 26 | repo_model "code.gitea.io/gitea/models/repo" |
| 26 | 27 | unit_model "code.gitea.io/gitea/models/unit" |
| 27 | 28 | user_model "code.gitea.io/gitea/models/user" |
| @@ -294,8 +295,8 @@ func renderReadmeFile(ctx *context.Context, readmeFile *namedBlob, readmeTreelin · 266 unmodified lines | ||
| 294 | 295 | if isTextFile && setting.LFS.StartServer { |
| 295 | 296 | pointer, _ := lfs.ReadPointerFromBuffer(buf) |
| 296 | 297 | if pointer.IsValid() { |
| 297 | − meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) | |
| 298 | − if err != nil && err != models.ErrLFSObjectNotExist { | |
| 298 | + meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) | |
| 299 | + if err != nil && err != git_model.ErrLFSObjectNotExist { | |
| 299 | 300 | ctx.ServerError("GetLFSMetaObject", err) |
| 300 | 301 | return |
| 301 | 302 | } |
| @@ -417,8 +418,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st · 115 unmodified lines | ||
| 417 | 418 | if isTextFile && setting.LFS.StartServer { |
| 418 | 419 | pointer, _ := lfs.ReadPointerFromBuffer(buf) |
| 419 | 420 | if pointer.IsValid() { |
| 420 | − meta, err := models.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) | |
| 421 | − if err != nil && err != models.ErrLFSObjectNotExist { | |
| 421 | + meta, err := git_model.GetLFSMetaObjectByOid(ctx.Repo.Repository.ID, pointer.Oid) | |
| 422 | + if err != nil && err != git_model.ErrLFSObjectNotExist { | |
| 422 | 423 | ctx.ServerError("GetLFSMetaObject", err) |
| 423 | 424 | return |
| 424 | 425 | } |
| @@ -466,7 +467,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st · 41 unmodified lines | ||
| 466 | 467 | ctx.Data["IsTextSource"] = isTextFile || isDisplayingSource |
| 467 | 468 | |
| 468 | 469 | // Check LFS Lock |
| 469 | − lfsLock, err := models.GetTreePathLock(ctx.Repo.Repository.ID, ctx.Repo.TreePath) | |
| 470 | + lfsLock, err := git_model.GetTreePathLock(ctx.Repo.Repository.ID, ctx.Repo.TreePath) | |
| 470 | 471 | ctx.Data["LFSLock"] = lfsLock |
| 471 | 472 | if err != nil { |
| 472 | 473 | ctx.ServerError("GetTreePathLock", err) |
| @@ -842,7 +843,7 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri · 369 unmodified lines | ||
| 842 | 843 | verification := asymkey_model.ParseCommitWithSignature(latestCommit) |
| 843 | 844 | |
| 844 | 845 | if err := asymkey_model.CalculateTrustStatus(verification, ctx.Repo.Repository.GetTrustModel(), func(user *user_model.User) (bool, error) { |
| 845 | − return models.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID) | |
| 846 | + return repo_model.IsOwnerMemberCollaborator(ctx.Repo.Repository, user.ID) | |
| 846 | 847 | }, nil); err != nil { |
| 847 | 848 | ctx.ServerError("CalculateTrustStatus", err) |
| 848 | 849 | return nil |
| @@ -851,12 +852,12 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri · 2 unmodified lines | ||
| 851 | 852 | ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(latestCommit) |
| 852 | 853 | } |
| 853 | 854 | |
| 854 | − statuses, _, err := models.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{}) | |
| 855 | + statuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, ctx.Repo.Commit.ID.String(), db.ListOptions{}) | |
| 855 | 856 | if err != nil { |
| 856 | 857 | log.Error("GetLatestCommitStatus: %v", err) |
| 857 | 858 | } |
| 858 | 859 | |
| 859 | − ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(statuses) | |
| 860 | + ctx.Data["LatestCommitStatus"] = git_model.CalcCommitStatus(statuses) | |
| 860 | 861 | ctx.Data["LatestCommitStatuses"] = statuses |
| 861 | 862 | |
| 862 | 863 | branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL() |
| @@ -991,12 +992,12 @@ func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOp · 128 unmodified lines | ||
| 991 | 992 | if page <= 0 { |
| 992 | 993 | page = 1 |
| 993 | 994 | } |
| 994 | − pager := context.NewPagination(total, models.ItemsPerPage, page, 5) | |
| 995 | + pager := context.NewPagination(total, setting.ItemsPerPage, page, 5) | |
| 995 | 996 | ctx.Data["Page"] = pager |
| 996 | 997 | |
| 997 | 998 | items, err := getter(db.ListOptions{ |
| 998 | 999 | Page: pager.Paginater.Current(), |
| 999 | − PageSize: models.ItemsPerPage, | |
| 1000 | + PageSize: setting.ItemsPerPage, | |
| 1000 | 1001 | }) |
| 1001 | 1002 | if err != nil { |
| 1002 | 1003 | ctx.ServerError("getter", err) |
| @@ -1037,12 +1038,12 @@ func Forks(ctx *context.Context) { · 34 unmodified lines | ||
| 1037 | 1038 | page = 1 |
| 1038 | 1039 | } |
| 1039 | 1040 | |
| 1040 | − pager := context.NewPagination(ctx.Repo.Repository.NumForks, models.ItemsPerPage, page, 5) | |
| 1041 | + pager := context.NewPagination(ctx.Repo.Repository.NumForks, setting.ItemsPerPage, page, 5) | |
| 1041 | 1042 | ctx.Data["Page"] = pager |
| 1042 | 1043 | |
| 1043 | 1044 | forks, err := repo_model.GetForks(ctx.Repo.Repository, db.ListOptions{ |
| 1044 | 1045 | Page: pager.Paginater.Current(), |
| 1045 | − PageSize: models.ItemsPerPage, | |
| 1046 | + PageSize: setting.ItemsPerPage, | |
| 1046 | 1047 | }) |
| 1047 | 1048 | if err != nil { |
| 1048 | 1049 | ctx.ServerError("GetForks", err) |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | "time" |
| 17 | 17 | |
| 18 | 18 | "code.gitea.io/gitea/models" |
| 19 | + git_model "code.gitea.io/gitea/models/git" | |
| 19 | 20 | "code.gitea.io/gitea/models/unit" |
| 20 | 21 | "code.gitea.io/gitea/modules/base" |
| 21 | 22 | "code.gitea.io/gitea/modules/charset" |
| @@ -350,7 +351,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) · 328 unmodified lines | ||
| 350 | 351 | ctx.ServerError("CommitsByFileAndRangeNoFollow", err) |
| 351 | 352 | return nil, nil |
| 352 | 353 | } |
| 353 | − ctx.Data["Commits"] = models.ConvertFromGitCommit(commitsHistory, ctx.Repo.Repository) | |
| 354 | + ctx.Data["Commits"] = git_model.ConvertFromGitCommit(commitsHistory, ctx.Repo.Repository) | |
| 354 | 355 | |
| 355 | 356 | pager := context.NewPagination(int(commitsCount), setting.Git.CommitsRangeSize, page, 5) |
| 356 | 357 | pager.SetDefaultParams(ctx) |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 14 | 14 | "code.gitea.io/gitea/models/auth" |
| 15 | 15 | "code.gitea.io/gitea/models/db" |
| 16 | + git_model "code.gitea.io/gitea/models/git" | |
| 16 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 18 | "code.gitea.io/gitea/modules/git" |
| 18 | 19 | "code.gitea.io/gitea/modules/log" |
| @@ -310,14 +311,14 @@ Loop: · 291 unmodified lines | ||
| 310 | 311 | return false, "", nil, &ErrWontSign{twofa} |
| 311 | 312 | } |
| 312 | 313 | case approved: |
| 313 | − protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, pr.BaseBranch) | |
| 314 | + protectedBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, pr.BaseBranch) | |
| 314 | 315 | if err != nil { |
| 315 | 316 | return false, "", nil, err |
| 316 | 317 | } |
| 317 | 318 | if protectedBranch == nil { |
| 318 | 319 | return false, "", nil, &ErrWontSign{approved} |
| 319 | 320 | } |
| 320 | − if protectedBranch.GetGrantedApprovalsCount(ctx, pr) < 1 { | |
| 321 | + if models.GetGrantedApprovalsCount(ctx, protectedBranch, pr) < 1 { | |
| 321 | 322 | return false, "", nil, &ErrWontSign{approved} |
| 322 | 323 | } |
| 323 | 324 | case baseSigned: |
| @@ -9,6 +9,7 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | "time" |
| 10 | 10 | |
| 11 | 11 | "code.gitea.io/gitea/models" |
| 12 | + git_model "code.gitea.io/gitea/models/git" | |
| 12 | 13 | user_model "code.gitea.io/gitea/models/user" |
| 13 | 14 | "code.gitea.io/gitea/models/webhook" |
| 14 | 15 | "code.gitea.io/gitea/modules/setting" |
| @@ -109,7 +110,7 @@ func registerDeletedBranchesCleanup() { · 94 unmodified lines | ||
| 109 | 110 | OlderThan: 24 * time.Hour, |
| 110 | 111 | }, func(ctx context.Context, _ *user_model.User, config Config) error { |
| 111 | 112 | realConfig := config.(*OlderThanConfig) |
| 112 | − models.RemoveOldDeletedBranches(ctx, realConfig.OlderThan) | |
| 113 | + git_model.RemoveOldDeletedBranches(ctx, realConfig.OlderThan) | |
| 113 | 114 | return nil |
| 114 | 115 | }) |
| 115 | 116 | } |
| @@ -22,6 +22,7 @@ import ( · 21 unmodified lines | ||
| 22 | 22 | |
| 23 | 23 | "code.gitea.io/gitea/models" |
| 24 | 24 | "code.gitea.io/gitea/models/db" |
| 25 | + git_model "code.gitea.io/gitea/models/git" | |
| 25 | 26 | pull_model "code.gitea.io/gitea/models/pull" |
| 26 | 27 | user_model "code.gitea.io/gitea/models/user" |
| 27 | 28 | "code.gitea.io/gitea/modules/analyze" |
| @@ -1219,7 +1220,7 @@ func parseHunks(curFile *DiffFile, maxLines, maxLineCharacters int, input *bufio · 1191 unmodified lines | ||
| 1219 | 1220 | } else if curFileLFSPrefix && strings.HasPrefix(line[1:], lfs.MetaFileOidPrefix) { |
| 1220 | 1221 | oid := strings.TrimPrefix(line[1:], lfs.MetaFileOidPrefix) |
| 1221 | 1222 | if len(oid) == 64 { |
| 1222 | − m := &models.LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}} | |
| 1223 | + m := &git_model.LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}} | |
| 1223 | 1224 | count, err := db.CountByBean(db.DefaultContext, m) |
| 1224 | 1225 | |
| 1225 | 1226 | if err == nil && count > 0 { |
| @@ -9,7 +9,7 @@ import ( · 8 unmodified lines | ||
| 9 | 9 | "strconv" |
| 10 | 10 | "strings" |
| 11 | 11 | |
| 12 | − "code.gitea.io/gitea/models" | |
| 12 | + git_model "code.gitea.io/gitea/models/git" | |
| 13 | 13 | repo_model "code.gitea.io/gitea/models/repo" |
| 14 | 14 | "code.gitea.io/gitea/modules/context" |
| 15 | 15 | "code.gitea.io/gitea/modules/convert" |
| @@ -20,9 +20,9 @@ import ( · 4 unmodified lines | ||
| 20 | 20 | api "code.gitea.io/gitea/modules/structs" |
| 21 | 21 | ) |
| 22 | 22 | |
| 23 | −func handleLockListOut(ctx *context.Context, repo *repo_model.Repository, lock *models.LFSLock, err error) { | |
| 23 | +func handleLockListOut(ctx *context.Context, repo *repo_model.Repository, lock *git_model.LFSLock, err error) { | |
| 24 | 24 | if err != nil { |
| 25 | − if models.IsErrLFSLockNotExist(err) { | |
| 25 | + if git_model.IsErrLFSLockNotExist(err) { | |
| 26 | 26 | ctx.JSON(http.StatusOK, api.LFSLockList{ |
| 27 | 27 | Locks: []*api.LFSLock{}, |
| 28 | 28 | }) |
| @@ -88,8 +88,8 @@ func GetListLockHandler(ctx *context.Context) { · 59 unmodified lines | ||
| 88 | 88 | }) |
| 89 | 89 | return |
| 90 | 90 | } |
| 91 | − lock, err := models.GetLFSLockByID(ctx, v) | |
| 92 | − if err != nil && !models.IsErrLFSLockNotExist(err) { | |
| 91 | + lock, err := git_model.GetLFSLockByID(ctx, v) | |
| 92 | + if err != nil && !git_model.IsErrLFSLockNotExist(err) { | |
| 93 | 93 | log.Error("Unable to get lock with ID[%s]: Error: %v", v, err) |
| 94 | 94 | } |
| 95 | 95 | handleLockListOut(ctx, repository, lock, err) |
| @@ -98,8 +98,8 @@ func GetListLockHandler(ctx *context.Context) { · 2 unmodified lines | ||
| 98 | 98 | |
| 99 | 99 | path := ctx.FormString("path") |
| 100 | 100 | if path != "" { // Case where we request a specific id |
| 101 | − lock, err := models.GetLFSLock(ctx, repository, path) | |
| 102 | − if err != nil && !models.IsErrLFSLockNotExist(err) { | |
| 101 | + lock, err := git_model.GetLFSLock(ctx, repository, path) | |
| 102 | + if err != nil && !git_model.IsErrLFSLockNotExist(err) { | |
| 103 | 103 | log.Error("Unable to get lock for repository %-v with path %s: Error: %v", repository, path, err) |
| 104 | 104 | } |
| 105 | 105 | handleLockListOut(ctx, repository, lock, err) |
| @@ -107,7 +107,7 @@ func GetListLockHandler(ctx *context.Context) { · 1 unmodified line | ||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // If no query params path or id |
| 110 | − lockList, err := models.GetLFSLockByRepoID(repository.ID, cursor, limit) | |
| 110 | + lockList, err := git_model.GetLFSLockByRepoID(repository.ID, cursor, limit) | |
| 111 | 111 | if err != nil { |
| 112 | 112 | log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err) |
| 113 | 113 | ctx.JSON(http.StatusInternalServerError, api.LFSLockError{ |
| @@ -168,19 +168,19 @@ func PostLockHandler(ctx *context.Context) { · 54 unmodified lines | ||
| 168 | 168 | return |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | − lock, err := models.CreateLFSLock(repository, &models.LFSLock{ | |
| 171 | + lock, err := git_model.CreateLFSLock(repository, &git_model.LFSLock{ | |
| 172 | 172 | Path: req.Path, |
| 173 | 173 | OwnerID: ctx.Doer.ID, |
| 174 | 174 | }) |
| 175 | 175 | if err != nil { |
| 176 | − if models.IsErrLFSLockAlreadyExist(err) { | |
| 176 | + if git_model.IsErrLFSLockAlreadyExist(err) { | |
| 177 | 177 | ctx.JSON(http.StatusConflict, api.LFSLockError{ |
| 178 | 178 | Lock: convert.ToLFSLock(lock), |
| 179 | 179 | Message: "already created lock", |
| 180 | 180 | }) |
| 181 | 181 | return |
| 182 | 182 | } |
| 183 | − if models.IsErrLFSUnauthorizedAction(err) { | |
| 183 | + if git_model.IsErrLFSUnauthorizedAction(err) { | |
| 184 | 184 | ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") |
| 185 | 185 | ctx.JSON(http.StatusUnauthorized, api.LFSLockError{ |
| 186 | 186 | Message: "You must have push access to create locks : " + err.Error(), |
| @@ -234,7 +234,7 @@ func VerifyLockHandler(ctx *context.Context) { · 47 unmodified lines | ||
| 234 | 234 | } else if limit < 0 { |
| 235 | 235 | limit = 0 |
| 236 | 236 | } |
| 237 | − lockList, err := models.GetLFSLockByRepoID(repository.ID, cursor, limit) | |
| 237 | + lockList, err := git_model.GetLFSLockByRepoID(repository.ID, cursor, limit) | |
| 238 | 238 | if err != nil { |
| 239 | 239 | log.Error("Unable to list locks for repository ID[%d]: Error: %v", repository.ID, err) |
| 240 | 240 | ctx.JSON(http.StatusInternalServerError, api.LFSLockError{ |
| @@ -301,9 +301,9 @@ func UnLockHandler(ctx *context.Context) { · 60 unmodified lines | ||
| 301 | 301 | return |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | − lock, err := models.DeleteLFSLockByID(ctx.ParamsInt64("lid"), repository, ctx.Doer, req.Force) | |
| 304 | + lock, err := git_model.DeleteLFSLockByID(ctx.ParamsInt64("lid"), repository, ctx.Doer, req.Force) | |
| 305 | 305 | if err != nil { |
| 306 | − if models.IsErrLFSUnauthorizedAction(err) { | |
| 306 | + if git_model.IsErrLFSUnauthorizedAction(err) { | |
| 307 | 307 | ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") |
| 308 | 308 | ctx.JSON(http.StatusUnauthorized, api.LFSLockError{ |
| 309 | 309 | Message: "You must have push access to delete locks : " + err.Error(), |
| @@ -18,7 +18,7 @@ import ( · 17 unmodified lines | ||
| 18 | 18 | "strconv" |
| 19 | 19 | "strings" |
| 20 | 20 | |
| 21 | − "code.gitea.io/gitea/models" | |
| 21 | + git_model "code.gitea.io/gitea/models/git" | |
| 22 | 22 | "code.gitea.io/gitea/models/perm" |
| 23 | 23 | access_model "code.gitea.io/gitea/models/perm/access" |
| 24 | 24 | repo_model "code.gitea.io/gitea/models/repo" |
| @@ -197,8 +197,8 @@ func BatchHandler(ctx *context.Context) { · 172 unmodified lines | ||
| 197 | 197 | return |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | − meta, err := models.GetLFSMetaObjectByOid(repository.ID, p.Oid) | |
| 201 | − if err != nil && err != models.ErrLFSObjectNotExist { | |
| 200 | + meta, err := git_model.GetLFSMetaObjectByOid(repository.ID, p.Oid) | |
| 201 | + if err != nil && err != git_model.ErrLFSObjectNotExist { | |
| 202 | 202 | log.Error("Unable to get LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err) |
| 203 | 203 | writeStatus(ctx, http.StatusInternalServerError) |
| 204 | 204 | return |
| @@ -223,14 +223,14 @@ func BatchHandler(ctx *context.Context) { · 18 unmodified lines | ||
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | if exists && meta == nil { |
| 226 | − accessible, err := models.LFSObjectAccessible(ctx.Doer, p.Oid) | |
| 226 | + accessible, err := git_model.LFSObjectAccessible(ctx.Doer, p.Oid) | |
| 227 | 227 | if err != nil { |
| 228 | 228 | log.Error("Unable to check if LFS MetaObject [%s] is accessible. Error: %v", p.Oid, err) |
| 229 | 229 | writeStatus(ctx, http.StatusInternalServerError) |
| 230 | 230 | return |
| 231 | 231 | } |
| 232 | 232 | if accessible { |
| 233 | − _, err := models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: p, RepositoryID: repository.ID}) | |
| 233 | + _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID}) | |
| 234 | 234 | if err != nil { |
| 235 | 235 | log.Error("Unable to create LFS MetaObject [%s] for %s/%s. Error: %v", p.Oid, rc.User, rc.Repo, err) |
| 236 | 236 | writeStatus(ctx, http.StatusInternalServerError) |
| @@ -297,7 +297,7 @@ func UploadHandler(ctx *context.Context) { · 60 unmodified lines | ||
| 297 | 297 | |
| 298 | 298 | uploadOrVerify := func() error { |
| 299 | 299 | if exists { |
| 300 | − accessible, err := models.LFSObjectAccessible(ctx.Doer, p.Oid) | |
| 300 | + accessible, err := git_model.LFSObjectAccessible(ctx.Doer, p.Oid) | |
| 301 | 301 | if err != nil { |
| 302 | 302 | log.Error("Unable to check if LFS MetaObject [%s] is accessible. Error: %v", p.Oid, err) |
| 303 | 303 | return err |
| @@ -323,7 +323,7 @@ func UploadHandler(ctx *context.Context) { · 19 unmodified lines | ||
| 323 | 323 | log.Error("Error putting LFS MetaObject [%s] into content store. Error: %v", p.Oid, err) |
| 324 | 324 | return err |
| 325 | 325 | } |
| 326 | − _, err := models.NewLFSMetaObject(&models.LFSMetaObject{Pointer: p, RepositoryID: repository.ID}) | |
| 326 | + _, err := git_model.NewLFSMetaObject(&git_model.LFSMetaObject{Pointer: p, RepositoryID: repository.ID}) | |
| 327 | 327 | return err |
| 328 | 328 | } |
| 329 | 329 | |
| @@ -335,7 +335,7 @@ func UploadHandler(ctx *context.Context) { · 5 unmodified lines | ||
| 335 | 335 | } else { |
| 336 | 336 | writeStatus(ctx, http.StatusInternalServerError) |
| 337 | 337 | } |
| 338 | − if _, err = models.RemoveLFSMetaObjectByOid(repository.ID, p.Oid); err != nil { | |
| 338 | + if _, err = git_model.RemoveLFSMetaObjectByOid(repository.ID, p.Oid); err != nil { | |
| 339 | 339 | log.Error("Error whilst removing metaobject for LFS OID[%s]: %v", p.Oid, err) |
| 340 | 340 | } |
| 341 | 341 | return |
| @@ -386,7 +386,7 @@ func getRequestContext(ctx *context.Context) *requestContext { · 44 unmodified lines | ||
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | −func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module.Pointer, requireWrite bool) *models.LFSMetaObject { | |
| 389 | +func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module.Pointer, requireWrite bool) *git_model.LFSMetaObject { | |
| 390 | 390 | if !p.IsValid() { |
| 391 | 391 | log.Info("Attempt to access invalid LFS OID[%s] in %s/%s", p.Oid, rc.User, rc.Repo) |
| 392 | 392 | writeStatusMessage(ctx, http.StatusUnprocessableEntity, "Oid or size are invalid") |
| @@ -398,7 +398,7 @@ func getAuthenticatedMeta(ctx *context.Context, rc *requestContext, p lfs_module · 5 unmodified lines | ||
| 398 | 398 | return nil |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | − meta, err := models.GetLFSMetaObjectByOid(repository.ID, p.Oid) | |
| 401 | + meta, err := git_model.GetLFSMetaObjectByOid(repository.ID, p.Oid) | |
| 402 | 402 | if err != nil { |
| 403 | 403 | log.Error("Unable to get LFS OID[%s] Error: %v", p.Oid, err) |
| 404 | 404 | writeStatus(ctx, http.StatusNotFound) |
| @@ -10,6 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | |
| 11 | 11 | "code.gitea.io/gitea/models" |
| 12 | 12 | "code.gitea.io/gitea/models/db" |
| 13 | + git_model "code.gitea.io/gitea/models/git" | |
| 13 | 14 | "code.gitea.io/gitea/modules/git" |
| 14 | 15 | "code.gitea.io/gitea/modules/structs" |
| 15 | 16 | |
| @@ -17,9 +18,9 @@ import ( · 1 unmodified line | ||
| 17 | 18 | ) |
| 18 | 19 | |
| 19 | 20 | // MergeRequiredContextsCommitStatus returns a commit status state for given required contexts |
| 20 | −func MergeRequiredContextsCommitStatus(commitStatuses []*models.CommitStatus, requiredContexts []string) structs.CommitStatusState { | |
| 21 | +func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus, requiredContexts []string) structs.CommitStatusState { | |
| 21 | 22 | if len(requiredContexts) == 0 { |
| 22 | − status := models.CalcCommitStatus(commitStatuses) | |
| 23 | + status := git_model.CalcCommitStatus(commitStatuses) | |
| 23 | 24 | if status != nil { |
| 24 | 25 | return status.State |
| 25 | 26 | } |
| @@ -38,7 +39,7 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*models.CommitStatus, re · 12 unmodified lines | ||
| 38 | 39 | |
| 39 | 40 | if targetStatus == "" { |
| 40 | 41 | targetStatus = structs.CommitStatusPending |
| 41 | − commitStatuses = append(commitStatuses, &models.CommitStatus{ | |
| 42 | + commitStatuses = append(commitStatuses, &git_model.CommitStatus{ | |
| 42 | 43 | State: targetStatus, |
| 43 | 44 | Context: ctx, |
| 44 | 45 | Description: "Pending", |
| @@ -52,10 +53,10 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*models.CommitStatus, re · 7 unmodified lines | ||
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | // IsCommitStatusContextSuccess returns true if all required status check contexts succeed. |
| 55 | −func IsCommitStatusContextSuccess(commitStatuses []*models.CommitStatus, requiredContexts []string) bool { | |
| 56 | +func IsCommitStatusContextSuccess(commitStatuses []*git_model.CommitStatus, requiredContexts []string) bool { | |
| 56 | 57 | // If no specific context is required, require that last commit status is a success |
| 57 | 58 | if len(requiredContexts) == 0 { |
| 58 | − status := models.CalcCommitStatus(commitStatuses) | |
| 59 | + status := git_model.CalcCommitStatus(commitStatuses) | |
| 59 | 60 | if status == nil || status.State != structs.CommitStatusSuccess { |
| 60 | 61 | return false |
| 61 | 62 | } |
| @@ -132,7 +133,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *models.PullRequest · 70 unmodified lines | ||
| 132 | 133 | return "", errors.Wrap(err, "LoadBaseRepo") |
| 133 | 134 | } |
| 134 | 135 | |
| 135 | − commitStatuses, _, err := models.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptions{}) | |
| 136 | + commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptions{}) | |
| 136 | 137 | if err != nil { |
| 137 | 138 | return "", errors.Wrap(err, "GetLatestCommitStatus") |
| 138 | 139 | } |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "sync" |
| 14 | 14 | |
| 15 | 15 | "code.gitea.io/gitea/models" |
| 16 | + git_model "code.gitea.io/gitea/models/git" | |
| 16 | 17 | "code.gitea.io/gitea/modules/git/pipeline" |
| 17 | 18 | "code.gitea.io/gitea/modules/lfs" |
| 18 | 19 | "code.gitea.io/gitea/modules/log" |
| @@ -115,8 +116,8 @@ func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg · 96 unmodified lines | ||
| 115 | 116 | } |
| 116 | 117 | |
| 117 | 118 | // Then we need to check that this pointer is in the db |
| 118 | − if _, err := models.GetLFSMetaObjectByOid(pr.HeadRepo.ID, pointer.Oid); err != nil { | |
| 119 | − if err == models.ErrLFSObjectNotExist { | |
| 119 | + if _, err := git_model.GetLFSMetaObjectByOid(pr.HeadRepo.ID, pointer.Oid); err != nil { | |
| 120 | + if err == git_model.ErrLFSObjectNotExist { | |
| 120 | 121 | log.Warn("During merge of: %d in %-v, there is a pointer to LFS Oid: %s which although present in the LFS store is not associated with the head repo %-v", pr.Index, pr.BaseRepo, pointer.Oid, pr.HeadRepo) |
| 121 | 122 | continue |
| 122 | 123 | } |
| @@ -126,9 +127,9 @@ func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg · 3 unmodified lines | ||
| 126 | 127 | // OK we have a pointer that is associated with the head repo |
| 127 | 128 | // and is actually a file in the LFS |
| 128 | 129 | // Therefore it should be associated with the base repo |
| 129 | − meta := &models.LFSMetaObject{Pointer: pointer} | |
| 130 | + meta := &git_model.LFSMetaObject{Pointer: pointer} | |
| 130 | 131 | meta.RepositoryID = pr.BaseRepoID |
| 131 | − if _, err := models.NewLFSMetaObject(meta); err != nil { | |
| 132 | + if _, err := git_model.NewLFSMetaObject(meta); err != nil { | |
| 132 | 133 | _ = catFileBatchReader.CloseWithError(err) |
| 133 | 134 | break |
| 134 | 135 | } |
| @@ -19,6 +19,7 @@ import ( · 18 unmodified lines | ||
| 19 | 19 | |
| 20 | 20 | "code.gitea.io/gitea/models" |
| 21 | 21 | "code.gitea.io/gitea/models/db" |
| 22 | + git_model "code.gitea.io/gitea/models/git" | |
| 22 | 23 | access_model "code.gitea.io/gitea/models/perm/access" |
| 23 | 24 | pull_model "code.gitea.io/gitea/models/pull" |
| 24 | 25 | repo_model "code.gitea.io/gitea/models/repo" |
| @@ -756,7 +757,7 @@ func IsUserAllowedToMerge(ctx context.Context, pr *models.PullRequest, p access_ · 731 unmodified lines | ||
| 756 | 757 | return false, err |
| 757 | 758 | } |
| 758 | 759 | |
| 759 | − if (p.CanWrite(unit.TypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && models.IsUserMergeWhitelisted(ctx, pr.ProtectedBranch, user.ID, p)) { | |
| 760 | + if (p.CanWrite(unit.TypeCode) && pr.ProtectedBranch == nil) || (pr.ProtectedBranch != nil && git_model.IsUserMergeWhitelisted(ctx, pr.ProtectedBranch, user.ID, p)) { | |
| 760 | 761 | return true, nil |
| 761 | 762 | } |
| 762 | 763 | |
| @@ -786,23 +787,23 @@ func CheckPullBranchProtections(ctx context.Context, pr *models.PullRequest, ski · 23 unmodified lines | ||
| 786 | 787 | } |
| 787 | 788 | } |
| 788 | 789 | |
| 789 | − if !pr.ProtectedBranch.HasEnoughApprovals(ctx, pr) { | |
| 790 | + if !models.HasEnoughApprovals(ctx, pr.ProtectedBranch, pr) { | |
| 790 | 791 | return models.ErrDisallowedToMerge{ |
| 791 | 792 | Reason: "Does not have enough approvals", |
| 792 | 793 | } |
| 793 | 794 | } |
| 794 | − if pr.ProtectedBranch.MergeBlockedByRejectedReview(ctx, pr) { | |
| 795 | + if models.MergeBlockedByRejectedReview(ctx, pr.ProtectedBranch, pr) { | |
| 795 | 796 | return models.ErrDisallowedToMerge{ |
| 796 | 797 | Reason: "There are requested changes", |
| 797 | 798 | } |
| 798 | 799 | } |
| 799 | − if pr.ProtectedBranch.MergeBlockedByOfficialReviewRequests(ctx, pr) { | |
| 800 | + if models.MergeBlockedByOfficialReviewRequests(ctx, pr.ProtectedBranch, pr) { | |
| 800 | 801 | return models.ErrDisallowedToMerge{ |
| 801 | 802 | Reason: "There are official review requests", |
| 802 | 803 | } |
| 803 | 804 | } |
| 804 | 805 | |
| 805 | − if pr.ProtectedBranch.MergeBlockedByOutdatedBranch(pr) { | |
| 806 | + if models.MergeBlockedByOutdatedBranch(pr.ProtectedBranch, pr) { | |
| 806 | 807 | return models.ErrDisallowedToMerge{ |
| 807 | 808 | Reason: "The head branch is behind the base branch", |
| 808 | 809 | } |
| @@ -812,7 +813,7 @@ func CheckPullBranchProtections(ctx context.Context, pr *models.PullRequest, ski · 3 unmodified lines | ||
| 812 | 813 | return nil |
| 813 | 814 | } |
| 814 | 815 | |
| 815 | − if pr.ProtectedBranch.MergeBlockedByProtectedFiles(pr) { | |
| 816 | + if pr.ProtectedBranch.MergeBlockedByProtectedFiles(pr.ChangedProtectedFiles) { | |
| 816 | 817 | return models.ErrDisallowedToMerge{ |
| 817 | 818 | Reason: "Changed protected files", |
| 818 | 819 | } |
| @@ -16,6 +16,7 @@ import ( · 15 unmodified lines | ||
| 16 | 16 | |
| 17 | 17 | "code.gitea.io/gitea/models" |
| 18 | 18 | "code.gitea.io/gitea/models/db" |
| 19 | + git_model "code.gitea.io/gitea/models/git" | |
| 19 | 20 | repo_model "code.gitea.io/gitea/models/repo" |
| 20 | 21 | user_model "code.gitea.io/gitea/models/user" |
| 21 | 22 | "code.gitea.io/gitea/modules/git" |
| @@ -735,13 +736,13 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *models.PullRequest) s · 713 unmodified lines | ||
| 735 | 736 | } |
| 736 | 737 | |
| 737 | 738 | // GetIssuesLastCommitStatus returns a map of issue ID to the most recent commit's latest status |
| 738 | −func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (map[int64]*models.CommitStatus, error) { | |
| 739 | +func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (map[int64]*git_model.CommitStatus, error) { | |
| 739 | 740 | _, lastStatus, err := GetIssuesAllCommitStatus(ctx, issues) |
| 740 | 741 | return lastStatus, err |
| 741 | 742 | } |
| 742 | 743 | |
| 743 | 744 | // GetIssuesAllCommitStatus returns a map of issue ID to a list of all statuses for the most recent commit as well as a map of issue ID to only the commit's latest status |
| 744 | −func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map[int64][]*models.CommitStatus, map[int64]*models.CommitStatus, error) { | |
| 745 | +func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map[int64][]*git_model.CommitStatus, map[int64]*git_model.CommitStatus, error) { | |
| 745 | 746 | if err := issues.LoadPullRequests(); err != nil { |
| 746 | 747 | return nil, nil, err |
| 747 | 748 | } |
| @@ -751,8 +752,8 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map · 3 unmodified lines | ||
| 751 | 752 | |
| 752 | 753 | var ( |
| 753 | 754 | gitRepos = make(map[int64]*git.Repository) |
| 754 | − res = make(map[int64][]*models.CommitStatus) | |
| 755 | − lastRes = make(map[int64]*models.CommitStatus) | |
| 755 | + res = make(map[int64][]*git_model.CommitStatus) | |
| 756 | + lastRes = make(map[int64]*git_model.CommitStatus) | |
| 756 | 757 | err error |
| 757 | 758 | ) |
| 758 | 759 | defer func() { |
| @@ -787,14 +788,14 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map · 28 unmodified lines | ||
| 787 | 788 | } |
| 788 | 789 | |
| 789 | 790 | // getAllCommitStatus get pr's commit statuses. |
| 790 | −func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (statuses []*models.CommitStatus, lastStatus *models.CommitStatus, err error) { | |
| 791 | +func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (statuses []*git_model.CommitStatus, lastStatus *git_model.CommitStatus, err error) { | |
| 791 | 792 | sha, shaErr := gitRepo.GetRefCommitID(pr.GetGitRefName()) |
| 792 | 793 | if shaErr != nil { |
| 793 | 794 | return nil, nil, shaErr |
| 794 | 795 | } |
| 795 | 796 | |
| 796 | − statuses, _, err = models.GetLatestCommitStatus(db.DefaultContext, pr.BaseRepo.ID, sha, db.ListOptions{}) | |
| 797 | − lastStatus = models.CalcCommitStatus(statuses) | |
| 797 | + statuses, _, err = git_model.GetLatestCommitStatus(db.DefaultContext, pr.BaseRepo.ID, sha, db.ListOptions{}) | |
| 798 | + lastStatus = git_model.CalcCommitStatus(statuses) | |
| 798 | 799 | return statuses, lastStatus, err |
| 799 | 800 | } |
| 800 | 801 | |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | |
| 13 | 13 | "code.gitea.io/gitea/models" |
| 14 | 14 | "code.gitea.io/gitea/models/db" |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 15 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 16 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 18 | "code.gitea.io/gitea/modules/git" |
| @@ -32,11 +33,11 @@ func createTag(gitRepo *git.Repository, rel *models.Release, msg string) (bool, · 14 unmodified lines | ||
| 32 | 33 | return false, err |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | − protectedTags, err := models.GetProtectedTags(rel.Repo.ID) | |
| 36 | + protectedTags, err := git_model.GetProtectedTags(rel.Repo.ID) | |
| 36 | 37 | if err != nil { |
| 37 | 38 | return false, fmt.Errorf("GetProtectedTags: %v", err) |
| 38 | 39 | } |
| 39 | − isAllowed, err := models.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID) | |
| 40 | + isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID) | |
| 40 | 41 | if err != nil { |
| 41 | 42 | return false, err |
| 42 | 43 | } |
| @@ -11,6 +11,7 @@ import ( · 10 unmodified lines | ||
| 11 | 11 | "strings" |
| 12 | 12 | |
| 13 | 13 | "code.gitea.io/gitea/models" |
| 14 | + git_model "code.gitea.io/gitea/models/git" | |
| 14 | 15 | repo_model "code.gitea.io/gitea/models/repo" |
| 15 | 16 | user_model "code.gitea.io/gitea/models/user" |
| 16 | 17 | "code.gitea.io/gitea/modules/git" |
| @@ -118,7 +119,7 @@ func RenameBranch(repo *repo_model.Repository, doer *user_model.User, gitRepo *g · 101 unmodified lines | ||
| 118 | 119 | return "from_not_exist", nil |
| 119 | 120 | } |
| 120 | 121 | |
| 121 | − if err := models.RenameBranch(repo, from, to, func(isDefault bool) error { | |
| 122 | + if err := git_model.RenameBranch(repo, from, to, func(isDefault bool) error { | |
| 122 | 123 | err2 := gitRepo.RenameBranch(from, to) |
| 123 | 124 | if err2 != nil { |
| 124 | 125 | return err2 |
| @@ -158,7 +159,7 @@ func DeleteBranch(doer *user_model.User, repo *repo_model.Repository, gitRepo *g · 33 unmodified lines | ||
| 158 | 159 | return ErrBranchIsDefault |
| 159 | 160 | } |
| 160 | 161 | |
| 161 | − isProtected, err := models.IsProtectedBranch(repo.ID, branchName) | |
| 162 | + isProtected, err := git_model.IsProtectedBranch(repo.ID, branchName) | |
| 162 | 163 | if err != nil { |
| 163 | 164 | return err |
| 164 | 165 | } |
| @@ -196,7 +197,7 @@ func DeleteBranch(doer *user_model.User, repo *repo_model.Repository, gitRepo *g · 31 unmodified lines | ||
| 196 | 197 | log.Error("Update: %v", err) |
| 197 | 198 | } |
| 198 | 199 | |
| 199 | − if err := models.AddDeletedBranch(repo.ID, branchName, commit.ID.String(), doer.ID); err != nil { | |
| 200 | + if err := git_model.AddDeletedBranch(repo.ID, branchName, commit.ID.String(), doer.ID); err != nil { | |
| 200 | 201 | log.Warn("AddDeletedBranch: %v", err) |
| 201 | 202 | } |
| 202 | 203 | |
| @@ -8,8 +8,8 @@ import ( · 7 unmodified lines | ||
| 8 | 8 | "context" |
| 9 | 9 | "fmt" |
| 10 | 10 | |
| 11 | − "code.gitea.io/gitea/models" | |
| 12 | 11 | asymkey_model "code.gitea.io/gitea/models/asymkey" |
| 12 | + git_model "code.gitea.io/gitea/models/git" | |
| 13 | 13 | repo_model "code.gitea.io/gitea/models/repo" |
| 14 | 14 | user_model "code.gitea.io/gitea/models/user" |
| 15 | 15 | "code.gitea.io/gitea/modules/git" |
| @@ -20,7 +20,7 @@ import ( · 4 unmodified lines | ||
| 20 | 20 | // CreateCommitStatus creates a new CommitStatus given a bunch of parameters |
| 21 | 21 | // NOTE: All text-values will be trimmed from whitespaces. |
| 22 | 22 | // Requires: Repo, Creator, SHA |
| 23 | −func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error { | |
| 23 | +func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creator *user_model.User, sha string, status *git_model.CommitStatus) error { | |
| 24 | 24 | repoPath := repo.RepoPath() |
| 25 | 25 | |
| 26 | 26 | // confirm that commit is exist |
| @@ -36,7 +36,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato · 9 unmodified lines | ||
| 36 | 36 | } |
| 37 | 37 | gitRepo.Close() |
| 38 | 38 | |
| 39 | − if err := models.NewCommitStatus(models.NewCommitStatusOptions{ | |
| 39 | + if err := git_model.NewCommitStatus(git_model.NewCommitStatusOptions{ | |
| 40 | 40 | Repo: repo, |
| 41 | 41 | Creator: creator, |
| 42 | 42 | SHA: sha, |
| @@ -10,6 +10,7 @@ import ( · 9 unmodified lines | ||
| 10 | 10 | "strings" |
| 11 | 11 | |
| 12 | 12 | "code.gitea.io/gitea/models" |
| 13 | + git_model "code.gitea.io/gitea/models/git" | |
| 13 | 14 | repo_model "code.gitea.io/gitea/models/repo" |
| 14 | 15 | user_model "code.gitea.io/gitea/models/user" |
| 15 | 16 | "code.gitea.io/gitea/modules/git" |
| @@ -66,7 +67,7 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode · 50 unmodified lines | ||
| 66 | 67 | return err |
| 67 | 68 | } |
| 68 | 69 | } else { |
| 69 | − protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, opts.OldBranch) | |
| 70 | + protectedBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, opts.OldBranch) | |
| 70 | 71 | if err != nil { |
| 71 | 72 | return err |
| 72 | 73 | } |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | "time" |
| 14 | 14 | |
| 15 | 15 | "code.gitea.io/gitea/models" |
| 16 | + git_model "code.gitea.io/gitea/models/git" | |
| 16 | 17 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 18 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 19 | "code.gitea.io/gitea/modules/charset" |
| @@ -75,8 +76,8 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *repo_model.Repository) (st · 56 unmodified lines | ||
| 75 | 76 | if setting.LFS.StartServer { |
| 76 | 77 | pointer, _ := lfs.ReadPointerFromBuffer(buf) |
| 77 | 78 | if pointer.IsValid() { |
| 78 | − meta, err := models.GetLFSMetaObjectByOid(repo.ID, pointer.Oid) | |
| 79 | − if err != nil && err != models.ErrLFSObjectNotExist { | |
| 79 | + meta, err := git_model.GetLFSMetaObjectByOid(repo.ID, pointer.Oid) | |
| 80 | + if err != nil && err != git_model.ErrLFSObjectNotExist { | |
| 80 | 81 | // return default |
| 81 | 82 | return "UTF-8", false |
| 82 | 83 | } |
| @@ -364,7 +365,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 281 unmodified lines | ||
| 364 | 365 | } |
| 365 | 366 | // Reset the opts.Content to our adjusted content to ensure that LFS gets the correct content |
| 366 | 367 | opts.Content = content |
| 367 | − var lfsMetaObject *models.LFSMetaObject | |
| 368 | + var lfsMetaObject *git_model.LFSMetaObject | |
| 368 | 369 | |
| 369 | 370 | if setting.LFS.StartServer && hasOldBranch { |
| 370 | 371 | // Check there is no way this can return multiple infos |
| @@ -383,7 +384,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 12 unmodified lines | ||
| 383 | 384 | if err != nil { |
| 384 | 385 | return nil, err |
| 385 | 386 | } |
| 386 | − lfsMetaObject = &models.LFSMetaObject{Pointer: pointer, RepositoryID: repo.ID} | |
| 387 | + lfsMetaObject = &git_model.LFSMetaObject{Pointer: pointer, RepositoryID: repo.ID} | |
| 387 | 388 | content = pointer.StringContent() |
| 388 | 389 | } |
| 389 | 390 | } |
| @@ -423,7 +424,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 33 unmodified lines | ||
| 423 | 424 | |
| 424 | 425 | if lfsMetaObject != nil { |
| 425 | 426 | // We have an LFS object - create it |
| 426 | − lfsMetaObject, err = models.NewLFSMetaObject(lfsMetaObject) | |
| 427 | + lfsMetaObject, err = git_model.NewLFSMetaObject(lfsMetaObject) | |
| 427 | 428 | if err != nil { |
| 428 | 429 | return nil, err |
| 429 | 430 | } |
| @@ -434,7 +435,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 4 unmodified lines | ||
| 434 | 435 | } |
| 435 | 436 | if !exist { |
| 436 | 437 | if err := contentStore.Put(lfsMetaObject.Pointer, strings.NewReader(opts.Content)); err != nil { |
| 437 | − if _, err2 := models.RemoveLFSMetaObjectByOid(repo.ID, lfsMetaObject.Oid); err2 != nil { | |
| 438 | + if _, err2 := git_model.RemoveLFSMetaObjectByOid(repo.ID, lfsMetaObject.Oid); err2 != nil { | |
| 438 | 439 | return nil, fmt.Errorf("Error whilst removing failed inserted LFS object %s: %v (Prev Error: %v)", lfsMetaObject.Oid, err2, err) |
| 439 | 440 | } |
| 440 | 441 | return nil, err |
| @@ -462,7 +463,7 @@ func CreateOrUpdateRepoFile(ctx context.Context, repo *repo_model.Repository, do · 21 unmodified lines | ||
| 462 | 463 | |
| 463 | 464 | // VerifyBranchProtection verify the branch protection for modifying the given treePath on the given branch |
| 464 | 465 | func VerifyBranchProtection(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, branchName, treePath string) error { |
| 465 | − protectedBranch, err := models.GetProtectedBranchBy(ctx, repo.ID, branchName) | |
| 466 | + protectedBranch, err := git_model.GetProtectedBranchBy(ctx, repo.ID, branchName) | |
| 466 | 467 | if err != nil { |
| 467 | 468 | return err |
| 468 | 469 | } |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | "strings" |
| 13 | 13 | |
| 14 | 14 | "code.gitea.io/gitea/models" |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 15 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 16 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 18 | "code.gitea.io/gitea/modules/git" |
| @@ -32,7 +33,7 @@ type UploadRepoFileOptions struct { · 14 unmodified lines | ||
| 32 | 33 | |
| 33 | 34 | type uploadInfo struct { |
| 34 | 35 | upload *models.Upload |
| 35 | − lfsMetaObject *models.LFSMetaObject | |
| 36 | + lfsMetaObject *git_model.LFSMetaObject | |
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, original error) error { |
| @@ -41,7 +42,7 @@ func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, orig · 2 unmodified lines | ||
| 41 | 42 | continue |
| 42 | 43 | } |
| 43 | 44 | if !info.lfsMetaObject.Existing { |
| 44 | − if _, err := models.RemoveLFSMetaObjectByOid(t.repo.ID, info.lfsMetaObject.Oid); err != nil { | |
| 45 | + if _, err := git_model.RemoveLFSMetaObjectByOid(t.repo.ID, info.lfsMetaObject.Oid); err != nil { | |
| 45 | 46 | original = fmt.Errorf("%v, %v", original, err) |
| 46 | 47 | } |
| 47 | 48 | } |
| @@ -65,7 +66,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use · 17 unmodified lines | ||
| 65 | 66 | for i, upload := range uploads { |
| 66 | 67 | // Check file is not lfs locked, will return nil if lock setting not enabled |
| 67 | 68 | filepath := path.Join(opts.TreePath, upload.Name) |
| 68 | − lfsLock, err := models.GetTreePathLock(repo.ID, filepath) | |
| 69 | + lfsLock, err := git_model.GetTreePathLock(repo.ID, filepath) | |
| 69 | 70 | if err != nil { |
| 70 | 71 | return err |
| 71 | 72 | } |
| @@ -74,7 +75,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use · 2 unmodified lines | ||
| 74 | 75 | if err != nil { |
| 75 | 76 | return err |
| 76 | 77 | } |
| 77 | − return models.ErrLFSFileLocked{RepoID: repo.ID, Path: filepath, UserName: u.Name} | |
| 78 | + return git_model.ErrLFSFileLocked{RepoID: repo.ID, Path: filepath, UserName: u.Name} | |
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | names[i] = upload.Name |
| @@ -133,7 +134,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use · 52 unmodified lines | ||
| 133 | 134 | if infos[i].lfsMetaObject == nil { |
| 134 | 135 | continue |
| 135 | 136 | } |
| 136 | − infos[i].lfsMetaObject, err = models.NewLFSMetaObject(infos[i].lfsMetaObject) | |
| 137 | + infos[i].lfsMetaObject, err = git_model.NewLFSMetaObject(infos[i].lfsMetaObject) | |
| 137 | 138 | if err != nil { |
| 138 | 139 | // OK Now we need to cleanup |
| 139 | 140 | return cleanUpAfterFailure(&infos, t, err) |
| @@ -175,7 +176,7 @@ func copyUploadedLFSFileIntoRepository(info *uploadInfo, filename2attribute2info · 35 unmodified lines | ||
| 175 | 176 | return err |
| 176 | 177 | } |
| 177 | 178 | |
| 178 | − info.lfsMetaObject = &models.LFSMetaObject{Pointer: pointer, RepositoryID: t.repo.ID} | |
| 179 | + info.lfsMetaObject = &git_model.LFSMetaObject{Pointer: pointer, RepositoryID: t.repo.ID} | |
| 179 | 180 | |
| 180 | 181 | if objectHash, err = t.HashObject(strings.NewReader(pointer.StringContent())); err != nil { |
| 181 | 182 | return err |
| @@ -12,6 +12,7 @@ import ( · 11 unmodified lines | ||
| 12 | 12 | |
| 13 | 13 | "code.gitea.io/gitea/models" |
| 14 | 14 | "code.gitea.io/gitea/models/db" |
| 15 | + git_model "code.gitea.io/gitea/models/git" | |
| 15 | 16 | repo_model "code.gitea.io/gitea/models/repo" |
| 16 | 17 | user_model "code.gitea.io/gitea/models/user" |
| 17 | 18 | "code.gitea.io/gitea/modules/git" |
| @@ -101,7 +102,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork · 83 unmodified lines | ||
| 101 | 102 | } |
| 102 | 103 | |
| 103 | 104 | // copy lfs files failure should not be ignored |
| 104 | − if err = models.CopyLFS(txCtx, repo, opts.BaseRepo); err != nil { | |
| 105 | + if err = git_model.CopyLFS(txCtx, repo, opts.BaseRepo); err != nil { | |
| 105 | 106 | return err |
| 106 | 107 | } |
| 107 | 108 | |
| @@ -13,6 +13,7 @@ import ( · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | "code.gitea.io/gitea/models" |
| 15 | 15 | "code.gitea.io/gitea/models/db" |
| 16 | + git_model "code.gitea.io/gitea/models/git" | |
| 16 | 17 | repo_model "code.gitea.io/gitea/models/repo" |
| 17 | 18 | user_model "code.gitea.io/gitea/models/user" |
| 18 | 19 | "code.gitea.io/gitea/modules/cache" |
| @@ -252,7 +253,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { · 233 unmodified lines | ||
| 252 | 253 | |
| 253 | 254 | notification.NotifyPushCommits(pusher, repo, opts, commits) |
| 254 | 255 | |
| 255 | − if err = models.RemoveDeletedBranchByName(repo.ID, branch); err != nil { | |
| 256 | + if err = git_model.RemoveDeletedBranchByName(repo.ID, branch); err != nil { | |
| 256 | 257 | log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err) |
| 257 | 258 | } |
| 258 | 259 | |