Skip to content
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
74626c9
Merge branch 'main' of github.com:go-vela/server
jbrockopp Feb 14, 2023
974c8e6
Merge branch 'main' of github.com:go-vela/server
jbrockopp Mar 3, 2023
2f2c425
Merge branch 'main' of github.com:go-vela/server
jbrockopp Mar 20, 2023
528291a
Merge branch 'main' of github.com:go-vela/server
jbrockopp Apr 8, 2023
b53c687
Merge branch 'main' of github.com:go-vela/server
jbrockopp Apr 8, 2023
4734dcb
Merge branch 'main' of github.com:go-vela/server
jbrockopp Apr 16, 2023
1fb52df
Merge branch 'main' of github.com:go-vela/server
jbrockopp Apr 21, 2023
e996aa6
Merge branch 'main' of github.com:go-vela/server
jbrockopp Apr 27, 2023
6d250b0
feat(api/types): add support for schedules
jbrockopp Apr 28, 2023
661dca8
feat(database/types): add support for schedules
jbrockopp Apr 28, 2023
98b7565
feat(database): add support for schedules
jbrockopp Apr 28, 2023
737e5f8
chore: update go dependencies
jbrockopp Apr 28, 2023
5a045c2
Merge branch 'feature/schedule/types' of github.com:go-vela/server in…
jbrockopp Apr 28, 2023
bd4c5d2
feat(database): add schedule engine
jbrockopp Apr 28, 2023
2e4ba0e
feat(api): add support for schedules
JordanSussman May 1, 2023
1b6be80
add routes
JordanSussman May 1, 2023
328afc0
fix: parse entry for schedules
jbrockopp May 1, 2023
4401490
Merge branch 'feature/schedule/types' of github.com:go-vela/server in…
jbrockopp May 1, 2023
8563be9
more wip code
JordanSussman May 2, 2023
abf5003
add schedule allowlist
JordanSussman May 3, 2023
02e636a
fix tests
JordanSussman May 3, 2023
fe77a28
add validation for entry
JordanSussman May 3, 2023
84769fc
add mocks w/o updated payloads
JordanSussman May 3, 2023
443dc69
fix issues with create
JordanSussman May 3, 2023
2b908d7
update mock responses
JordanSussman May 3, 2023
2295ed0
use schedule mocks
JordanSussman May 4, 2023
95b09d0
make linter happy
JordanSussman May 4, 2023
8c9df8f
use proper func
JordanSussman May 4, 2023
9d64b09
couple more updates
JordanSussman May 4, 2023
bb8a5fd
fix mock pathing
JordanSussman May 4, 2023
a36d9bc
enhance: switch to adhocore/gronx
jbrockopp May 4, 2023
e3d4d5a
Merge branch 'feature/schedule/types' of github.com:go-vela/server in…
jbrockopp May 4, 2023
f296d4d
chore: update go deps
jbrockopp May 4, 2023
6e91e34
Merge branch 'feature/schedule/types' of github.com:go-vela/server in…
jbrockopp May 4, 2023
0181548
goimports
JordanSussman May 4, 2023
ecd6d3c
yet another goimports
JordanSussman May 4, 2023
8951f96
sigh
JordanSussman May 4, 2023
387ba84
wildcard goimport
JordanSussman May 4, 2023
9c7cc35
chore: address linter feedback
jbrockopp May 5, 2023
b9ab6a0
Merge branch 'main' into feature/schedule/database
jbrockopp May 5, 2023
05226a4
Merge branch 'main' into feature/schedule/api
jbrockopp May 5, 2023
8bc2f9d
Merge branch 'feature/schedule/api' of github.com:go-vela/server into…
jbrockopp May 5, 2023
ad0f5f8
Merge branch 'feature/schedule/database' of github.com:go-vela/server…
jbrockopp May 5, 2023
071db76
Merge branch 'main' into feature/schedule/api
jbrockopp May 11, 2023
c299ee4
Merge branch 'main' of github.com:go-vela/server
jbrockopp May 11, 2023
e487db6
Merge branch 'feature/schedule/api' of github.com:go-vela/server into…
jbrockopp May 11, 2023
b518a78
chore: save work
jbrockopp May 15, 2023
a32e43b
chore: remove new types
jbrockopp May 15, 2023
81dbbac
chore: updates for removed types
jbrockopp May 16, 2023
56e12eb
Merge branch 'feature/schedule/database' of github.com:go-vela/server…
jbrockopp May 16, 2023
32d83df
Merge branch 'main' of github.com:go-vela/server into feature/schedul…
jbrockopp May 16, 2023
f4c3099
chore: update go dependencies
jbrockopp May 16, 2023
115c2eb
chore: address review feedback
jbrockopp May 16, 2023
999a586
Merge branch 'feature/schedule/api' of github.com:go-vela/server into…
jbrockopp May 17, 2023
142d09b
Merge branch 'feature/schedule/database' of github.com:go-vela/server…
jbrockopp May 17, 2023
9ba0153
chore: remove new types
jbrockopp May 17, 2023
3829dc2
Merge branch 'feature/schedule/api' of github.com:go-vela/server into…
jbrockopp May 17, 2023
a45f4b1
feat: initial code for scheduler
jbrockopp May 17, 2023
e269fe5
chore: misc updates
jbrockopp May 17, 2023
a9cb2ce
chore: update go dependencies
jbrockopp May 17, 2023
16e8889
chore: updates for local testing
jbrockopp May 17, 2023
457cabd
chore: save work
jbrockopp May 18, 2023
dd5aed3
fix: introduce jitter
jbrockopp May 18, 2023
7497b05
Merge branch 'main' of github.com:go-vela/server into feature/schedul…
jbrockopp May 22, 2023
6f740fa
chore: address review feedback
jbrockopp May 22, 2023
9e673ff
chore: address review feedback
jbrockopp May 22, 2023
ef9e0e3
Merge branch 'main' into feature/schedule/compiler
jbrockopp May 22, 2023
e03c4a2
chore: update go dependencies
jbrockopp May 22, 2023
46fcc27
Merge branch 'feature/schedule/compiler' of github.com:go-vela/server…
jbrockopp May 22, 2023
b269d32
chore: address review feedback
jbrockopp May 23, 2023
8dcef6a
Merge branch 'main' into feature/schedule/compiler
jbrockopp May 23, 2023
88dc5be
Merge branch 'feature/schedule/compiler' of github.com:go-vela/server…
jbrockopp May 23, 2023
b48b9f8
fix(scheduler): use WithCommit in compiler
jbrockopp May 23, 2023
536c7f5
chore: address review feedback
jbrockopp May 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ __debug_bin
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode
31 changes: 14 additions & 17 deletions api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,23 @@ import (
"strings"
"time"

"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/router/middleware/org"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/compiler"
"github.com/go-vela/server/database"
"github.com/go-vela/server/internal/token"
"github.com/go-vela/server/queue"
"github.com/go-vela/server/router/middleware/build"
"github.com/go-vela/server/router/middleware/claims"
"github.com/go-vela/server/router/middleware/executors"
"github.com/go-vela/server/router/middleware/org"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/scm"
"github.com/go-vela/server/util"

"github.com/go-vela/types"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -292,7 +289,7 @@ func CreateBuild(c *gin.Context) {
r.SetPipelineType(pipelineType)

// skip the build if only the init or clone steps are found
skip := skipEmptyBuild(p)
skip := SkipEmptyBuild(p)
if skip != "" {
// set build to successful status
input.SetStatus(constants.StatusSuccess)
Expand Down Expand Up @@ -342,7 +339,7 @@ func CreateBuild(c *gin.Context) {
input.SetPipelineID(pipeline.GetID())

// create the objects from the pipeline in the database
err = planBuild(database.FromContext(c), p, input, r)
err = PlanBuild(database.FromContext(c), p, input, r)
if err != nil {
util.HandleError(c, http.StatusInternalServerError, err)

Expand Down Expand Up @@ -371,7 +368,7 @@ func CreateBuild(c *gin.Context) {
}

// publish the build to the queue
go publishToQueue(
go PublishToQueue(
queue.FromGinContext(c),
database.FromContext(c),
p,
Expand All @@ -381,11 +378,11 @@ func CreateBuild(c *gin.Context) {
)
}

// skipEmptyBuild checks if the build should be skipped due to it
// SkipEmptyBuild checks if the build should be skipped due to it
// not containing any steps besides init or clone.
//
//nolint:goconst // ignore init and clone constants
func skipEmptyBuild(p *pipeline.Build) string {
func SkipEmptyBuild(p *pipeline.Build) string {
if len(p.Stages) == 1 {
if p.Stages[0].Name == "init" {
return "skipping build since only init stage found"
Expand Down Expand Up @@ -1221,7 +1218,7 @@ func RestartBuild(c *gin.Context) {
r.SetPipelineType(pipelineType)

// skip the build if only the init or clone steps are found
skip := skipEmptyBuild(p)
skip := SkipEmptyBuild(p)
if skip != "" {
// set build to successful status
b.SetStatus(constants.StatusSkipped)
Expand Down Expand Up @@ -1271,7 +1268,7 @@ func RestartBuild(c *gin.Context) {
b.SetPipelineID(pipeline.GetID())

// create the objects from the pipeline in the database
err = planBuild(database.FromContext(c), p, b, r)
err = PlanBuild(database.FromContext(c), p, b, r)
if err != nil {
util.HandleError(c, http.StatusInternalServerError, err)

Expand Down Expand Up @@ -1299,7 +1296,7 @@ func RestartBuild(c *gin.Context) {
}

// publish the build to the queue
go publishToQueue(
go PublishToQueue(
queue.FromGinContext(c),
database.FromContext(c),
p,
Expand Down Expand Up @@ -1566,12 +1563,12 @@ func getPRNumberFromBuild(b *library.Build) (int, error) {
return strconv.Atoi(parts[2])
}

// planBuild is a helper function to plan the build for
// PlanBuild is a helper function to plan the build for
// execution. This creates all resources, like steps
// and services, for the build in the configured backend.
// TODO:
// - return build and error.
func planBuild(database database.Interface, p *pipeline.Build, b *library.Build, r *library.Repo) error {
func PlanBuild(database database.Interface, p *pipeline.Build, b *library.Build, r *library.Repo) error {
// update fields in build object
b.SetCreated(time.Now().UTC().Unix())

Expand Down
8 changes: 4 additions & 4 deletions api/build_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

Expand All @@ -10,7 +10,7 @@ import (
"github.com/go-vela/types/pipeline"
)

func Test_skipEmptyBuild(t *testing.T) {
func Test_SkipEmptyBuild(t *testing.T) {
type args struct {
p *pipeline.Build
}
Expand Down Expand Up @@ -72,8 +72,8 @@ func Test_skipEmptyBuild(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := skipEmptyBuild(tt.args.p); got != tt.want {
t.Errorf("skipEmptyBuild() = %v, want %v", got, tt.want)
if got := SkipEmptyBuild(tt.args.p); got != tt.want {
t.Errorf("SkipEmptyBuild() = %v, want %v", got, tt.want)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion api/schedule/create.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

Expand Down
2 changes: 1 addition & 1 deletion api/schedule/delete.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

Expand Down
2 changes: 1 addition & 1 deletion api/schedule/get.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

Expand Down
2 changes: 1 addition & 1 deletion api/schedule/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

Expand Down
3 changes: 1 addition & 2 deletions api/schedule/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import (
"net/http"
"time"

"github.com/go-vela/server/router/middleware/schedule"

"github.com/gin-gonic/gin"
"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/schedule"
"github.com/go-vela/server/util"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
Expand Down
10 changes: 5 additions & 5 deletions api/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func PostWebhook(c *gin.Context) {
repo.SetPipelineType(pipelineType)

// skip the build if only the init or clone steps are found
skip := skipEmptyBuild(p)
skip := SkipEmptyBuild(p)
if skip != "" {
// set build to successful status
b.SetStatus(constants.StatusSkipped)
Expand Down Expand Up @@ -608,7 +608,7 @@ func PostWebhook(c *gin.Context) {
// using the same Number and thus create a constraint
// conflict; consider deleting the partially created
// build object in the database
err = planBuild(database.FromContext(c), p, b, repo)
err = PlanBuild(database.FromContext(c), p, b, repo)
if err != nil {
retErr := fmt.Errorf("%s: %w", baseErr, err)

Expand Down Expand Up @@ -695,7 +695,7 @@ func PostWebhook(c *gin.Context) {
}

// publish the build to the queue
go publishToQueue(
go PublishToQueue(
queue.FromGinContext(c),
database.FromContext(c),
p,
Expand All @@ -705,9 +705,9 @@ func PostWebhook(c *gin.Context) {
)
}

// publishToQueue is a helper function that creates
// PublishToQueue is a helper function that creates
// a build item and publishes it to the queue.
func publishToQueue(queue queue.Service, db database.Interface, p *pipeline.Build, b *library.Build, r *library.Repo, u *library.User) {
func PublishToQueue(queue queue.Service, db database.Interface, p *pipeline.Build, b *library.Build, r *library.Repo, u *library.User) {
item := types.ToItem(p, b, r, u)

logrus.Infof("Converting queue item to json for build %d for %s", b.GetNumber(), r.GetFullName())
Expand Down
Loading