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