diff options
Diffstat (limited to 'modules/convert')
-rw-r--r-- | modules/convert/convert.go | 4 | ||||
-rw-r--r-- | modules/convert/issue.go | 21 | ||||
-rw-r--r-- | modules/convert/issue_comment.go | 14 | ||||
-rw-r--r-- | modules/convert/issue_test.go | 3 | ||||
-rw-r--r-- | modules/convert/pull.go | 8 | ||||
-rw-r--r-- | modules/convert/pull_review.go | 20 | ||||
-rw-r--r-- | modules/convert/pull_test.go | 6 |
7 files changed, 37 insertions, 39 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 4e8aa59067..c8cb23261e 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -11,11 +11,11 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/db" git_model "code.gitea.io/gitea/models/git" + issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" @@ -55,7 +55,7 @@ func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *git if err != nil { return nil, err } - canPush = models.CanMaintainerWriteToBranch(perms, b.Name, user) + canPush = issues_model.CanMaintainerWriteToBranch(perms, b.Name, user) } return &api.Branch{ diff --git a/modules/convert/issue.go b/modules/convert/issue.go index a4512e424f..35eff05229 100644 --- a/modules/convert/issue.go +++ b/modules/convert/issue.go @@ -9,7 +9,6 @@ import ( "net/url" "strings" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" @@ -23,7 +22,7 @@ import ( // it assumes some fields assigned with values: // Required - Poster, Labels, // Optional - Milestone, Assignee, PullRequest -func ToAPIIssue(issue *models.Issue) *api.Issue { +func ToAPIIssue(issue *issues_model.Issue) *api.Issue { if err := issue.LoadLabels(db.DefaultContext); err != nil { return &api.Issue{} } @@ -100,7 +99,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue { } // ToAPIIssueList converts an IssueList to API format -func ToAPIIssueList(il models.IssueList) []*api.Issue { +func ToAPIIssueList(il issues_model.IssueList) []*api.Issue { result := make([]*api.Issue, len(il)) for i := range il { result[i] = ToAPIIssue(il[i]) @@ -109,7 +108,7 @@ func ToAPIIssueList(il models.IssueList) []*api.Issue { } // ToTrackedTime converts TrackedTime to API format -func ToTrackedTime(t *models.TrackedTime) (apiT *api.TrackedTime) { +func ToTrackedTime(t *issues_model.TrackedTime) (apiT *api.TrackedTime) { apiT = &api.TrackedTime{ ID: t.ID, IssueID: t.IssueID, @@ -128,13 +127,13 @@ func ToTrackedTime(t *models.TrackedTime) (apiT *api.TrackedTime) { } // ToStopWatches convert Stopwatch list to api.StopWatches -func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) { +func ToStopWatches(sws []*issues_model.Stopwatch) (api.StopWatches, error) { result := api.StopWatches(make([]api.StopWatch, 0, len(sws))) - issueCache := make(map[int64]*models.Issue) + issueCache := make(map[int64]*issues_model.Issue) repoCache := make(map[int64]*repo_model.Repository) var ( - issue *models.Issue + issue *issues_model.Issue repo *repo_model.Repository ok bool err error @@ -143,7 +142,7 @@ func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) { for _, sw := range sws { issue, ok = issueCache[sw.IssueID] if !ok { - issue, err = models.GetIssueByID(sw.IssueID) + issue, err = issues_model.GetIssueByID(db.DefaultContext, sw.IssueID) if err != nil { return nil, err } @@ -170,7 +169,7 @@ func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) { } // ToTrackedTimeList converts TrackedTimeList to API format -func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList { +func ToTrackedTimeList(tl issues_model.TrackedTimeList) api.TrackedTimeList { result := make([]*api.TrackedTime, 0, len(tl)) for _, t := range tl { result = append(result, ToTrackedTime(t)) @@ -179,7 +178,7 @@ func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList { } // ToLabel converts Label to API format -func ToLabel(label *models.Label, repo *repo_model.Repository, org *user_model.User) *api.Label { +func ToLabel(label *issues_model.Label, repo *repo_model.Repository, org *user_model.User) *api.Label { result := &api.Label{ ID: label.ID, Name: label.Name, @@ -206,7 +205,7 @@ func ToLabel(label *models.Label, repo *repo_model.Repository, org *user_model.U } // ToLabelList converts list of Label to API format -func ToLabelList(labels []*models.Label, repo *repo_model.Repository, org *user_model.User) []*api.Label { +func ToLabelList(labels []*issues_model.Label, repo *repo_model.Repository, org *user_model.User) []*api.Label { result := make([]*api.Label, len(labels)) for i := range labels { result[i] = ToLabel(labels[i], repo, org) diff --git a/modules/convert/issue_comment.go b/modules/convert/issue_comment.go index eaa7f64ea3..ccc94b2496 100644 --- a/modules/convert/issue_comment.go +++ b/modules/convert/issue_comment.go @@ -5,16 +5,16 @@ package convert import ( - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" ) -// ToComment converts a models.Comment to the api.Comment format -func ToComment(c *models.Comment) *api.Comment { +// ToComment converts a issues_model.Comment to the api.Comment format +func ToComment(c *issues_model.Comment) *api.Comment { return &api.Comment{ ID: c.ID, Poster: ToUser(c.Poster, nil), @@ -27,8 +27,8 @@ func ToComment(c *models.Comment) *api.Comment { } } -// ToTimelineComment converts a models.Comment to the api.TimelineComment format -func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineComment { +// ToTimelineComment converts a issues_model.Comment to the api.TimelineComment format +func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.TimelineComment { err := c.LoadMilestone() if err != nil { log.Error("LoadMilestone: %v", err) @@ -105,7 +105,7 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo } if c.RefIssueID != 0 { - issue, err := models.GetIssueByID(c.RefIssueID) + issue, err := issues_model.GetIssueByID(db.DefaultContext, c.RefIssueID) if err != nil { log.Error("GetIssueByID(%d): %v", c.RefIssueID, err) return nil @@ -114,7 +114,7 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo } if c.RefCommentID != 0 { - com, err := models.GetCommentByID(db.DefaultContext, c.RefCommentID) + com, err := issues_model.GetCommentByID(db.DefaultContext, c.RefCommentID) if err != nil { log.Error("GetCommentByID(%d): %v", c.RefCommentID, err) return nil diff --git a/modules/convert/issue_test.go b/modules/convert/issue_test.go index b237c18f69..5bf04bcb52 100644 --- a/modules/convert/issue_test.go +++ b/modules/convert/issue_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - "code.gitea.io/gitea/models" issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" @@ -22,7 +21,7 @@ import ( func TestLabel_ToLabel(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - label := unittest.AssertExistsAndLoadBean(t, &models.Label{ID: 1}).(*models.Label) + label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1}).(*issues_model.Label) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: label.RepoID}).(*repo_model.Repository) assert.Equal(t, &api.Label{ ID: label.ID, diff --git a/modules/convert/pull.go b/modules/convert/pull.go index 310a7626c9..9c31f9bd2c 100644 --- a/modules/convert/pull.go +++ b/modules/convert/pull.go @@ -8,7 +8,7 @@ import ( "context" "fmt" - "code.gitea.io/gitea/models" + issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" user_model "code.gitea.io/gitea/models/user" @@ -20,7 +20,7 @@ import ( // ToAPIPullRequest assumes following fields have been assigned with valid values: // Required - Issue // Optional - Merger -func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_model.User) *api.PullRequest { +func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User) *api.PullRequest { var ( baseBranch *git.Branch headBranch *git.Branch @@ -114,7 +114,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo } } - if pr.Flow == models.PullRequestFlowAGit { + if pr.Flow == issues_model.PullRequestFlowAGit { gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath()) if err != nil { log.Error("OpenRepository[%s]: %v", pr.GetGitRefName(), err) @@ -132,7 +132,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo apiPullRequest.Head.Name = "" } - if pr.HeadRepo != nil && pr.Flow == models.PullRequestFlowGithub { + if pr.HeadRepo != nil && pr.Flow == issues_model.PullRequestFlowGithub { p, err := access_model.GetUserRepoPermission(ctx, pr.HeadRepo, doer) if err != nil { log.Error("GetUserRepoPermission[%d]: %v", pr.HeadRepoID, err) diff --git a/modules/convert/pull_review.go b/modules/convert/pull_review.go index 907ccafb66..93ce208224 100644 --- a/modules/convert/pull_review.go +++ b/modules/convert/pull_review.go @@ -8,13 +8,13 @@ import ( "context" "strings" - "code.gitea.io/gitea/models" + issues_model "code.gitea.io/gitea/models/issues" user_model "code.gitea.io/gitea/models/user" api "code.gitea.io/gitea/modules/structs" ) // ToPullReview convert a review to api format -func ToPullReview(ctx context.Context, r *models.Review, doer *user_model.User) (*api.PullReview, error) { +func ToPullReview(ctx context.Context, r *issues_model.Review, doer *user_model.User) (*api.PullReview, error) { if err := r.LoadAttributes(ctx); err != nil { if !user_model.IsErrUserNotExist(err) { return nil, err @@ -44,15 +44,15 @@ func ToPullReview(ctx context.Context, r *models.Review, doer *user_model.User) } switch r.Type { - case models.ReviewTypeApprove: + case issues_model.ReviewTypeApprove: result.State = api.ReviewStateApproved - case models.ReviewTypeReject: + case issues_model.ReviewTypeReject: result.State = api.ReviewStateRequestChanges - case models.ReviewTypeComment: + case issues_model.ReviewTypeComment: result.State = api.ReviewStateComment - case models.ReviewTypePending: + case issues_model.ReviewTypePending: result.State = api.ReviewStatePending - case models.ReviewTypeRequest: + case issues_model.ReviewTypeRequest: result.State = api.ReviewStateRequestReview } @@ -60,11 +60,11 @@ func ToPullReview(ctx context.Context, r *models.Review, doer *user_model.User) } // ToPullReviewList convert a list of review to it's api format -func ToPullReviewList(ctx context.Context, rl []*models.Review, doer *user_model.User) ([]*api.PullReview, error) { +func ToPullReviewList(ctx context.Context, rl []*issues_model.Review, doer *user_model.User) ([]*api.PullReview, error) { result := make([]*api.PullReview, 0, len(rl)) for i := range rl { // show pending reviews only for the user who created them - if rl[i].Type == models.ReviewTypePending && !(doer.IsAdmin || doer.ID == rl[i].ReviewerID) { + if rl[i].Type == issues_model.ReviewTypePending && !(doer.IsAdmin || doer.ID == rl[i].ReviewerID) { continue } r, err := ToPullReview(ctx, rl[i], doer) @@ -77,7 +77,7 @@ func ToPullReviewList(ctx context.Context, rl []*models.Review, doer *user_model } // ToPullReviewCommentList convert the CodeComments of an review to it's api format -func ToPullReviewCommentList(ctx context.Context, review *models.Review, doer *user_model.User) ([]*api.PullReviewComment, error) { +func ToPullReviewCommentList(ctx context.Context, review *issues_model.Review, doer *user_model.User) ([]*api.PullReviewComment, error) { if err := review.LoadAttributes(ctx); err != nil { if !user_model.IsErrUserNotExist(err) { return nil, err diff --git a/modules/convert/pull_test.go b/modules/convert/pull_test.go index 8574ccfd26..10ef311399 100644 --- a/modules/convert/pull_test.go +++ b/modules/convert/pull_test.go @@ -7,7 +7,7 @@ package convert import ( "testing" - "code.gitea.io/gitea/models" + issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/perm" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" @@ -21,7 +21,7 @@ func TestPullRequest_APIFormat(t *testing.T) { // with HeadRepo assert.NoError(t, unittest.PrepareTestDatabase()) headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository) - pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest) + pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}).(*issues_model.PullRequest) assert.NoError(t, pr.LoadAttributes()) assert.NoError(t, pr.LoadIssue()) apiPullRequest := ToAPIPullRequest(git.DefaultContext, pr, nil) @@ -35,7 +35,7 @@ func TestPullRequest_APIFormat(t *testing.T) { }, apiPullRequest.Head) // withOut HeadRepo - pr = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest) + pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}).(*issues_model.PullRequest) assert.NoError(t, pr.LoadIssue()) assert.NoError(t, pr.LoadAttributes()) // simulate fork deletion |