Skip to content

Commit

Permalink
fix: StartTime maybe nil (#91)
Browse files Browse the repository at this point in the history
Why:
- avoid nil pointer access

Signed-off-by: lijie <lijie@pingcap.com>
  • Loading branch information
lijie0123 committed Feb 29, 2024
1 parent 051c1fd commit 04297de
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tibuild/pkg/webhook/service/cloudevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log/slog"
"strconv"
"strings"
"time"

rest "github.com/PingCAP-QE/ee-apps/tibuild/pkg/rest/service"
cloudevents "github.com/cloudevents/sdk-go/v2"
Expand Down Expand Up @@ -93,14 +94,21 @@ func toDevbuildPipeline(pipeline tekton.PipelineRun) (*rest.TektonPipeline, erro
if err != nil {
return nil, fmt.Errorf("parse image failed:%w", err)
}
var startAt, endAt *time.Time
if pipeline.Status.StartTime != nil {
startAt = &pipeline.Status.StartTime.Time
}
if pipeline.Status.CompletionTime != nil {
endAt = &pipeline.Status.CompletionTime.Time
}
return &rest.TektonPipeline{
Name: pipeline.Name,
Platform: parsePlatform(pipeline),
GitHash: parseGitHash(pipeline),
OciArtifacts: convertOciArtifacts(pipeline),
Images: images,
StartAt: &pipeline.Status.StartTime.Time,
EndAt: &pipeline.Status.CompletionTime.Time,
StartAt: startAt,
EndAt: endAt,
}, nil
}

Expand Down

0 comments on commit 04297de

Please sign in to comment.