Skip to content

Commit 3ebd7d0

Browse files
authored
fix(revert): use commit status API only (#1405)
* fix(revert): use commit status API only * update Plan function signatures
1 parent cefcb53 commit 3ebd7d0

File tree

19 files changed

+43
-1185
lines changed

19 files changed

+43
-1185
lines changed

api/build/cancel.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515

1616
"github.com/go-vela/server/api/types"
1717
"github.com/go-vela/server/cache"
18-
"github.com/go-vela/server/cache/models"
1918
"github.com/go-vela/server/compiler/types/yaml"
2019
"github.com/go-vela/server/constants"
2120
"github.com/go-vela/server/database"
@@ -159,17 +158,9 @@ func CancelBuild(c *gin.Context) {
159158
return
160159
}
161160

162-
var (
163-
checks []models.CheckRun
164-
scmToken string
165-
)
161+
var scmToken string
166162

167163
if b.GetRepo().GetInstallID() != 0 {
168-
checks, err = cache.FromContext(c).GetCheckRuns(ctx, b)
169-
if err != nil {
170-
l.Errorf("unable to retrieve check runs for build %s: %v", entry, err)
171-
}
172-
173164
scmToken, _, err = scm.FromContext(c).GetNetrcPassword(ctx, database.FromContext(c), cache.FromContext(c), b, yaml.Git{})
174165
if err != nil {
175166
l.Errorf("unable to generate new installation token for build %s: %v", entry, err)
@@ -181,7 +172,7 @@ func CancelBuild(c *gin.Context) {
181172
}
182173

183174
// send API call to set the status on the commit
184-
_, err = scm.FromContext(c).Status(ctx, b, scmToken, checks)
175+
err = scm.FromContext(c).Status(ctx, b, scmToken)
185176
if err != nil {
186177
l.Errorf("unable to set commit status for build %s: %v", entry, err)
187178
}

api/build/compile_publish.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func CompileAndPublish(
267267
b.SetStatus(constants.StatusSkipped)
268268

269269
// send API call to set the status on the commit using installation OR owner token
270-
_, err = scm.Status(ctx, b, p.Token, nil)
270+
err = scm.Status(ctx, b, p.Token)
271271
if err != nil {
272272
logger.Errorf("unable to set commit status for %s/%d: %v", r.GetFullName(), b.GetNumber(), err)
273273
}
@@ -329,7 +329,7 @@ func CompileAndPublish(
329329
// using the same Number and thus create a constraint
330330
// conflict; consider deleting the partially created
331331
// build object in the database
332-
b, err = PlanBuild(ctx, cache, database, scm, p, b, r)
332+
b, err = PlanBuild(ctx, database, scm, p, b, r)
333333
if err != nil {
334334
retErr := fmt.Errorf("%s: %w", baseErr, err)
335335

api/build/gatekeep.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/sirupsen/logrus"
1010

1111
"github.com/go-vela/server/api/types"
12-
"github.com/go-vela/server/cache"
1312
"github.com/go-vela/server/constants"
1413
"github.com/go-vela/server/database"
1514
"github.com/go-vela/server/scm"
@@ -46,15 +45,10 @@ func GatekeepBuild(c *gin.Context, b *types.Build, r *types.Repo, token string)
4645
}
4746

4847
// send API call to set the status on the commit
49-
checks, err := scm.FromContext(c).Status(c, b, token, nil)
48+
err = scm.FromContext(c).Status(c, b, token)
5049
if err != nil {
5150
l.Errorf("unable to set commit status for %s/%d: %v", r.GetFullName(), b.GetNumber(), err)
5251
}
5352

54-
err = cache.FromContext(c).StoreCheckRuns(c, b.GetID(), checks, r)
55-
if err != nil {
56-
l.Errorf("unable to store check runs for %s/%d: %v", r.GetFullName(), b.GetNumber(), err)
57-
}
58-
5953
return nil
6054
}

api/build/plan.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/go-vela/server/api/service"
1313
"github.com/go-vela/server/api/step"
1414
"github.com/go-vela/server/api/types"
15-
"github.com/go-vela/server/cache"
1615
"github.com/go-vela/server/compiler/types/pipeline"
1716
"github.com/go-vela/server/database"
1817
"github.com/go-vela/server/scm"
@@ -23,7 +22,7 @@ import (
2322
// and services, for the build.
2423
// TODO:
2524
// - return build and error.
26-
func PlanBuild(ctx context.Context, cache cache.Service, database database.Interface, scm scm.Service, p *pipeline.Build, b *types.Build, r *types.Repo) (*types.Build, error) {
25+
func PlanBuild(ctx context.Context, database database.Interface, scm scm.Service, p *pipeline.Build, b *types.Build, r *types.Repo) (*types.Build, error) {
2726
// update fields in build object
2827
b.SetCreated(time.Now().UTC().Unix())
2928

@@ -57,7 +56,7 @@ func PlanBuild(ctx context.Context, cache cache.Service, database database.Inter
5756
}
5857

5958
// plan all steps for the build
60-
steps, err := step.PlanSteps(ctx, cache, database, scm, p, b)
59+
steps, err := step.PlanSteps(ctx, database, scm, p, b)
6160
if err != nil {
6261
// clean up the objects from the pipeline in the database
6362
CleanBuild(ctx, database, b, services, steps, err)

api/build/restart.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,11 @@ func RestartBuild(c *gin.Context) {
191191

192192
if shouldEnqueue {
193193
// send API call to set the status on the commit
194-
checks, err := scm.Status(c.Request.Context(), b, p.Token, nil)
194+
err := scm.Status(c.Request.Context(), b, p.Token)
195195
if err != nil {
196196
l.Errorf("unable to set commit status for %s/%d: %v", r.GetFullName(), b.GetNumber(), err)
197197
}
198198

199-
err = cache.FromContext(c).StoreCheckRuns(ctx, b.GetID(), checks, r)
200-
if err != nil {
201-
l.Errorf("unable to store check runs for %s/%d: %v", r.GetFullName(), b.GetNumber(), err)
202-
}
203-
204199
// publish the build to the queue
205200
go Enqueue(
206201
context.WithoutCancel(c.Request.Context()),

api/build/update.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/go-vela/server/api/types"
1414
"github.com/go-vela/server/cache"
15-
"github.com/go-vela/server/cache/models"
1615
"github.com/go-vela/server/constants"
1716
"github.com/go-vela/server/database"
1817
"github.com/go-vela/server/router/middleware/auth"
@@ -182,17 +181,8 @@ func UpdateBuild(c *gin.Context) {
182181
return
183182
}
184183

185-
var checks []models.CheckRun
186-
187-
if b.GetRepo().GetInstallID() != 0 {
188-
checks, err = cache.FromContext(c).GetCheckRuns(ctx, b)
189-
if err != nil {
190-
l.Errorf("unable to retrieve check runs for build %s: %v", entry, err)
191-
}
192-
}
193-
194184
// send API call to set the status on the commit
195-
_, err = scm.FromContext(c).Status(ctx, b, scmToken, checks)
185+
err = scm.FromContext(c).Status(ctx, b, scmToken)
196186
if err != nil {
197187
l.Errorf("unable to set commit status for build %s: %v", entry, err)
198188
}
@@ -262,17 +252,8 @@ func UpdateComponentStatuses(c *gin.Context, b *types.Build, status, scmToken st
262252
}).Infof("step status updated")
263253

264254
if len(step.GetReportAs()) > 0 {
265-
var checks []models.CheckRun
266-
267-
if b.GetRepo().GetInstallID() != 0 {
268-
checks, err = cache.FromContext(c).GetStepCheckRuns(ctx, step)
269-
if err != nil {
270-
l.Errorf("unable to retrieve check runs for step %s: %v", step.GetName(), err)
271-
}
272-
}
273-
274255
// send API call to set the status on the commit
275-
_, err = scm.FromContext(c).StepStatus(ctx, b, step, scmToken, checks)
256+
err = scm.FromContext(c).StepStatus(ctx, b, step, scmToken)
276257
if err != nil {
277258
l.Errorf("unable to set commit status for step %s: %v", step.GetName(), err)
278259
}

api/step/plan.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/sirupsen/logrus"
1111

1212
"github.com/go-vela/server/api/types"
13-
"github.com/go-vela/server/cache"
1413
"github.com/go-vela/server/compiler/types/pipeline"
1514
"github.com/go-vela/server/constants"
1615
"github.com/go-vela/server/database"
@@ -20,7 +19,7 @@ import (
2019
// PlanSteps is a helper function to plan all steps
2120
// in the build for execution. This creates the steps
2221
// for the build.
23-
func PlanSteps(ctx context.Context, cache cache.Service, database database.Interface, scm scm.Service, p *pipeline.Build, b *types.Build) ([]*types.Step, error) {
22+
func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service, p *pipeline.Build, b *types.Build) ([]*types.Step, error) {
2423
// variable to store planned steps
2524
steps := []*types.Step{}
2625

@@ -29,7 +28,7 @@ func PlanSteps(ctx context.Context, cache cache.Service, database database.Inter
2928
// iterate through all steps for each pipeline stage
3029
for _, step := range stage.Steps {
3130
// create the step object
32-
s, err := planStep(ctx, cache, database, scm, b, step, stage.Name)
31+
s, err := planStep(ctx, database, scm, b, step, stage.Name)
3332
if err != nil {
3433
return steps, err
3534
}
@@ -40,7 +39,7 @@ func PlanSteps(ctx context.Context, cache cache.Service, database database.Inter
4039

4140
// iterate through all pipeline steps
4241
for _, step := range p.Steps {
43-
s, err := planStep(ctx, cache, database, scm, b, step, "")
42+
s, err := planStep(ctx, database, scm, b, step, "")
4443
if err != nil {
4544
return steps, err
4645
}
@@ -51,7 +50,7 @@ func PlanSteps(ctx context.Context, cache cache.Service, database database.Inter
5150
return steps, nil
5251
}
5352

54-
func planStep(ctx context.Context, cache cache.Service, database database.Interface, scm scm.Service, b *types.Build, c *pipeline.Container, stage string) (*types.Step, error) {
53+
func planStep(ctx context.Context, database database.Interface, scm scm.Service, b *types.Build, c *pipeline.Container, stage string) (*types.Step, error) {
5554
// create the step object
5655
s := new(types.Step)
5756
s.SetBuildID(b.GetID())
@@ -109,15 +108,10 @@ func planStep(ctx context.Context, cache cache.Service, database database.Interf
109108

110109
if len(s.GetReportAs()) > 0 {
111110
// send API call to set the status on the commit using token in environment
112-
stepCheckRuns, err := scm.StepStatus(ctx, b, s, c.Environment["VELA_NETRC_PASSWORD"], nil)
111+
err := scm.StepStatus(ctx, b, s, c.Environment["VELA_NETRC_PASSWORD"])
113112
if err != nil {
114113
logrus.Errorf("unable to set commit status for build: %v", err)
115114
}
116-
117-
err = cache.StoreStepCheckRuns(ctx, s.GetID(), stepCheckRuns, b.GetRepo())
118-
if err != nil {
119-
logrus.Errorf("unable to store step check runs in cache: %v", err)
120-
}
121115
}
122116

123117
return s, nil

api/step/update.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"github.com/sirupsen/logrus"
1212

1313
"github.com/go-vela/server/api/types"
14-
"github.com/go-vela/server/cache"
15-
"github.com/go-vela/server/cache/models"
1614
"github.com/go-vela/server/constants"
1715
"github.com/go-vela/server/database"
1816
"github.com/go-vela/server/router/middleware/auth"
@@ -174,17 +172,8 @@ func UpdateStep(c *gin.Context) {
174172
scmToken = r.GetOwner().GetToken()
175173
}
176174

177-
var checks []models.CheckRun
178-
179-
if b.GetRepo().GetInstallID() != 0 {
180-
checks, err = cache.FromContext(c).GetStepCheckRuns(ctx, s)
181-
if err != nil {
182-
l.Errorf("unable to retrieve check runs for build %s: %v", entry, err)
183-
}
184-
}
185-
186175
// send API call to set the status on the commit
187-
_, err = scm.FromContext(c).StepStatus(ctx, b, s, scmToken, checks)
176+
err = scm.FromContext(c).StepStatus(ctx, b, s, scmToken)
188177
if err != nil {
189178
l.Errorf("unable to set commit status for build %s: %v", entry, err)
190179
}

api/webhook/post.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ func PostWebhook(c *gin.Context) {
483483

484484
util.HandleError(c, code, err)
485485

486-
_, err = scm.FromContext(c).Status(ctx, b, p.Token, nil)
486+
err = scm.FromContext(c).Status(ctx, b, p.Token)
487487
if err != nil {
488488
l.Debugf("unable to set commit status for %s/%d: %v", repo.GetFullName(), b.GetNumber(), err)
489489
}
@@ -616,16 +616,11 @@ func PostWebhook(c *gin.Context) {
616616

617617
if shouldEnqueue {
618618
// send API call to set the status on the commit
619-
checks, err := scm.FromContext(c).Status(c.Request.Context(), b, p.Token, nil)
619+
err := scm.FromContext(c).Status(c.Request.Context(), b, p.Token)
620620
if err != nil {
621621
l.Errorf("unable to set commit status for %s/%d: %v", repo.GetFullName(), b.GetNumber(), err)
622622
}
623623

624-
err = cache.FromContext(c).StoreCheckRuns(ctx, b.GetID(), checks, repo)
625-
if err != nil {
626-
l.Errorf("unable to store check runs for %s/%d: %v", repo.GetFullName(), b.GetNumber(), err)
627-
}
628-
629624
// publish the build to the queue
630625
go build.Enqueue(
631626
context.WithoutCancel(c.Request.Context()),

cache/models/check_run.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)