forked from forgejo/forgejo
[API] ListIssues add filter for milestones (#10148)
* Refactor Issue Filter Func * ListIssues add filter for milestones * as per @lafriks * documentation ...
This commit is contained in:
parent
cbf5dffaf2
commit
bfda0f3864
10 changed files with 102 additions and 29 deletions
|
@ -1560,6 +1560,7 @@ func (err ErrLabelNotExist) Error() string {
|
|||
type ErrMilestoneNotExist struct {
|
||||
ID int64
|
||||
RepoID int64
|
||||
Name string
|
||||
}
|
||||
|
||||
// IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
|
||||
|
@ -1569,6 +1570,9 @@ func IsErrMilestoneNotExist(err error) bool {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
poster_id: 1
|
||||
name: issue3
|
||||
content: content for the third issue
|
||||
milestone_id: 3
|
||||
is_closed: false
|
||||
is_pull: true
|
||||
created_unix: 946684820
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
name: milestone3
|
||||
content: content3
|
||||
is_closed: true
|
||||
num_issues: 0
|
||||
num_issues: 1
|
||||
|
||||
-
|
||||
id: 4
|
||||
|
|
|
@ -1058,7 +1058,7 @@ type IssuesOptions struct {
|
|||
AssigneeID int64
|
||||
PosterID int64
|
||||
MentionedID int64
|
||||
MilestoneID int64
|
||||
MilestoneIDs []int64
|
||||
IsClosed util.OptionalBool
|
||||
IsPull util.OptionalBool
|
||||
LabelIDs []int64
|
||||
|
@ -1143,8 +1143,8 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
|
|||
And("issue_user.uid = ?", opts.MentionedID)
|
||||
}
|
||||
|
||||
if opts.MilestoneID > 0 {
|
||||
sess.And("issue.milestone_id=?", opts.MilestoneID)
|
||||
if len(opts.MilestoneIDs) > 0 {
|
||||
sess.In("issue.milestone_id", opts.MilestoneIDs)
|
||||
}
|
||||
|
||||
switch opts.IsPull {
|
||||
|
|
|
@ -109,15 +109,12 @@ func NewMilestone(m *Milestone) (err error) {
|
|||
}
|
||||
|
||||
func getMilestoneByRepoID(e Engine, repoID, id int64) (*Milestone, error) {
|
||||
m := &Milestone{
|
||||
ID: id,
|
||||
RepoID: repoID,
|
||||
}
|
||||
has, err := e.Get(m)
|
||||
m := new(Milestone)
|
||||
has, err := e.ID(id).Where("repo_id=?", repoID).Get(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrMilestoneNotExist{id, repoID}
|
||||
return nil, ErrMilestoneNotExist{ID: id, RepoID: repoID}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
@ -127,6 +124,19 @@ func GetMilestoneByRepoID(repoID, id int64) (*Milestone, error) {
|
|||
return getMilestoneByRepoID(x, repoID, id)
|
||||
}
|
||||
|
||||
// GetMilestoneByRepoIDANDName return a milestone if one exist by name and repo
|
||||
func GetMilestoneByRepoIDANDName(repoID int64, name string) (*Milestone, error) {
|
||||
var mile Milestone
|
||||
has, err := x.Where("repo_id=? AND name=?", repoID, name).Get(&mile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !has {
|
||||
return nil, ErrMilestoneNotExist{Name: name, RepoID: repoID}
|
||||
}
|
||||
return &mile, nil
|
||||
}
|
||||
|
||||
// GetMilestoneByID returns the milestone via id .
|
||||
func GetMilestoneByID(id int64) (*Milestone, error) {
|
||||
var m Milestone
|
||||
|
@ -134,7 +144,7 @@ func GetMilestoneByID(id int64) (*Milestone, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrMilestoneNotExist{id, 0}
|
||||
return nil, ErrMilestoneNotExist{ID: id, RepoID: 0}
|
||||
}
|
||||
return &m, nil
|
||||
}
|
||||
|
|
|
@ -240,14 +240,14 @@ func TestUpdateMilestoneClosedNum(t *testing.T) {
|
|||
|
||||
issue.IsClosed = true
|
||||
issue.ClosedUnix = timeutil.TimeStampNow()
|
||||
_, err := x.Cols("is_closed", "closed_unix").Update(issue)
|
||||
_, err := x.ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, updateMilestoneClosedNum(x, issue.MilestoneID))
|
||||
CheckConsistencyFor(t, &Milestone{})
|
||||
|
||||
issue.IsClosed = false
|
||||
issue.ClosedUnix = 0
|
||||
_, err = x.Cols("is_closed", "closed_unix").Update(issue)
|
||||
_, err = x.ID(issue.ID).Cols("is_closed", "closed_unix").Update(issue)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, updateMilestoneClosedNum(x, issue.MilestoneID))
|
||||
CheckConsistencyFor(t, &Milestone{})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue