Skip to content

Commit 2849e1d

Browse files
Josh-Everettdirgim
authored andcommitted
feat(STONEINTG-1253): add workflow type annotation to snapshot
Add a new annotation "test.appstudio.openshift.io/integration-workflow" to snapshots created from build pipelines. The annotation value is set to "push" or "pull-request" based on the PipelineRun's event type. Signed-off-by: Josh Everett <[email protected]>
1 parent 6743403 commit 2849e1d

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

gitops/snapshot.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ const (
111111
// BuildPipelineLastBuiltTime contains the time of the last built pipelineRun
112112
BuildPipelineLastBuiltTime = "test.appstudio.openshift.io/lastbuilttime"
113113

114+
// IntegrationWorkflowAnnotation contains the workflow type that triggered the snapshot (push or pull-request)
115+
IntegrationWorkflowAnnotation = "test.appstudio.openshift.io/integration-workflow"
116+
114117
// BuildPipelineRunPrefix contains the build pipeline run related labels and annotations
115118
BuildPipelineRunPrefix = "build.appstudio"
116119

@@ -189,6 +192,12 @@ const (
189192
// PipelineAsCodeMergeRequestType is the type of merge request event which triggered the pipelinerun in build service
190193
PipelineAsCodeMergeRequestType = "merge request"
191194

195+
// IntegrationWorkflowPushValue is the value for push workflow snapshots
196+
IntegrationWorkflowPushValue = "push"
197+
198+
// IntegrationWorkflowPullRequestValue is the value for pull request workflow snapshots
199+
IntegrationWorkflowPullRequestValue = "pull-request"
200+
192201
// PipelineAsCodeGitHubProviderType is the git provider type for a GitHub event which triggered the pipelinerun in build service.
193202
PipelineAsCodeGitHubProviderType = "github"
194203

internal/controller/buildpipeline/buildpipeline_adapter.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,13 @@ func (a *Adapter) prepareSnapshotForPipelineRun(pipelineRun *tektonv1.PipelineRu
570570
snapshot.Annotations[gitops.BuildPipelineRunStartTime] = strconv.FormatInt(pipelineRun.Status.StartTime.Unix(), 10)
571571
}
572572

573+
// Set the integration workflow annotation based on the PipelineRun type
574+
if tekton.IsPLRCreatedByPACPushEvent(pipelineRun) {
575+
snapshot.Annotations[gitops.IntegrationWorkflowAnnotation] = gitops.IntegrationWorkflowPushValue
576+
} else {
577+
snapshot.Annotations[gitops.IntegrationWorkflowAnnotation] = gitops.IntegrationWorkflowPullRequestValue
578+
}
579+
573580
return snapshot, nil
574581
}
575582

internal/controller/buildpipeline/buildpipeline_adapter_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,34 @@ var _ = Describe("Pipeline Adapter", Ordered, func() {
717717
Expect(found).To(BeFalse())
718718
})
719719

720+
It("ensures integration workflow annotation is set to 'pull-request' for pr events", func() {
721+
// default buildPipelineRun already has event-type set to pull_request
722+
snapshot, err := adapter.prepareSnapshotForPipelineRun(buildPipelineRun, hasComp, hasApp)
723+
Expect(err).ToNot(HaveOccurred())
724+
Expect(snapshot).ToNot(BeNil())
725+
726+
annotation, found := snapshot.GetAnnotations()[gitops.IntegrationWorkflowAnnotation]
727+
Expect(found).To(BeTrue())
728+
Expect(annotation).To(Equal(gitops.IntegrationWorkflowPullRequestValue))
729+
Expect(annotation).To(Equal("pull-request"))
730+
})
731+
732+
It("ensures integration workflow annotation is set to 'push' for push events", func() {
733+
// copy buildPipelineRun and modify it to be a push event
734+
pushPipelineRun := buildPipelineRun.DeepCopy()
735+
pushPipelineRun.Labels["pipelinesascode.tekton.dev/event-type"] = "push"
736+
delete(pushPipelineRun.Labels, "pipelinesascode.tekton.dev/pull-request")
737+
738+
snapshot, err := adapter.prepareSnapshotForPipelineRun(pushPipelineRun, hasComp, hasApp)
739+
Expect(err).ToNot(HaveOccurred())
740+
Expect(snapshot).ToNot(BeNil())
741+
742+
annotation, found := snapshot.GetAnnotations()[gitops.IntegrationWorkflowAnnotation]
743+
Expect(found).To(BeTrue())
744+
Expect(annotation).To(Equal(gitops.IntegrationWorkflowPushValue))
745+
Expect(annotation).To(Equal("push"))
746+
})
747+
720748
It("ensure snapshot will not be created in instance when chains is incomplete", func() {
721749
var buf bytes.Buffer
722750
log := helpers.IntegrationLogger{Logger: buflogr.NewWithBuffer(&buf)}

0 commit comments

Comments
 (0)