Move milestone to models/issues/ (#19278)
* Move milestone to models/issues/ * Fix lint * Fix test * Fix lint * Fix lint
This commit is contained in:
parent
84ceaa98bd
commit
1dfa26e00e
|
@ -9,7 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -21,7 +21,7 @@ import (
|
||||||
func TestAPIIssuesMilestone(t *testing.T) {
|
func TestAPIIssuesMilestone(t *testing.T) {
|
||||||
defer prepareTestEnv(t)()
|
defer prepareTestEnv(t)()
|
||||||
|
|
||||||
milestone := unittest.AssertExistsAndLoadBean(t, &models.Milestone{ID: 1}).(*models.Milestone)
|
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}).(*issues_model.Milestone)
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: milestone.RepoID}).(*repo_model.Repository)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: milestone.RepoID}).(*repo_model.Repository)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
|
||||||
assert.Equal(t, int64(1), int64(milestone.NumIssues))
|
assert.Equal(t, int64(1), int64(milestone.NumIssues))
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
|
@ -23,7 +24,7 @@ func TestAPIIssuesReactions(t *testing.T) {
|
||||||
defer prepareTestEnv(t)()
|
defer prepareTestEnv(t)()
|
||||||
|
|
||||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
|
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
|
||||||
_ = issue.LoadRepo()
|
_ = issue.LoadRepo(db.DefaultContext)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
||||||
|
|
||||||
session := loginUser(t, owner.Name)
|
session := loginUser(t, owner.Name)
|
||||||
|
@ -82,7 +83,7 @@ func TestAPICommentReactions(t *testing.T) {
|
||||||
comment := unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
|
comment := unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
|
||||||
_ = comment.LoadIssue()
|
_ = comment.LoadIssue()
|
||||||
issue := comment.Issue
|
issue := comment.Issue
|
||||||
_ = issue.LoadRepo()
|
_ = issue.LoadRepo(db.DefaultContext)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
||||||
|
|
||||||
session := loginUser(t, owner.Name)
|
session := loginUser(t, owner.Name)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -45,7 +46,7 @@ func TestAPIStopStopWatches(t *testing.T) {
|
||||||
defer prepareTestEnv(t)()
|
defer prepareTestEnv(t)()
|
||||||
|
|
||||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
||||||
_ = issue.LoadRepo()
|
_ = issue.LoadRepo(db.DefaultContext)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||||
|
|
||||||
|
@ -61,7 +62,7 @@ func TestAPICancelStopWatches(t *testing.T) {
|
||||||
defer prepareTestEnv(t)()
|
defer prepareTestEnv(t)()
|
||||||
|
|
||||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
|
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
|
||||||
_ = issue.LoadRepo()
|
_ = issue.LoadRepo(db.DefaultContext)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ func TestAPIStartStopWatches(t *testing.T) {
|
||||||
defer prepareTestEnv(t)()
|
defer prepareTestEnv(t)()
|
||||||
|
|
||||||
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
|
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
|
||||||
_ = issue.LoadRepo()
|
_ = issue.LoadRepo(db.DefaultContext)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
@ -23,7 +24,7 @@ func TestAPIGetTrackedTimes(t *testing.T) {
|
||||||
|
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||||
issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
||||||
assert.NoError(t, issue2.LoadRepo())
|
assert.NoError(t, issue2.LoadRepo(db.DefaultContext))
|
||||||
|
|
||||||
session := loginUser(t, user2.Name)
|
session := loginUser(t, user2.Name)
|
||||||
token := getTokenForLoggedInUser(t, session)
|
token := getTokenForLoggedInUser(t, session)
|
||||||
|
@ -65,7 +66,7 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
|
||||||
|
|
||||||
time6 := unittest.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 6}).(*models.TrackedTime)
|
time6 := unittest.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 6}).(*models.TrackedTime)
|
||||||
issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
||||||
assert.NoError(t, issue2.LoadRepo())
|
assert.NoError(t, issue2.LoadRepo(db.DefaultContext))
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||||
|
|
||||||
session := loginUser(t, user2.Name)
|
session := loginUser(t, user2.Name)
|
||||||
|
@ -99,7 +100,7 @@ func TestAPIAddTrackedTimes(t *testing.T) {
|
||||||
defer prepareTestEnv(t)()
|
defer prepareTestEnv(t)()
|
||||||
|
|
||||||
issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
issue2 := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
|
||||||
assert.NoError(t, issue2.LoadRepo())
|
assert.NoError(t, issue2.LoadRepo(db.DefaultContext))
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||||
admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
|
||||||
|
|
||||||
|
|
|
@ -243,7 +243,7 @@ func (a *Action) getCommentLink(ctx context.Context) string {
|
||||||
return "#"
|
return "#"
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return "#"
|
return "#"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,10 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -33,3 +36,70 @@ func TestDeleteOrphanedObjects(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, countBefore, countAfter)
|
assert.EqualValues(t, countBefore, countAfter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewMilestone(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
milestone := &issues_model.Milestone{
|
||||||
|
RepoID: 1,
|
||||||
|
Name: "milestoneName",
|
||||||
|
Content: "milestoneContent",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, issues_model.NewMilestone(milestone))
|
||||||
|
unittest.AssertExistsAndLoadBean(t, milestone)
|
||||||
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChangeMilestoneStatus(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}).(*issues_model.Milestone)
|
||||||
|
|
||||||
|
assert.NoError(t, issues_model.ChangeMilestoneStatus(milestone, true))
|
||||||
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}, "is_closed=1")
|
||||||
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
|
||||||
|
|
||||||
|
assert.NoError(t, issues_model.ChangeMilestoneStatus(milestone, false))
|
||||||
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}, "is_closed=0")
|
||||||
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &issues_model.Milestone{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeleteMilestoneByRepoID(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
assert.NoError(t, issues_model.DeleteMilestoneByRepoID(1, 1))
|
||||||
|
unittest.AssertNotExistsBean(t, &issues_model.Milestone{ID: 1})
|
||||||
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: 1})
|
||||||
|
|
||||||
|
assert.NoError(t, issues_model.DeleteMilestoneByRepoID(unittest.NonexistentID, unittest.NonexistentID))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateMilestone(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
|
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}).(*issues_model.Milestone)
|
||||||
|
milestone.Name = " newMilestoneName "
|
||||||
|
milestone.Content = "newMilestoneContent"
|
||||||
|
assert.NoError(t, issues_model.UpdateMilestone(milestone, milestone.IsClosed))
|
||||||
|
milestone = unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}).(*issues_model.Milestone)
|
||||||
|
assert.EqualValues(t, "newMilestoneName", milestone.Name)
|
||||||
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateMilestoneCounters(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
issue := unittest.AssertExistsAndLoadBean(t, &Issue{MilestoneID: 1},
|
||||||
|
"is_closed=0").(*Issue)
|
||||||
|
|
||||||
|
issue.IsClosed = true
|
||||||
|
issue.ClosedUnix = timeutil.TimeStampNow()
|
||||||
|
_, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NoError(t, issues_model.UpdateMilestoneCounters(db.DefaultContext, issue.MilestoneID))
|
||||||
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{})
|
||||||
|
|
||||||
|
issue.IsClosed = false
|
||||||
|
issue.ClosedUnix = 0
|
||||||
|
_, err = db.GetEngine(db.DefaultContext).ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NoError(t, issues_model.UpdateMilestoneCounters(db.DefaultContext, issue.MilestoneID))
|
||||||
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{})
|
||||||
|
}
|
||||||
|
|
|
@ -1048,33 +1048,6 @@ func (err ErrLabelNotExist) Error() string {
|
||||||
return fmt.Sprintf("label does not exist [label_id: %d]", err.LabelID)
|
return fmt.Sprintf("label does not exist [label_id: %d]", err.LabelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// _____ .__.__ __
|
|
||||||
// / \ |__| | ____ _______/ |_ ____ ____ ____
|
|
||||||
// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
|
|
||||||
// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
|
|
||||||
// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
|
|
||||||
// \/ \/ \/ \/ \/
|
|
||||||
|
|
||||||
// ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
|
|
||||||
type ErrMilestoneNotExist struct {
|
|
||||||
ID int64
|
|
||||||
RepoID int64
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
|
|
||||||
func IsErrMilestoneNotExist(err error) bool {
|
|
||||||
_, ok := err.(ErrMilestoneNotExist)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err ErrMilestoneNotExist) Error() string {
|
|
||||||
if len(err.Name) > 0 {
|
|
||||||
return fmt.Sprintf("milestone does not exist [name: %s, repo_id: %d]", err.Name, err.RepoID)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ____ ___ .__ .___
|
// ____ ___ .__ .___
|
||||||
// | | \______ | | _________ __| _/
|
// | | \______ | | _________ __| _/
|
||||||
// | | /\____ \| | / _ \__ \ / __ |
|
// | | /\____ \| | / _ \__ \ / __ |
|
||||||
|
|
109
models/issue.go
109
models/issue.go
|
@ -16,7 +16,7 @@ import (
|
||||||
admin_model "code.gitea.io/gitea/models/admin"
|
admin_model "code.gitea.io/gitea/models/admin"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/foreignreference"
|
"code.gitea.io/gitea/models/foreignreference"
|
||||||
"code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
project_model "code.gitea.io/gitea/models/project"
|
project_model "code.gitea.io/gitea/models/project"
|
||||||
|
@ -46,14 +46,14 @@ type Issue struct {
|
||||||
PosterID int64 `xorm:"INDEX"`
|
PosterID int64 `xorm:"INDEX"`
|
||||||
Poster *user_model.User `xorm:"-"`
|
Poster *user_model.User `xorm:"-"`
|
||||||
OriginalAuthor string
|
OriginalAuthor string
|
||||||
OriginalAuthorID int64 `xorm:"index"`
|
OriginalAuthorID int64 `xorm:"index"`
|
||||||
Title string `xorm:"name"`
|
Title string `xorm:"name"`
|
||||||
Content string `xorm:"LONGTEXT"`
|
Content string `xorm:"LONGTEXT"`
|
||||||
RenderedContent string `xorm:"-"`
|
RenderedContent string `xorm:"-"`
|
||||||
Labels []*Label `xorm:"-"`
|
Labels []*Label `xorm:"-"`
|
||||||
MilestoneID int64 `xorm:"INDEX"`
|
MilestoneID int64 `xorm:"INDEX"`
|
||||||
Milestone *Milestone `xorm:"-"`
|
Milestone *issues_model.Milestone `xorm:"-"`
|
||||||
Project *project_model.Project `xorm:"-"`
|
Project *project_model.Project `xorm:"-"`
|
||||||
Priority int
|
Priority int
|
||||||
AssigneeID int64 `xorm:"-"`
|
AssigneeID int64 `xorm:"-"`
|
||||||
Assignee *user_model.User `xorm:"-"`
|
Assignee *user_model.User `xorm:"-"`
|
||||||
|
@ -72,7 +72,7 @@ type Issue struct {
|
||||||
|
|
||||||
Attachments []*repo_model.Attachment `xorm:"-"`
|
Attachments []*repo_model.Attachment `xorm:"-"`
|
||||||
Comments []*Comment `xorm:"-"`
|
Comments []*Comment `xorm:"-"`
|
||||||
Reactions issues.ReactionList `xorm:"-"`
|
Reactions issues_model.ReactionList `xorm:"-"`
|
||||||
TotalTrackedTime int64 `xorm:"-"`
|
TotalTrackedTime int64 `xorm:"-"`
|
||||||
Assignees []*user_model.User `xorm:"-"`
|
Assignees []*user_model.User `xorm:"-"`
|
||||||
ForeignReference *foreignreference.ForeignReference `xorm:"-"`
|
ForeignReference *foreignreference.ForeignReference `xorm:"-"`
|
||||||
|
@ -124,11 +124,7 @@ func (issue *Issue) IsOverdue() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadRepo loads issue's repository
|
// LoadRepo loads issue's repository
|
||||||
func (issue *Issue) LoadRepo() error {
|
func (issue *Issue) LoadRepo(ctx context.Context) (err error) {
|
||||||
return issue.loadRepo(db.DefaultContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (issue *Issue) loadRepo(ctx context.Context) (err error) {
|
|
||||||
if issue.Repo == nil {
|
if issue.Repo == nil {
|
||||||
issue.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, issue.RepoID)
|
issue.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, issue.RepoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -144,7 +140,7 @@ func (issue *Issue) IsTimetrackerEnabled() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (issue *Issue) isTimetrackerEnabled(ctx context.Context) bool {
|
func (issue *Issue) isTimetrackerEnabled(ctx context.Context) bool {
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error(fmt.Sprintf("loadRepo: %v", err))
|
log.Error(fmt.Sprintf("loadRepo: %v", err))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -244,17 +240,17 @@ func (issue *Issue) loadReactions(ctx context.Context) (err error) {
|
||||||
if issue.Reactions != nil {
|
if issue.Reactions != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
reactions, _, err := issues.FindReactions(ctx, issues.FindReactionsOptions{
|
reactions, _, err := issues_model.FindReactions(ctx, issues_model.FindReactionsOptions{
|
||||||
IssueID: issue.ID,
|
IssueID: issue.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Load reaction user data
|
// Load reaction user data
|
||||||
if _, err := issues.ReactionList(reactions).LoadUsers(ctx, issue.Repo); err != nil {
|
if _, err := issues_model.ReactionList(reactions).LoadUsers(ctx, issue.Repo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,10 +293,10 @@ func (issue *Issue) loadForeignReference(ctx context.Context) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (issue *Issue) loadMilestone(e db.Engine) (err error) {
|
func (issue *Issue) loadMilestone(ctx context.Context) (err error) {
|
||||||
if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 {
|
if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 {
|
||||||
issue.Milestone, err = getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
|
issue.Milestone, err = issues_model.GetMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID)
|
||||||
if err != nil && !IsErrMilestoneNotExist(err) {
|
if err != nil && !issues_model.IsErrMilestoneNotExist(err) {
|
||||||
return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err)
|
return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,7 +305,7 @@ func (issue *Issue) loadMilestone(e db.Engine) (err error) {
|
||||||
|
|
||||||
func (issue *Issue) loadAttributes(ctx context.Context) (err error) {
|
func (issue *Issue) loadAttributes(ctx context.Context) (err error) {
|
||||||
e := db.GetEngine(ctx)
|
e := db.GetEngine(ctx)
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +317,7 @@ func (issue *Issue) loadAttributes(ctx context.Context) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue.loadMilestone(e); err != nil {
|
if err = issue.loadMilestone(ctx); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +368,7 @@ func (issue *Issue) LoadAttributes() error {
|
||||||
|
|
||||||
// LoadMilestone load milestone of this issue.
|
// LoadMilestone load milestone of this issue.
|
||||||
func (issue *Issue) LoadMilestone() error {
|
func (issue *Issue) LoadMilestone() error {
|
||||||
return issue.loadMilestone(db.GetEngine(db.DefaultContext))
|
return issue.loadMilestone(db.DefaultContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIsRead load the `IsRead` field of the issue
|
// GetIsRead load the `IsRead` field of the issue
|
||||||
|
@ -391,7 +387,7 @@ func (issue *Issue) GetIsRead(userID int64) error {
|
||||||
// APIURL returns the absolute APIURL to this issue.
|
// APIURL returns the absolute APIURL to this issue.
|
||||||
func (issue *Issue) APIURL() string {
|
func (issue *Issue) APIURL() string {
|
||||||
if issue.Repo == nil {
|
if issue.Repo == nil {
|
||||||
err := issue.LoadRepo()
|
err := issue.LoadRepo(db.DefaultContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Issue[%d].APIURL(): %v", issue.ID, err)
|
log.Error("Issue[%d].APIURL(): %v", issue.ID, err)
|
||||||
return ""
|
return ""
|
||||||
|
@ -491,7 +487,7 @@ func ClearIssueLabels(issue *Issue, doer *user_model.User) (err error) {
|
||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err = issue.loadPullRequest(db.GetEngine(ctx)); err != nil {
|
} else if err = issue.loadPullRequest(db.GetEngine(ctx)); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -539,7 +535,7 @@ func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (e
|
||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,7 +603,8 @@ func (issue *Issue) ReadBy(userID int64) error {
|
||||||
return setIssueNotificationStatusReadIfUnread(db.GetEngine(db.DefaultContext), userID, issue.ID)
|
return setIssueNotificationStatusReadIfUnread(db.GetEngine(db.DefaultContext), userID, issue.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateIssueCols(ctx context.Context, issue *Issue, cols ...string) error {
|
// UpdateIssueCols updates cols of issue
|
||||||
|
func UpdateIssueCols(ctx context.Context, issue *Issue, cols ...string) error {
|
||||||
if _, err := db.GetEngine(ctx).ID(issue.ID).Cols(cols...).Update(issue); err != nil {
|
if _, err := db.GetEngine(ctx).ID(issue.ID).Cols(cols...).Update(issue); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -658,7 +655,7 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
|
||||||
issue.ClosedUnix = 0
|
issue.ClosedUnix = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := updateIssueCols(ctx, issue, "is_closed", "closed_unix"); err != nil {
|
if err := UpdateIssueCols(ctx, issue, "is_closed", "closed_unix"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,7 +671,7 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
|
||||||
|
|
||||||
// Update issue count of milestone
|
// Update issue count of milestone
|
||||||
if issue.MilestoneID > 0 {
|
if issue.MilestoneID > 0 {
|
||||||
if err := updateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
|
if err := issues_model.UpdateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -691,7 +688,7 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
|
||||||
cmtType = CommentTypeMergePull
|
cmtType = CommentTypeMergePull
|
||||||
}
|
}
|
||||||
|
|
||||||
return createComment(ctx, &CreateCommentOptions{
|
return CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Type: cmtType,
|
Type: cmtType,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
@ -707,7 +704,7 @@ func ChangeIssueStatus(issue *Issue, doer *user_model.User, isClosed bool) (*Com
|
||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := issue.loadPoster(db.GetEngine(ctx)); err != nil {
|
if err := issue.loadPoster(db.GetEngine(ctx)); err != nil {
|
||||||
|
@ -734,11 +731,11 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err
|
||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
if err = updateIssueCols(ctx, issue, "name"); err != nil {
|
if err = UpdateIssueCols(ctx, issue, "name"); err != nil {
|
||||||
return fmt.Errorf("updateIssueCols: %v", err)
|
return fmt.Errorf("updateIssueCols: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return fmt.Errorf("loadRepo: %v", err)
|
return fmt.Errorf("loadRepo: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,7 +747,7 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err
|
||||||
OldTitle: oldTitle,
|
OldTitle: oldTitle,
|
||||||
NewTitle: issue.Title,
|
NewTitle: issue.Title,
|
||||||
}
|
}
|
||||||
if _, err = createComment(ctx, opts); err != nil {
|
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||||
return fmt.Errorf("createComment: %v", err)
|
return fmt.Errorf("createComment: %v", err)
|
||||||
}
|
}
|
||||||
if err = issue.addCrossReferences(ctx, doer, true); err != nil {
|
if err = issue.addCrossReferences(ctx, doer, true); err != nil {
|
||||||
|
@ -768,11 +765,11 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err
|
||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
if err = updateIssueCols(ctx, issue, "ref"); err != nil {
|
if err = UpdateIssueCols(ctx, issue, "ref"); err != nil {
|
||||||
return fmt.Errorf("updateIssueCols: %v", err)
|
return fmt.Errorf("updateIssueCols: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return fmt.Errorf("loadRepo: %v", err)
|
return fmt.Errorf("loadRepo: %v", err)
|
||||||
}
|
}
|
||||||
oldRefFriendly := strings.TrimPrefix(oldRef, git.BranchPrefix)
|
oldRefFriendly := strings.TrimPrefix(oldRef, git.BranchPrefix)
|
||||||
|
@ -786,7 +783,7 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err
|
||||||
OldRef: oldRefFriendly,
|
OldRef: oldRefFriendly,
|
||||||
NewRef: newRefFriendly,
|
NewRef: newRefFriendly,
|
||||||
}
|
}
|
||||||
if _, err = createComment(ctx, opts); err != nil {
|
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||||
return fmt.Errorf("createComment: %v", err)
|
return fmt.Errorf("createComment: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -811,7 +808,7 @@ func AddDeletePRBranchComment(doer *user_model.User, repo *repo_model.Repository
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
OldRef: branchName,
|
OldRef: branchName,
|
||||||
}
|
}
|
||||||
if _, err = createComment(ctx, opts); err != nil {
|
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -846,12 +843,12 @@ func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (er
|
||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
hasContentHistory, err := issues.HasIssueContentHistory(ctx, issue.ID, 0)
|
hasContentHistory, err := issues_model.HasIssueContentHistory(ctx, issue.ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("HasIssueContentHistory: %v", err)
|
return fmt.Errorf("HasIssueContentHistory: %v", err)
|
||||||
}
|
}
|
||||||
if !hasContentHistory {
|
if !hasContentHistory {
|
||||||
if err = issues.SaveIssueContentHistory(db.GetEngine(ctx), issue.PosterID, issue.ID, 0,
|
if err = issues_model.SaveIssueContentHistory(db.GetEngine(ctx), issue.PosterID, issue.ID, 0,
|
||||||
issue.CreatedUnix, issue.Content, true); err != nil {
|
issue.CreatedUnix, issue.Content, true); err != nil {
|
||||||
return fmt.Errorf("SaveIssueContentHistory: %v", err)
|
return fmt.Errorf("SaveIssueContentHistory: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -859,11 +856,11 @@ func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (er
|
||||||
|
|
||||||
issue.Content = content
|
issue.Content = content
|
||||||
|
|
||||||
if err = updateIssueCols(ctx, issue, "content"); err != nil {
|
if err = UpdateIssueCols(ctx, issue, "content"); err != nil {
|
||||||
return fmt.Errorf("UpdateIssueCols: %v", err)
|
return fmt.Errorf("UpdateIssueCols: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issues.SaveIssueContentHistory(db.GetEngine(ctx), doer.ID, issue.ID, 0,
|
if err = issues_model.SaveIssueContentHistory(db.GetEngine(ctx), doer.ID, issue.ID, 0,
|
||||||
timeutil.TimeStampNow(), issue.Content, false); err != nil {
|
timeutil.TimeStampNow(), issue.Content, false); err != nil {
|
||||||
return fmt.Errorf("SaveIssueContentHistory: %v", err)
|
return fmt.Errorf("SaveIssueContentHistory: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -943,8 +940,8 @@ func newIssue(ctx context.Context, doer *user_model.User, opts NewIssueOptions)
|
||||||
opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)
|
opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)
|
||||||
|
|
||||||
if opts.Issue.MilestoneID > 0 {
|
if opts.Issue.MilestoneID > 0 {
|
||||||
milestone, err := getMilestoneByRepoID(e, opts.Issue.RepoID, opts.Issue.MilestoneID)
|
milestone, err := issues_model.GetMilestoneByRepoID(ctx, opts.Issue.RepoID, opts.Issue.MilestoneID)
|
||||||
if err != nil && !IsErrMilestoneNotExist(err) {
|
if err != nil && !issues_model.IsErrMilestoneNotExist(err) {
|
||||||
return fmt.Errorf("getMilestoneByID: %v", err)
|
return fmt.Errorf("getMilestoneByID: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -968,7 +965,7 @@ func newIssue(ctx context.Context, doer *user_model.User, opts NewIssueOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Issue.MilestoneID > 0 {
|
if opts.Issue.MilestoneID > 0 {
|
||||||
if err := updateMilestoneCounters(ctx, opts.Issue.MilestoneID); err != nil {
|
if err := issues_model.UpdateMilestoneCounters(ctx, opts.Issue.MilestoneID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -980,7 +977,7 @@ func newIssue(ctx context.Context, doer *user_model.User, opts NewIssueOptions)
|
||||||
OldMilestoneID: 0,
|
OldMilestoneID: 0,
|
||||||
MilestoneID: opts.Issue.MilestoneID,
|
MilestoneID: opts.Issue.MilestoneID,
|
||||||
}
|
}
|
||||||
if _, err = createComment(ctx, opts); err != nil {
|
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1956,7 +1953,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
sess := db.GetEngine(ctx)
|
sess := db.GetEngine(ctx)
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return nil, false, fmt.Errorf("loadRepo: %v", err)
|
return nil, false, fmt.Errorf("loadRepo: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1983,7 +1980,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
|
||||||
OldTitle: currentIssue.Title,
|
OldTitle: currentIssue.Title,
|
||||||
NewTitle: issue.Title,
|
NewTitle: issue.Title,
|
||||||
}
|
}
|
||||||
_, err := createComment(ctx, opts)
|
_, err := CreateCommentCtx(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, fmt.Errorf("createComment: %v", err)
|
return nil, false, fmt.Errorf("createComment: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -2015,7 +2012,7 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
// Update the deadline
|
// Update the deadline
|
||||||
if err = updateIssueCols(ctx, &Issue{ID: issue.ID, DeadlineUnix: deadlineUnix}, "deadline_unix"); err != nil {
|
if err = UpdateIssueCols(ctx, &Issue{ID: issue.ID, DeadlineUnix: deadlineUnix}, "deadline_unix"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2104,14 +2101,14 @@ func deleteIssue(ctx context.Context, issue *Issue) error {
|
||||||
|
|
||||||
// delete all database data still assigned to this issue
|
// delete all database data still assigned to this issue
|
||||||
if err := deleteInIssue(e, issue.ID,
|
if err := deleteInIssue(e, issue.ID,
|
||||||
&issues.ContentHistory{},
|
&issues_model.ContentHistory{},
|
||||||
&Comment{},
|
&Comment{},
|
||||||
&IssueLabel{},
|
&IssueLabel{},
|
||||||
&IssueDependency{},
|
&IssueDependency{},
|
||||||
&IssueAssignees{},
|
&IssueAssignees{},
|
||||||
&IssueUser{},
|
&IssueUser{},
|
||||||
&Notification{},
|
&Notification{},
|
||||||
&issues.Reaction{},
|
&issues_model.Reaction{},
|
||||||
&IssueWatch{},
|
&IssueWatch{},
|
||||||
&Stopwatch{},
|
&Stopwatch{},
|
||||||
&TrackedTime{},
|
&TrackedTime{},
|
||||||
|
@ -2242,7 +2239,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
|
||||||
if len(mentions) == 0 {
|
if len(mentions) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2401,7 +2398,7 @@ func deleteIssuesByRepoID(sess db.Engine, repoID int64) (attachmentPaths []strin
|
||||||
|
|
||||||
// Delete content histories
|
// Delete content histories
|
||||||
if _, err = sess.In("issue_id", deleteCond).
|
if _, err = sess.In("issue_id", deleteCond).
|
||||||
Delete(&issues.ContentHistory{}); err != nil {
|
Delete(&issues_model.ContentHistory{}); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2429,7 +2426,7 @@ func deleteIssuesByRepoID(sess db.Engine, repoID int64) (attachmentPaths []strin
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = sess.In("issue_id", deleteCond).
|
if _, err = sess.In("issue_id", deleteCond).
|
||||||
Delete(&issues.Reaction{}); err != nil {
|
Delete(&issues_model.Reaction{}); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ func toggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.Use
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo infos
|
// Repo infos
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return false, nil, fmt.Errorf("loadRepo: %v", err)
|
return false, nil, fmt.Errorf("loadRepo: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ func toggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.Use
|
||||||
AssigneeID: assigneeID,
|
AssigneeID: assigneeID,
|
||||||
}
|
}
|
||||||
// Comment
|
// Comment
|
||||||
comment, err = createComment(ctx, opts)
|
comment, err = CreateCommentCtx(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, fmt.Errorf("createComment: %v", err)
|
return false, nil, fmt.Errorf("createComment: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
project_model "code.gitea.io/gitea/models/project"
|
project_model "code.gitea.io/gitea/models/project"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -209,8 +209,8 @@ type Comment struct {
|
||||||
Project *project_model.Project `xorm:"-"`
|
Project *project_model.Project `xorm:"-"`
|
||||||
OldMilestoneID int64
|
OldMilestoneID int64
|
||||||
MilestoneID int64
|
MilestoneID int64
|
||||||
OldMilestone *Milestone `xorm:"-"`
|
OldMilestone *issues_model.Milestone `xorm:"-"`
|
||||||
Milestone *Milestone `xorm:"-"`
|
Milestone *issues_model.Milestone `xorm:"-"`
|
||||||
TimeID int64
|
TimeID int64
|
||||||
Time *TrackedTime `xorm:"-"`
|
Time *TrackedTime `xorm:"-"`
|
||||||
AssigneeID int64
|
AssigneeID int64
|
||||||
|
@ -243,8 +243,8 @@ type Comment struct {
|
||||||
// Reference issue in commit message
|
// Reference issue in commit message
|
||||||
CommitSHA string `xorm:"VARCHAR(40)"`
|
CommitSHA string `xorm:"VARCHAR(40)"`
|
||||||
|
|
||||||
Attachments []*repo_model.Attachment `xorm:"-"`
|
Attachments []*repo_model.Attachment `xorm:"-"`
|
||||||
Reactions issues.ReactionList `xorm:"-"`
|
Reactions issues_model.ReactionList `xorm:"-"`
|
||||||
|
|
||||||
// For view issue page.
|
// For view issue page.
|
||||||
ShowRole RoleDescriptor `xorm:"-"`
|
ShowRole RoleDescriptor `xorm:"-"`
|
||||||
|
@ -358,7 +358,7 @@ func (c *Comment) HTMLURL() string {
|
||||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
err = c.Issue.loadRepo(db.DefaultContext)
|
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||||
if err != nil { // Silently dropping errors :unamused:
|
if err != nil { // Silently dropping errors :unamused:
|
||||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||||
return ""
|
return ""
|
||||||
|
@ -387,7 +387,7 @@ func (c *Comment) APIURL() string {
|
||||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
err = c.Issue.loadRepo(db.DefaultContext)
|
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||||
if err != nil { // Silently dropping errors :unamused:
|
if err != nil { // Silently dropping errors :unamused:
|
||||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||||
return ""
|
return ""
|
||||||
|
@ -408,7 +408,7 @@ func (c *Comment) IssueURL() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Issue.loadRepo(db.DefaultContext)
|
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||||
if err != nil { // Silently dropping errors :unamused:
|
if err != nil { // Silently dropping errors :unamused:
|
||||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||||
return ""
|
return ""
|
||||||
|
@ -424,7 +424,7 @@ func (c *Comment) PRURL() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Issue.loadRepo(db.DefaultContext)
|
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||||
if err != nil { // Silently dropping errors :unamused:
|
if err != nil { // Silently dropping errors :unamused:
|
||||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||||
return ""
|
return ""
|
||||||
|
@ -495,7 +495,7 @@ func (c *Comment) LoadProject() error {
|
||||||
// LoadMilestone if comment.Type is CommentTypeMilestone, then load milestone
|
// LoadMilestone if comment.Type is CommentTypeMilestone, then load milestone
|
||||||
func (c *Comment) LoadMilestone() error {
|
func (c *Comment) LoadMilestone() error {
|
||||||
if c.OldMilestoneID > 0 {
|
if c.OldMilestoneID > 0 {
|
||||||
var oldMilestone Milestone
|
var oldMilestone issues_model.Milestone
|
||||||
has, err := db.GetEngine(db.DefaultContext).ID(c.OldMilestoneID).Get(&oldMilestone)
|
has, err := db.GetEngine(db.DefaultContext).ID(c.OldMilestoneID).Get(&oldMilestone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -505,7 +505,7 @@ func (c *Comment) LoadMilestone() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.MilestoneID > 0 {
|
if c.MilestoneID > 0 {
|
||||||
var milestone Milestone
|
var milestone issues_model.Milestone
|
||||||
has, err := db.GetEngine(db.DefaultContext).ID(c.MilestoneID).Get(&milestone)
|
has, err := db.GetEngine(db.DefaultContext).ID(c.MilestoneID).Get(&milestone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -574,7 +574,7 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.Issue.LoadRepo(); err != nil {
|
if err = c.Issue.LoadRepo(db.DefaultContext); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,7 +635,7 @@ func (c *Comment) loadReactions(ctx context.Context, repo *repo_model.Repository
|
||||||
if c.Reactions != nil {
|
if c.Reactions != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c.Reactions, _, err = issues.FindReactions(ctx, issues.FindReactionsOptions{
|
c.Reactions, _, err = issues_model.FindReactions(ctx, issues_model.FindReactionsOptions{
|
||||||
IssueID: c.IssueID,
|
IssueID: c.IssueID,
|
||||||
CommentID: c.ID,
|
CommentID: c.ID,
|
||||||
})
|
})
|
||||||
|
@ -717,7 +717,7 @@ func (c *Comment) CodeCommentURL() string {
|
||||||
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
log.Error("LoadIssue(%d): %v", c.IssueID, err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
err = c.Issue.loadRepo(db.DefaultContext)
|
err = c.Issue.LoadRepo(db.DefaultContext)
|
||||||
if err != nil { // Silently dropping errors :unamused:
|
if err != nil { // Silently dropping errors :unamused:
|
||||||
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
|
||||||
return ""
|
return ""
|
||||||
|
@ -761,7 +761,8 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createComment(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, err error) {
|
// CreateCommentCtx creates comment with context
|
||||||
|
func CreateCommentCtx(ctx context.Context, opts *CreateCommentOptions) (_ *Comment, err error) {
|
||||||
e := db.GetEngine(ctx)
|
e := db.GetEngine(ctx)
|
||||||
var LabelID int64
|
var LabelID int64
|
||||||
if opts.Label != nil {
|
if opts.Label != nil {
|
||||||
|
@ -863,7 +864,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// update the issue's updated_unix column
|
// update the issue's updated_unix column
|
||||||
return updateIssueCols(ctx, opts.Issue, "updated_unix")
|
return UpdateIssueCols(ctx, opts.Issue, "updated_unix")
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) {
|
func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) {
|
||||||
|
@ -884,7 +885,7 @@ func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Is
|
||||||
content = newDeadlineUnix.Format("2006-01-02") + "|" + issue.DeadlineUnix.Format("2006-01-02")
|
content = newDeadlineUnix.Format("2006-01-02") + "|" + issue.DeadlineUnix.Format("2006-01-02")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -895,7 +896,7 @@ func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Is
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Content: content,
|
Content: content,
|
||||||
}
|
}
|
||||||
comment, err := createComment(ctx, opts)
|
comment, err := CreateCommentCtx(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -908,7 +909,7 @@ func createIssueDependencyComment(ctx context.Context, doer *user_model.User, is
|
||||||
if !add {
|
if !add {
|
||||||
cType = CommentTypeRemoveDependency
|
cType = CommentTypeRemoveDependency
|
||||||
}
|
}
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -920,7 +921,7 @@ func createIssueDependencyComment(ctx context.Context, doer *user_model.User, is
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
DependentIssueID: dependentIssue.ID,
|
DependentIssueID: dependentIssue.ID,
|
||||||
}
|
}
|
||||||
if _, err = createComment(ctx, opts); err != nil {
|
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,7 +932,7 @@ func createIssueDependencyComment(ctx context.Context, doer *user_model.User, is
|
||||||
Issue: dependentIssue,
|
Issue: dependentIssue,
|
||||||
DependentIssueID: issue.ID,
|
DependentIssueID: issue.ID,
|
||||||
}
|
}
|
||||||
_, err = createComment(ctx, opts)
|
_, err = CreateCommentCtx(ctx, opts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -981,7 +982,7 @@ func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
|
||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
comment, err = createComment(ctx, opts)
|
comment, err = CreateCommentCtx(ctx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1159,7 +1160,7 @@ func deleteComment(ctx context.Context, comment *Comment) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := e.Delete(&issues.ContentHistory{
|
if _, err := e.Delete(&issues_model.ContentHistory{
|
||||||
CommentID: comment.ID,
|
CommentID: comment.ID,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1178,7 +1179,7 @@ func deleteComment(ctx context.Context, comment *Comment) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return issues.DeleteReaction(ctx, &issues.ReactionOptions{CommentID: comment.ID})
|
return issues_model.DeleteReaction(ctx, &issues_model.ReactionOptions{CommentID: comment.ID})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS
|
// CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS
|
||||||
|
@ -1230,7 +1231,7 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
|
@ -139,7 +140,7 @@ func (comments CommentList) loadMilestones(e db.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
milestoneMaps := make(map[int64]*Milestone, len(milestoneIDs))
|
milestoneMaps := make(map[int64]*issues_model.Milestone, len(milestoneIDs))
|
||||||
left := len(milestoneIDs)
|
left := len(milestoneIDs)
|
||||||
for left > 0 {
|
for left > 0 {
|
||||||
limit := defaultMaxInSize
|
limit := defaultMaxInSize
|
||||||
|
@ -182,7 +183,7 @@ func (comments CommentList) loadOldMilestones(e db.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
milestoneMaps := make(map[int64]*Milestone, len(milestoneIDs))
|
milestoneMaps := make(map[int64]*issues_model.Milestone, len(milestoneIDs))
|
||||||
left := len(milestoneIDs)
|
left := len(milestoneIDs)
|
||||||
for left > 0 {
|
for left > 0 {
|
||||||
limit := defaultMaxInSize
|
limit := defaultMaxInSize
|
||||||
|
@ -387,7 +388,7 @@ func (comments CommentList) loadDependentIssues(ctx context.Context) error {
|
||||||
if comment.DependentIssue == nil {
|
if comment.DependentIssue == nil {
|
||||||
comment.DependentIssue = issues[comment.DependentIssueID]
|
comment.DependentIssue = issues[comment.DependentIssueID]
|
||||||
if comment.DependentIssue != nil {
|
if comment.DependentIssue != nil {
|
||||||
if err := comment.DependentIssue.loadRepo(ctx); err != nil {
|
if err := comment.DependentIssue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -586,7 +586,7 @@ func newIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *user_m
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ func newIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *user_m
|
||||||
Label: label,
|
Label: label,
|
||||||
Content: "1",
|
Content: "1",
|
||||||
}
|
}
|
||||||
if _, err = createComment(ctx, opts); err != nil {
|
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,7 +618,7 @@ func NewIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
sess := db.GetEngine(ctx)
|
sess := db.GetEngine(ctx)
|
||||||
|
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,7 +642,7 @@ func NewIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error
|
||||||
// newIssueLabels add labels to an issue. It will check if the labels are valid for the issue
|
// newIssueLabels add labels to an issue. It will check if the labels are valid for the issue
|
||||||
func newIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *user_model.User) (err error) {
|
func newIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *user_model.User) (err error) {
|
||||||
e := db.GetEngine(ctx)
|
e := db.GetEngine(ctx)
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
|
@ -691,7 +691,7 @@ func deleteIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *use
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue.loadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -702,7 +702,7 @@ func deleteIssueLabel(ctx context.Context, issue *Issue, label *Label, doer *use
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Label: label,
|
Label: label,
|
||||||
}
|
}
|
||||||
if _, err = createComment(ctx, opts); err != nil {
|
if _, err = CreateCommentCtx(ctx, opts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
|
@ -199,7 +200,7 @@ func (issues IssueList) loadMilestones(e db.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
milestoneMaps := make(map[int64]*Milestone, len(milestoneIDs))
|
milestoneMaps := make(map[int64]*issues_model.Milestone, len(milestoneIDs))
|
||||||
left := len(milestoneIDs)
|
left := len(milestoneIDs)
|
||||||
for left > 0 {
|
for left > 0 {
|
||||||
limit := defaultMaxInSize
|
limit := defaultMaxInSize
|
||||||
|
|
|
@ -46,7 +46,7 @@ func updateIssueLock(opts *IssueLockOptions, lock bool) error {
|
||||||
}
|
}
|
||||||
defer committer.Close()
|
defer committer.Close()
|
||||||
|
|
||||||
if err := updateIssueCols(ctx, opts.Issue, "is_locked"); err != nil {
|
if err := UpdateIssueCols(ctx, opts.Issue, "is_locked"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func updateIssueLock(opts *IssueLockOptions, lock bool) error {
|
||||||
Type: commentType,
|
Type: commentType,
|
||||||
Content: opts.Reason,
|
Content: opts.Reason,
|
||||||
}
|
}
|
||||||
if _, err := createComment(ctx, opt); err != nil {
|
if _, err := CreateCommentCtx(ctx, opt); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,12 +129,12 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldProjectID > 0 || newProjectID > 0 {
|
if oldProjectID > 0 || newProjectID > 0 {
|
||||||
if _, err := createComment(ctx, &CreateCommentOptions{
|
if _, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Type: CommentTypeProject,
|
Type: CommentTypeProject,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
|
|
@ -157,11 +157,11 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := createComment(ctx, &CreateCommentOptions{
|
if _, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Doer: user,
|
Doer: user,
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
@ -178,7 +178,7 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss
|
||||||
// CreateIssueStopwatch creates a stopwatch if not exist, otherwise return an error
|
// CreateIssueStopwatch creates a stopwatch if not exist, otherwise return an error
|
||||||
func CreateIssueStopwatch(ctx context.Context, user *user_model.User, issue *Issue) error {
|
func CreateIssueStopwatch(ctx context.Context, user *user_model.User, issue *Issue) error {
|
||||||
e := db.GetEngine(ctx)
|
e := db.GetEngine(ctx)
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,11 +208,11 @@ func CreateIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := createComment(ctx, &CreateCommentOptions{
|
if _, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Doer: user,
|
Doer: user,
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
@ -249,11 +249,11 @@ func cancelStopwatch(ctx context.Context, user *user_model.User, issue *Issue) e
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := createComment(ctx, &CreateCommentOptions{
|
if _, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Doer: user,
|
Doer: user,
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/foreignreference"
|
"code.gitea.io/gitea/models/foreignreference"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -132,7 +133,7 @@ func TestUpdateIssueCols(t *testing.T) {
|
||||||
issue.Content = "This should have no effect"
|
issue.Content = "This should have no effect"
|
||||||
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
assert.NoError(t, updateIssueCols(db.DefaultContext, issue, "name"))
|
assert.NoError(t, UpdateIssueCols(db.DefaultContext, issue, "name"))
|
||||||
then := time.Now().Unix()
|
then := time.Now().Unix()
|
||||||
|
|
||||||
updatedIssue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue)
|
updatedIssue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue)
|
||||||
|
@ -568,3 +569,23 @@ func TestIssueForeignReference(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, found.Index, issue.Index)
|
assert.EqualValues(t, found.Index, issue.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMilestoneList_LoadTotalTrackedTimes(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
miles := issues_model.MilestoneList{
|
||||||
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}).(*issues_model.Milestone),
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, miles.LoadTotalTrackedTimes())
|
||||||
|
|
||||||
|
assert.Equal(t, int64(3682), miles[0].TotalTrackedTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLoadTotalTrackedTime(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}).(*issues_model.Milestone)
|
||||||
|
|
||||||
|
assert.NoError(t, milestone.LoadTotalTrackedTime())
|
||||||
|
|
||||||
|
assert.Equal(t, int64(3682), milestone.TotalTrackedTime)
|
||||||
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ func (t *TrackedTime) loadAttributes(ctx context.Context) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = t.Issue.loadRepo(ctx)
|
err = t.Issue.LoadRepo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -170,11 +170,11 @@ func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Tim
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := createComment(ctx, &CreateCommentOptions{
|
if _, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
Doer: user,
|
Doer: user,
|
||||||
|
@ -254,10 +254,10 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error {
|
||||||
return ErrNotExist{}
|
return ErrNotExist{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := createComment(ctx, &CreateCommentOptions{
|
if _, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
Doer: user,
|
Doer: user,
|
||||||
|
@ -286,7 +286,7 @@ func DeleteTime(t *TrackedTime) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := createComment(ctx, &CreateCommentOptions{
|
if _, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Issue: t.Issue,
|
Issue: t.Issue,
|
||||||
Repo: t.Issue.Repo,
|
Repo: t.Issue.Repo,
|
||||||
Doer: t.User,
|
Doer: t.User,
|
||||||
|
|
|
@ -129,7 +129,7 @@ func (issue *Issue) createCrossReferences(stdCtx context.Context, ctx *crossRefe
|
||||||
RefAction: xref.Action,
|
RefAction: xref.Action,
|
||||||
RefIsPull: ctx.OrigIssue.IsPull,
|
RefIsPull: ctx.OrigIssue.IsPull,
|
||||||
}
|
}
|
||||||
_, err := createComment(stdCtx, opts)
|
_, err := CreateCommentCtx(stdCtx, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ func (issue *Issue) getCrossReferences(stdCtx context.Context, ctx *crossReferen
|
||||||
for _, ref := range allrefs {
|
for _, ref := range allrefs {
|
||||||
if ref.Owner == "" && ref.Name == "" {
|
if ref.Owner == "" && ref.Name == "" {
|
||||||
// Issues in the same repository
|
// Issues in the same repository
|
||||||
if err := ctx.OrigIssue.loadRepo(stdCtx); err != nil {
|
if err := ctx.OrigIssue.LoadRepo(stdCtx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
refRepo = ctx.OrigIssue.Repo
|
refRepo = ctx.OrigIssue.Repo
|
||||||
|
@ -204,7 +204,7 @@ func (issue *Issue) verifyReferencedIssue(stdCtx context.Context, ctx *crossRefe
|
||||||
if has, _ := e.Get(refIssue); !has {
|
if has, _ := e.Get(refIssue); !has {
|
||||||
return nil, references.XRefActionNone, nil
|
return nil, references.XRefActionNone, nil
|
||||||
}
|
}
|
||||||
if err := refIssue.loadRepo(stdCtx); err != nil {
|
if err := refIssue.LoadRepo(stdCtx); err != nil {
|
||||||
return nil, references.XRefActionNone, err
|
return nil, references.XRefActionNone, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ func (comment *Comment) LoadRefIssue() (err error) {
|
||||||
}
|
}
|
||||||
comment.RefIssue, err = GetIssueByID(comment.RefIssueID)
|
comment.RefIssue, err = GetIssueByID(comment.RefIssueID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = comment.RefIssue.loadRepo(db.DefaultContext)
|
err = comment.RefIssue.LoadRepo(db.DefaultContext)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,6 @@ func TestMain(m *testing.M) {
|
||||||
"reaction.yml",
|
"reaction.yml",
|
||||||
"user.yml",
|
"user.yml",
|
||||||
"repository.yml",
|
"repository.yml",
|
||||||
|
"milestone.yml",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package models
|
package issues
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -12,7 +12,6 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
@ -20,6 +19,26 @@ import (
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
|
||||||
|
type ErrMilestoneNotExist struct {
|
||||||
|
ID int64
|
||||||
|
RepoID int64
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
|
||||||
|
func IsErrMilestoneNotExist(err error) bool {
|
||||||
|
_, ok := err.(ErrMilestoneNotExist)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrMilestoneNotExist) Error() string {
|
||||||
|
if len(err.Name) > 0 {
|
||||||
|
return fmt.Sprintf("milestone does not exist [name: %s, repo_id: %d]", err.Name, err.RepoID)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
|
||||||
|
}
|
||||||
|
|
||||||
// Milestone represents a milestone of repository.
|
// Milestone represents a milestone of repository.
|
||||||
type Milestone struct {
|
type Milestone struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
|
@ -105,9 +124,10 @@ func NewMilestone(m *Milestone) (err error) {
|
||||||
return committer.Commit()
|
return committer.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMilestoneByRepoID(e db.Engine, repoID, id int64) (*Milestone, error) {
|
// GetMilestoneByRepoID returns the milestone in a repository.
|
||||||
|
func GetMilestoneByRepoID(ctx context.Context, repoID, id int64) (*Milestone, error) {
|
||||||
m := new(Milestone)
|
m := new(Milestone)
|
||||||
has, err := e.ID(id).Where("repo_id=?", repoID).Get(m)
|
has, err := db.GetEngine(ctx).ID(id).Where("repo_id=?", repoID).Get(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
|
@ -116,11 +136,6 @@ func getMilestoneByRepoID(e db.Engine, repoID, id int64) (*Milestone, error) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMilestoneByRepoID returns the milestone in a repository.
|
|
||||||
func GetMilestoneByRepoID(repoID, id int64) (*Milestone, error) {
|
|
||||||
return getMilestoneByRepoID(db.GetEngine(db.DefaultContext), repoID, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMilestoneByRepoIDANDName return a milestone if one exist by name and repo
|
// GetMilestoneByRepoIDANDName return a milestone if one exist by name and repo
|
||||||
func GetMilestoneByRepoIDANDName(repoID int64, name string) (*Milestone, error) {
|
func GetMilestoneByRepoIDANDName(repoID int64, name string) (*Milestone, error) {
|
||||||
var mile Milestone
|
var mile Milestone
|
||||||
|
@ -166,11 +181,11 @@ func updateMilestone(ctx context.Context, m *Milestone) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return updateMilestoneCounters(ctx, m.ID)
|
return UpdateMilestoneCounters(ctx, m.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateMilestoneCounters calculates NumIssues, NumClosesIssues and Completeness
|
// UpdateMilestoneCounters calculates NumIssues, NumClosesIssues and Completeness
|
||||||
func updateMilestoneCounters(ctx context.Context, id int64) error {
|
func UpdateMilestoneCounters(ctx context.Context, id int64) error {
|
||||||
e := db.GetEngine(ctx)
|
e := db.GetEngine(ctx)
|
||||||
_, err := e.ID(id).
|
_, err := e.ID(id).
|
||||||
SetExpr("num_issues", builder.Select("count(*)").From("issue").Where(
|
SetExpr("num_issues", builder.Select("count(*)").From("issue").Where(
|
||||||
|
@ -250,65 +265,9 @@ func changeMilestoneStatus(ctx context.Context, m *Milestone, isClosed bool) err
|
||||||
return updateRepoMilestoneNum(ctx, m.RepoID)
|
return updateRepoMilestoneNum(ctx, m.RepoID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *Issue, oldMilestoneID int64) error {
|
|
||||||
if err := updateIssueCols(ctx, issue, "milestone_id"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if oldMilestoneID > 0 {
|
|
||||||
if err := updateMilestoneCounters(ctx, oldMilestoneID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if issue.MilestoneID > 0 {
|
|
||||||
if err := updateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if oldMilestoneID > 0 || issue.MilestoneID > 0 {
|
|
||||||
if err := issue.loadRepo(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := &CreateCommentOptions{
|
|
||||||
Type: CommentTypeMilestone,
|
|
||||||
Doer: doer,
|
|
||||||
Repo: issue.Repo,
|
|
||||||
Issue: issue,
|
|
||||||
OldMilestoneID: oldMilestoneID,
|
|
||||||
MilestoneID: issue.MilestoneID,
|
|
||||||
}
|
|
||||||
if _, err := createComment(ctx, opts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
|
||||||
func ChangeMilestoneAssign(issue *Issue, doer *user_model.User, oldMilestoneID int64) (err error) {
|
|
||||||
ctx, committer, err := db.TxContext()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer committer.Close()
|
|
||||||
|
|
||||||
if err = changeMilestoneAssign(ctx, doer, issue, oldMilestoneID); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = committer.Commit(); err != nil {
|
|
||||||
return fmt.Errorf("Commit: %v", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteMilestoneByRepoID deletes a milestone from a repository.
|
// DeleteMilestoneByRepoID deletes a milestone from a repository.
|
||||||
func DeleteMilestoneByRepoID(repoID, id int64) error {
|
func DeleteMilestoneByRepoID(repoID, id int64) error {
|
||||||
m, err := GetMilestoneByRepoID(repoID, id)
|
m, err := GetMilestoneByRepoID(db.DefaultContext, repoID, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if IsErrMilestoneNotExist(err) {
|
if IsErrMilestoneNotExist(err) {
|
||||||
return nil
|
return nil
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package models
|
package issues
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -11,10 +11,8 @@ import (
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
|
@ -25,28 +23,15 @@ func TestMilestone_State(t *testing.T) {
|
||||||
assert.Equal(t, api.StateClosed, (&Milestone{IsClosed: true}).State())
|
assert.Equal(t, api.StateClosed, (&Milestone{IsClosed: true}).State())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewMilestone(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
milestone := &Milestone{
|
|
||||||
RepoID: 1,
|
|
||||||
Name: "milestoneName",
|
|
||||||
Content: "milestoneContent",
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.NoError(t, NewMilestone(milestone))
|
|
||||||
unittest.AssertExistsAndLoadBean(t, milestone)
|
|
||||||
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &Milestone{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetMilestoneByRepoID(t *testing.T) {
|
func TestGetMilestoneByRepoID(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
milestone, err := GetMilestoneByRepoID(1, 1)
|
milestone, err := GetMilestoneByRepoID(db.DefaultContext, 1, 1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, milestone.ID)
|
assert.EqualValues(t, 1, milestone.ID)
|
||||||
assert.EqualValues(t, 1, milestone.RepoID)
|
assert.EqualValues(t, 1, milestone.RepoID)
|
||||||
|
|
||||||
_, err = GetMilestoneByRepoID(unittest.NonexistentID, unittest.NonexistentID)
|
_, err = GetMilestoneByRepoID(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID)
|
||||||
assert.True(t, IsErrMilestoneNotExist(err))
|
assert.True(t, IsErrMilestoneNotExist(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,18 +145,6 @@ func TestGetMilestones(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateMilestone(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
|
|
||||||
milestone := unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
|
||||||
milestone.Name = " newMilestoneName "
|
|
||||||
milestone.Content = "newMilestoneContent"
|
|
||||||
assert.NoError(t, UpdateMilestone(milestone, milestone.IsClosed))
|
|
||||||
milestone = unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
|
||||||
assert.EqualValues(t, "newMilestoneName", milestone.Name)
|
|
||||||
unittest.CheckConsistencyFor(t, &Milestone{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCountRepoMilestones(t *testing.T) {
|
func TestCountRepoMilestones(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
test := func(repoID int64) {
|
test := func(repoID int64) {
|
||||||
|
@ -206,78 +179,6 @@ func TestCountRepoClosedMilestones(t *testing.T) {
|
||||||
assert.EqualValues(t, 0, count)
|
assert.EqualValues(t, 0, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChangeMilestoneStatus(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
milestone := unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
|
||||||
|
|
||||||
assert.NoError(t, ChangeMilestoneStatus(milestone, true))
|
|
||||||
unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}, "is_closed=1")
|
|
||||||
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &Milestone{})
|
|
||||||
|
|
||||||
assert.NoError(t, ChangeMilestoneStatus(milestone, false))
|
|
||||||
unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}, "is_closed=0")
|
|
||||||
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: milestone.RepoID}, &Milestone{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUpdateMilestoneCounters(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
issue := unittest.AssertExistsAndLoadBean(t, &Issue{MilestoneID: 1},
|
|
||||||
"is_closed=0").(*Issue)
|
|
||||||
|
|
||||||
issue.IsClosed = true
|
|
||||||
issue.ClosedUnix = timeutil.TimeStampNow()
|
|
||||||
_, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NoError(t, updateMilestoneCounters(db.DefaultContext, issue.MilestoneID))
|
|
||||||
unittest.CheckConsistencyFor(t, &Milestone{})
|
|
||||||
|
|
||||||
issue.IsClosed = false
|
|
||||||
issue.ClosedUnix = 0
|
|
||||||
_, err = db.GetEngine(db.DefaultContext).ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NoError(t, updateMilestoneCounters(db.DefaultContext, issue.MilestoneID))
|
|
||||||
unittest.CheckConsistencyFor(t, &Milestone{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestChangeMilestoneAssign(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
issue := unittest.AssertExistsAndLoadBean(t, &Issue{RepoID: 1}).(*Issue)
|
|
||||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
|
||||||
assert.NotNil(t, issue)
|
|
||||||
assert.NotNil(t, doer)
|
|
||||||
|
|
||||||
oldMilestoneID := issue.MilestoneID
|
|
||||||
issue.MilestoneID = 2
|
|
||||||
assert.NoError(t, ChangeMilestoneAssign(issue, doer, oldMilestoneID))
|
|
||||||
unittest.AssertExistsAndLoadBean(t, &Comment{
|
|
||||||
IssueID: issue.ID,
|
|
||||||
Type: CommentTypeMilestone,
|
|
||||||
MilestoneID: issue.MilestoneID,
|
|
||||||
OldMilestoneID: oldMilestoneID,
|
|
||||||
})
|
|
||||||
unittest.CheckConsistencyFor(t, &Milestone{}, &Issue{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDeleteMilestoneByRepoID(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
assert.NoError(t, DeleteMilestoneByRepoID(1, 1))
|
|
||||||
unittest.AssertNotExistsBean(t, &Milestone{ID: 1})
|
|
||||||
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: 1})
|
|
||||||
|
|
||||||
assert.NoError(t, DeleteMilestoneByRepoID(unittest.NonexistentID, unittest.NonexistentID))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMilestoneList_LoadTotalTrackedTimes(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
miles := MilestoneList{
|
|
||||||
unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone),
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.NoError(t, miles.LoadTotalTrackedTimes())
|
|
||||||
|
|
||||||
assert.Equal(t, int64(3682), miles[0].TotalTrackedTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCountMilestonesByRepoIDs(t *testing.T) {
|
func TestCountMilestonesByRepoIDs(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
milestonesCount := func(repoID int64) (int, int) {
|
milestonesCount := func(repoID int64) (int, int) {
|
||||||
|
@ -343,15 +244,6 @@ func TestGetMilestonesByRepoIDs(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadTotalTrackedTime(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
milestone := unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
|
||||||
|
|
||||||
assert.NoError(t, milestone.LoadTotalTrackedTime())
|
|
||||||
|
|
||||||
assert.Equal(t, int64(3682), milestone.TotalTrackedTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetMilestonesStats(t *testing.T) {
|
func TestGetMilestonesStats(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
|
@ -7,6 +7,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
@ -29,7 +30,7 @@ func TestFixturesAreConsistent(t *testing.T) {
|
||||||
&repo_model.Repository{},
|
&repo_model.Repository{},
|
||||||
&Issue{},
|
&Issue{},
|
||||||
&PullRequest{},
|
&PullRequest{},
|
||||||
&Milestone{},
|
&issues_model.Milestone{},
|
||||||
&Label{},
|
&Label{},
|
||||||
&organization.Team{},
|
&organization.Team{},
|
||||||
&Action{})
|
&Action{})
|
||||||
|
|
|
@ -8,13 +8,14 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/modules/structs"
|
"code.gitea.io/gitea/modules/structs"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InsertMilestones creates milestones of repository.
|
// InsertMilestones creates milestones of repository.
|
||||||
func InsertMilestones(ms ...*Milestone) (err error) {
|
func InsertMilestones(ms ...*issues_model.Milestone) (err error) {
|
||||||
if len(ms) == 0 {
|
if len(ms) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/foreignreference"
|
"code.gitea.io/gitea/models/foreignreference"
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -22,7 +23,7 @@ func TestMigrate_InsertMilestones(t *testing.T) {
|
||||||
reponame := "repo1"
|
reponame := "repo1"
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}).(*repo_model.Repository)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}).(*repo_model.Repository)
|
||||||
name := "milestonetest1"
|
name := "milestonetest1"
|
||||||
ms := &Milestone{
|
ms := &issues_model.Milestone{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
Name: name,
|
Name: name,
|
||||||
}
|
}
|
||||||
|
@ -32,7 +33,7 @@ func TestMigrate_InsertMilestones(t *testing.T) {
|
||||||
repoModified := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID}).(*repo_model.Repository)
|
repoModified := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID}).(*repo_model.Repository)
|
||||||
assert.EqualValues(t, repo.NumMilestones+1, repoModified.NumMilestones)
|
assert.EqualValues(t, repo.NumMilestones+1, repoModified.NumMilestones)
|
||||||
|
|
||||||
unittest.CheckConsistencyFor(t, &Milestone{})
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertCreateIssues(t *testing.T, isPull bool) {
|
func assertCreateIssues(t *testing.T, isPull bool) {
|
||||||
|
@ -41,7 +42,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}).(*repo_model.Repository)
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}).(*repo_model.Repository)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
|
||||||
label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
|
label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
|
||||||
milestone := unittest.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}).(*issues_model.Milestone)
|
||||||
assert.EqualValues(t, milestone.ID, 1)
|
assert.EqualValues(t, milestone.ID, 1)
|
||||||
reaction := &issues_model.Reaction{
|
reaction := &issues_model.Reaction{
|
||||||
Type: "heart",
|
Type: "heart",
|
||||||
|
@ -90,7 +91,7 @@ func TestMigrate_CreateIssuesIsPullTrue(t *testing.T) {
|
||||||
func TestMigrate_InsertIssueComments(t *testing.T) {
|
func TestMigrate_InsertIssueComments(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||||
_ = issue.LoadRepo()
|
_ = issue.LoadRepo(db.DefaultContext)
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID}).(*user_model.User)
|
||||||
reaction := &issues_model.Reaction{
|
reaction := &issues_model.Reaction{
|
||||||
Type: "heart",
|
Type: "heart",
|
||||||
|
|
|
@ -255,7 +255,7 @@ func createOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = issue.loadRepo(ctx)
|
err = issue.LoadRepo(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,7 +407,7 @@ func (pr *PullRequest) SetMerged() (bool, error) {
|
||||||
return false, fmt.Errorf("PullRequest[%d] already closed", pr.Index)
|
return false, fmt.Errorf("PullRequest[%d] already closed", pr.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.Issue.loadRepo(ctx); err != nil {
|
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
admin_model "code.gitea.io/gitea/models/admin"
|
admin_model "code.gitea.io/gitea/models/admin"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
project_model "code.gitea.io/gitea/models/project"
|
project_model "code.gitea.io/gitea/models/project"
|
||||||
|
@ -698,7 +699,7 @@ func DeleteRepository(doer *user_model.User, uid, repoID int64) error {
|
||||||
&webhook.HookTask{RepoID: repoID},
|
&webhook.HookTask{RepoID: repoID},
|
||||||
&LFSLock{RepoID: repoID},
|
&LFSLock{RepoID: repoID},
|
||||||
&repo_model.LanguageStat{RepoID: repoID},
|
&repo_model.LanguageStat{RepoID: repoID},
|
||||||
&Milestone{RepoID: repoID},
|
&issues_model.Milestone{RepoID: repoID},
|
||||||
&repo_model.Mirror{RepoID: repoID},
|
&repo_model.Mirror{RepoID: repoID},
|
||||||
&Notification{RepoID: repoID},
|
&Notification{RepoID: repoID},
|
||||||
&ProtectedBranch{RepoID: repoID},
|
&ProtectedBranch{RepoID: repoID},
|
||||||
|
@ -945,10 +946,6 @@ func labelStatsCorrectNumClosedIssuesRepo(ctx context.Context, id int64) error {
|
||||||
|
|
||||||
var milestoneStatsQueryNumIssues = "SELECT `milestone`.id FROM `milestone` WHERE `milestone`.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE `issue`.milestone_id=`milestone`.id AND `issue`.is_closed=?) OR `milestone`.num_issues!=(SELECT COUNT(*) FROM `issue` WHERE `issue`.milestone_id=`milestone`.id)"
|
var milestoneStatsQueryNumIssues = "SELECT `milestone`.id FROM `milestone` WHERE `milestone`.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE `issue`.milestone_id=`milestone`.id AND `issue`.is_closed=?) OR `milestone`.num_issues!=(SELECT COUNT(*) FROM `issue` WHERE `issue`.milestone_id=`milestone`.id)"
|
||||||
|
|
||||||
func milestoneStatsCorrectNumIssues(ctx context.Context, id int64) error {
|
|
||||||
return updateMilestoneCounters(ctx, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func milestoneStatsCorrectNumIssuesRepo(ctx context.Context, id int64) error {
|
func milestoneStatsCorrectNumIssuesRepo(ctx context.Context, id int64) error {
|
||||||
e := db.GetEngine(ctx)
|
e := db.GetEngine(ctx)
|
||||||
results, err := e.Query(milestoneStatsQueryNumIssues+" AND `milestone`.repo_id = ?", true, id)
|
results, err := e.Query(milestoneStatsQueryNumIssues+" AND `milestone`.repo_id = ?", true, id)
|
||||||
|
@ -957,7 +954,7 @@ func milestoneStatsCorrectNumIssuesRepo(ctx context.Context, id int64) error {
|
||||||
}
|
}
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
|
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
|
||||||
err = milestoneStatsCorrectNumIssues(ctx, id)
|
err = issues_model.UpdateMilestoneCounters(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1049,7 +1046,7 @@ func CheckRepoStats(ctx context.Context) error {
|
||||||
// Milestone.Num{,Closed}Issues
|
// Milestone.Num{,Closed}Issues
|
||||||
{
|
{
|
||||||
statsQuery(milestoneStatsQueryNumIssues, true),
|
statsQuery(milestoneStatsQueryNumIssues, true),
|
||||||
milestoneStatsCorrectNumIssues,
|
issues_model.UpdateMilestoneCounters,
|
||||||
"milestone count 'num_closed_issues' and 'num_issues'",
|
"milestone count 'num_closed_issues' and 'num_issues'",
|
||||||
},
|
},
|
||||||
// User.NumRepos
|
// User.NumRepos
|
||||||
|
|
|
@ -427,7 +427,7 @@ func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
comm, err := createComment(ctx, &CreateCommentOptions{
|
comm, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Type: CommentTypeReview,
|
Type: CommentTypeReview,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Content: review.Content,
|
Content: review.Content,
|
||||||
|
@ -662,7 +662,7 @@ func AddReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Comment,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err := createComment(ctx, &CreateCommentOptions{
|
comment, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Type: CommentTypeReviewRequest,
|
Type: CommentTypeReviewRequest,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
@ -717,7 +717,7 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err := createComment(ctx, &CreateCommentOptions{
|
comment, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Type: CommentTypeReviewRequest,
|
Type: CommentTypeReviewRequest,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
@ -776,7 +776,7 @@ func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err := createComment(ctx, &CreateCommentOptions{
|
comment, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Type: CommentTypeReviewRequest,
|
Type: CommentTypeReviewRequest,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
@ -786,7 +786,7 @@ func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_
|
||||||
ReviewID: review.ID,
|
ReviewID: review.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("createComment(): %v", err)
|
return nil, fmt.Errorf("CreateCommentCtx(): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return comment, committer.Commit()
|
return comment, committer.Commit()
|
||||||
|
@ -837,7 +837,7 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *us
|
||||||
return nil, committer.Commit()
|
return nil, committer.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
comment, err := createComment(ctx, &CreateCommentOptions{
|
comment, err := CreateCommentCtx(ctx, &CreateCommentOptions{
|
||||||
Type: CommentTypeReviewRequest,
|
Type: CommentTypeReviewRequest,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: issue.Repo,
|
Repo: issue.Repo,
|
||||||
|
@ -846,7 +846,7 @@ func RemoveTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *us
|
||||||
AssigneeTeamID: reviewer.ID, // Use AssigneeTeamID as reviewer team ID
|
AssigneeTeamID: reviewer.ID, // Use AssigneeTeamID as reviewer team ID
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("createComment(): %v", err)
|
return nil, fmt.Errorf("CreateCommentCtx(): %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return comment, committer.Commit()
|
return comment, committer.Commit()
|
||||||
|
@ -887,7 +887,7 @@ func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
if doer.ID != issue.PosterID {
|
if doer.ID != issue.PosterID {
|
||||||
if err = issue.LoadRepo(); err != nil {
|
if err = issue.LoadRepo(db.DefaultContext); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
"code.gitea.io/gitea/models/auth"
|
"code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
project_model "code.gitea.io/gitea/models/project"
|
project_model "code.gitea.io/gitea/models/project"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -102,7 +103,7 @@ func GetStatistic() (stats Statistic) {
|
||||||
stats.Counter.Release, _ = e.Count(new(Release))
|
stats.Counter.Release, _ = e.Count(new(Release))
|
||||||
stats.Counter.AuthSource = auth.CountSources()
|
stats.Counter.AuthSource = auth.CountSources()
|
||||||
stats.Counter.Webhook, _ = e.Count(new(webhook.Webhook))
|
stats.Counter.Webhook, _ = e.Count(new(webhook.Webhook))
|
||||||
stats.Counter.Milestone, _ = e.Count(new(Milestone))
|
stats.Counter.Milestone, _ = e.Count(new(issues_model.Milestone))
|
||||||
stats.Counter.Label, _ = e.Count(new(Label))
|
stats.Counter.Label, _ = e.Count(new(Label))
|
||||||
stats.Counter.HookTask, _ = e.Count(new(webhook.HookTask))
|
stats.Counter.HookTask, _ = e.Count(new(webhook.HookTask))
|
||||||
stats.Counter.Team, _ = e.Count(new(organization.Team))
|
stats.Counter.Team, _ = e.Count(new(organization.Team))
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
@ -29,7 +30,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
|
||||||
if err := issue.LoadPoster(); err != nil {
|
if err := issue.LoadPoster(); err != nil {
|
||||||
return &api.Issue{}
|
return &api.Issue{}
|
||||||
}
|
}
|
||||||
if err := issue.LoadRepo(); err != nil {
|
if err := issue.LoadRepo(db.DefaultContext); err != nil {
|
||||||
return &api.Issue{}
|
return &api.Issue{}
|
||||||
}
|
}
|
||||||
if err := issue.Repo.GetOwner(db.DefaultContext); err != nil {
|
if err := issue.Repo.GetOwner(db.DefaultContext); err != nil {
|
||||||
|
@ -214,7 +215,7 @@ func ToLabelList(labels []*models.Label, repo *repo_model.Repository, org *user_
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToAPIMilestone converts Milestone into API Format
|
// ToAPIMilestone converts Milestone into API Format
|
||||||
func ToAPIMilestone(m *models.Milestone) *api.Milestone {
|
func ToAPIMilestone(m *issues_model.Milestone) *api.Milestone {
|
||||||
apiMilestone := &api.Milestone{
|
apiMilestone := &api.Milestone{
|
||||||
ID: m.ID,
|
ID: m.ID,
|
||||||
State: m.State(),
|
State: m.State(),
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
@ -32,7 +33,7 @@ func TestLabel_ToLabel(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMilestone_APIFormat(t *testing.T) {
|
func TestMilestone_APIFormat(t *testing.T) {
|
||||||
milestone := &models.Milestone{
|
milestone := &issues_model.Milestone{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
RepoID: 4,
|
RepoID: 4,
|
||||||
Name: "milestoneName",
|
Name: "milestoneName",
|
||||||
|
|
|
@ -27,7 +27,7 @@ func ToAPIPullRequest(ctx context.Context, pr *models.PullRequest, doer *user_mo
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
if err = pr.Issue.LoadRepo(); err != nil {
|
if err = pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error("pr.Issue.LoadRepo[%d]: %v", pr.ID, err)
|
log.Error("pr.Issue.LoadRepo[%d]: %v", pr.ID, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/graceful"
|
"code.gitea.io/gitea/modules/graceful"
|
||||||
|
@ -37,7 +38,7 @@ func (a *actionNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_mo
|
||||||
log.Error("issue.LoadPoster: %v", err)
|
log.Error("issue.LoadPoster: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := issue.LoadRepo(); err != nil {
|
if err := issue.LoadRepo(db.DefaultContext); err != nil {
|
||||||
log.Error("issue.LoadRepo: %v", err)
|
log.Error("issue.LoadRepo: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -130,7 +131,7 @@ func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions
|
||||||
log.Error("pull.LoadIssue: %v", err)
|
log.Error("pull.LoadIssue: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := pull.Issue.LoadRepo(); err != nil {
|
if err := pull.Issue.LoadRepo(db.DefaultContext); err != nil {
|
||||||
log.Error("pull.Issue.LoadRepo: %v", err)
|
log.Error("pull.Issue.LoadRepo: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *m
|
||||||
log.Error("comment.LoadIssue: %v", err)
|
log.Error("comment.LoadIssue: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = comment.Issue.LoadRepo(); err != nil {
|
if err = comment.Issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error("comment.Issue.LoadRepo: %v", err)
|
log.Error("comment.Issue.LoadRepo: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
packages_model "code.gitea.io/gitea/models/packages"
|
packages_model "code.gitea.io/gitea/models/packages"
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
@ -46,7 +47,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *m
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.LoadRepo(); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error("LoadRepo: %v", err)
|
log.Error("LoadRepo: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -282,7 +283,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
|
func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) {
|
||||||
if err := issue.LoadRepo(); err != nil {
|
if err := issue.LoadRepo(db.DefaultContext); err != nil {
|
||||||
log.Error("issue.LoadRepo: %v", err)
|
log.Error("issue.LoadRepo: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -311,7 +312,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest, mention
|
||||||
log.Error("pull.LoadIssue: %v", err)
|
log.Error("pull.LoadIssue: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := pull.Issue.LoadRepo(); err != nil {
|
if err := pull.Issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error("pull.Issue.LoadRepo: %v", err)
|
log.Error("pull.Issue.LoadRepo: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -507,7 +508,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if err = issue.LoadRepo(); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error("LoadRepo: %v", err)
|
log.Error("LoadRepo: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -634,7 +635,7 @@ func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *use
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.Issue.LoadRepo(); err != nil {
|
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error("pr.Issue.LoadRepo: %v", err)
|
log.Error("pr.Issue.LoadRepo: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -405,12 +406,12 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
for i := range part {
|
for i := range part {
|
||||||
// uses names and fall back to ids
|
// uses names and fall back to ids
|
||||||
// non existent milestones are discarded
|
// non existent milestones are discarded
|
||||||
mile, err := models.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, part[i])
|
mile, err := issues_model.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, part[i])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mileIDs = append(mileIDs, mile.ID)
|
mileIDs = append(mileIDs, mile.ID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !models.IsErrMilestoneNotExist(err) {
|
if !issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoIDANDName", err)
|
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoIDANDName", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -418,12 +419,12 @@ func ListIssues(ctx *context.APIContext) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mile, err = models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, id)
|
mile, err = issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, id)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mileIDs = append(mileIDs, mile.ID)
|
mileIDs = append(mileIDs, mile.ID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
@ -57,7 +57,7 @@ func ListMilestones(ctx *context.APIContext) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/MilestoneList"
|
// "$ref": "#/responses/MilestoneList"
|
||||||
|
|
||||||
milestones, total, err := models.GetMilestones(models.GetMilestonesOption{
|
milestones, total, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{
|
||||||
ListOptions: utils.GetListOptions(ctx),
|
ListOptions: utils.GetListOptions(ctx),
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
State: api.StateType(ctx.FormString("state")),
|
State: api.StateType(ctx.FormString("state")),
|
||||||
|
@ -146,7 +146,7 @@ func CreateMilestone(ctx *context.APIContext) {
|
||||||
form.Deadline = &defaultDeadline
|
form.Deadline = &defaultDeadline
|
||||||
}
|
}
|
||||||
|
|
||||||
milestone := &models.Milestone{
|
milestone := &issues_model.Milestone{
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
Name: form.Title,
|
Name: form.Title,
|
||||||
Content: form.Description,
|
Content: form.Description,
|
||||||
|
@ -158,7 +158,7 @@ func CreateMilestone(ctx *context.APIContext) {
|
||||||
milestone.ClosedDateUnix = timeutil.TimeStampNow()
|
milestone.ClosedDateUnix = timeutil.TimeStampNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.NewMilestone(milestone); err != nil {
|
if err := issues_model.NewMilestone(milestone); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "NewMilestone", err)
|
ctx.Error(http.StatusInternalServerError, "NewMilestone", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ func EditMilestone(ctx *context.APIContext) {
|
||||||
milestone.IsClosed = *form.State == string(api.StateClosed)
|
milestone.IsClosed = *form.State == string(api.StateClosed)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.UpdateMilestone(milestone, oldIsClosed); err != nil {
|
if err := issues_model.UpdateMilestone(milestone, oldIsClosed); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UpdateMilestone", err)
|
ctx.Error(http.StatusInternalServerError, "UpdateMilestone", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ func DeleteMilestone(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, m.ID); err != nil {
|
if err := issues_model.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, m.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "DeleteMilestoneByRepoID", err)
|
ctx.Error(http.StatusInternalServerError, "DeleteMilestoneByRepoID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -263,23 +263,23 @@ func DeleteMilestone(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getMilestoneByIDOrName get milestone by ID and if not available by name
|
// getMilestoneByIDOrName get milestone by ID and if not available by name
|
||||||
func getMilestoneByIDOrName(ctx *context.APIContext) *models.Milestone {
|
func getMilestoneByIDOrName(ctx *context.APIContext) *issues_model.Milestone {
|
||||||
mile := ctx.Params(":id")
|
mile := ctx.Params(":id")
|
||||||
mileID, _ := strconv.ParseInt(mile, 0, 64)
|
mileID, _ := strconv.ParseInt(mile, 0, 64)
|
||||||
|
|
||||||
if mileID != 0 {
|
if mileID != 0 {
|
||||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, mileID)
|
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, mileID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return milestone
|
return milestone
|
||||||
} else if !models.IsErrMilestoneNotExist(err) {
|
} else if !issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
milestone, err := models.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, mile)
|
milestone, err := issues_model.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, mile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -342,9 +343,9 @@ func CreatePullRequest(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if form.Milestone > 0 {
|
if form.Milestone > 0 {
|
||||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, form.Milestone)
|
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, form.Milestone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.NotFound()
|
ctx.NotFound()
|
||||||
} else {
|
} else {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
|
||||||
|
|
|
@ -75,7 +75,7 @@ func ListPullReviews(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = pr.Issue.LoadRepo(); err != nil {
|
if err = pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "LoadRepo", err)
|
ctx.Error(http.StatusInternalServerError, "LoadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ func CreatePullReview(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.Issue.LoadRepo(); err != nil {
|
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "pr.Issue.LoadRepo", err)
|
ctx.Error(http.StatusInternalServerError, "pr.Issue.LoadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -657,7 +657,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.Issue.LoadRepo(); err != nil {
|
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "pr.Issue.LoadRepo", err)
|
ctx.Error(http.StatusInternalServerError, "pr.Issue.LoadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,7 +403,7 @@ func Issues(ctx *context.Context) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
// Get milestones
|
// Get milestones
|
||||||
ctx.Data["Milestones"], _, err = models.GetMilestones(models.GetMilestonesOption{
|
ctx.Data["Milestones"], _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
State: api.StateType(ctx.FormString("state")),
|
State: api.StateType(ctx.FormString("state")),
|
||||||
})
|
})
|
||||||
|
@ -420,7 +420,7 @@ func Issues(ctx *context.Context) {
|
||||||
// RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
|
// RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
|
||||||
func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.Repository) {
|
func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.Repository) {
|
||||||
var err error
|
var err error
|
||||||
ctx.Data["OpenMilestones"], _, err = models.GetMilestones(models.GetMilestonesOption{
|
ctx.Data["OpenMilestones"], _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
State: api.StateOpen,
|
State: api.StateOpen,
|
||||||
})
|
})
|
||||||
|
@ -428,7 +428,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
|
||||||
ctx.ServerError("GetMilestones", err)
|
ctx.ServerError("GetMilestones", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["ClosedMilestones"], _, err = models.GetMilestones(models.GetMilestonesOption{
|
ctx.Data["ClosedMilestones"], _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
State: api.StateClosed,
|
State: api.StateClosed,
|
||||||
})
|
})
|
||||||
|
@ -806,7 +806,7 @@ func NewIssue(ctx *context.Context) {
|
||||||
|
|
||||||
milestoneID := ctx.FormInt64("milestone")
|
milestoneID := ctx.FormInt64("milestone")
|
||||||
if milestoneID > 0 {
|
if milestoneID > 0 {
|
||||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, milestoneID)
|
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, milestoneID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("GetMilestoneByID: %d: %v", milestoneID, err)
|
log.Error("GetMilestoneByID: %d: %v", milestoneID, err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -915,7 +915,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
|
||||||
// Check milestone.
|
// Check milestone.
|
||||||
milestoneID := form.MilestoneID
|
milestoneID := form.MilestoneID
|
||||||
if milestoneID > 0 {
|
if milestoneID > 0 {
|
||||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, milestoneID)
|
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, milestoneID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetMilestoneByID", err)
|
ctx.ServerError("GetMilestoneByID", err)
|
||||||
return nil, nil, 0, 0
|
return nil, nil, 0, 0
|
||||||
|
@ -1325,7 +1325,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.ServerError("GetIssueByID", err)
|
ctx.ServerError("GetIssueByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = otherIssue.LoadRepo(); err != nil {
|
if err = otherIssue.LoadRepo(ctx); err != nil {
|
||||||
ctx.ServerError("LoadRepo", err)
|
ctx.ServerError("LoadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1405,7 +1405,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
ctx.ServerError("LoadMilestone", err)
|
ctx.ServerError("LoadMilestone", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ghostMilestone := &models.Milestone{
|
ghostMilestone := &issues_model.Milestone{
|
||||||
ID: -1,
|
ID: -1,
|
||||||
Name: ctx.Tr("repo.issues.deleted_milestone"),
|
Name: ctx.Tr("repo.issues.deleted_milestone"),
|
||||||
}
|
}
|
||||||
|
@ -1994,7 +1994,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, issue := range issues {
|
for _, issue := range issues {
|
||||||
if err := issue.LoadRepo(); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.ServerError("issue.LoadRepo", err)
|
ctx.ServerError("issue.LoadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2344,12 +2344,12 @@ func ListIssues(ctx *context.Context) {
|
||||||
for i := range part {
|
for i := range part {
|
||||||
// uses names and fall back to ids
|
// uses names and fall back to ids
|
||||||
// non existent milestones are discarded
|
// non existent milestones are discarded
|
||||||
mile, err := models.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, part[i])
|
mile, err := issues_model.GetMilestoneByRepoIDANDName(ctx.Repo.Repository.ID, part[i])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mileIDs = append(mileIDs, mile.ID)
|
mileIDs = append(mileIDs, mile.ID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !models.IsErrMilestoneNotExist(err) {
|
if !issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2357,12 +2357,12 @@ func ListIssues(ctx *context.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mile, err = models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, id)
|
mile, err = issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, id)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mileIDs = append(mileIDs, mile.ID)
|
mileIDs = append(mileIDs, mile.ID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||||
|
|
|
@ -29,7 +29,7 @@ func AddDependency(ctx *context.Context) {
|
||||||
|
|
||||||
depID := ctx.FormInt64("newDependency")
|
depID := ctx.FormInt64("newDependency")
|
||||||
|
|
||||||
if err = issue.LoadRepo(); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.ServerError("LoadRepo", err)
|
ctx.ServerError("LoadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func RemoveDependency(ctx *context.Context) {
|
||||||
|
|
||||||
depID := ctx.FormInt64("removeDependencyID")
|
depID := ctx.FormInt64("removeDependencyID")
|
||||||
|
|
||||||
if err = issue.LoadRepo(); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.ServerError("LoadRepo", err)
|
ctx.ServerError("LoadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,18 +64,18 @@ func CancelStopwatch(c *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetActiveStopwatch is the middleware that sets .ActiveStopwatch on context
|
// GetActiveStopwatch is the middleware that sets .ActiveStopwatch on context
|
||||||
func GetActiveStopwatch(c *context.Context) {
|
func GetActiveStopwatch(ctx *context.Context) {
|
||||||
if strings.HasPrefix(c.Req.URL.Path, "/api") {
|
if strings.HasPrefix(ctx.Req.URL.Path, "/api") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.IsSigned {
|
if !ctx.IsSigned {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, sw, err := models.HasUserStopwatch(c.Doer.ID)
|
_, sw, err := models.HasUserStopwatch(ctx.Doer.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ServerError("HasUserStopwatch", err)
|
ctx.ServerError("HasUserStopwatch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,15 +85,15 @@ func GetActiveStopwatch(c *context.Context) {
|
||||||
|
|
||||||
issue, err := models.GetIssueByID(sw.IssueID)
|
issue, err := models.GetIssueByID(sw.IssueID)
|
||||||
if err != nil || issue == nil {
|
if err != nil || issue == nil {
|
||||||
c.ServerError("GetIssueByID", err)
|
ctx.ServerError("GetIssueByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = issue.LoadRepo(); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
c.ServerError("LoadRepo", err)
|
ctx.ServerError("LoadRepo", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["ActiveStopwatch"] = StopwatchTmplInfo{
|
ctx.Data["ActiveStopwatch"] = StopwatchTmplInfo{
|
||||||
issue.Link(),
|
issue.Link(),
|
||||||
issue.Repo.FullName(),
|
issue.Repo.FullName(),
|
||||||
issue.Index,
|
issue.Index,
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/markup"
|
"code.gitea.io/gitea/modules/markup"
|
||||||
|
@ -38,7 +38,7 @@ func Milestones(ctx *context.Context) {
|
||||||
ctx.Data["PageIsMilestones"] = true
|
ctx.Data["PageIsMilestones"] = true
|
||||||
|
|
||||||
isShowClosed := ctx.FormString("state") == "closed"
|
isShowClosed := ctx.FormString("state") == "closed"
|
||||||
stats, err := models.GetMilestonesStatsByRepoCond(builder.And(builder.Eq{"id": ctx.Repo.Repository.ID}))
|
stats, err := issues_model.GetMilestonesStatsByRepoCond(builder.And(builder.Eq{"id": ctx.Repo.Repository.ID}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("MilestoneStats", err)
|
ctx.ServerError("MilestoneStats", err)
|
||||||
return
|
return
|
||||||
|
@ -60,7 +60,7 @@ func Milestones(ctx *context.Context) {
|
||||||
state = structs.StateClosed
|
state = structs.StateClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
miles, total, err := models.GetMilestones(models.GetMilestonesOption{
|
miles, total, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
Page: page,
|
Page: page,
|
||||||
PageSize: setting.UI.IssuePagingNum,
|
PageSize: setting.UI.IssuePagingNum,
|
||||||
|
@ -143,7 +143,7 @@ func NewMilestonePost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, deadline.Location())
|
deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, deadline.Location())
|
||||||
if err = models.NewMilestone(&models.Milestone{
|
if err = issues_model.NewMilestone(&issues_model.Milestone{
|
||||||
RepoID: ctx.Repo.Repository.ID,
|
RepoID: ctx.Repo.Repository.ID,
|
||||||
Name: form.Title,
|
Name: form.Title,
|
||||||
Content: form.Content,
|
Content: form.Content,
|
||||||
|
@ -163,9 +163,9 @@ func EditMilestone(ctx *context.Context) {
|
||||||
ctx.Data["PageIsMilestones"] = true
|
ctx.Data["PageIsMilestones"] = true
|
||||||
ctx.Data["PageIsEditMilestone"] = true
|
ctx.Data["PageIsEditMilestone"] = true
|
||||||
|
|
||||||
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
m, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.NotFound("", nil)
|
ctx.NotFound("", nil)
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("GetMilestoneByRepoID", err)
|
ctx.ServerError("GetMilestoneByRepoID", err)
|
||||||
|
@ -203,9 +203,9 @@ func EditMilestonePost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, deadline.Location())
|
deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, deadline.Location())
|
||||||
m, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
m, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.NotFound("", nil)
|
ctx.NotFound("", nil)
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("GetMilestoneByRepoID", err)
|
ctx.ServerError("GetMilestoneByRepoID", err)
|
||||||
|
@ -215,7 +215,7 @@ func EditMilestonePost(ctx *context.Context) {
|
||||||
m.Name = form.Title
|
m.Name = form.Title
|
||||||
m.Content = form.Content
|
m.Content = form.Content
|
||||||
m.DeadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
m.DeadlineUnix = timeutil.TimeStamp(deadline.Unix())
|
||||||
if err = models.UpdateMilestone(m, m.IsClosed); err != nil {
|
if err = issues_model.UpdateMilestone(m, m.IsClosed); err != nil {
|
||||||
ctx.ServerError("UpdateMilestone", err)
|
ctx.ServerError("UpdateMilestone", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -237,8 +237,8 @@ func ChangeMilestoneStatus(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
id := ctx.ParamsInt64(":id")
|
id := ctx.ParamsInt64(":id")
|
||||||
|
|
||||||
if err := models.ChangeMilestoneStatusByRepoIDAndID(ctx.Repo.Repository.ID, id, toClose); err != nil {
|
if err := issues_model.ChangeMilestoneStatusByRepoIDAndID(ctx.Repo.Repository.ID, id, toClose); err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.NotFound("", err)
|
ctx.NotFound("", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.ServerError("ChangeMilestoneStatusByIDAndRepoID", err)
|
ctx.ServerError("ChangeMilestoneStatusByIDAndRepoID", err)
|
||||||
|
@ -250,7 +250,7 @@ func ChangeMilestoneStatus(ctx *context.Context) {
|
||||||
|
|
||||||
// DeleteMilestone delete a milestone
|
// DeleteMilestone delete a milestone
|
||||||
func DeleteMilestone(ctx *context.Context) {
|
func DeleteMilestone(ctx *context.Context) {
|
||||||
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
|
if err := issues_model.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
|
||||||
ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
|
ctx.Flash.Error("DeleteMilestoneByRepoID: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.milestones.deletion_success"))
|
||||||
|
@ -264,9 +264,9 @@ func DeleteMilestone(ctx *context.Context) {
|
||||||
// MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone
|
// MilestoneIssuesAndPulls lists all the issues and pull requests of the milestone
|
||||||
func MilestoneIssuesAndPulls(ctx *context.Context) {
|
func MilestoneIssuesAndPulls(ctx *context.Context) {
|
||||||
milestoneID := ctx.ParamsInt64(":id")
|
milestoneID := ctx.ParamsInt64(":id")
|
||||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, milestoneID)
|
milestone, err := issues_model.GetMilestoneByRepoID(ctx, ctx.Repo.Repository.ID, milestoneID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrMilestoneNotExist(err) {
|
if issues_model.IsErrMilestoneNotExist(err) {
|
||||||
ctx.NotFound("GetMilestoneByID", err)
|
ctx.NotFound("GetMilestoneByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,7 +266,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
|
||||||
ctx.ServerError("LoadPoster", err)
|
ctx.ServerError("LoadPoster", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := issue.LoadRepo(); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
ctx.ServerError("LoadRepo", err)
|
ctx.ServerError("LoadRepo", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
"code.gitea.io/gitea/models/organization"
|
"code.gitea.io/gitea/models/organization"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
|
@ -219,13 +220,13 @@ func Milestones(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
counts, err := models.CountMilestonesByRepoCondAndKw(userRepoCond, keyword, isShowClosed)
|
counts, err := issues_model.CountMilestonesByRepoCondAndKw(userRepoCond, keyword, isShowClosed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CountMilestonesByRepoIDs", err)
|
ctx.ServerError("CountMilestonesByRepoIDs", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
milestones, err := models.SearchMilestones(repoCond, page, isShowClosed, sortType, keyword)
|
milestones, err := issues_model.SearchMilestones(repoCond, page, isShowClosed, sortType, keyword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("SearchMilestones", err)
|
ctx.ServerError("SearchMilestones", err)
|
||||||
return
|
return
|
||||||
|
@ -271,17 +272,17 @@ func Milestones(ctx *context.Context) {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
milestoneStats, err := models.GetMilestonesStatsByRepoCondAndKw(repoCond, keyword)
|
milestoneStats, err := issues_model.GetMilestonesStatsByRepoCondAndKw(repoCond, keyword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetMilestoneStats", err)
|
ctx.ServerError("GetMilestoneStats", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var totalMilestoneStats *models.MilestonesStats
|
var totalMilestoneStats *issues_model.MilestonesStats
|
||||||
if len(repoIDs) == 0 {
|
if len(repoIDs) == 0 {
|
||||||
totalMilestoneStats = milestoneStats
|
totalMilestoneStats = milestoneStats
|
||||||
} else {
|
} else {
|
||||||
totalMilestoneStats, err = models.GetMilestonesStatsByRepoCondAndKw(userRepoCond, keyword)
|
totalMilestoneStats, err = issues_model.GetMilestonesStatsByRepoCondAndKw(userRepoCond, keyword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetMilestoneStats", err)
|
ctx.ServerError("GetMilestoneStats", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -6,6 +6,7 @@ package issue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
)
|
)
|
||||||
|
@ -43,7 +44,7 @@ func AddLabels(issue *models.Issue, doer *user_model.User, labels []*models.Labe
|
||||||
|
|
||||||
// RemoveLabel removes a label from issue by given ID.
|
// RemoveLabel removes a label from issue by given ID.
|
||||||
func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error {
|
func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error {
|
||||||
if err := issue.LoadRepo(); err != nil {
|
if err := issue.LoadRepo(db.DefaultContext); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,68 @@
|
||||||
package issue
|
package issue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *models.Issue, oldMilestoneID int64) error {
|
||||||
|
if err := models.UpdateIssueCols(ctx, issue, "milestone_id"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if oldMilestoneID > 0 {
|
||||||
|
if err := issues_model.UpdateMilestoneCounters(ctx, oldMilestoneID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if issue.MilestoneID > 0 {
|
||||||
|
if err := issues_model.UpdateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if oldMilestoneID > 0 || issue.MilestoneID > 0 {
|
||||||
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := &models.CreateCommentOptions{
|
||||||
|
Type: models.CommentTypeMilestone,
|
||||||
|
Doer: doer,
|
||||||
|
Repo: issue.Repo,
|
||||||
|
Issue: issue,
|
||||||
|
OldMilestoneID: oldMilestoneID,
|
||||||
|
MilestoneID: issue.MilestoneID,
|
||||||
|
}
|
||||||
|
if _, err := models.CreateCommentCtx(ctx, opts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
||||||
func ChangeMilestoneAssign(issue *models.Issue, doer *user_model.User, oldMilestoneID int64) (err error) {
|
func ChangeMilestoneAssign(issue *models.Issue, doer *user_model.User, oldMilestoneID int64) (err error) {
|
||||||
if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil {
|
ctx, committer, err := db.TxContext()
|
||||||
return
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer committer.Close()
|
||||||
|
|
||||||
|
if err = changeMilestoneAssign(ctx, doer, issue, oldMilestoneID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = committer.Commit(); err != nil {
|
||||||
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
|
notification.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
|
||||||
|
|
35
services/issue/milestone_test.go
Normal file
35
services/issue/milestone_test.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package issue
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestChangeMilestoneAssign(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{RepoID: 1}).(*models.Issue)
|
||||||
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||||
|
assert.NotNil(t, issue)
|
||||||
|
assert.NotNil(t, doer)
|
||||||
|
|
||||||
|
oldMilestoneID := issue.MilestoneID
|
||||||
|
issue.MilestoneID = 2
|
||||||
|
assert.NoError(t, ChangeMilestoneAssign(issue, doer, oldMilestoneID))
|
||||||
|
unittest.AssertExistsAndLoadBean(t, &models.Comment{
|
||||||
|
IssueID: issue.ID,
|
||||||
|
Type: models.CommentTypeMilestone,
|
||||||
|
MilestoneID: issue.MilestoneID,
|
||||||
|
OldMilestoneID: oldMilestoneID,
|
||||||
|
})
|
||||||
|
unittest.CheckConsistencyFor(t, &issues_model.Milestone{}, &models.Issue{})
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
|
@ -404,7 +405,7 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issue.LoadRepo(); err != nil {
|
if err := issue.LoadRepo(db.DefaultContext); err != nil {
|
||||||
log.Error("Unable to load repo [%d] for issue #%d [%d]. Error: %v", issue.RepoID, issue.Index, issue.ID, err)
|
log.Error("Unable to load repo [%d] for issue #%d [%d]. Error: %v", issue.RepoID, issue.Index, issue.ID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ const (
|
||||||
// 2. Users who are not in 1. but get mentioned in current issue/comment.
|
// 2. Users who are not in 1. but get mentioned in current issue/comment.
|
||||||
func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error {
|
func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error {
|
||||||
// Required by the mail composer; make sure to load these before calling the async function
|
// Required by the mail composer; make sure to load these before calling the async function
|
||||||
if err := ctx.Issue.LoadRepo(); err != nil {
|
if err := ctx.Issue.LoadRepo(ctx); err != nil {
|
||||||
return fmt.Errorf("LoadRepo(): %v", err)
|
return fmt.Errorf("LoadRepo(): %v", err)
|
||||||
}
|
}
|
||||||
if err := ctx.Issue.LoadPoster(); err != nil {
|
if err := ctx.Issue.LoadPoster(); err != nil {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
texttmpl "text/template"
|
texttmpl "text/template"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -57,7 +58,7 @@ func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Re
|
||||||
doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1, Owner: doer}).(*repo_model.Repository)
|
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1, Owner: doer}).(*repo_model.Repository)
|
||||||
issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
|
issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
|
||||||
assert.NoError(t, issue.LoadRepo())
|
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
|
||||||
comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2, Issue: issue}).(*models.Comment)
|
comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2, Issue: issue}).(*models.Comment)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -180,7 +181,7 @@ func TestTemplateSelection(t *testing.T) {
|
||||||
|
|
||||||
func TestTemplateServices(t *testing.T) {
|
func TestTemplateServices(t *testing.T) {
|
||||||
doer, _, issue, comment := prepareMailerTest(t)
|
doer, _, issue, comment := prepareMailerTest(t)
|
||||||
assert.NoError(t, issue.LoadRepo())
|
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
|
||||||
|
|
||||||
expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
|
expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
|
||||||
actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
|
actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (g *GiteaLocalUploader) MaxBatchInsertSize(tp string) int {
|
||||||
case "comment":
|
case "comment":
|
||||||
return db.MaxBatchInsertSize(new(models.Comment))
|
return db.MaxBatchInsertSize(new(models.Comment))
|
||||||
case "milestone":
|
case "milestone":
|
||||||
return db.MaxBatchInsertSize(new(models.Milestone))
|
return db.MaxBatchInsertSize(new(issues_model.Milestone))
|
||||||
case "label":
|
case "label":
|
||||||
return db.MaxBatchInsertSize(new(models.Label))
|
return db.MaxBatchInsertSize(new(models.Label))
|
||||||
case "release":
|
case "release":
|
||||||
|
@ -164,7 +164,7 @@ func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
|
||||||
|
|
||||||
// CreateMilestones creates milestones
|
// CreateMilestones creates milestones
|
||||||
func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error {
|
func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error {
|
||||||
mss := make([]*models.Milestone, 0, len(milestones))
|
mss := make([]*issues_model.Milestone, 0, len(milestones))
|
||||||
for _, milestone := range milestones {
|
for _, milestone := range milestones {
|
||||||
var deadline timeutil.TimeStamp
|
var deadline timeutil.TimeStamp
|
||||||
if milestone.Deadline != nil {
|
if milestone.Deadline != nil {
|
||||||
|
@ -187,7 +187,7 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err
|
||||||
milestone.Updated = &milestone.Created
|
milestone.Updated = &milestone.Created
|
||||||
}
|
}
|
||||||
|
|
||||||
ms := models.Milestone{
|
ms := issues_model.Milestone{
|
||||||
RepoID: g.repo.ID,
|
RepoID: g.repo.ID,
|
||||||
Name: milestone.Title,
|
Name: milestone.Title,
|
||||||
Content: milestone.Description,
|
Content: milestone.Description,
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -65,14 +66,14 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||||
assert.True(t, repo.HasWiki())
|
assert.True(t, repo.HasWiki())
|
||||||
assert.EqualValues(t, repo_model.RepositoryReady, repo.Status)
|
assert.EqualValues(t, repo_model.RepositoryReady, repo.Status)
|
||||||
|
|
||||||
milestones, _, err := models.GetMilestones(models.GetMilestonesOption{
|
milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
State: structs.StateOpen,
|
State: structs.StateOpen,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, milestones, 1)
|
assert.Len(t, milestones, 1)
|
||||||
|
|
||||||
milestones, _, err = models.GetMilestones(models.GetMilestonesOption{
|
milestones, _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
State: structs.StateClosed,
|
State: structs.StateClosed,
|
||||||
})
|
})
|
||||||
|
|
|
@ -76,7 +76,7 @@ func Merge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, b
|
||||||
log.Error("loadIssue [%d]: %v", pr.ID, err)
|
log.Error("loadIssue [%d]: %v", pr.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pr.Issue.LoadRepo(); err != nil {
|
if err := pr.Issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error("loadRepo for issue [%d]: %v", pr.ID, err)
|
log.Error("loadRepo for issue [%d]: %v", pr.ID, err)
|
||||||
}
|
}
|
||||||
if err := pr.Issue.Repo.GetOwner(ctx); err != nil {
|
if err := pr.Issue.Repo.GetOwner(ctx); err != nil {
|
||||||
|
@ -99,7 +99,7 @@ func Merge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, b
|
||||||
if err = ref.LoadIssue(); err != nil {
|
if err = ref.LoadIssue(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = ref.Issue.LoadRepo(); err != nil {
|
if err = ref.Issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
close := ref.RefAction == references.XRefActionCloses
|
close := ref.RefAction == references.XRefActionCloses
|
||||||
|
|
|
@ -44,7 +44,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
|
||||||
|
|
||||||
// Comments that are replies don't require a review header to show up in the issue view
|
// Comments that are replies don't require a review header to show up in the issue view
|
||||||
if !isReview && existsReview {
|
if !isReview && existsReview {
|
||||||
if err = issue.LoadRepo(); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue