Repository: openshift-pipelines/pipelines-as-code (go)

Issue:
Pipelines gets created twice on a pull request push when it's not coming from a fork
If a user has a repo and push a branch to a repo for a PR we gets two different PipelineRun created.

Since we intercept the push (for pushing to main nightly branch etc) a pipelinerun gets created before the filtering is done to see if it match to repository.

Since we update (or syncronize) the pull_request another PR gets created.

The problem is that another pipelinerun gets created and update the status even tho it cannot find a match for it (or hopefully it shouldnt)


Pull request:
Skip creating status if there is no match on push
The problem when we have a push and pull_request the two would create
status and since the push is meant for pull_request it shoudl not update
the status.

Tested as working on https://github.com/chmouel/scratchmyback/pull/1/checks

Closes #103

Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>

Patch:
diff --git a/pkg/pipelineascode/pipelineascode.go b/pkg/pipelineascode/pipelineascode.go
index 1a0fe85b..84754ac6 100644
--- a/pkg/pipelineascode/pipelineascode.go
+++ b/pkg/pipelineascode/pipelineascode.go
@@ -67,9 +67,14 @@ func Run(ctx context.Context, cs *cli.Clients, k8int cli.KubeInteractionIntf, ru
 	}
 	if repo.Spec.Namespace == "" {
 		msg := fmt.Sprintf("Could not find a namespace match for %s/%s on target-branch:%s event-type: %s", runinfo.Owner, runinfo.Repository, runinfo.BaseBranch, runinfo.EventType)
-		err = createStatus(ctx, cs, runinfo, "completed", "skipped", msg, "https://tenor.com/search/sad-cat-gifs", true)
-		if err != nil {
-			return err
+
+		if runinfo.EventType == "pull_request" {
+			err = createStatus(ctx, cs, runinfo, "completed", "skipped", msg, "https://tenor.com/search/sad-cat-gifs", true)
+			if err != nil {
+				return err
+			}
+		} else {
+			cs.Log.Infof("Skipping creating status check: %s", msg)
 		}
 		return nil
 	}


Test patch:
diff --git a/pkg/pipelineascode/pipelineascode_test.go b/pkg/pipelineascode/pipelineascode_test.go
index e35c4dc0..b741858a 100644
--- a/pkg/pipelineascode/pipelineascode_test.go
+++ b/pkg/pipelineascode/pipelineascode_test.go
@@ -223,7 +223,7 @@ func TestRun(t *testing.T) {
 		tektondir                    string
 		wantErr                      string
 		finalStatus                  string
-		finalStatusText              string
+		finalLogText                 string
 		repositories                 []*v1alpha1.Repository
 		skipReplyingOrgPublicMembers bool
 	}{
@@ -239,9 +239,9 @@ func TestRun(t *testing.T) {
 				Sender:     "fantasio",
 				EventType:  "pull_request",
 			},
-			tektondir:       "testdata/pull_request",
-			finalStatus:     "neutral",
-			finalStatusText: "More detailed status",
+			tektondir:    "testdata/pull_request",
+			finalStatus:  "neutral",
+			finalLogText: "More detailed status",
 		},
 		{
 			name: "No match",
@@ -303,10 +303,31 @@ func TestRun(t *testing.T) {
 				BaseBranch: "nomatch",
 				EventType:  "pull_request",
 			},
-			tektondir:       "",
-			finalStatus:     "skipped",
-			finalStatusText: "directory for this repository",
+			tektondir:    "",
+			finalStatus:  "skipped",
+			finalLogText: "directory for this repository",
 		},
+		{
+			name: "Skipped/Test no repositories match on different event_type",
+			runinfo: &webvcs.RunInfo{
+				SHA:        "principale",
+				Owner:      "organizationes",
+				Repository: "lagaffe",
+				URL:        "https://service/documentation",
+				HeadBranch: "press",
+				Sender:     "fantasio",
+				BaseBranch: "nomatch",
+				EventType:  "push",
+			},
+			tektondir:    "",
+			finalStatus:  "skipped",
+			finalLogText: "Skipping creating status check",
+			repositories: []*v1alpha1.Repository{
+				newRepo("test-run", "https://service/documentation",
+					"a branch", "namespace", "namespace", "pull_request"),
+			},
+		},
+
 		{
 			name: "Skipped/Test no repositories match",
 			runinfo: &webvcs.RunInfo{
@@ -319,14 +340,15 @@ func TestRun(t *testing.T) {
 				BaseBranch: "nomatch",
 				EventType:  "pull_request",
 			},
-			tektondir:       "",
-			finalStatus:     "skipped",
-			finalStatusText: "not find a namespace match",
+			tektondir:    "",
+			finalStatus:  "skipped",
+			finalLogText: "not find a namespace match",
 			repositories: []*v1alpha1.Repository{
 				newRepo("test-run", "https://nowhere.com",
 					"a branch", "namespace", "namespace", "pull_request"),
 			},
 		},
+
 		{
 			name: "Skipped/User is not allowed",
 			runinfo: &webvcs.RunInfo{
@@ -341,7 +363,7 @@ func TestRun(t *testing.T) {
 			},
 			tektondir:                    "testdata/pull_request",
 			finalStatus:                  "skipped",
-			finalStatusText:              "is not allowed to run CI on this repo",
+			finalLogText:                 "is not allowed to run CI on this repo",
 			skipReplyingOrgPublicMembers: true,
 		},
 	}
@@ -367,7 +389,7 @@ func TestRun(t *testing.T) {
 			fakeclient, mux, _, teardown := ghtesthelper.SetupGH()
 			defer teardown()
 
-			testSetupCommonGhReplies(t, mux, tt.runinfo, tt.finalStatus, tt.finalStatusText, tt.skipReplyingOrgPublicMembers)
+			testSetupCommonGhReplies(t, mux, tt.runinfo, tt.finalStatus, tt.finalLogText, tt.skipReplyingOrgPublicMembers)
 			if tt.tektondir != "" {
 				testSetupTektonDir(mux, tt.runinfo, tt.tektondir)
 			}