mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-07 08:05:26 +00:00
Fix events filter in GetPipelines API (#4498)
This commit is contained in:
parent
3c31284e7b
commit
8cfb8f93fa
2 changed files with 19 additions and 1 deletions
|
@ -132,7 +132,7 @@ func GetPipelines(c *gin.Context) {
|
||||||
if events := c.Query("event"); events != "" {
|
if events := c.Query("event"); events != "" {
|
||||||
eventList := strings.Split(events, ",")
|
eventList := strings.Split(events, ",")
|
||||||
wel := make(model.WebhookEventList, 0, len(eventList))
|
wel := make(model.WebhookEventList, 0, len(eventList))
|
||||||
for _, event := range events {
|
for _, event := range eventList {
|
||||||
we := model.WebhookEvent(event)
|
we := model.WebhookEvent(event)
|
||||||
if err := we.Validate(); err != nil {
|
if err := we.Validate(); err != nil {
|
||||||
_ = c.AbortWithError(http.StatusBadRequest, err)
|
_ = c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
|
|
@ -96,6 +96,24 @@ func TestGetPipelines(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, c.Writer.Status())
|
assert.Equal(t, http.StatusOK, c.Writer.Status())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("should filter pipelines by events", func(t *testing.T) {
|
||||||
|
pipelines := []*model.Pipeline{fakePipeline}
|
||||||
|
mockStore := store_mocks.NewStore(t)
|
||||||
|
mockStore.On("GetPipelineList", mock.Anything, mock.Anything, mock.Anything).Return(pipelines, nil)
|
||||||
|
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
c, _ := gin.CreateTestContext(w)
|
||||||
|
c.Set("store", mockStore)
|
||||||
|
c.Request, _ = http.NewRequest(http.MethodGet, "/?event=push,pull_request", nil)
|
||||||
|
|
||||||
|
GetPipelines(c)
|
||||||
|
|
||||||
|
mockStore.AssertCalled(t, "GetPipelineList", mock.Anything, mock.Anything, &model.PipelineFilter{
|
||||||
|
Events: model.WebhookEventList{model.EventPush, model.EventPull},
|
||||||
|
})
|
||||||
|
assert.Equal(t, http.StatusOK, c.Writer.Status())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeletePipeline(t *testing.T) {
|
func TestDeletePipeline(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue