2021-11-13 19:18:06 +00:00
|
|
|
// Copyright 2021 Woodpecker Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package datastore
|
|
|
|
|
|
|
|
import (
|
2022-10-31 15:08:57 +00:00
|
|
|
"xorm.io/builder"
|
|
|
|
|
2023-12-08 07:15:08 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
2021-11-13 19:18:06 +00:00
|
|
|
)
|
|
|
|
|
2024-06-27 07:32:06 +00:00
|
|
|
var feedItemSelect = `repos.id as repo_id,
|
|
|
|
pipelines.id as pipeline_id,
|
|
|
|
pipelines.number as pipeline_number,
|
|
|
|
pipelines.event as pipeline_event,
|
|
|
|
pipelines.status as pipeline_status,
|
|
|
|
pipelines.created as pipeline_created,
|
|
|
|
pipelines.started as pipeline_started,
|
|
|
|
pipelines.finished as pipeline_finished,
|
|
|
|
'pipelines.commit' as pipeline_commit,
|
|
|
|
pipelines.branch as pipeline_branch,
|
|
|
|
pipelines.ref as pipeline_ref,
|
|
|
|
pipelines.refspec as pipeline_refspec,
|
|
|
|
pipelines.title as pipeline_title,
|
|
|
|
pipelines.message as pipeline_message,
|
|
|
|
pipelines.author as pipeline_author,
|
|
|
|
pipelines.email as pipeline_email,
|
|
|
|
pipelines.avatar as pipeline_avatar`
|
2022-10-31 15:08:57 +00:00
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
func (s storage) GetPipelineQueue() ([]*model.Feed, error) {
|
2021-11-13 19:18:06 +00:00
|
|
|
feed := make([]*model.Feed, 0, perPage)
|
2022-10-31 15:08:57 +00:00
|
|
|
err := s.engine.Table("pipelines").
|
|
|
|
Select(feedItemSelect).
|
2024-06-27 07:32:06 +00:00
|
|
|
Join("INNER", "repos", "pipelines.repo_id = repos.id").
|
|
|
|
In("pipelines.status", model.StatusPending, model.StatusRunning).
|
2022-10-31 15:08:57 +00:00
|
|
|
Find(&feed)
|
2021-11-13 19:18:06 +00:00
|
|
|
return feed, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s storage) UserFeed(user *model.User) ([]*model.Feed, error) {
|
|
|
|
feed := make([]*model.Feed, 0, perPage)
|
2022-10-31 15:08:57 +00:00
|
|
|
err := s.engine.Table("repos").
|
|
|
|
Select(feedItemSelect).
|
2024-06-27 07:32:06 +00:00
|
|
|
Join("INNER", "perms", "repos.id = perms.repo_id").
|
|
|
|
Join("INNER", "pipelines", "repos.id = pipelines.repo_id").
|
2022-10-31 15:08:57 +00:00
|
|
|
Where(userPushOrAdminCondition(user.ID)).
|
2024-06-27 07:32:06 +00:00
|
|
|
Desc("pipelines.id").
|
2022-10-31 15:08:57 +00:00
|
|
|
Limit(perPage).
|
|
|
|
Find(&feed)
|
|
|
|
|
|
|
|
return feed, err
|
2021-11-13 19:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s storage) RepoListLatest(user *model.User) ([]*model.Feed, error) {
|
|
|
|
feed := make([]*model.Feed, 0, perPage)
|
2022-10-31 15:08:57 +00:00
|
|
|
|
|
|
|
err := s.engine.Table("repos").
|
|
|
|
Select(feedItemSelect).
|
2024-06-27 07:32:06 +00:00
|
|
|
Join("INNER", "perms", "repos.id = perms.repo_id").
|
|
|
|
Join("LEFT", "pipelines", "pipelines.id = "+`(
|
|
|
|
SELECT pipelines.id FROM pipelines
|
|
|
|
WHERE pipelines.repo_id = repos.id
|
|
|
|
ORDER BY pipelines.id DESC
|
2022-10-31 15:08:57 +00:00
|
|
|
LIMIT 1
|
|
|
|
)`).
|
|
|
|
Where(userPushOrAdminCondition(user.ID)).
|
2024-06-27 07:32:06 +00:00
|
|
|
And(builder.Eq{"repos.active": true}).
|
|
|
|
Asc("repos.full_name").
|
2021-11-13 19:18:06 +00:00
|
|
|
Find(&feed)
|
2022-10-31 15:08:57 +00:00
|
|
|
|
|
|
|
return feed, err
|
2021-11-13 19:18:06 +00:00
|
|
|
}
|