Ignore blocked pipelines for badge rendering (#4582)

This commit is contained in:
Robert Kaussow 2024-12-18 08:58:08 +01:00 committed by GitHub
parent 077cab3b46
commit 7fa474c5c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 151 additions and 130 deletions

View file

@ -15,7 +15,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.35.2
// protoc-gen-go v1.36.0
// protoc v4.24.4
// source: woodpecker.proto
@ -36,16 +36,15 @@ const (
)
type StepState struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
StepUuid string `protobuf:"bytes,1,opt,name=step_uuid,json=stepUuid,proto3" json:"step_uuid,omitempty"`
Started int64 `protobuf:"varint,2,opt,name=started,proto3" json:"started,omitempty"`
Finished int64 `protobuf:"varint,3,opt,name=finished,proto3" json:"finished,omitempty"`
Exited bool `protobuf:"varint,4,opt,name=exited,proto3" json:"exited,omitempty"`
ExitCode int32 `protobuf:"varint,5,opt,name=exit_code,json=exitCode,proto3" json:"exit_code,omitempty"`
Error string `protobuf:"bytes,6,opt,name=error,proto3" json:"error,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *StepState) Reset() {
@ -121,13 +120,12 @@ func (x *StepState) GetError() string {
}
type WorkflowState struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Started int64 `protobuf:"varint,4,opt,name=started,proto3" json:"started,omitempty"`
Finished int64 `protobuf:"varint,5,opt,name=finished,proto3" json:"finished,omitempty"`
Error string `protobuf:"bytes,6,opt,name=error,proto3" json:"error,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *WorkflowState) Reset() {
@ -182,15 +180,14 @@ func (x *WorkflowState) GetError() string {
}
type LogEntry struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
StepUuid string `protobuf:"bytes,1,opt,name=step_uuid,json=stepUuid,proto3" json:"step_uuid,omitempty"`
Time int64 `protobuf:"varint,2,opt,name=time,proto3" json:"time,omitempty"`
Line int32 `protobuf:"varint,3,opt,name=line,proto3" json:"line,omitempty"`
Type int32 `protobuf:"varint,4,opt,name=type,proto3" json:"type,omitempty"` // 0 = stdout, 1 = stderr, 2 = exit-code, 3 = metadata, 4 = progress
Data []byte `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *LogEntry) Reset() {
@ -259,11 +256,10 @@ func (x *LogEntry) GetData() []byte {
}
type Filter struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
state protoimpl.MessageState `protogen:"open.v1"`
Labels map[string]string `protobuf:"bytes,1,rep,name=labels,proto3" json:"labels,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
unknownFields protoimpl.UnknownFields
Labels map[string]string `protobuf:"bytes,1,rep,name=labels,proto3" json:"labels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
sizeCache protoimpl.SizeCache
}
func (x *Filter) Reset() {
@ -304,13 +300,12 @@ func (x *Filter) GetLabels() map[string]string {
}
type Workflow struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Timeout int64 `protobuf:"varint,2,opt,name=timeout,proto3" json:"timeout,omitempty"`
Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Workflow) Reset() {
@ -365,11 +360,10 @@ func (x *Workflow) GetPayload() []byte {
}
type NextRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Filter *Filter `protobuf:"bytes,1,opt,name=filter,proto3" json:"filter,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *NextRequest) Reset() {
@ -410,12 +404,11 @@ func (x *NextRequest) GetFilter() *Filter {
}
type InitRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
State *WorkflowState `protobuf:"bytes,2,opt,name=state,proto3" json:"state,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *InitRequest) Reset() {
@ -463,11 +456,10 @@ func (x *InitRequest) GetState() *WorkflowState {
}
type WaitRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *WaitRequest) Reset() {
@ -508,12 +500,11 @@ func (x *WaitRequest) GetId() string {
}
type DoneRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
State *WorkflowState `protobuf:"bytes,2,opt,name=state,proto3" json:"state,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *DoneRequest) Reset() {
@ -561,11 +552,10 @@ func (x *DoneRequest) GetState() *WorkflowState {
}
type ExtendRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ExtendRequest) Reset() {
@ -606,12 +596,11 @@ func (x *ExtendRequest) GetId() string {
}
type UpdateRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
State *StepState `protobuf:"bytes,2,opt,name=state,proto3" json:"state,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *UpdateRequest) Reset() {
@ -659,11 +648,10 @@ func (x *UpdateRequest) GetState() *StepState {
}
type LogRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
LogEntries []*LogEntry `protobuf:"bytes,1,rep,name=logEntries,proto3" json:"logEntries,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *LogRequest) Reset() {
@ -704,9 +692,9 @@ func (x *LogRequest) GetLogEntries() []*LogEntry {
}
type Empty struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Empty) Reset() {
@ -740,11 +728,10 @@ func (*Empty) Descriptor() ([]byte, []int) {
}
type ReportHealthRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ReportHealthRequest) Reset() {
@ -785,15 +772,14 @@ func (x *ReportHealthRequest) GetStatus() string {
}
type AgentInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,omitempty"`
Capacity int32 `protobuf:"varint,2,opt,name=capacity,proto3" json:"capacity,omitempty"`
Backend string `protobuf:"bytes,3,opt,name=backend,proto3" json:"backend,omitempty"`
Version string `protobuf:"bytes,4,opt,name=version,proto3" json:"version,omitempty"`
CustomLabels map[string]string `protobuf:"bytes,5,rep,name=customLabels,proto3" json:"customLabels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
CustomLabels map[string]string `protobuf:"bytes,5,rep,name=customLabels,proto3" json:"customLabels,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AgentInfo) Reset() {
@ -862,11 +848,10 @@ func (x *AgentInfo) GetCustomLabels() map[string]string {
}
type RegisterAgentRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Info *AgentInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RegisterAgentRequest) Reset() {
@ -907,12 +892,11 @@ func (x *RegisterAgentRequest) GetInfo() *AgentInfo {
}
type VersionResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
GrpcVersion int32 `protobuf:"varint,1,opt,name=grpc_version,json=grpcVersion,proto3" json:"grpc_version,omitempty"`
ServerVersion string `protobuf:"bytes,2,opt,name=server_version,json=serverVersion,proto3" json:"server_version,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *VersionResponse) Reset() {
@ -960,11 +944,10 @@ func (x *VersionResponse) GetServerVersion() string {
}
type NextResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Workflow *Workflow `protobuf:"bytes,1,opt,name=workflow,proto3" json:"workflow,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *NextResponse) Reset() {
@ -1005,11 +988,10 @@ func (x *NextResponse) GetWorkflow() *Workflow {
}
type RegisterAgentResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
AgentId int64 `protobuf:"varint,1,opt,name=agent_id,json=agentId,proto3" json:"agent_id,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RegisterAgentResponse) Reset() {
@ -1050,12 +1032,11 @@ func (x *RegisterAgentResponse) GetAgentId() int64 {
}
type AuthRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
AgentToken string `protobuf:"bytes,1,opt,name=agent_token,json=agentToken,proto3" json:"agent_token,omitempty"`
AgentId int64 `protobuf:"varint,2,opt,name=agent_id,json=agentId,proto3" json:"agent_id,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AuthRequest) Reset() {
@ -1103,13 +1084,12 @@ func (x *AuthRequest) GetAgentId() int64 {
}
type AuthResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
state protoimpl.MessageState `protogen:"open.v1"`
Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"`
AgentId int64 `protobuf:"varint,2,opt,name=agent_id,json=agentId,proto3" json:"agent_id,omitempty"`
AccessToken string `protobuf:"bytes,3,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AuthResponse) Reset() {

View file

@ -72,7 +72,7 @@ func GetBadge(c *gin.Context) {
branch = repo.Branch
}
pipeline, err := _store.GetPipelineLast(repo, branch)
pipeline, err := _store.GetPipelineBadge(repo, branch)
if err != nil {
if !errors.Is(err, types.RecordNotExist) {
log.Warn().Err(err).Msg("could not get last pipeline for badge")

View file

@ -282,7 +282,7 @@ func (_m *Forge) Login(ctx context.Context, r *types.OAuthRequest) (*model.User,
return r0, r1, r2
}
// Name provides a mock function with given fields:
// Name provides a mock function with no fields
func (_m *Forge) Name() string {
ret := _m.Called()
@ -528,7 +528,7 @@ func (_m *Forge) Teams(ctx context.Context, u *model.User) ([]*model.Team, error
return r0, r1
}
// URL provides a mock function with given fields:
// URL provides a mock function with no fields
func (_m *Forge) URL() string {
ret := _m.Called()

View file

@ -150,7 +150,7 @@ func (_m *Queue) KickAgentWorkers(agentID int64) {
_m.Called(agentID)
}
// Pause provides a mock function with given fields:
// Pause provides a mock function with no fields
func (_m *Queue) Pause() {
_m.Called()
}
@ -221,7 +221,7 @@ func (_m *Queue) PushAtOnce(c context.Context, tasks []*model.Task) error {
return r0
}
// Resume provides a mock function with given fields:
// Resume provides a mock function with no fields
func (_m *Queue) Resume() {
_m.Called()
}

View file

@ -48,7 +48,7 @@ func (_m *Manager) ConfigServiceFromRepo(repo *model.Repo) config.Service {
return r0
}
// EnvironmentService provides a mock function with given fields:
// EnvironmentService provides a mock function with no fields
func (_m *Manager) EnvironmentService() environment.Service {
ret := _m.Called()
@ -158,7 +158,7 @@ func (_m *Manager) ForgeFromUser(user *model.User) (forge.Forge, error) {
return r0, r1
}
// RegistryService provides a mock function with given fields:
// RegistryService provides a mock function with no fields
func (_m *Manager) RegistryService() registry.Service {
ret := _m.Called()
@ -198,7 +198,7 @@ func (_m *Manager) RegistryServiceFromRepo(repo *model.Repo) registry.Service {
return r0
}
// SecretService provides a mock function with given fields:
// SecretService provides a mock function with no fields
func (_m *Manager) SecretService() secret.Service {
ret := _m.Called()
@ -238,7 +238,7 @@ func (_m *Manager) SecretServiceFromRepo(repo *model.Repo) secret.Service {
return r0
}
// SignaturePublicKey provides a mock function with given fields:
// SignaturePublicKey provides a mock function with no fields
func (_m *Manager) SignaturePublicKey() crypto.PublicKey {
ret := _m.Called()

View file

@ -35,6 +35,15 @@ func (s storage) GetPipelineNumber(repo *model.Repo, num int64) (*model.Pipeline
).Get(pipeline))
}
func (s storage) GetPipelineBadge(repo *model.Repo, branch string) (*model.Pipeline, error) {
pipeline := new(model.Pipeline)
return pipeline, wrapGet(s.engine.
Desc("number").
Where(builder.Eq{"repo_id": repo.ID, "branch": branch, "event": model.EventPush}).
Where(builder.Neq{"status": model.StatusBlocked}).
Get(pipeline))
}
func (s storage) GetPipelineLast(repo *model.Repo, branch string) (*model.Pipeline, error) {
pipeline := new(model.Pipeline)
return pipeline, wrapGet(s.engine.

View file

@ -191,7 +191,7 @@ func (_m *Store) AgentUpdate(_a0 *model.Agent) error {
return r0
}
// Close provides a mock function with given fields:
// Close provides a mock function with no fields
func (_m *Store) Close() error {
ret := _m.Called()
@ -748,7 +748,37 @@ func (_m *Store) GetPipeline(_a0 int64) (*model.Pipeline, error) {
return r0, r1
}
// GetPipelineCount provides a mock function with given fields:
// GetPipelineBadge provides a mock function with given fields: _a0, _a1
func (_m *Store) GetPipelineBadge(_a0 *model.Repo, _a1 string) (*model.Pipeline, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for GetPipelineBadge")
}
var r0 *model.Pipeline
var r1 error
if rf, ok := ret.Get(0).(func(*model.Repo, string) (*model.Pipeline, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(*model.Repo, string) *model.Pipeline); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Pipeline)
}
}
if rf, ok := ret.Get(1).(func(*model.Repo, string) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetPipelineCount provides a mock function with no fields
func (_m *Store) GetPipelineCount() (int64, error) {
ret := _m.Called()
@ -896,7 +926,7 @@ func (_m *Store) GetPipelineNumber(_a0 *model.Repo, _a1 int64) (*model.Pipeline,
return r0, r1
}
// GetPipelineQueue provides a mock function with given fields:
// GetPipelineQueue provides a mock function with no fields
func (_m *Store) GetPipelineQueue() ([]*model.Feed, error) {
ret := _m.Called()
@ -956,7 +986,7 @@ func (_m *Store) GetRepo(_a0 int64) (*model.Repo, error) {
return r0, r1
}
// GetRepoCount provides a mock function with given fields:
// GetRepoCount provides a mock function with no fields
func (_m *Store) GetRepoCount() (int64, error) {
ret := _m.Called()
@ -1104,7 +1134,7 @@ func (_m *Store) GetUser(_a0 int64) (*model.User, error) {
return r0, r1
}
// GetUserCount provides a mock function with given fields:
// GetUserCount provides a mock function with no fields
func (_m *Store) GetUserCount() (int64, error) {
ret := _m.Called()
@ -1796,7 +1826,7 @@ func (_m *Store) PermUpsert(perm *model.Perm) error {
return r0
}
// Ping provides a mock function with given fields:
// Ping provides a mock function with no fields
func (_m *Store) Ping() error {
ret := _m.Called()
@ -1928,7 +1958,7 @@ func (_m *Store) RegistryList(_a0 *model.Repo, _a1 bool, _a2 *model.ListOptions)
return r0, r1
}
// RegistryListAll provides a mock function with given fields:
// RegistryListAll provides a mock function with no fields
func (_m *Store) RegistryListAll() ([]*model.Registry, error) {
ret := _m.Called()
@ -2162,7 +2192,7 @@ func (_m *Store) SecretList(_a0 *model.Repo, _a1 bool, _a2 *model.ListOptions) (
return r0, r1
}
// SecretListAll provides a mock function with given fields:
// SecretListAll provides a mock function with no fields
func (_m *Store) SecretListAll() ([]*model.Secret, error) {
ret := _m.Called()
@ -2508,7 +2538,7 @@ func (_m *Store) TaskInsert(_a0 *model.Task) error {
return r0
}
// TaskList provides a mock function with given fields:
// TaskList provides a mock function with no fields
func (_m *Store) TaskList() ([]*model.Task, error) {
ret := _m.Called()

View file

@ -72,6 +72,8 @@ type Store interface {
GetPipeline(int64) (*model.Pipeline, error)
// GetPipelineNumber gets a pipeline by number.
GetPipelineNumber(*model.Repo, int64) (*model.Pipeline, error)
// GetPipelineBadge gets the last relevant pipeline for the badge.
GetPipelineBadge(*model.Repo, string) (*model.Pipeline, error)
// GetPipelineLast gets the last pipeline for the branch.
GetPipelineLast(*model.Repo, string) (*model.Pipeline, error)
// GetPipelineLastBefore gets the last pipeline before pipeline number N.

View file

@ -95,7 +95,7 @@ func (_m *Client) AgentDelete(_a0 int64) error {
return r0
}
// AgentList provides a mock function with given fields:
// AgentList provides a mock function with no fields
func (_m *Client) AgentList() ([]*woodpecker.Agent, error) {
ret := _m.Called()
@ -629,7 +629,7 @@ func (_m *Client) GlobalSecretUpdate(secret *woodpecker.Secret) (*woodpecker.Sec
return r0, r1
}
// LogLevel provides a mock function with given fields:
// LogLevel provides a mock function with no fields
func (_m *Client) LogLevel() (*woodpecker.LogLevel, error) {
ret := _m.Called()
@ -1241,7 +1241,7 @@ func (_m *Client) PipelineMetadata(repoID int64, pipelineNumber int) ([]byte, er
return r0, r1
}
// PipelineQueue provides a mock function with given fields:
// PipelineQueue provides a mock function with no fields
func (_m *Client) PipelineQueue() ([]*woodpecker.Feed, error) {
ret := _m.Called()
@ -1319,7 +1319,7 @@ func (_m *Client) PipelineStop(repoID int64, pipeline int64) error {
return r0
}
// QueueInfo provides a mock function with given fields:
// QueueInfo provides a mock function with no fields
func (_m *Client) QueueInfo() (*woodpecker.Info, error) {
ret := _m.Called()
@ -1859,7 +1859,7 @@ func (_m *Client) SecretUpdate(repoID int64, secret *woodpecker.Secret) (*woodpe
return r0, r1
}
// Self provides a mock function with given fields:
// Self provides a mock function with no fields
func (_m *Client) Self() (*woodpecker.User, error) {
ret := _m.Called()