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