mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-02-13 21:00:00 +00:00
server.store: rename GetPipelineLast to GetPipelineLastByBranch (#6071)
This commit is contained in:
@@ -231,7 +231,7 @@ func DeletePipeline(c *gin.Context) {
|
||||
func GetPipeline(c *gin.Context) {
|
||||
_store := store.FromContext(c)
|
||||
if c.Param("number") == "latest" {
|
||||
GetPipelineLast(c)
|
||||
GetPipelineLastByBranch(c)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -255,12 +255,12 @@ func GetPipeline(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, pl)
|
||||
}
|
||||
|
||||
func GetPipelineLast(c *gin.Context) {
|
||||
func GetPipelineLastByBranch(c *gin.Context) {
|
||||
_store := store.FromContext(c)
|
||||
repo := session.Repo(c)
|
||||
branch := c.DefaultQuery("branch", repo.Branch)
|
||||
|
||||
pl, err := _store.GetPipelineLast(repo, branch)
|
||||
pl, err := _store.GetPipelineLastByBranch(repo, branch)
|
||||
if err != nil {
|
||||
handleDBError(c, err)
|
||||
return
|
||||
|
||||
@@ -48,7 +48,7 @@ func (s storage) GetPipelineBadge(repo *model.Repo, branch string, events []mode
|
||||
Get(pipeline))
|
||||
}
|
||||
|
||||
func (s storage) GetPipelineLast(repo *model.Repo, branch string) (*model.Pipeline, error) {
|
||||
func (s storage) GetPipelineLastByBranch(repo *model.Repo, branch string) (*model.Pipeline, error) {
|
||||
pipeline := new(model.Pipeline)
|
||||
return pipeline, wrapGet(s.engine.
|
||||
Desc("number").
|
||||
|
||||
@@ -56,6 +56,7 @@ func TestPipelines(t *testing.T) {
|
||||
RepoID: repo.ID,
|
||||
Status: model.StatusSuccess,
|
||||
Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
|
||||
Event: model.EventPush,
|
||||
Branch: "some-branch",
|
||||
}
|
||||
err = store.CreatePipeline(&pipeline)
|
||||
@@ -76,10 +77,9 @@ func TestPipelines(t *testing.T) {
|
||||
|
||||
// update pipeline
|
||||
pipeline.Status = model.StatusRunning
|
||||
err1 := store.UpdatePipeline(&pipeline)
|
||||
GetPipeline, err2 := store.GetPipeline(pipeline.ID)
|
||||
assert.NoError(t, err1)
|
||||
assert.NoError(t, err2)
|
||||
require.NoError(t, store.UpdatePipeline(&pipeline))
|
||||
GetPipeline, err1 := store.GetPipeline(pipeline.ID)
|
||||
require.NoError(t, err1)
|
||||
assert.Equal(t, pipeline.ID, GetPipeline.ID)
|
||||
assert.Equal(t, pipeline.RepoID, GetPipeline.RepoID)
|
||||
assert.Equal(t, pipeline.Status, GetPipeline.Status)
|
||||
@@ -91,38 +91,33 @@ func TestPipelines(t *testing.T) {
|
||||
Event: model.EventPush,
|
||||
Branch: "main",
|
||||
}
|
||||
err2 = store.CreatePipeline(pipeline2, []*model.Step{}...)
|
||||
assert.NoError(t, err2)
|
||||
require.NoError(t, store.CreatePipeline(pipeline2, []*model.Step{}...))
|
||||
GetPipeline, err3 := store.GetPipelineNumber(&model.Repo{ID: 1}, pipeline2.Number)
|
||||
assert.NoError(t, err3)
|
||||
require.NoError(t, err3)
|
||||
assert.Equal(t, pipeline2.ID, GetPipeline.ID)
|
||||
assert.Equal(t, pipeline2.RepoID, GetPipeline.RepoID)
|
||||
assert.Equal(t, pipeline2.Number, GetPipeline.Number)
|
||||
|
||||
GetPipeline, err3 = store.GetPipelineLast(&model.Repo{ID: repo.ID}, pipeline2.Branch)
|
||||
assert.NoError(t, err3)
|
||||
GetPipeline, err4 := store.GetPipelineLastByBranch(&model.Repo{ID: repo.ID}, pipeline2.Branch)
|
||||
require.NoError(t, err4)
|
||||
assert.Equal(t, pipeline2.ID, GetPipeline.ID)
|
||||
assert.Equal(t, pipeline2.RepoID, GetPipeline.RepoID)
|
||||
assert.Equal(t, pipeline2.Number, GetPipeline.Number)
|
||||
assert.Equal(t, pipeline2.Status, GetPipeline.Status)
|
||||
|
||||
pipeline3 := &model.Pipeline{
|
||||
RepoID: repo.ID,
|
||||
Status: model.StatusRunning,
|
||||
Branch: "main",
|
||||
Commit: "85f8c029b902ed9400bc600bac301a0aadb144aa",
|
||||
RepoID: repo.ID,
|
||||
Status: model.StatusRunning,
|
||||
Branch: "main",
|
||||
Event: model.EventPull,
|
||||
Commit: "85f8c029b902ed9400bc600bac301a0aadb144aa",
|
||||
ForgeURL: "example.com/id3",
|
||||
}
|
||||
err1 = store.CreatePipeline(pipeline3, []*model.Step{}...)
|
||||
assert.NoError(t, err1)
|
||||
require.NoError(t, store.CreatePipeline(pipeline3))
|
||||
|
||||
GetPipeline, err4 := store.GetPipelineLastBefore(&model.Repo{ID: 1}, pipeline3.Branch, pipeline3.ID)
|
||||
assert.NoError(t, err4)
|
||||
assert.Equal(t, pipeline2.ID, GetPipeline.ID)
|
||||
assert.Equal(t, pipeline2.RepoID, GetPipeline.RepoID)
|
||||
assert.Equal(t, pipeline2.Number, GetPipeline.Number)
|
||||
assert.Equal(t, pipeline2.Status, GetPipeline.Status)
|
||||
assert.Equal(t, pipeline2.Branch, GetPipeline.Branch)
|
||||
assert.Equal(t, pipeline2.Commit, GetPipeline.Commit)
|
||||
GetPipeline, err5 := store.GetPipelineLastBefore(&model.Repo{ID: 1}, pipeline3.Branch, pipeline3.ID)
|
||||
require.NoError(t, err5)
|
||||
assert.EqualValues(t, pipeline2, GetPipeline)
|
||||
}
|
||||
|
||||
func TestPipelineListFilter(t *testing.T) {
|
||||
|
||||
@@ -1948,74 +1948,6 @@ func (_c *MockStore_GetPipelineCount_Call) RunAndReturn(run func() (int64, error
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetPipelineLast provides a mock function for the type MockStore
|
||||
func (_mock *MockStore) GetPipelineLast(repo *model.Repo, s string) (*model.Pipeline, error) {
|
||||
ret := _mock.Called(repo, s)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetPipelineLast")
|
||||
}
|
||||
|
||||
var r0 *model.Pipeline
|
||||
var r1 error
|
||||
if returnFunc, ok := ret.Get(0).(func(*model.Repo, string) (*model.Pipeline, error)); ok {
|
||||
return returnFunc(repo, s)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(0).(func(*model.Repo, string) *model.Pipeline); ok {
|
||||
r0 = returnFunc(repo, s)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Pipeline)
|
||||
}
|
||||
}
|
||||
if returnFunc, ok := ret.Get(1).(func(*model.Repo, string) error); ok {
|
||||
r1 = returnFunc(repo, s)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockStore_GetPipelineLast_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPipelineLast'
|
||||
type MockStore_GetPipelineLast_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// GetPipelineLast is a helper method to define mock.On call
|
||||
// - repo *model.Repo
|
||||
// - s string
|
||||
func (_e *MockStore_Expecter) GetPipelineLast(repo interface{}, s interface{}) *MockStore_GetPipelineLast_Call {
|
||||
return &MockStore_GetPipelineLast_Call{Call: _e.mock.On("GetPipelineLast", repo, s)}
|
||||
}
|
||||
|
||||
func (_c *MockStore_GetPipelineLast_Call) Run(run func(repo *model.Repo, s string)) *MockStore_GetPipelineLast_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 *model.Repo
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(*model.Repo)
|
||||
}
|
||||
var arg1 string
|
||||
if args[1] != nil {
|
||||
arg1 = args[1].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
arg1,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockStore_GetPipelineLast_Call) Return(pipeline *model.Pipeline, err error) *MockStore_GetPipelineLast_Call {
|
||||
_c.Call.Return(pipeline, err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockStore_GetPipelineLast_Call) RunAndReturn(run func(repo *model.Repo, s string) (*model.Pipeline, error)) *MockStore_GetPipelineLast_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetPipelineLastBefore provides a mock function for the type MockStore
|
||||
func (_mock *MockStore) GetPipelineLastBefore(repo *model.Repo, s string, n int64) (*model.Pipeline, error) {
|
||||
ret := _mock.Called(repo, s, n)
|
||||
@@ -2090,6 +2022,74 @@ func (_c *MockStore_GetPipelineLastBefore_Call) RunAndReturn(run func(repo *mode
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetPipelineLastByBranch provides a mock function for the type MockStore
|
||||
func (_mock *MockStore) GetPipelineLastByBranch(repo *model.Repo, s string) (*model.Pipeline, error) {
|
||||
ret := _mock.Called(repo, s)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetPipelineLastByBranch")
|
||||
}
|
||||
|
||||
var r0 *model.Pipeline
|
||||
var r1 error
|
||||
if returnFunc, ok := ret.Get(0).(func(*model.Repo, string) (*model.Pipeline, error)); ok {
|
||||
return returnFunc(repo, s)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(0).(func(*model.Repo, string) *model.Pipeline); ok {
|
||||
r0 = returnFunc(repo, s)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Pipeline)
|
||||
}
|
||||
}
|
||||
if returnFunc, ok := ret.Get(1).(func(*model.Repo, string) error); ok {
|
||||
r1 = returnFunc(repo, s)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockStore_GetPipelineLastByBranch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPipelineLastByBranch'
|
||||
type MockStore_GetPipelineLastByBranch_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// GetPipelineLastByBranch is a helper method to define mock.On call
|
||||
// - repo *model.Repo
|
||||
// - s string
|
||||
func (_e *MockStore_Expecter) GetPipelineLastByBranch(repo interface{}, s interface{}) *MockStore_GetPipelineLastByBranch_Call {
|
||||
return &MockStore_GetPipelineLastByBranch_Call{Call: _e.mock.On("GetPipelineLastByBranch", repo, s)}
|
||||
}
|
||||
|
||||
func (_c *MockStore_GetPipelineLastByBranch_Call) Run(run func(repo *model.Repo, s string)) *MockStore_GetPipelineLastByBranch_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 *model.Repo
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(*model.Repo)
|
||||
}
|
||||
var arg1 string
|
||||
if args[1] != nil {
|
||||
arg1 = args[1].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
arg1,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockStore_GetPipelineLastByBranch_Call) Return(pipeline *model.Pipeline, err error) *MockStore_GetPipelineLastByBranch_Call {
|
||||
_c.Call.Return(pipeline, err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockStore_GetPipelineLastByBranch_Call) RunAndReturn(run func(repo *model.Repo, s string) (*model.Pipeline, error)) *MockStore_GetPipelineLastByBranch_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetPipelineList provides a mock function for the type MockStore
|
||||
func (_mock *MockStore) GetPipelineList(repo *model.Repo, listOptions *model.ListOptions, pipelineFilter *model.PipelineFilter) ([]*model.Pipeline, error) {
|
||||
ret := _mock.Called(repo, listOptions, pipelineFilter)
|
||||
|
||||
@@ -72,8 +72,8 @@ type Store interface {
|
||||
GetPipelineNumber(*model.Repo, int64) (*model.Pipeline, error)
|
||||
// GetPipelineBadge gets the last relevant pipeline for the badge.
|
||||
GetPipelineBadge(*model.Repo, string, []model.WebhookEvent) (*model.Pipeline, error)
|
||||
// GetPipelineLast gets the last pipeline for the branch.
|
||||
GetPipelineLast(*model.Repo, string) (*model.Pipeline, error)
|
||||
// GetPipelineLastByBranch gets the last pipeline for the branch.
|
||||
GetPipelineLastByBranch(*model.Repo, string) (*model.Pipeline, error)
|
||||
// GetPipelineLastBefore gets the last pipeline before pipeline number N.
|
||||
GetPipelineLastBefore(*model.Repo, string, int64) (*model.Pipeline, error)
|
||||
// GetPipelineList gets a list of pipelines for the repository
|
||||
|
||||
Reference in New Issue
Block a user