mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-18 14:36:30 +00:00
Ignore blocked pipelines for badge rendering
This commit is contained in:
parent
e8216bc123
commit
c9c84133e7
1 changed files with 17 additions and 6 deletions
|
@ -31,6 +31,7 @@ import (
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/store"
|
"go.woodpecker-ci.org/woodpecker/v2/server/store"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/store/types"
|
"go.woodpecker-ci.org/woodpecker/v2/server/store/types"
|
||||||
|
shared_utils "go.woodpecker-ci.org/woodpecker/v2/shared/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetBadge
|
// GetBadge
|
||||||
|
@ -72,17 +73,27 @@ func GetBadge(c *gin.Context) {
|
||||||
branch = repo.Branch
|
branch = repo.Branch
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline, err := _store.GetPipelineLast(repo, branch)
|
pipelines, err := shared_utils.Paginate(func(page int) ([]*model.Pipeline, error) {
|
||||||
if err != nil {
|
list, err := _store.GetPipelineList(repo, &model.ListOptions{Page: page, PerPage: 2}, &model.PipelineFilter{Branch: branch}) //nolint:mnd
|
||||||
if !errors.Is(err, types.RecordNotExist) {
|
if len(list) > 0 {
|
||||||
log.Warn().Err(err).Msg("could not get last pipeline for badge")
|
// Find first non-blocked pipeline in this batch
|
||||||
|
for _, p := range list {
|
||||||
|
if p.Status != model.StatusBlocked {
|
||||||
|
// Return smaller batch to trigger len(batch) < lenFirstBatch
|
||||||
|
return []*model.Pipeline{p}, nil
|
||||||
}
|
}
|
||||||
pipeline = nil
|
}
|
||||||
|
}
|
||||||
|
return list, err
|
||||||
|
}, -1)
|
||||||
|
if err != nil {
|
||||||
|
handleDBError(c, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// we serve an SVG, so set content type appropriately.
|
// we serve an SVG, so set content type appropriately.
|
||||||
c.Writer.Header().Set("Content-Type", "image/svg+xml")
|
c.Writer.Header().Set("Content-Type", "image/svg+xml")
|
||||||
c.String(http.StatusOK, badges.Generate(pipeline))
|
c.String(http.StatusOK, badges.Generate(pipelines[len(pipelines)-1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCC
|
// GetCC
|
||||||
|
|
Loading…
Reference in a new issue