Skip to content

Commit

Permalink
Example of ignoring removal or creation of branches
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 16, 2018
1 parent a4713a8 commit 108723a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/test/java/org/jenkinsci/plugins/gwt/bdd/Stepdefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.google.common.base.Strings.isNullOrEmpty;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.jenkinsci.plugins.gwt.Renderer.renderText;

import com.google.gson.GsonBuilder;
Expand All @@ -12,6 +13,8 @@
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import org.assertj.core.api.Assertions;
import org.jenkinsci.plugins.gwt.ExpressionType;
import org.jenkinsci.plugins.gwt.GenericVariable;
import org.jenkinsci.plugins.gwt.Renderer;
Expand Down Expand Up @@ -77,25 +80,23 @@ public void variablesAreResolved(final List<GenericVariablesResolvedPojo> given)

@Then("^the job is triggered$")
public void jobShouldBeTriggered() {
assertThat(isMatching()) //
.isTrue();
isMatching(true);
}

@Then("^the job is not triggered$")
public void jobShouldNotBeTriggered() {
assertThat(isMatching()) //
.isFalse();
isMatching(false);
}

private boolean isMatching() {
private boolean isMatching(boolean expected) {
final Map<String, String> resolvedVariables = getResolvedVariables();

final String renderedRegexpFilterText =
renderText(featureState.getRegexpFilterText(), resolvedVariables);
final boolean isMatching =
Renderer.isMatching(renderedRegexpFilterText, featureState.getRegexpFilterExpression());
if (!isMatching) {
LOG.info(
if (!isMatching && expected || isMatching && !expected) {
fail(
"Text: \""
+ renderedRegexpFilterText
+ "\" does not match \""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Feature: It should be possible to trigger for GitLab push events and ignore branch creation.

Scenario: Push events happens.

Given the following generic variables are configured:
| variable | expression | expressionType | defaultValue | regexpFilter |
| object_kind | $.object_kind | JSONPath | | |
| before | $.before | JSONPath | | |
| after | $.after | JSONPath | | |
| ref | $.ref | JSONPath | | |
| git_ssh_url | $.repository.git_ssh_url | JSONPath | | |

Given filter is configured with text: $object_kind $before $after
Given filter is configured with expression: ^push\s(?!0{40}).{40}\s(?!0{40}).{40}$


When received post content is:
"""
{
"object_kind": "push",
"before": "0000000000000000000000000000000000000000",
"after": "f34c80f418afb802094f1ba42ad0ec1a20c7a02s",
"ref": "refs/heads/master",
"repository":{
"git_ssh_url":"git@example.com:mike/diaspora.git",
}
}
"""
Then the job is not triggered
Then variables are resolved to:
| variable | value |
| object_kind | push |
| before | 0000000000000000000000000000000000000000 |
| after | f34c80f418afb802094f1ba42ad0ec1a20c7a02s |
| ref | refs/heads/master |
| git_ssh_url | git@example.com:mike/diaspora.git |


When received post content is:
"""
{
"object_kind": "push",
"before": "f34c80f418afb802094f1ba42ad0ec1a20c7a02s",
"after": "0000000000000000000000000000000000000000",
"ref": "refs/heads/master",
"repository":{
"git_ssh_url":"git@example.com:mike/diaspora.git",
}
}
"""
Then the job is not triggered
Then variables are resolved to:
| variable | value |
| object_kind | push |
| before | f34c80f418afb802094f1ba42ad0ec1a20c7a02s |
| after | 0000000000000000000000000000000000000000 |
| ref | refs/heads/master |
| git_ssh_url | git@example.com:mike/diaspora.git |


When received post content is:
"""
{
"object_kind": "push",
"before": "0023123123123123123123123123123123101010",
"after": "f34c80f418afb802094f1ba42ad0ec1a20c7a02s",
"ref": "refs/heads/master",
"repository":{
"git_ssh_url":"git@example.com:mike/diaspora.git",
}
}
"""
Then the job is triggered
Then variables are resolved to:
| variable | value |
| object_kind | push |
| before | 0023123123123123123123123123123123101010 |
| after | f34c80f418afb802094f1ba42ad0ec1a20c7a02s |
| ref | refs/heads/master |
| git_ssh_url | git@example.com:mike/diaspora.git |

0 comments on commit 108723a

Please sign in to comment.