mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-21 23:21:26 +01:00
filter jobs by status
This commit is contained in:
parent
1c2babda0a
commit
10adb7567f
@ -58,7 +58,7 @@ func (ra *RepJobAPI) Prepare() {
|
||||
// List filters jobs according to the policy and repository
|
||||
func (ra *RepJobAPI) List() {
|
||||
var policyID int64
|
||||
var repository string
|
||||
var repository, status string
|
||||
var err error
|
||||
|
||||
policyIDStr := ra.GetString("policy_id")
|
||||
@ -70,10 +70,11 @@ func (ra *RepJobAPI) List() {
|
||||
}
|
||||
|
||||
repository = ra.GetString("repository")
|
||||
status = ra.GetString("status")
|
||||
|
||||
jobs, err := dao.FilterRepJobs(repository, policyID)
|
||||
jobs, err := dao.FilterRepJobs(policyID, repository, status)
|
||||
if err != nil {
|
||||
log.Errorf("failed to filter jobs according policy ID %d and repository %s: %v", policyID, repository, err)
|
||||
log.Errorf("failed to filter jobs according policy ID %d, repository %s, status %s: %v", policyID, repository, status, err)
|
||||
ra.RenderError(http.StatusInternalServerError, "Failed to query job")
|
||||
return
|
||||
}
|
||||
|
@ -1141,7 +1141,7 @@ func TestDeleteRepJob(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFilterRepJobs(t *testing.T) {
|
||||
jobs, err := FilterRepJobs("", policyID)
|
||||
jobs, err := FilterRepJobs(policyID, "", "")
|
||||
if err != nil {
|
||||
log.Errorf("Error occured in FilterRepJobs: %v, policy ID: %d", err, policyID)
|
||||
return
|
||||
|
@ -302,29 +302,24 @@ func GetRepJobByPolicy(policyID int64) ([]*models.RepJob, error) {
|
||||
}
|
||||
|
||||
// FilterRepJobs filters jobs by repo and policy ID
|
||||
func FilterRepJobs(repo string, policyID int64) ([]*models.RepJob, error) {
|
||||
func FilterRepJobs(policyID int64, repository, status string) ([]*models.RepJob, error) {
|
||||
o := GetOrmer()
|
||||
|
||||
var args []interface{}
|
||||
|
||||
sql := `select * from replication_job `
|
||||
|
||||
if len(repo) != 0 && policyID != 0 {
|
||||
sql += `where repository like ? and policy_id = ? `
|
||||
args = append(args, "%"+repo+"%")
|
||||
args = append(args, policyID)
|
||||
} else if len(repo) != 0 {
|
||||
sql += `where repository like ? `
|
||||
args = append(args, "%"+repo+"%")
|
||||
} else if policyID != 0 {
|
||||
sql += `where policy_id = ? `
|
||||
args = append(args, policyID)
|
||||
qs := o.QueryTable(new(models.RepJob))
|
||||
if policyID != 0 {
|
||||
qs = qs.Filter("PolicyID", policyID)
|
||||
}
|
||||
|
||||
sql += `order by creation_time`
|
||||
if len(repository) != 0 {
|
||||
qs = qs.Filter("Repository__icontains", repository)
|
||||
}
|
||||
if len(status) != 0 {
|
||||
qs = qs.Filter("Status__icontains", status)
|
||||
}
|
||||
qs = qs.OrderBy("CreationTime")
|
||||
|
||||
var jobs []*models.RepJob
|
||||
if _, err := o.Raw(sql, args).QueryRows(&jobs); err != nil {
|
||||
_, err := qs.All(&jobs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user