Skip to content

Commit e231eb7

Browse files
committedMar 17, 2025
chore: pass tektonClient from param in ConvertPipelineRun
1 parent 443eca4 commit e231eb7

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed
 

‎pkg/engines/tekton/activity.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,20 @@ import (
77
"knative.dev/pkg/apis"
88

99
"github.com/jenkins-x/lighthouse/pkg/apis/lighthouse/v1alpha1"
10-
"github.com/jenkins-x/lighthouse/pkg/clients"
1110
"github.com/jenkins-x/lighthouse/pkg/config/job"
1211
"github.com/jenkins-x/lighthouse/pkg/util"
1312
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
13+
tektonversioned "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
1414
corev1 "k8s.io/api/core/v1"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
)
1717

1818
// ConvertPipelineRun translates a PipelineRun into an ActivityRecord
19-
func ConvertPipelineRun(pr *pipelinev1.PipelineRun) (*v1alpha1.ActivityRecord, error) {
19+
func ConvertPipelineRun(tektonclient tektonversioned.Interface, pr *pipelinev1.PipelineRun) (*v1alpha1.ActivityRecord, error) {
2020
if pr == nil {
2121
return nil, nil
2222
}
2323

24-
tektonclient, _, _, _, err := clients.GetAPIClients()
25-
if err != nil {
26-
return nil, err
27-
}
28-
2924
record := new(v1alpha1.ActivityRecord)
3025

3126
record.Name = pr.Name

‎pkg/engines/tekton/activity_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/jenkins-x/lighthouse/pkg/util"
1212
"github.com/stretchr/testify/assert"
1313
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
14+
tektonfake "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake"
1415
"sigs.k8s.io/yaml"
1516
)
1617

@@ -40,7 +41,8 @@ func TestConvertPipelineRun(t *testing.T) {
4041
testDir := filepath.Join("test_data", "activity", tc.name)
4142
pr := loadPipelineRun(t, testDir)
4243

43-
converted, err := tekton.ConvertPipelineRun(pr)
44+
tektonfakeClient := tektonfake.NewSimpleClientset(pr)
45+
converted, err := tekton.ConvertPipelineRun(tektonfakeClient, pr)
4446
assert.NoError(t, err)
4547
expected := loadRecord(t, testDir)
4648

‎pkg/engines/tekton/controller.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"text/template"
99

1010
lighthousev1alpha1 "github.com/jenkins-x/lighthouse/pkg/apis/lighthouse/v1alpha1"
11+
"github.com/jenkins-x/lighthouse/pkg/clients"
1112
configjob "github.com/jenkins-x/lighthouse/pkg/config/job"
1213
"github.com/jenkins-x/lighthouse/pkg/util"
1314
"github.com/pkg/errors"
@@ -179,7 +180,11 @@ func (r *LighthouseJobReconciler) Reconcile(ctx context.Context, req ctrl.Reques
179180
if r.dashboardURL != "" {
180181
job.Status.ReportURL = r.getPipelingetPipelineTargetURLeTargetURL(pipelineRun)
181182
}
182-
activity, err := ConvertPipelineRun(&pipelineRun)
183+
tektonclient, _, _, _, err := clients.GetAPIClients()
184+
if err != nil {
185+
return errors.Wrapf(err, "failed to get api clients")
186+
}
187+
activity, err := ConvertPipelineRun(tektonclient, &pipelineRun)
183188
if err != nil {
184189
return errors.Wrapf(err, "failed to convert PipelineRun")
185190
}

0 commit comments

Comments
 (0)