@@ -168,9 +168,11 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException
168168 }
169169
170170 String jSecret = null ;
171- String branchFilter = null ;
172171 boolean foundJob = false ;
173172
173+ // filter branch, if ref not match branch filter, skip trigger job.
174+ boolean isRefMatched = true ;
175+
174176 String ref = (String ) jsonObject .getString ("ref" );
175177 payloadProcessor .setPayload ("ref" , ref );
176178 payloadProcessor .setPayload ("before" , jsonObject .getString ("before" ));
@@ -186,7 +188,7 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException
186188 final GogsProjectProperty property = (GogsProjectProperty ) job .getProperty (GogsProjectProperty .class );
187189 if (property != null ) { /* only if Gogs secret is defined on the job */
188190 jSecret = property .getGogsSecret (); /* Secret provided by Jenkins */
189- branchFilter = property .getGogsBranchFilter (); /* branch filter provided by jenkins */
191+ isRefMatched = property .filterBranch ( ref );
190192 }
191193 } else {
192194 String [] components = ref .split ("/" );
@@ -206,7 +208,7 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException
206208 final GogsProjectProperty property = (GogsProjectProperty ) job .getProperty (GogsProjectProperty .class );
207209 if (property != null ) { /* only if Gogs secret is defined on the job */
208210 jSecret = property .getGogsSecret (); /* Secret provided by Jenkins */
209- branchFilter = property .getGogsBranchFilter (); /* branch filter provided by jenkins */
211+ isRefMatched = property .filterBranch ( ref );
210212 }
211213 }
212214 }
@@ -228,18 +230,12 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException
228230 }
229231 }
230232
231- // filter branch, not ref not match branch filter, skip trigger.
232- boolean isRefMatched = true ;
233- if (branchFilter != null && !branchFilter .equals ("*" ) && branchFilter .length () > 0 ) {
234- isRefMatched = ref == null || ref .length () == 0 || ref .endsWith (branchFilter );
235- }
236-
237233 if (!foundJob ) {
238234 String msg = String .format ("Job '%s' is not defined in Jenkins" , jobName );
239235 result .setStatus (404 , msg );
240236 LOGGER .warning (msg );
241237 } else if (!isRefMatched ) {
242- String msg = String .format ("received ref ('%s') is not matched with branch filter in job '%s' ('%s') " , ref , jobName , branchFilter );
238+ String msg = String .format ("received ref ('%s') is not matched with branch filter in job '%s'" , ref , jobName );
243239 result .setStatus (200 , msg );
244240 LOGGER .info (msg );
245241 } else if (isNullOrEmpty (jSecret ) && isNullOrEmpty (gSecret )) {
0 commit comments