From ecef33d9aab474a7d65ca665c3fde2fc0cb10e4d Mon Sep 17 00:00:00 2001
From: Michal Kovarik <mkovarik@redhat.com>
Date: Jun 01 2020 07:58:21 +0000
Subject: Fix: Catch only requested messages


JMS Messaging plugin is using regexp for catching messages, which caused
that also forked project triggered these jobs.

---

diff --git a/roles/c3i/templates/build-workflow/build-pagure.Jenkinsfile b/roles/c3i/templates/build-workflow/build-pagure.Jenkinsfile
index ba0d554..98212a8 100644
--- a/roles/c3i/templates/build-workflow/build-pagure.Jenkinsfile
+++ b/roles/c3i/templates/build-workflow/build-pagure.Jenkinsfile
@@ -38,11 +38,11 @@ pipeline {
           overrides: [topic: "{{ topic }}"],
           checks: [
             {% if "premerge" == job_vars.workflow %}
-            [field: '$.pullrequest.project.url_path', expectedValue: params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')],
-            [field: '$.pullrequest.branch', expectedValue: params.GIT_MAIN_BRANCH],
+            [field: '$.pullrequest.project.url_path', expectedValue: "^${params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')}\$"],
+            [field: '$.pullrequest.branch', expectedValue: "^${params.GIT_MAIN_BRANCH}\$"],
             {% elif "job-updater" == job_vars.workflow %}
             [field: '$.repo.url_path', expectedValue: "^${params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')}\$"],
-            [field: '$.branch', expectedValue: params.GIT_MAIN_BRANCH],
+            [field: '$.branch', expectedValue: "^${params.GIT_MAIN_BRANCH}\$"],
             {% endif %}
           ]
         ),
diff --git a/verification/c3i-role-verification.Jenkinsfile b/verification/c3i-role-verification.Jenkinsfile
index 94af931..867cfc4 100644
--- a/verification/c3i-role-verification.Jenkinsfile
+++ b/verification/c3i-role-verification.Jenkinsfile
@@ -27,32 +27,32 @@ pipeline {
           name: params.MESSAGING_FEDMSG_PROVIDER,
           overrides: [topic: "io.pagure.prod.pagure.pull-request.new"],
           checks: [
-            [field: '$.pullrequest.project.url_path', expectedValue: params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')],
-            [field: '$.pullrequest.branch', expectedValue: params.GIT_MAIN_BRANCH],
+            [field: '$.pullrequest.project.url_path', expectedValue: "^${params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')}\$"],
+            [field: '$.pullrequest.branch', expectedValue: "^${params.GIT_MAIN_BRANCH}\$"],
           ]
         ),
         fedmsgSubscriber(
           name: params.MESSAGING_FEDMSG_PROVIDER,
           overrides: [topic: "io.pagure.prod.pagure.pull-request.update"],
           checks: [
-            [field: '$.pullrequest.project.url_path', expectedValue: params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')],
-            [field: '$.pullrequest.branch', expectedValue: params.GIT_MAIN_BRANCH],
+            [field: '$.pullrequest.project.url_path', expectedValue: "^${params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')}\$"],
+            [field: '$.pullrequest.branch', expectedValue: "^${params.GIT_MAIN_BRANCH}\$"],
           ]
         ),
         fedmsgSubscriber(
           name: params.MESSAGING_FEDMSG_PROVIDER,
           overrides: [topic: "io.pagure.prod.pagure.pull-request.reopened"],
           checks: [
-            [field: '$.pullrequest.project.url_path', expectedValue: params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')],
-            [field: '$.pullrequest.branch', expectedValue: params.GIT_MAIN_BRANCH],
+            [field: '$.pullrequest.project.url_path', expectedValue: "^${params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')}\$"],
+            [field: '$.pullrequest.branch', expectedValue: "^${params.GIT_MAIN_BRANCH}\$"],
           ]
         ),
         fedmsgSubscriber(
           name: params.MESSAGING_FEDMSG_PROVIDER,
           overrides: [topic: "io.pagure.prod.pagure.pull-request.rebased"],
           checks: [
-            [field: '$.pullrequest.project.url_path', expectedValue: params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')],
-            [field: '$.pullrequest.branch', expectedValue: params.GIT_MAIN_BRANCH],
+            [field: '$.pullrequest.project.url_path', expectedValue: "^${params.GIT_REPO.split('/')[3..-1].join('/').replace('forks/', 'fork/').replaceAll(/.git$/, '')}\$"],
+            [field: '$.pullrequest.branch', expectedValue: "^${params.GIT_MAIN_BRANCH}\$"],
           ]
         ),
       ]

