Skip to content

Commit f4ee846

Browse files
author
Shivam Mukhade
committed
Fixes involved object in Event emitted
when we emit event, we add repository as involved object but were adding only name and namespace, which was causing failure in filtering out events so we add rest of the metadata now. Signed-off-by: Shivam Mukhade <[email protected]>
1 parent 4aca11b commit f4ee846

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

pkg/apis/pipelinesascode/register.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ package pipelinesascode
1818

1919
// GroupName is the group name used in this package
2020
const (
21-
GroupName = "pipelinesascode.tekton.dev"
21+
GroupName = "pipelinesascode.tekton.dev"
22+
RepositoryKind = "Repository"
23+
V1alpha1Version = "v1alpha1"
2224
)

pkg/events/emit.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ func makeEvent(repo *v1alpha1.Repository, loggerLevel zapcore.Level, reason, mes
6363
Reason: reason,
6464
Type: v1.EventTypeWarning,
6565
InvolvedObject: v1.ObjectReference{
66-
Kind: "Repository",
67-
Name: repo.Name,
68-
Namespace: repo.Namespace,
66+
APIVersion: pipelinesascode.V1alpha1Version,
67+
Kind: pipelinesascode.RepositoryKind,
68+
Namespace: repo.Namespace,
69+
Name: repo.Name,
70+
UID: repo.UID,
71+
ResourceVersion: repo.ResourceVersion,
72+
},
73+
Source: v1.EventSource{
74+
Component: "Pipelines As Code",
6975
},
7076
}
7177
if loggerLevel == zap.InfoLevel {

pkg/events/emit_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"testing"
66

7+
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode"
78
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
89
testclient "github.com/openshift-pipelines/pipelines-as-code/pkg/test/clients"
910
"go.uber.org/zap"
@@ -45,6 +46,7 @@ func TestEventEmitter_EmitMessage(t *testing.T) {
4546
ObjectMeta: metav1.ObjectMeta{
4647
Name: "test-repo",
4748
Namespace: "test-ns",
49+
UID: "uid",
4850
},
4951
Spec: v1alpha1.RepositorySpec{},
5052
},
@@ -76,6 +78,12 @@ func TestEventEmitter_EmitMessage(t *testing.T) {
7678
assert.Equal(t, events.Items[0].Message, tt.message)
7779
assert.Equal(t, events.Items[0].Type, v1.EventTypeNormal)
7880
assert.Equal(t, events.Items[0].Reason, tt.reason)
81+
assert.Equal(t, events.Items[0].InvolvedObject.Name, tt.repo.Name)
82+
assert.Equal(t, events.Items[0].InvolvedObject.Namespace, tt.repo.Namespace)
83+
assert.Equal(t, events.Items[0].InvolvedObject.UID, tt.repo.UID)
84+
assert.Equal(t, events.Items[0].InvolvedObject.Kind, pipelinesascode.RepositoryKind)
85+
assert.Equal(t, events.Items[0].InvolvedObject.APIVersion, pipelinesascode.V1alpha1Version)
86+
assert.Assert(t, events.Items[0].Source.Component != "")
7987
}
8088
})
8189
}

0 commit comments

Comments
 (0)