@@ -13,6 +13,7 @@ import (
13
13
"github.com/openshift-pipelines/pipelines-as-code/pkg/formatting"
14
14
"github.com/openshift-pipelines/pipelines-as-code/pkg/kubeinteraction"
15
15
"github.com/openshift-pipelines/pipelines-as-code/pkg/matcher"
16
+ "github.com/openshift-pipelines/pipelines-as-code/pkg/opscomments"
16
17
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
17
18
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/clients"
18
19
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
@@ -23,6 +24,7 @@ import (
23
24
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
24
25
"go.uber.org/zap"
25
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
+ "knative.dev/pkg/apis"
26
28
)
27
29
28
30
const (
@@ -187,6 +189,32 @@ func (p *PacRun) startPR(ctx context.Context, match matcher.Match) (*tektonv1.Pi
187
189
match .PipelineRun .Annotations [keys .State ] = kubeinteraction .StateQueued
188
190
}
189
191
192
+ // check for existing pipelineruns with the same SHA for ok-to-test or retest events
193
+ if (p .event .EventType == opscomments .RetestAllCommentEventType .String () ||
194
+ p .event .EventType == opscomments .OkToTestCommentEventType .String ()) &&
195
+ p .event .SHA != "" {
196
+ labelSelector := fmt .Sprintf ("%s=%s" , keys .SHA , formatting .CleanValueKubernetes (p .event .SHA ))
197
+ existingPRs , err := p .run .Clients .Tekton .TektonV1 ().PipelineRuns (match .Repo .GetNamespace ()).List (ctx , metav1.ListOptions {
198
+ LabelSelector : labelSelector ,
199
+ })
200
+ if err == nil && len (existingPRs .Items ) > 0 {
201
+ var lastRun tektonv1.PipelineRun
202
+ lastRun = existingPRs .Items [0 ]
203
+
204
+ for _ , pr := range existingPRs .Items {
205
+ if pr .CreationTimestamp .After (lastRun .CreationTimestamp .Time ) {
206
+ lastRun = pr
207
+ }
208
+ }
209
+
210
+ if lastRun .Status .GetCondition (apis .ConditionSucceeded ).IsTrue () {
211
+ p .logger .Infof ("skipping creation of new pipelinerun for sha %s as the last pipelinerun '%s' has already succeeded" ,
212
+ p .event .SHA , lastRun .Name )
213
+ return & lastRun , nil
214
+ }
215
+ }
216
+ }
217
+
190
218
// Create the actual pipelineRun
191
219
pr , err := p .run .Clients .Tekton .TektonV1 ().PipelineRuns (match .Repo .GetNamespace ()).Create (ctx ,
192
220
match .PipelineRun , metav1.CreateOptions {})
0 commit comments