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-11-07 07:04:33 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/server/model"
|
2021-11-13 19:18:06 +00:00
|
|
|
)
|
|
|
|
|
2023-06-12 23:07:52 +00:00
|
|
|
var feedItemSelect = `repos.repo_id as feed_repo_id,
|
2022-11-18 09:59:24 +00:00
|
|
|
pipelines.pipeline_id as feed_pipeline_id,
|
2022-10-31 15:08:57 +00:00
|
|
|
pipelines.pipeline_number as feed_pipeline_number,
|
|
|
|
pipelines.pipeline_event as feed_pipeline_event,
|
|
|
|
pipelines.pipeline_status as feed_pipeline_status,
|
|
|
|
pipelines.pipeline_created as feed_pipeline_created,
|
|
|
|
pipelines.pipeline_started as feed_pipeline_started,
|
|
|
|
pipelines.pipeline_finished as feed_pipeline_finished,
|
|
|
|
pipelines.pipeline_commit as feed_pipeline_commit,
|
|
|
|
pipelines.pipeline_branch as feed_pipeline_branch,
|
|
|
|
pipelines.pipeline_ref as feed_pipeline_ref,
|
|
|
|
pipelines.pipeline_refspec as feed_pipeline_refspec,
|
2022-11-04 23:35:06 +00:00
|
|
|
pipelines.pipeline_clone_url as feed_pipeline_clone_url,
|
2022-10-31 15:08:57 +00:00
|
|
|
pipelines.pipeline_title as feed_pipeline_title,
|
|
|
|
pipelines.pipeline_message as feed_pipeline_message,
|
|
|
|
pipelines.pipeline_author as feed_pipeline_author,
|
|
|
|
pipelines.pipeline_email as feed_pipeline_email,
|
|
|
|
pipelines.pipeline_avatar as feed_pipeline_avatar`
|
|
|
|
|
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).
|
|
|
|
Join("INNER", "repos", "pipelines.pipeline_repo_id = repos.repo_id").
|
|
|
|
In("pipelines.pipeline_status", model.StatusPending, model.StatusRunning).
|
|
|
|
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).
|
|
|
|
Join("INNER", "perms", "repos.repo_id = perms.perm_repo_id").
|
|
|
|
Join("INNER", "pipelines", "repos.repo_id = pipelines.pipeline_repo_id").
|
|
|
|
Where(userPushOrAdminCondition(user.ID)).
|
|
|
|
Desc("pipelines.pipeline_id").
|
|
|
|
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).
|
|
|
|
Join("INNER", "perms", "repos.repo_id = perms.perm_repo_id").
|
|
|
|
Join("LEFT", "pipelines", "pipelines.pipeline_id = "+`(
|
|
|
|
SELECT pipelines.pipeline_id FROM pipelines
|
|
|
|
WHERE pipelines.pipeline_repo_id = repos.repo_id
|
|
|
|
ORDER BY pipelines.pipeline_id DESC
|
|
|
|
LIMIT 1
|
|
|
|
)`).
|
|
|
|
Where(userPushOrAdminCondition(user.ID)).
|
|
|
|
And(builder.Eq{"repos.repo_active": true}).
|
|
|
|
Asc("repos.repo_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
|
|
|
}
|